mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
|
|
using System;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using BotFramework;
|
||
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
||
|
|
using Telegram.Bot;
|
||
|
|
using Telegram.Bot.Types;
|
||
|
|
using Telegram.Bot.Types.Enums;
|
||
|
|
using West.TelegramBot.ChatManagement.Extensions;
|
||
|
|
|
||
|
|
namespace West.TelegramBot.ChatManagement.Handler
|
||
|
|
{
|
||
|
|
public class ManagementHandler : BotEventHandler
|
||
|
|
{
|
||
|
|
protected User GetVictim()
|
||
|
|
{
|
||
|
|
return RawUpdate.Message?.ReplyToMessage?.From;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected async Task<bool> CanPunish()
|
||
|
|
{
|
||
|
|
return GetVictim() != null && await Bot.CanPunishMember(Chat, From, GetVictim());
|
||
|
|
}
|
||
|
|
|
||
|
|
protected async Task BanMember(User user, DateTime? banEnd = null, bool sendMessage = true)
|
||
|
|
{
|
||
|
|
await BanMember(user.Id, banEnd, sendMessage);
|
||
|
|
|
||
|
|
if (sendMessage)
|
||
|
|
{
|
||
|
|
await Bot.SendTextMessageAsync(
|
||
|
|
Chat.Id,
|
||
|
|
$"{From.ToHtml(false)} <code>заблокировал</code> {user.ToHtml(false)} <code>на 7 дней</code>",
|
||
|
|
disableNotification: true, parseMode: ParseMode.Html);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected async Task BanMember(long userId, DateTime? banEnd = null, bool sendMessage = true)
|
||
|
|
{
|
||
|
|
await Bot.RestrictChatMemberAsync(
|
||
|
|
Chat.Id,
|
||
|
|
userId,
|
||
|
|
new ChatPermissions
|
||
|
|
{
|
||
|
|
CanSendMessages = false
|
||
|
|
},
|
||
|
|
banEnd ?? DateTime.Now.AddDays(7)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|