mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Use file-scoped namespaces
This commit is contained in:
@@ -11,49 +11,48 @@ using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace Kruzya.TelegramBot.UrlLimitations
|
||||
{
|
||||
public class MessageHandler : BotEventHandler
|
||||
{
|
||||
protected ILogger Logger;
|
||||
protected readonly CoreContext dbCtx;
|
||||
namespace Kruzya.TelegramBot.UrlLimitations;
|
||||
|
||||
public MessageHandler(ILogger<MessageHandler> logger, CoreContext coreContext)
|
||||
public class MessageHandler : BotEventHandler
|
||||
{
|
||||
protected ILogger Logger;
|
||||
protected readonly CoreContext dbCtx;
|
||||
|
||||
public MessageHandler(ILogger<MessageHandler> logger, CoreContext coreContext)
|
||||
{
|
||||
Logger = logger;
|
||||
dbCtx = coreContext;
|
||||
}
|
||||
|
||||
[InChat(InChat.Public)]
|
||||
[Message(MessageFlag.HasText)]
|
||||
public async Task OnMessageReceived()
|
||||
{
|
||||
var option = await dbCtx.UserValues.FindOption(Chat.Id, From.Id, "urlLimitations.messagesAfterJoin");
|
||||
if (option == null)
|
||||
{
|
||||
Logger = logger;
|
||||
dbCtx = coreContext;
|
||||
return;
|
||||
}
|
||||
|
||||
[InChat(InChat.Public)]
|
||||
[Message(MessageFlag.HasText)]
|
||||
public async Task OnMessageReceived()
|
||||
var messageCount = option.GetValue<UInt16>();
|
||||
if (messageCount > 10)
|
||||
{
|
||||
var option = await dbCtx.UserValues.FindOption(Chat.Id, From.Id, "urlLimitations.messagesAfterJoin");
|
||||
if (option == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
dbCtx.UserValues.Remove(option);
|
||||
return;
|
||||
}
|
||||
|
||||
var messageCount = option.GetValue<UInt16>();
|
||||
if (messageCount > 10)
|
||||
{
|
||||
dbCtx.UserValues.Remove(option);
|
||||
return;
|
||||
}
|
||||
|
||||
option.SetValue(messageCount + 1);
|
||||
var message = RawUpdate.Message;
|
||||
if (message.Entities.Count(e => e.Type == MessageEntityType.Url || e.Type == MessageEntityType.TextLink) >
|
||||
0 || await message.HasUnknownMention(Bot))
|
||||
{
|
||||
var targetChat = new ChatId(Chat.Id);
|
||||
Task.WaitAll(
|
||||
Bot.BanChatMemberAsync(new ChatId(Chat.Id), From.Id, DateTime.Now.AddDays(1)),
|
||||
Bot.DeleteMessageAsync(targetChat, message.MessageId),
|
||||
Bot.SendTextMessageAsync(targetChat,
|
||||
option.SetValue(messageCount + 1);
|
||||
var message = RawUpdate.Message;
|
||||
if (message.Entities.Count(e => e.Type == MessageEntityType.Url || e.Type == MessageEntityType.TextLink) >
|
||||
0 || await message.HasUnknownMention(Bot))
|
||||
{
|
||||
var targetChat = new ChatId(Chat.Id);
|
||||
Task.WaitAll(
|
||||
Bot.BanChatMemberAsync(new ChatId(Chat.Id), From.Id, DateTime.Now.AddDays(1)),
|
||||
Bot.DeleteMessageAsync(targetChat, message.MessageId),
|
||||
Bot.SendTextMessageAsync(targetChat,
|
||||
$"Member {From.ToHtml(true)} has been banned.\n<b>Reason</b>: <pre>Spam suspicion</pre>", parseMode: ParseMode.Html)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user