Merge pull request #36 from Bubuni-Team/feature/bot-framework-2.0

Update to Telegram Bot Framework 2.0
This commit is contained in:
Andriy
2023-07-29 13:25:03 +03:00
committed by GitHub
24 changed files with 86 additions and 47 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Core' " />
<ItemGroup>
<PackageReference Include="AleXr64.BotFramework" Version="0.7.4-g573fdc8e7e" />
<PackageReference Include="AleXr64.BotFramework" Version="2.0.4-g9e14fb7bfc" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+5 -3
View File
@@ -23,7 +23,8 @@ public class SettingsHandler : CommonHandler
_options = serviceProvider.GetServices<IOption>();
}
[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;
@@ -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!;
+2 -1
View File
@@ -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!;
+4 -2
View File
@@ -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))
+2 -1
View File
@@ -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;
+2 -1
View File
@@ -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;
+2 -1
View File
@@ -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;
+1
View File
@@ -17,6 +17,7 @@ public class NSFW : BotEventHandler
_db = db;
}
[InChat(InChat.Public)]
[Command("nsfw", CommandParseMode.Both)]
public async Task HandleNSFW()
{
+4 -2
View File
@@ -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;
+1 -1
View File
@@ -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))
+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.
+2 -1
View File
@@ -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))
+12 -6
View File
@@ -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} репутацию </code>{receiver.ToHtml()}<code>({Math.Round(receiverRepCount, 2)})</code>");
}
}
[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();
+1 -1
View File
@@ -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|"))
+1 -1
View File
@@ -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;
+2 -1
View File
@@ -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");
+3 -2
View File
@@ -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)
+5 -3
View File
@@ -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))