mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Whois command. Some refactorings.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework;
|
||||
using JetBrains.Annotations;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
@@ -9,21 +13,34 @@ using West.TelegramBot.ChatManagement.Extensions;
|
||||
|
||||
namespace West.TelegramBot.ChatManagement.Handler
|
||||
{
|
||||
public class ManagementHandler : BotEventHandler
|
||||
public abstract class ManagementHandler : BotEventHandler
|
||||
{
|
||||
protected User GetVictim()
|
||||
{
|
||||
return RawUpdate.Message?.ReplyToMessage?.From;
|
||||
}
|
||||
protected readonly CoreContext Db;
|
||||
|
||||
protected Message? Message => RawUpdate.Message;
|
||||
|
||||
protected User? RepliedUser => Message?.ReplyToMessage?.From;
|
||||
|
||||
protected async Task<bool> CanPunish()
|
||||
protected ManagementHandler(CoreContext db)
|
||||
{
|
||||
return GetVictim() != null && await Bot.CanPunishMember(Chat, From, GetVictim());
|
||||
Db = db;
|
||||
}
|
||||
|
||||
protected async Task<Message> Reply(string text)
|
||||
{
|
||||
return await Bot.SendTextMessageAsync(Chat.Id, text,
|
||||
replyToMessageId: Message?.MessageId, parseMode: ParseMode.Html);
|
||||
}
|
||||
|
||||
protected async Task<bool> CanPunish()
|
||||
{
|
||||
return RepliedUser != null && await Bot.CanPunishMember(Chat, From, RepliedUser);
|
||||
}
|
||||
|
||||
#region Bans
|
||||
protected async Task BanMember(User user, DateTime? banEnd = null, bool sendMessage = true)
|
||||
{
|
||||
await BanMember(user.Id, banEnd, sendMessage);
|
||||
await BanMember(user.Id, banEnd);
|
||||
|
||||
if (sendMessage)
|
||||
{
|
||||
@@ -34,7 +51,7 @@ namespace West.TelegramBot.ChatManagement.Handler
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task BanMember(long userId, DateTime? banEnd = null, bool sendMessage = true)
|
||||
protected async Task BanMember(long userId, DateTime? banEnd = null)
|
||||
{
|
||||
await Bot.RestrictChatMemberAsync(
|
||||
Chat.Id,
|
||||
@@ -46,5 +63,11 @@ namespace West.TelegramBot.ChatManagement.Handler
|
||||
banEnd ?? DateTime.Now.AddDays(7)
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected async Task<BotUserValue> GetWarnOption(User user)
|
||||
{
|
||||
return await Db.UserValues.FindOrCreateOption(Chat.Id, user.Id, "warnCount");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user