Update to Telegram Bot Framework 2.0

This commit is contained in:
Andriy
2023-07-29 01:50:28 +03:00
parent 5d06529c92
commit 0677060429
24 changed files with 86 additions and 47 deletions
+2 -1
View File
@@ -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))
+5 -3
View File
@@ -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())
@@ -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();
+5 -3
View File
@@ -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();
+4 -2
View File
@@ -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;
+7 -3
View File
@@ -27,7 +27,8 @@ public class Roll : CommonHandler
private readonly UserService _userService;
private readonly ConcurrentBag<DeleteRequest> _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<Message> Reply(string text)
{
// TODO: move feature with autocleaning to Core CommonHandler.