mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Assorted improvements.
- Move BotExtension to Core. - Update BotFramework - Fix Fun commands. - Remove ChatManagement dependency from Entertainment.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
public static class BotExtension
|
||||
{
|
||||
public static async Task<bool> CanPunishMember(this ITelegramBotClient bot, Chat chat, User user, User victim = null)
|
||||
{
|
||||
var callerMember = await bot.GetChatMemberAsync(chat, user.Id);
|
||||
var canUse = callerMember is ChatMemberOwner;
|
||||
|
||||
if (callerMember is ChatMemberAdministrator callerAdmin)
|
||||
{
|
||||
canUse = callerAdmin.CanRestrictMembers;
|
||||
}
|
||||
|
||||
if (victim != null && canUse)
|
||||
{
|
||||
var victimMember = await bot.GetChatMemberAsync(chat, victim.Id);
|
||||
canUse = victimMember is not ChatMemberOwner && victimMember is not ChatMemberAdministrator && !victim.IsBot;
|
||||
}
|
||||
|
||||
return canUse;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user