From 0677060429edd314983f513ffbee6bc07ef0efea Mon Sep 17 00:00:00 2001
From: Andriy <30056636+West14@users.noreply.github.com>
Date: Sat, 29 Jul 2023 01:50:28 +0300
Subject: [PATCH] Update to Telegram Bot Framework 2.0
---
Core/Core.csproj | 2 +-
Core/Handler/SettingsHandler.cs | 8 +++++---
.../Handler/BanStickerSet.Handler.cs | 12 ++++++++----
modules/ChatManagement/Handler/Greet.cs | 3 ++-
modules/ChatManagement/Handler/Rules.cs | 6 ++++--
modules/ChatQuotes/Handler/Quote.cs | 3 ++-
modules/CodeWatcher/Handler.cs | 3 ++-
modules/CombotAntiSpam/UserJoinHandler.cs | 3 ++-
modules/ContentStore/Handler/NSFW.cs | 1 +
modules/ContentStore/Handler/Store.cs | 6 ++++--
modules/DebugTools/Handler.cs | 2 +-
modules/Entertainment/Handler/Common.cs | 3 ++-
modules/Entertainment/Handler/Fun/Bayan.cs | 8 +++++---
.../Entertainment/Handler/Fun/JavaScript.cs | 8 +++++---
modules/Entertainment/Handler/Fun/Python.cs | 8 +++++---
modules/Entertainment/Handler/Guess.cs | 6 ++++--
modules/Entertainment/Handler/Roll.cs | 10 +++++++---
modules/Reputation/Handler/Debug.cs | 3 ++-
modules/Reputation/Handler/Reputation.cs | 18 ++++++++++++------
modules/RichSiteSummary/Handler/FeedList.cs | 2 +-
modules/StickerTools/Handler.cs | 2 +-
modules/UrlLimitations/MessageHandler.cs | 3 ++-
modules/UrlLimitations/UserJoinHandler.cs | 5 +++--
modules/UserGroupTag/Handler.cs | 8 +++++---
24 files changed, 86 insertions(+), 47 deletions(-)
diff --git a/Core/Core.csproj b/Core/Core.csproj
index f28bf9a..a0043f6 100644
--- a/Core/Core.csproj
+++ b/Core/Core.csproj
@@ -8,7 +8,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/Core/Handler/SettingsHandler.cs b/Core/Handler/SettingsHandler.cs
index 9ab34a8..039efbd 100644
--- a/Core/Handler/SettingsHandler.cs
+++ b/Core/Handler/SettingsHandler.cs
@@ -23,7 +23,8 @@ public class SettingsHandler : CommonHandler
_options = serviceProvider.GetServices();
}
- [Command(InChat.Public, "settings", CommandParseMode.WithUsername)]
+ [InChat(InChat.Public)]
+ [Command("settings", CommandParseMode.WithUsername)]
public async Task HandleSettings()
{
if (!await Bot.IsUserAdminAsync(Chat, From))
@@ -37,8 +38,9 @@ public class SettingsHandler : CommonHandler
replyMarkup: GetSettingsMarkup()
);
}
-
- [Update(InChat.Public, UpdateFlag.CallbackQuery)]
+
+ [InChat(InChat.Public)]
+ [Update(UpdateFlag.CallbackQuery)]
public async Task HandleCallback()
{
var query = CallbackQuery;
diff --git a/modules/ChatManagement/Handler/BanStickerSet.Handler.cs b/modules/ChatManagement/Handler/BanStickerSet.Handler.cs
index 3ff303d..ab8063d 100644
--- a/modules/ChatManagement/Handler/BanStickerSet.Handler.cs
+++ b/modules/ChatManagement/Handler/BanStickerSet.Handler.cs
@@ -12,7 +12,8 @@ namespace West.TelegramBot.ChatManagement.Handler;
public partial class BanStickerSet
{
- [ParametrizedCommand(InChat.Public, "stick_ban", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [ParametrizedCommand("stick_ban", CommandParseMode.Both)]
public async Task HandleBanSticker(StickerSet.Param stickerSet)
{
if (!await PreCommand(stickerSet))
@@ -43,7 +44,8 @@ public partial class BanStickerSet
await Reply(FormatStickerSetAction(stickerSet.Set, "заблокирован"));
}
- [ParametrizedCommand(InChat.Public, "stick_unban", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [ParametrizedCommand("stick_unban", CommandParseMode.Both)]
public async Task HandleUnBanSticker(string stickerSet)
{
if (!await PreCommand())
@@ -68,7 +70,8 @@ public partial class BanStickerSet
await Reply(FormatStickerSetAction(stickerSet, "разблокирован"));
}
- [Command(InChat.Public, "stick_banlist", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("stick_banlist", CommandParseMode.Both)]
public async Task HandleSBanList()
{
var option = await GetBannedStickerSetOption();
@@ -109,7 +112,8 @@ public partial class BanStickerSet
await Reply(msg);
}
- [Message(InChat.Public, MessageFlag.HasSticker)]
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasSticker)]
public async Task HandleMessage()
{
var message = Message!;
diff --git a/modules/ChatManagement/Handler/Greet.cs b/modules/ChatManagement/Handler/Greet.cs
index a785a8d..6048837 100644
--- a/modules/ChatManagement/Handler/Greet.cs
+++ b/modules/ChatManagement/Handler/Greet.cs
@@ -21,7 +21,8 @@ public class Greet : BotEventHandler
_rulesService = rulesService;
}
- [Message(InChat.Public, MessageFlag.HasNewChatMembers)]
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasNewChatMembers)]
public async Task HandleNewChatMembers()
{
var message = RawUpdate.Message!;
diff --git a/modules/ChatManagement/Handler/Rules.cs b/modules/ChatManagement/Handler/Rules.cs
index 1c73e14..67ec764 100644
--- a/modules/ChatManagement/Handler/Rules.cs
+++ b/modules/ChatManagement/Handler/Rules.cs
@@ -14,7 +14,8 @@ class Rules : CommonHandler
{
private readonly RulesService _rulesService;
- [Command(InChat.Public, "setrules", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("setrules", CommandParseMode.Both)]
public async Task HandleSetRules()
{
var replyToMessage = Message?.ReplyToMessage;
@@ -27,7 +28,8 @@ class Rules : CommonHandler
await _rulesService.SetRulesAsync(Chat, replyToMessage.MessageId);
}
- [Command(InChat.Public, "rules", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("rules", CommandParseMode.Both)]
public async Task HandleRules()
{
if (!await _rulesService.HasRulesAsync(Chat))
diff --git a/modules/ChatQuotes/Handler/Quote.cs b/modules/ChatQuotes/Handler/Quote.cs
index 9e58e1d..eadc57c 100644
--- a/modules/ChatQuotes/Handler/Quote.cs
+++ b/modules/ChatQuotes/Handler/Quote.cs
@@ -15,7 +15,8 @@ public class Quote : BotEventHandler
_quoteGenerator = quoteGenerator;
}
- [Command(InChat.Public, "q", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("q", CommandParseMode.Both)]
public async Task HandleQuote()
{
var msg = RawUpdate.Message;
diff --git a/modules/CodeWatcher/Handler.cs b/modules/CodeWatcher/Handler.cs
index 939d520..96e7f7f 100644
--- a/modules/CodeWatcher/Handler.cs
+++ b/modules/CodeWatcher/Handler.cs
@@ -25,7 +25,8 @@ public class Handler : BotEventHandler
_haste = haste;
}
- [Update(InChat.Public, UpdateFlag.Message | UpdateFlag.EditedMessage)]
+ [InChat(InChat.Public)]
+ [Update(UpdateFlag.Message | UpdateFlag.EditedMessage)]
public async Task HandleMessage()
{
var message = RawUpdate.Message ?? RawUpdate.EditedMessage;
diff --git a/modules/CombotAntiSpam/UserJoinHandler.cs b/modules/CombotAntiSpam/UserJoinHandler.cs
index 8beb975..78c7d30 100644
--- a/modules/CombotAntiSpam/UserJoinHandler.cs
+++ b/modules/CombotAntiSpam/UserJoinHandler.cs
@@ -23,7 +23,8 @@ public class UserJoinHandler : BotEventHandler
_combotClient = combotClient;
}
- [Message(InChat.Public, MessageFlag.HasNewChatMembers)]
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasNewChatMembers)]
public async Task OnUserJoined()
{
// var canKickMembers = (await Bot.GetChatMemberAsync(Chat, (await Bot.GetMeAsync()).Id)).CanRestrictMembers == true;
diff --git a/modules/ContentStore/Handler/NSFW.cs b/modules/ContentStore/Handler/NSFW.cs
index 3a5754e..48d156f 100644
--- a/modules/ContentStore/Handler/NSFW.cs
+++ b/modules/ContentStore/Handler/NSFW.cs
@@ -17,6 +17,7 @@ public class NSFW : BotEventHandler
_db = db;
}
+ [InChat(InChat.Public)]
[Command("nsfw", CommandParseMode.Both)]
public async Task HandleNSFW()
{
diff --git a/modules/ContentStore/Handler/Store.cs b/modules/ContentStore/Handler/Store.cs
index 21737fa..0005f99 100644
--- a/modules/ContentStore/Handler/Store.cs
+++ b/modules/ContentStore/Handler/Store.cs
@@ -27,7 +27,8 @@ public class Store : CommonHandler
_store = store;
}
- [Command(InChat.Public, "store", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("store", CommandParseMode.Both)]
public async Task HandleStore()
{
if (From.IsBot)
@@ -58,7 +59,8 @@ public class Store : CommonHandler
);
}
- [Update(InChat.Public, UpdateFlag.CallbackQuery)]
+ [InChat(InChat.Public)]
+ [Update(UpdateFlag.CallbackQuery)]
public async Task HandleStoreCallback()
{
var query = CallbackQuery;
diff --git a/modules/DebugTools/Handler.cs b/modules/DebugTools/Handler.cs
index 20bc14d..b8c43b0 100644
--- a/modules/DebugTools/Handler.cs
+++ b/modules/DebugTools/Handler.cs
@@ -18,7 +18,7 @@ public class Handler : BotEventHandler
_userService = userService;
}
- [Command(InChat.All, "dump", CommandParseMode.Both)]
+ [Command("dump", CommandParseMode.Both)]
public async Task HandleDump()
{
if (!_userService.IsUserSuper(From) && !await Bot.IsUserAdminAsync(Chat, From))
diff --git a/modules/Entertainment/Handler/Common.cs b/modules/Entertainment/Handler/Common.cs
index b3bf726..8fb02f5 100644
--- a/modules/Entertainment/Handler/Common.cs
+++ b/modules/Entertainment/Handler/Common.cs
@@ -28,7 +28,8 @@ namespace West.Entertainment.Handler
_userService = userService;
}
- [Command(InChat.Public, "cooldowns", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("cooldowns", CommandParseMode.Both)]
public async Task HandleCooldowns()
{
if (!_userService.IsUserSuper(From))
diff --git a/modules/Entertainment/Handler/Fun/Bayan.cs b/modules/Entertainment/Handler/Fun/Bayan.cs
index 47e12d7..08f0101 100644
--- a/modules/Entertainment/Handler/Fun/Bayan.cs
+++ b/modules/Entertainment/Handler/Fun/Bayan.cs
@@ -23,12 +23,14 @@ namespace West.Entertainment.Handler.Fun
protected override string GetAnimationName()
=> "bayan";
-
- [Command(InChat.Public, "setbayan", CommandParseMode.Both)]
+
+ [InChat(InChat.Public)]
+ [Command("setbayan", CommandParseMode.Both)]
public async Task HandleSetBayan()
=> await HandleSetAnimation();
- [Message(InChat.Public, MessageFlag.HasText)]
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasText)]
public async Task HandleBayan()
{
if (await HandleAnimation())
diff --git a/modules/Entertainment/Handler/Fun/JavaScript.cs b/modules/Entertainment/Handler/Fun/JavaScript.cs
index d360ab3..14d5064 100644
--- a/modules/Entertainment/Handler/Fun/JavaScript.cs
+++ b/modules/Entertainment/Handler/Fun/JavaScript.cs
@@ -17,12 +17,14 @@ namespace West.Entertainment.Handler.Fun
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
protected override string GetAnimationName() => "javascript";
-
- [Command(InChat.Public, "setjs", CommandParseMode.Both)]
+
+ [InChat(InChat.Public)]
+ [Command("setjs", CommandParseMode.Both)]
public async Task HandleSetJs()
=> await HandleSetAnimation();
- [Message(InChat.Public, MessageFlag.HasText)]
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasText)]
public async Task HandleJs()
{
await HandleAnimation();
diff --git a/modules/Entertainment/Handler/Fun/Python.cs b/modules/Entertainment/Handler/Fun/Python.cs
index ac2435e..75cb0a0 100644
--- a/modules/Entertainment/Handler/Fun/Python.cs
+++ b/modules/Entertainment/Handler/Fun/Python.cs
@@ -18,12 +18,14 @@ namespace West.Entertainment.Handler.Fun
protected override string GetAnimationName()
=> "python";
-
- [Command(InChat.Public, "setpython", CommandParseMode.Both)]
+
+ [InChat(InChat.Public)]
+ [Command("setpython", CommandParseMode.Both)]
public async Task HandleSetPython()
=> await HandleSetAnimation();
- [Message(InChat.Public, MessageFlag.HasText)]
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasText)]
public async Task HandlePython()
{
await HandleAnimation();
diff --git a/modules/Entertainment/Handler/Guess.cs b/modules/Entertainment/Handler/Guess.cs
index 15af1ce..e669fb6 100644
--- a/modules/Entertainment/Handler/Guess.cs
+++ b/modules/Entertainment/Handler/Guess.cs
@@ -35,7 +35,8 @@ public class Guess : CommonHandler
_requests = requests;
}
- [Command(InChat.Public, "guess", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("guess", CommandParseMode.Both)]
public async Task HandleGuess()
{
// Drop user message.
@@ -91,7 +92,8 @@ public class Guess : CommonHandler
_guessCache.SetValue(Chat.Id, guessDict, -1);
}
- [Update(InChat.Public, UpdateFlag.CallbackQuery)]
+ [InChat(InChat.Public)]
+ [Update(UpdateFlag.CallbackQuery)]
public async Task HandleGuessResponse()
{
var messageId = CallbackQuery.Message?.MessageId;
diff --git a/modules/Entertainment/Handler/Roll.cs b/modules/Entertainment/Handler/Roll.cs
index 8b82025..57c4531 100644
--- a/modules/Entertainment/Handler/Roll.cs
+++ b/modules/Entertainment/Handler/Roll.cs
@@ -27,7 +27,8 @@ public class Roll : CommonHandler
private readonly UserService _userService;
private readonly ConcurrentBag _requests;
- [Command(InChat.Public, "roll", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("roll", CommandParseMode.Both)]
public async Task HandleRoll()
{
var cdOption = await Db.UserValues.FindOrCreateOption(Chat.Id, From.Id, "rollNextUse");
@@ -77,7 +78,8 @@ public class Roll : CommonHandler
);
}
- [Command(InChat.Public, "reset_roll", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("reset_roll", CommandParseMode.Both)]
public async Task HandleResetRoll()
{
if (!_userService.IsUserSuper(From))
@@ -99,7 +101,8 @@ public class Roll : CommonHandler
await Reply($"Кулдаун /roll сброшен для чата \"{Chat.Title}\".");
}
- [ParametrizedCommand(InChat.Public, "rng_test", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [ParametrizedCommand("rng_test", CommandParseMode.Both)]
public async Task HandleRngTest(int minValue, int maxValue)
{
if (!_userService.IsUserSuper(From))
@@ -130,6 +133,7 @@ public class Roll : CommonHandler
await Bot.SendTextMessageAsync(Chat, $"Positive: {positive}.\nNegative: {negative}");
}
+
protected override async Task Reply(string text)
{
// TODO: move feature with autocleaning to Core CommonHandler.
diff --git a/modules/Reputation/Handler/Debug.cs b/modules/Reputation/Handler/Debug.cs
index c9c3962..5b4b31c 100644
--- a/modules/Reputation/Handler/Debug.cs
+++ b/modules/Reputation/Handler/Debug.cs
@@ -22,7 +22,8 @@ public class Debug : BotEventHandler
_userService = userService;
}
- [Command(InChat.Public, "dbg_migrate", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [Command("dbg_migrate", CommandParseMode.Both)]
public async Task HandleMigrate()
{
if (!_userService.IsUserSuper(From))
diff --git a/modules/Reputation/Handler/Reputation.cs b/modules/Reputation/Handler/Reputation.cs
index 6adb558..bece4af 100644
--- a/modules/Reputation/Handler/Reputation.cs
+++ b/modules/Reputation/Handler/Reputation.cs
@@ -55,7 +55,10 @@ public class Reputation : CommonHandler
_logger = logger;
}
- [Message(InChat.Public, MessageFlag.HasText | MessageFlag.HasSticker)]
+ [InChat(InChat.Public)]
+ [HandleCondition(ConditionType.Any)]
+ [Message(MessageFlag.HasText)]
+ [Message(MessageFlag.HasSticker)]
public async Task HandleReputation()
{
var text = Message?.Text;
@@ -124,8 +127,9 @@ public class Reputation : CommonHandler
$"{action} репутацию {receiver.ToHtml()}({Math.Round(receiverRepCount, 2)})");
}
}
-
- [ParametrizedCommand(InChat.Public, "setrep", CommandParseMode.Both)]
+
+ [InChat(InChat.Public)]
+ [ParametrizedCommand("setrep", CommandParseMode.Both)]
public async Task HandleSetRep(double reputation)
{
if (!CanModifyUserReputation(RepliedUser))
@@ -138,7 +142,8 @@ public class Reputation : CommonHandler
);
}
- [ParametrizedCommand(InChat.Public, "addrep", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [ParametrizedCommand("addrep", CommandParseMode.Both)]
public async Task HandleAddRep(double reputation)
{
if (!CanModifyUserReputation(RepliedUser))
@@ -150,8 +155,9 @@ public class Reputation : CommonHandler
await _reputationService.IncrementReputationAsync(Chat, RepliedUser, reputation)
);
}
-
- [Command(InChat.Public, "top", CommandParseMode.Both)]
+
+ [InChat(InChat.Public)]
+ [Command("top", CommandParseMode.Both)]
public async Task HandleTop()
{
var msg = new HtmlString();
diff --git a/modules/RichSiteSummary/Handler/FeedList.cs b/modules/RichSiteSummary/Handler/FeedList.cs
index 847b760..25a04c7 100644
--- a/modules/RichSiteSummary/Handler/FeedList.cs
+++ b/modules/RichSiteSummary/Handler/FeedList.cs
@@ -208,7 +208,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
#region Message handler
- [Update(InChat.All, UpdateFlag.CallbackQuery)]
+ [Update(UpdateFlag.CallbackQuery)]
public async Task HandleAction()
{
if (!RawUpdate.CallbackQuery.Data.StartsWith("feed|"))
diff --git a/modules/StickerTools/Handler.cs b/modules/StickerTools/Handler.cs
index 8f7710a..10ee052 100644
--- a/modules/StickerTools/Handler.cs
+++ b/modules/StickerTools/Handler.cs
@@ -10,7 +10,7 @@ namespace West.TelegramBot.StickerTools;
public class Handler : BotEventHandler
{
- [Command(InChat.All, "png", CommandParseMode.Both)]
+ [Command("png", CommandParseMode.Both)]
public async Task Sticker2Png()
{
var sticker = RawUpdate.Message?.ReplyToMessage?.Sticker;
diff --git a/modules/UrlLimitations/MessageHandler.cs b/modules/UrlLimitations/MessageHandler.cs
index a91ba03..8cbe9ce 100644
--- a/modules/UrlLimitations/MessageHandler.cs
+++ b/modules/UrlLimitations/MessageHandler.cs
@@ -26,7 +26,8 @@ namespace Kruzya.TelegramBot.UrlLimitations
dbCtx = coreContext;
}
- [Message(InChat.Public, MessageFlag.HasText)]
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasText)]
public async Task OnMessageReceived()
{
var option = await dbCtx.UserValues.FindOption(Chat.Id, From.Id, "urlLimitations.messagesAfterJoin");
diff --git a/modules/UrlLimitations/UserJoinHandler.cs b/modules/UrlLimitations/UserJoinHandler.cs
index 1355eb3..29dad15 100644
--- a/modules/UrlLimitations/UserJoinHandler.cs
+++ b/modules/UrlLimitations/UserJoinHandler.cs
@@ -19,8 +19,9 @@ namespace Kruzya.TelegramBot.UrlLimitations
{
dbCtx = coreContext;
}
-
- [Message(InChat.Public, MessageFlag.HasNewChatMembers)]
+
+ [InChat(InChat.Public)]
+ [Message(MessageFlag.HasNewChatMembers)]
public async Task OnChatMembersAdded()
{
foreach (var member in RawUpdate.Message.NewChatMembers)
diff --git a/modules/UserGroupTag/Handler.cs b/modules/UserGroupTag/Handler.cs
index 97e1e3b..14ceae0 100644
--- a/modules/UserGroupTag/Handler.cs
+++ b/modules/UserGroupTag/Handler.cs
@@ -27,8 +27,9 @@ namespace UserGroupTag
_db = db;
_userCache = userCache;
}
-
- [ParametrizedCommand(InChat.Public, "add_group", CommandParseMode.Both)]
+
+ [InChat(InChat.Public)]
+ [ParametrizedCommand("add_group", CommandParseMode.Both)]
public async Task HandleAddGroup(string groupName)
{
// var groupName = group.Text;
@@ -63,7 +64,8 @@ namespace UserGroupTag
parseMode: ParseMode.Html);
}
- [ParametrizedCommand(InChat.Public, "tag_group", CommandParseMode.Both)]
+ [InChat(InChat.Public)]
+ [ParametrizedCommand("tag_group", CommandParseMode.Both)]
public async Task HandleTagGroup(string groupName)
{
if (string.IsNullOrEmpty(groupName))