mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Add ChatManagement commands. Drop appsettings from version control.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user