mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[common] improve logging
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
|
public static class ChatExtension
|
||||||
|
{
|
||||||
|
public static string ToLog(this Chat chat)
|
||||||
|
{
|
||||||
|
var title = chat.Type switch
|
||||||
|
{
|
||||||
|
ChatType.Private => $"{chat.FirstName} {chat.LastName}".Trim(),
|
||||||
|
_ => chat.Title
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return $"{title} (ID: {chat.Id}, Username: {chat.Username ?? "N/A"})";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,10 @@ namespace West.Entertainment.Handler
|
|||||||
{
|
{
|
||||||
if (!_userService.IsUserSuper(From))
|
if (!_userService.IsUserSuper(From))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("{User} attempted to call /cooldowns in \"{Chat}\"", From, Chat.Title);
|
_logger.LogWarning("{User} attempted to use super-user command /cooldowns in {Chat}",
|
||||||
|
From.ToLog(),
|
||||||
|
Chat.ToLog()
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ public class Roll : CommonHandler
|
|||||||
{
|
{
|
||||||
if (!_userService.IsUserSuper(From))
|
if (!_userService.IsUserSuper(From))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("{user} attempted to use super-user command", From.ToLog());
|
_logger.LogWarning("{User} attempted to use super-user command /reset_roll in {Chat}",
|
||||||
|
From.ToLog(),
|
||||||
|
Chat.ToLog()
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,10 @@ public class Reputation : CommonHandler
|
|||||||
{
|
{
|
||||||
if (!_userService.IsUserSuper(From))
|
if (!_userService.IsUserSuper(From))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("{User} attempted to modify someones reputation in {Chat}", From, Chat.Title);
|
_logger.LogWarning("{User} attempted to modify reputation in {Chat}",
|
||||||
|
From.ToLog(),
|
||||||
|
Chat.ToLog()
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user