Files
telegram-bot/modules/ChatManagement/Handler/Ban.cs
T

46 lines
1.2 KiB
C#
Raw Normal View History

2021-12-27 22:53:13 +02:00
#nullable enable
using System.Threading.Tasks;
using BotFramework.Attributes;
using BotFramework.Enums;
using Kruzya.TelegramBot.Core;
2021-12-27 22:53:13 +02:00
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Telegram.Bot;
using Telegram.Bot.Types;
2022-02-14 10:35:28 +02:00
namespace West.TelegramBot.ChatManagement.Handler;
public class Ban : CommonHandler
{
2022-02-14 10:35:28 +02:00
public Ban(CoreContext db) : base(db) {}
2021-12-27 22:53:13 +02:00
2022-02-14 10:35:28 +02:00
[Command("ban", CommandParseMode.Both)]
public async Task HandleBan()
{
if (!await CanPunish()) return;
2022-02-14 10:35:28 +02:00
await BanMember(RepliedUser!);
}
2022-02-14 10:35:28 +02:00
[Command("unban", CommandParseMode.Both)]
public async Task HandleUnban()
{
if (!await CanPunish()) return;
2022-02-14 10:35:28 +02:00
await Bot.RestrictChatMemberAsync(Chat.Id, RepliedUser!.Id,
new ChatPermissions
{
CanSendMessages = true,
CanChangeInfo = true,
CanInviteUsers = true,
CanPinMessages = true,
CanSendPolls = true,
CanSendMediaMessages = true,
CanSendOtherMessages = true,
CanAddWebPagePreviews = true
});
await Reply($"{From.ToHtml()} <code>разблокировал</code> {RepliedUser!.ToHtml()}");
}
}