#nullable enable using System; using System.Threading.Tasks; using BotFramework; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; namespace Kruzya.TelegramBot.Core { public abstract class CommonHandler : BotEventHandler { protected readonly CoreContext Db; protected Message? Message => RawUpdate.Message; protected User? RepliedUser => Message?.ReplyToMessage?.From; protected CommonHandler(CoreContext db) { Db = db; } protected async Task Reply(string text) { return await Bot.SendTextMessageAsync(Chat.Id, text, replyToMessageId: Message?.MessageId, parseMode: ParseMode.Html); } protected async Task CanPunish() { return RepliedUser != null && await Bot.CanPunishMember(Chat, From, RepliedUser); } protected async Task BanMember(long userId, DateTime banEnd) { await Bot.RestrictChatMemberAsync( Chat.Id, userId, new ChatPermissions { CanSendMessages = false }, banEnd ); } protected async Task GetWarnOption(User user) { return await Db.UserValues.FindOrCreateOption(Chat.Id, user.Id, "warnCount"); } } }