mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
#nullable enable
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using BotFramework.Utils;
|
|
using Kruzya.TelegramBot.Core.Data;
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
using Telegram.Bot;
|
|
using Telegram.Bot.Types;
|
|
|
|
namespace West.TelegramBot.ChatManagement.Handler;
|
|
|
|
public partial class BanStickerSet
|
|
{
|
|
private async Task<bool> CanBotDeleteMessages()
|
|
{
|
|
return await Bot.GetChatMemberAsync(
|
|
Chat.Id,
|
|
(await Bot.GetMeAsync()).Id
|
|
) is ChatMemberAdministrator {CanDeleteMessages: true};
|
|
}
|
|
|
|
private async Task<bool> IsStickerBanned(Sticker sticker)
|
|
{
|
|
var bannedList = (await GetBannedStickerSetOption()).GetValue<List<string>>();
|
|
|
|
return bannedList != null && sticker.SetName != null && bannedList.Contains(sticker.SetName);
|
|
}
|
|
|
|
private async Task<BotUserValue> GetBannedStickerSetOption()
|
|
{
|
|
return await Db.UserValues.FindOrCreateOption(Chat.Id, "cmBannedStickers");
|
|
}
|
|
|
|
public async Task<bool> PreCommand(ParamParser.StickerSet.Param? stickerSetParam = null)
|
|
{
|
|
if (stickerSetParam is { IsValid: false })
|
|
{
|
|
await Reply("Неверный набор стикеров.");
|
|
return false;
|
|
}
|
|
|
|
return await CanUseCommands();
|
|
}
|
|
|
|
public string FormatStickerSetAction(StickerSet stickerSet, string action)
|
|
=> FormatStickerSetAction(stickerSet.Name, stickerSet.Title, action);
|
|
|
|
public string FormatStickerSetAction(string name, string action)
|
|
=> FormatStickerSetAction(name, name, action);
|
|
|
|
public string FormatStickerSetAction(string name, string title, string action)
|
|
=> new HtmlString()
|
|
.Text("Набор стикеров ")
|
|
.Url($"https://t.me/addstickers/{name}", title)
|
|
.Text($" {action}.")
|
|
.ToString();
|
|
|
|
private async Task<bool> CanUseCommands()
|
|
{
|
|
return await Bot.GetChatMemberAsync(Chat.Id, From.Id) is ChatMemberAdministrator {CanDeleteMessages: true}
|
|
or ChatMemberOwner;
|
|
}
|
|
} |