mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
#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.Handler;
|
|
|
|
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 virtual async Task<Message> Reply(string text)
|
|
{
|
|
return await Bot.SendMessage(Chat.Id, text,
|
|
replyParameters: Message?.MessageId, parseMode: ParseMode.Html);
|
|
}
|
|
|
|
protected async Task<bool> CanPunish()
|
|
{
|
|
return RepliedUser != null && await Bot.CanPunishMember(Chat, From, RepliedUser);
|
|
}
|
|
|
|
|
|
protected async Task BanMember(long userId, DateTime banEnd)
|
|
{
|
|
await Bot.RestrictChatMember(
|
|
Chat.Id,
|
|
userId,
|
|
new ChatPermissions(),
|
|
untilDate: banEnd
|
|
);
|
|
}
|
|
|
|
protected async Task<BotUserValue> GetWarnOption(User user)
|
|
{
|
|
return await Db.UserValues.FindOrCreateOption(Chat.Id, user.Id, "warnCount");
|
|
}
|
|
|
|
protected async Task AnswerQuery(string id, string? message = null)
|
|
{
|
|
await Bot.AnswerCallbackQuery(id, message);
|
|
}
|
|
} |