mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Use file-scoped namespaces
This commit is contained in:
@@ -2,45 +2,44 @@
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||
|
||||
public static class BotExtension
|
||||
{
|
||||
public static class BotExtension
|
||||
public static async Task<bool> CanPunishMember(this ITelegramBotClient bot, Chat chat, User user, User victim = null)
|
||||
{
|
||||
public static async Task<bool> CanPunishMember(this ITelegramBotClient bot, Chat chat, User user, User victim = null)
|
||||
var canUse = await IsUserAdminAsync(bot, chat, user);
|
||||
|
||||
if (victim != null && canUse)
|
||||
{
|
||||
var canUse = await IsUserAdminAsync(bot, chat, user);
|
||||
|
||||
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;
|
||||
var victimMember = await bot.GetChatMemberAsync(chat, victim.Id);
|
||||
canUse = victimMember is not ChatMemberOwner && victimMember is not ChatMemberAdministrator && !victim.IsBot;
|
||||
}
|
||||
|
||||
public static async Task<bool> IsUserAdminAsync(this ITelegramBotClient bot, Chat chat, User user)
|
||||
return canUse;
|
||||
}
|
||||
|
||||
public static async Task<bool> IsUserAdminAsync(this ITelegramBotClient bot, Chat chat, User user)
|
||||
{
|
||||
var callerMember = await bot.GetChatMemberAsync(chat, user.Id);
|
||||
var isAdmin = callerMember is ChatMemberOwner;
|
||||
|
||||
if (callerMember is ChatMemberAdministrator callerAdmin)
|
||||
{
|
||||
var callerMember = await bot.GetChatMemberAsync(chat, user.Id);
|
||||
var isAdmin = callerMember is ChatMemberOwner;
|
||||
|
||||
if (callerMember is ChatMemberAdministrator callerAdmin)
|
||||
{
|
||||
isAdmin = callerAdmin.CanRestrictMembers;
|
||||
}
|
||||
|
||||
return isAdmin;
|
||||
isAdmin = callerAdmin.CanRestrictMembers;
|
||||
}
|
||||
|
||||
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat)
|
||||
{
|
||||
return await CanDeleteMessagesAsync(bot, chat, await bot.GetMeAsync());
|
||||
}
|
||||
return isAdmin;
|
||||
}
|
||||
|
||||
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat, User user)
|
||||
{
|
||||
return await bot.GetChatMemberAsync(chat.Id, user.Id) is ChatMemberOwner
|
||||
or ChatMemberAdministrator {CanRestrictMembers: true};
|
||||
}
|
||||
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat)
|
||||
{
|
||||
return await CanDeleteMessagesAsync(bot, chat, await bot.GetMeAsync());
|
||||
}
|
||||
|
||||
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat, User user)
|
||||
{
|
||||
return await bot.GetChatMemberAsync(chat.Id, user.Id) is ChatMemberOwner
|
||||
or ChatMemberAdministrator {CanRestrictMembers: true};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user