Add ChatManagement commands. Drop appsettings from version control.

This commit is contained in:
West14
2021-12-26 15:40:14 +02:00
parent 685caf52b7
commit 7b37e2f35d
7 changed files with 190 additions and 98 deletions
@@ -0,0 +1,28 @@
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace West.TelegramBot.ChatManagement.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;
}
return canUse;
}
}
}