diff --git a/Core/AutoDelete/DeleteService.cs b/Core/AutoDelete/DeleteService.cs index 70f0250..574ba06 100644 --- a/Core/AutoDelete/DeleteService.cs +++ b/Core/AutoDelete/DeleteService.cs @@ -39,7 +39,7 @@ public class DeleteService : AbstractTimedHostedService { try { - await _bot.BotClient.DeleteMessageAsync(request.ChatId, request.MessageId); + await _bot.BotClient.DeleteMessage(request.ChatId, request.MessageId); } catch (ApiRequestException e) { diff --git a/Core/Extensions/BotExtension.cs b/Core/Extensions/BotExtension.cs index 2bd90ac..092ad8b 100644 --- a/Core/Extensions/BotExtension.cs +++ b/Core/Extensions/BotExtension.cs @@ -12,7 +12,7 @@ public static class BotExtension if (victim != null && canUse) { - var victimMember = await bot.GetChatMemberAsync(chat, victim.Id); + var victimMember = await bot.GetChatMember(chat, victim.Id); canUse = victimMember is not ChatMemberOwner && victimMember is not ChatMemberAdministrator && !victim.IsBot; } @@ -21,7 +21,7 @@ public static class BotExtension public static async Task IsUserAdminAsync(this ITelegramBotClient bot, Chat chat, User user) { - var callerMember = await bot.GetChatMemberAsync(chat, user.Id); + var callerMember = await bot.GetChatMember(chat, user.Id); var isAdmin = callerMember is ChatMemberOwner; if (callerMember is ChatMemberAdministrator callerAdmin) @@ -34,12 +34,12 @@ public static class BotExtension public static async Task CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat) { - return await CanDeleteMessagesAsync(bot, chat, await bot.GetMeAsync()); + return await CanDeleteMessagesAsync(bot, chat, await bot.GetMe()); } public static async Task CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat, User user) { - return await bot.GetChatMemberAsync(chat.Id, user.Id) is ChatMemberOwner + return await bot.GetChatMember(chat.Id, user.Id) is ChatMemberOwner or ChatMemberAdministrator {CanRestrictMembers: true}; } } \ No newline at end of file diff --git a/Core/Handler/CommonHandler.cs b/Core/Handler/CommonHandler.cs index fbf0286..e606d20 100644 --- a/Core/Handler/CommonHandler.cs +++ b/Core/Handler/CommonHandler.cs @@ -56,6 +56,6 @@ public abstract class CommonHandler : BotEventHandler protected async Task AnswerQuery(string id, string? message = null) { - await Bot.AnswerCallbackQueryAsync(id, message); + await Bot.AnswerCallbackQuery(id, message); } } \ No newline at end of file diff --git a/Core/Handler/SettingsHandler.cs b/Core/Handler/SettingsHandler.cs index 039efbd..0e9d321 100644 --- a/Core/Handler/SettingsHandler.cs +++ b/Core/Handler/SettingsHandler.cs @@ -32,7 +32,7 @@ public class SettingsHandler : CommonHandler return; } - await Bot.SendTextMessageAsync( + await Bot.SendMessage( Chat.Id, "What do you want to change?", replyMarkup: GetSettingsMarkup() @@ -66,7 +66,7 @@ public class SettingsHandler : CommonHandler if (paramList[2] == "main_menu") { await AnswerQuery(query.Id); - await Bot.EditMessageTextAsync(Chat.Id, query.Message!.MessageId, "What do you want to change?", + await Bot.EditMessageText(Chat.Id, query.Message!.MessageId, "What do you want to change?", replyMarkup: GetSettingsMarkup()); return; } @@ -103,14 +103,14 @@ public class SettingsHandler : CommonHandler await onOffOpt.SetValueAsync(chatId, !await onOffOpt.GetValueAsync(chatId)); await AnswerQuery(query.Id); - await Bot.EditMessageReplyMarkupAsync(chatId, messageId, GetSettingsMarkup()); + await Bot.EditMessageReplyMarkup(chatId, messageId, GetSettingsMarkup()); break; case OptionType.Select: var selectOpt = (IOption) option; await AnswerQuery(query.Id); - await Bot.EditMessageTextAsync(Chat.Id, messageId, "Here's what you can choose:", + await Bot.EditMessageText(Chat.Id, messageId, "Here's what you can choose:", replyMarkup: await GetChoiceSelectKeyboard(selectOpt)); break; @@ -133,7 +133,7 @@ public class SettingsHandler : CommonHandler await selectOption.SetValueAsync(Chat.Id, choice.Id); await AnswerQuery(query.Id); - await Bot.EditMessageReplyMarkupAsync(Chat.Id, query.Message!.MessageId, await GetChoiceSelectKeyboard(selectOption)); + await Bot.EditMessageReplyMarkup(Chat.Id, query.Message!.MessageId, await GetChoiceSelectKeyboard(selectOption)); } private async Task GetKeyboardButton(IOption option) diff --git a/Core/Service/UserService.cs b/Core/Service/UserService.cs index 116f92f..55e2d1f 100644 --- a/Core/Service/UserService.cs +++ b/Core/Service/UserService.cs @@ -69,7 +69,7 @@ public class UserService private async Task GetUserByChat(long chatId, long userId) { - return (await _bot.GetChatMemberAsync(chatId, userId)).User; + return (await _bot.GetChatMember(chatId, userId)).User; } public bool IsUserSuper(User user) diff --git a/Core/WebhookAspNetProvider.cs b/Core/WebhookAspNetProvider.cs index fe13169..2fc3088 100644 --- a/Core/WebhookAspNetProvider.cs +++ b/Core/WebhookAspNetProvider.cs @@ -29,12 +29,12 @@ namespace Kruzya.TelegramBot.Core public async Task StartAsync(CancellationToken token) { - await _client.SetWebhookAsync(_config.Webhook.Url, secretToken: _secretToken, cancellationToken: token); + await _client.SetWebhook(_config.Webhook.Url, secretToken: _secretToken, cancellationToken: token); } public async Task StopAsync(CancellationToken token) { - await _client.DeleteWebhookAsync(cancellationToken: token); + await _client.DeleteWebhook(cancellationToken: token); } } } diff --git a/modules/ChatManagement/Handler/Ban.cs b/modules/ChatManagement/Handler/Ban.cs index dd50369..9af4c02 100644 --- a/modules/ChatManagement/Handler/Ban.cs +++ b/modules/ChatManagement/Handler/Ban.cs @@ -42,11 +42,11 @@ public class Ban : CommonHandler } catch { - await Bot.SendTextMessageAsync(Chat.Id, "Нет прав на блокировку пользователя."); + await Bot.SendMessage(Chat.Id, "Нет прав на блокировку пользователя."); return; } - await Bot.SendTextMessageAsync( + await Bot.SendMessage( Chat.Id, $"{From.ToHtml()} заблокировал {RepliedUser!.ToHtml()} {banEndMsg}", disableNotification: true, parseMode: ParseMode.Html); diff --git a/modules/ChatManagement/Handler/BanStickerSet.Handler.cs b/modules/ChatManagement/Handler/BanStickerSet.Handler.cs index ab8063d..48639dd 100644 --- a/modules/ChatManagement/Handler/BanStickerSet.Handler.cs +++ b/modules/ChatManagement/Handler/BanStickerSet.Handler.cs @@ -38,7 +38,7 @@ public partial class BanStickerSet var replyToMsgId = Message?.ReplyToMessage?.MessageId; if (replyToMsgId != null) { - await Bot.DeleteMessageAsync(Chat.Id, (int) replyToMsgId); + await Bot.DeleteMessage(Chat.Id, (int) replyToMsgId); } await Reply(FormatStickerSetAction(stickerSet.Set, "заблокирован")); @@ -90,7 +90,7 @@ public partial class BanStickerSet { try { - var stickerSet = await Bot.GetStickerSetAsync(list[i]); + var stickerSet = await Bot.GetStickerSet(list[i]); htmlString.Text($"{i + 1}. ") .Url("https://t.me/addstickers/" + stickerSet.Name, stickerSet.Title) .Br(); @@ -125,7 +125,7 @@ public partial class BanStickerSet "Этот набор стикеров заблокирован. Чтобы я мог его удалить, выдайте мне право на удаление сообщений."); } - await Bot.DeleteMessageAsync(Chat.Id, message.MessageId); + await Bot.DeleteMessage(Chat.Id, message.MessageId); } } } \ No newline at end of file diff --git a/modules/ChatManagement/Handler/BanStickerSet.Utils.cs b/modules/ChatManagement/Handler/BanStickerSet.Utils.cs index 78e1d85..a45d5cd 100644 --- a/modules/ChatManagement/Handler/BanStickerSet.Utils.cs +++ b/modules/ChatManagement/Handler/BanStickerSet.Utils.cs @@ -14,9 +14,9 @@ public partial class BanStickerSet { private async Task CanBotDeleteMessages() { - return await Bot.GetChatMemberAsync( + return await Bot.GetChatMember( Chat.Id, - (await Bot.GetMeAsync()).Id + (await Bot.GetMe()).Id ) is ChatMemberAdministrator {CanDeleteMessages: true}; } @@ -58,7 +58,7 @@ public partial class BanStickerSet private async Task CanUseCommands() { - return await Bot.GetChatMemberAsync(Chat.Id, From.Id) is ChatMemberAdministrator {CanDeleteMessages: true} + return await Bot.GetChatMember(Chat.Id, From.Id) is ChatMemberAdministrator {CanDeleteMessages: true} or ChatMemberOwner; } } \ No newline at end of file diff --git a/modules/ChatManagement/Handler/Rules.cs b/modules/ChatManagement/Handler/Rules.cs index 67ec764..058e7e0 100644 --- a/modules/ChatManagement/Handler/Rules.cs +++ b/modules/ChatManagement/Handler/Rules.cs @@ -39,7 +39,7 @@ class Rules : CommonHandler try { - await Bot.CopyMessageAsync(Chat.Id, Chat.Id, await _rulesService.GetRulesMessageIdAsync(Chat) ?? 0); + await Bot.CopyMessage(Chat.Id, Chat.Id, await _rulesService.GetRulesMessageIdAsync(Chat) ?? 0); } catch (ApiRequestException) { diff --git a/modules/ChatManagement/Handler/WhoIs.cs b/modules/ChatManagement/Handler/WhoIs.cs index 4ff9ba3..86e563c 100644 --- a/modules/ChatManagement/Handler/WhoIs.cs +++ b/modules/ChatManagement/Handler/WhoIs.cs @@ -55,7 +55,7 @@ public class WhoIs : CommonHandler return customStatus; } - var chatMember = await Bot.GetChatMemberAsync(Chat.Id, user.Id); + var chatMember = await Bot.GetChatMember(Chat.Id, user.Id); return chatMember.Status switch { ChatMemberStatus.Creator => "Владелец", diff --git a/modules/ChatManagement/Notifier.cs b/modules/ChatManagement/Notifier.cs index 806aea0..7c873c2 100644 --- a/modules/ChatManagement/Notifier.cs +++ b/modules/ChatManagement/Notifier.cs @@ -9,14 +9,14 @@ public class Notifier { public static async void WarnNotify(ITelegramBotClient bot, Chat chat, User from, User to, int count, bool isBanned = false) { - await bot.SendTextMessageAsync(chat.Id, $"{to.ToHtml()}, Вам выдано предупреждение! " + + await bot.SendMessage(chat.Id, $"{to.ToHtml()}, Вам выдано предупреждение! " + $"Текущее кол-во: {count}/3", disableNotification: true, parseMode: ParseMode.Html); if (isBanned) { - await bot.SendTextMessageAsync( + await bot.SendMessage( chat.Id, $"{from.ToHtml()} заблокировал {to.ToHtml()} на 7 дней", disableNotification: true, parseMode: ParseMode.Html); @@ -25,7 +25,7 @@ public class Notifier public static async void UnWarnNotify(ITelegramBotClient bot, Chat chat, User from, User to, int count) { - await bot.SendTextMessageAsync(chat.Id, + await bot.SendMessage(chat.Id, $"{to.ToHtml()}, с Вас снято предупреждение! " + $"Текущее кол-во: {count}/3", disableNotification: true, diff --git a/modules/ChatManagement/ParamParser/StickerSet.cs b/modules/ChatManagement/ParamParser/StickerSet.cs index 676ae02..fc68970 100644 --- a/modules/ChatManagement/ParamParser/StickerSet.cs +++ b/modules/ChatManagement/ParamParser/StickerSet.cs @@ -43,7 +43,7 @@ public class StickerSet var sticker = message?.ReplyToMessage?.Sticker; if (sticker is { SetName: { } }) { - result.Set = bot.GetStickerSetAsync(sticker.SetName).GetAwaiter().GetResult(); + result.Set = bot.GetStickerSet(sticker.SetName).GetAwaiter().GetResult(); result.IsValid = true; return true; } @@ -56,7 +56,7 @@ public class StickerSet { try { - result.Set = bot.GetStickerSetAsync(setName.First()) + result.Set = bot.GetStickerSet(setName.First()) .GetAwaiter() .GetResult(); result.IsValid = true; diff --git a/modules/CodeWatcher/Handler.cs b/modules/CodeWatcher/Handler.cs index 96e7f7f..ccbf4c4 100644 --- a/modules/CodeWatcher/Handler.cs +++ b/modules/CodeWatcher/Handler.cs @@ -103,9 +103,9 @@ public class Handler : BotEventHandler public async Task UploadDetectedCode(Message message) { var resp = await _haste.PostDocumentAsync(message.Text!); - await Bot.DeleteMessageAsync(Chat.Id, message.MessageId); + await Bot.DeleteMessage(Chat.Id, message.MessageId); - await Bot.SendTextMessageAsync(Chat.Id, + await Bot.SendMessage(Chat.Id, $"{message.From?.ToHtml()}, you posted something long and pre-escaped, so I decided to upload it to our paste service for you.\n" + $"Here is the link: {_haste.GetHasteUri() + resp.Key}", parseMode: ParseMode.Html); @@ -113,8 +113,8 @@ public class Handler : BotEventHandler public async Task RemoveDetectedCode(Message message) { - await Bot.DeleteMessageAsync(Chat.Id, message.MessageId); - var notifyMsg = await Bot.SendTextMessageAsync(Chat.Id, + await Bot.DeleteMessage(Chat.Id, message.MessageId); + var notifyMsg = await Bot.SendMessage(Chat.Id, (message.From?.ToHtml() ?? "") + ", не стоит публиковать столь большой код прямо в чат. " + "Вместо этого загрузите его на https://pastebin.com и отправьте в виде ссылки.", parseMode: ParseMode.Html); diff --git a/modules/CombotAntiSpam/UserJoinHandler.cs b/modules/CombotAntiSpam/UserJoinHandler.cs index feac54b..53c21b4 100644 --- a/modules/CombotAntiSpam/UserJoinHandler.cs +++ b/modules/CombotAntiSpam/UserJoinHandler.cs @@ -23,7 +23,7 @@ public class UserJoinHandler : BotEventHandler [Message(MessageFlag.HasNewChatMembers)] public async Task OnUserJoined() { - var canKickMembers = await Bot.IsUserAdminAsync(Chat, await Bot.GetMeAsync()); + var canKickMembers = await Bot.IsUserAdminAsync(Chat, await Bot.GetMe()); foreach (var member in RawUpdate.Message!.NewChatMembers!) { @@ -38,11 +38,11 @@ public class UserJoinHandler : BotEventHandler messageText.Append( $"More details you can find on CAS site."); - await Bot.SendTextMessageAsync(Chat, messageText.ToString(), parseMode: ParseMode.Html); + await Bot.SendMessage(Chat, messageText.ToString(), parseMode: ParseMode.Html); if (canKickMembers) { - await Bot.BanChatMemberAsync(Chat, member.Id); + await Bot.BanChatMember(Chat, member.Id); } } } diff --git a/modules/ContentStore/Handler/Store.cs b/modules/ContentStore/Handler/Store.cs index 8c13e2c..bcbb8ff 100644 --- a/modules/ContentStore/Handler/Store.cs +++ b/modules/ContentStore/Handler/Store.cs @@ -38,14 +38,14 @@ public class Store : CommonHandler if (_reputation == null) { - await Bot.SendTextMessageAsync(Chat.Id, "Reputation is unavailable."); + await Bot.SendMessage(Chat.Id, "Reputation is unavailable."); return; } var user = From; var reputation = await _reputation.GetUserReputationAsync(Chat, user); - await Bot.SendTextMessageAsync(Chat.Id, $"{user.ToHtml()} ({reputation}), чего пожелаете?", parseMode: ParseMode.Html, + await Bot.SendMessage(Chat.Id, $"{user.ToHtml()} ({reputation}), чего пожелаете?", parseMode: ParseMode.Html, replyMarkup: new InlineKeyboardMarkup( _provider.GetServices() .ToAsyncEnumerable() @@ -99,7 +99,7 @@ public class Store : CommonHandler var reputation = await _reputation.GetUserReputationAsync(Chat, From); if (reputation < storeItem.Price) { - await Bot.EditMessageTextAsync( + await Bot.EditMessageText( Chat.Id, messageId, $"{From.ToHtml()} ({reputation}), продолжай работать и тебе обязательно хватит на покупку.", diff --git a/modules/Reputation/Handler/Reputation.cs b/modules/Reputation/Handler/Reputation.cs index bece4af..df1d059 100644 --- a/modules/Reputation/Handler/Reputation.cs +++ b/modules/Reputation/Handler/Reputation.cs @@ -182,7 +182,7 @@ public class Reputation : CommonHandler i++; } - await Bot.SendTextMessageAsync(Chat!, msg.ToString(), parseMode: ParseMode.Html, + await Bot.SendMessage(Chat!, msg.ToString(), parseMode: ParseMode.Html, disableNotification: true); }