mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[cm] ability to ban user for an arbitrary period
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
@@ -8,6 +9,8 @@ using Kruzya.TelegramBot.Core.Data;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using West.TelegramBot.ChatManagement.ParamParser;
|
||||
|
||||
namespace West.TelegramBot.ChatManagement.Handler;
|
||||
|
||||
@@ -15,18 +18,33 @@ public class Ban : CommonHandler
|
||||
{
|
||||
public Ban(CoreContext db) : base(db) {}
|
||||
|
||||
[Command("ban", CommandParseMode.Both)]
|
||||
public async Task HandleBan()
|
||||
[ParametrizedCommand("ban", CommandParseMode.Both)]
|
||||
public async Task HandleBan(BanLength.Param banLengthParam)
|
||||
{
|
||||
if (!await CanPunish()) return;
|
||||
if (!await CanPunish())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var now = DateTime.Now;
|
||||
var banEnd = now.AddDays(banLengthParam.DayCount);
|
||||
|
||||
await BanMember(RepliedUser!);
|
||||
var banEndMsg = (banEnd - now).Days > 366 ? "навсегда" : $"до {banEnd.ToUniversalTime()}";
|
||||
|
||||
await Bot.SendTextMessageAsync(
|
||||
Chat.Id,
|
||||
$"{From.ToHtml()} <code>заблокировал</code> {RepliedUser!.ToHtml()} <code>{banEndMsg}</code>",
|
||||
disableNotification: true, parseMode: ParseMode.Html);
|
||||
|
||||
await BanMember(RepliedUser!.Id, banEnd);
|
||||
}
|
||||
|
||||
[Command("unban", CommandParseMode.Both)]
|
||||
public async Task HandleUnban()
|
||||
{
|
||||
if (!await CanPunish()) return;
|
||||
if (!await CanPunish())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Bot.RestrictChatMemberAsync(Chat.Id, RepliedUser!.Id,
|
||||
new ChatPermissions
|
||||
|
||||
Reference in New Issue
Block a user