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

43 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;
2021-12-27 22:53:13 +02:00
using Kruzya.TelegramBot.Core.Data;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace West.TelegramBot.ChatManagement.Handler
{
public class Ban : ManagementHandler
{
2021-12-27 22:53:13 +02:00
public Ban(CoreContext db) : base(db) {}
[Command("ban", CommandParseMode.Both)]
public async Task HandleBan()
{
if (!await CanPunish()) return;
2021-12-27 22:53:13 +02:00
await BanMember(RepliedUser!);
}
[Command("unban", CommandParseMode.Both)]
public async Task HandleUnban()
{
if (!await CanPunish()) return;
2021-12-27 22:53:13 +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
});
}
}
}