mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[cm] ability to ban stickerset
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using BotFramework.Utils;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Telegram.Bot;
|
||||
using West.TelegramBot.ChatManagement.ParamParser;
|
||||
|
||||
namespace West.TelegramBot.ChatManagement.Handler;
|
||||
|
||||
public partial class BanStickerSet
|
||||
{
|
||||
[ParametrizedCommand(InChat.Public, "stick_ban", CommandParseMode.Both)]
|
||||
public async Task HandleBanSticker(StickerSet.Param stickerSet)
|
||||
{
|
||||
if (!await PreCommand(stickerSet))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var option = await GetBannedStickerSetOption();
|
||||
var stickerSetList = option.GetValue(new List<string>());
|
||||
|
||||
var setName = stickerSet.Set.Name;
|
||||
if (stickerSetList.Contains(setName))
|
||||
{
|
||||
await Reply("Этот набор стикеров уже заблокирован.");
|
||||
return;
|
||||
}
|
||||
|
||||
stickerSetList.Add(setName);
|
||||
option.SetValue(stickerSetList);
|
||||
Db.AddOrUpdate(option);
|
||||
|
||||
var replyToMsgId = Message?.ReplyToMessage?.MessageId;
|
||||
if (replyToMsgId != null)
|
||||
{
|
||||
await Bot.DeleteMessageAsync(Chat.Id, (int) replyToMsgId);
|
||||
}
|
||||
|
||||
await Reply(FormatStickerSetAction(stickerSet.Set, "заблокирован"));
|
||||
}
|
||||
|
||||
[ParametrizedCommand(InChat.Public, "stick_unban", CommandParseMode.Both)]
|
||||
public async Task HandleUnBanSticker(StickerSet.Param stickerSet)
|
||||
{
|
||||
if (!await PreCommand(stickerSet))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var option = await GetBannedStickerSetOption();
|
||||
var list = option.GetValue<List<string>>();
|
||||
if (list == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var setName = stickerSet.Set.Name;
|
||||
|
||||
list.Remove(setName);
|
||||
option.SetValue(list);
|
||||
Db.AddOrUpdate(option);
|
||||
|
||||
await Reply(FormatStickerSetAction(stickerSet.Set, "разблокирован"));
|
||||
}
|
||||
|
||||
[Command(InChat.Public, "stick_banlist", CommandParseMode.Both)]
|
||||
public async Task HandleSBanList()
|
||||
{
|
||||
var option = await GetBannedStickerSetOption();
|
||||
var list = option.GetValue<List<string>>();
|
||||
if (list == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string msg;
|
||||
if (list.Count > 0)
|
||||
{
|
||||
var htmlString = new HtmlString().Bold("Заблокированные наборы стикеров:").Br();
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var stickerSet = await Bot.GetStickerSetAsync(list[i]);
|
||||
htmlString.Text($"{i + 1}. ")
|
||||
.Url("https://t.me/addstickers/" + stickerSet.Name, stickerSet.Title)
|
||||
.Br();
|
||||
}
|
||||
|
||||
msg = htmlString.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "Нет заблокированных наборов стикеров.";
|
||||
}
|
||||
|
||||
await Reply(msg);
|
||||
}
|
||||
|
||||
[Message(InChat.Public, MessageFlag.HasSticker)]
|
||||
public async Task HandleMessage()
|
||||
{
|
||||
if (!await CanBotDeleteMessages())
|
||||
{
|
||||
await Reply(
|
||||
"Этот набор стикеров заблокирован. Чтобы я мог его удалить, выдайте мне право на удаление сообщений.");
|
||||
}
|
||||
|
||||
var message = Message!;
|
||||
if (await IsStickerBanned(message.Sticker!))
|
||||
{
|
||||
await Bot.DeleteMessageAsync(Chat.Id, message.MessageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user