From d3ccb178010a3b7116a10d8b8d1eea958c706dad Mon Sep 17 00:00:00 2001 From: thomkaptein Date: Tue, 19 Mar 2024 14:10:34 +0100 Subject: [PATCH] add error handling to fm --- .../SlashCommands/PlaySlashCommands.cs | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/FMBot.Bot/SlashCommands/PlaySlashCommands.cs b/src/FMBot.Bot/SlashCommands/PlaySlashCommands.cs index fa201b5d..393bdf5b 100644 --- a/src/FMBot.Bot/SlashCommands/PlaySlashCommands.cs +++ b/src/FMBot.Bot/SlashCommands/PlaySlashCommands.cs @@ -85,35 +85,44 @@ await RespondAsync( _ = DeferAsync(); - var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User); - var userSettings = await this._settingService.GetUser(user, contextUser, this.Context.Guild, this.Context.User, true); + try + { + var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User); + var userSettings = + await this._settingService.GetUser(user, contextUser, this.Context.Guild, this.Context.User, true); - var response = await this._playBuilder.NowPlayingAsync(new ContextModel(this.Context, contextUser), userSettings); + var response = + await this._playBuilder.NowPlayingAsync(new ContextModel(this.Context, contextUser), userSettings); - await this.Context.SendFollowUpResponse(this.Interactivity, response); - this.Context.LogCommandUsed(response.CommandResponse); + await this.Context.SendFollowUpResponse(this.Interactivity, response); + this.Context.LogCommandUsed(response.CommandResponse); - var message = await this.Context.Interaction.GetOriginalResponseAsync(); + var message = await this.Context.Interaction.GetOriginalResponseAsync(); - try - { - if (message != null && response.CommandResponse == CommandResponse.Ok) + try { - if (contextUser.EmoteReactions != null && contextUser.EmoteReactions.Any() && SupporterService.IsSupporter(contextUser.UserType)) + if (message != null && response.CommandResponse == CommandResponse.Ok) { - await GuildService.AddReactionsAsync(message, contextUser.EmoteReactions); - } - else if (this.Context.Guild != null) - { - await this._guildService.AddGuildReactionsAsync(message, this.Context.Guild); + if (contextUser.EmoteReactions != null && contextUser.EmoteReactions.Any() && SupporterService.IsSupporter(contextUser.UserType)) + { + await GuildService.AddReactionsAsync(message, contextUser.EmoteReactions); + } + else if (this.Context.Guild != null) + { + await this._guildService.AddGuildReactionsAsync(message, this.Context.Guild); + } } } + catch (Exception e) + { + await this.Context.HandleCommandException(e, "Could not add emote reactions", sendReply: false); + await ReplyAsync( + $"Could not add automatic emoji reactions to `/fm`. Make sure the emojis still exist, the bot is the same server as where the emojis come from and the bot has permission to `Add Reactions`."); + } } catch (Exception e) { - await this.Context.HandleCommandException(e, "Could not add emote reactions", sendReply: false); - await ReplyAsync( - $"Could not add automatic emoji reactions to `/fm`. Make sure the emojis still exist, the bot is the same server as where the emojis come from and the bot has permission to `Add Reactions`."); + await this.Context.HandleCommandException(e); } } @@ -153,7 +162,7 @@ public async Task StreakAsync( [Summary("User", "The user to show (defaults to self)")] string user = null) { _ = DeferAsync(); - + var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User); var userSettings = await this._settingService.GetUser(user, contextUser, this.Context.Guild, this.Context.User, true); var userWithStreak = await this._userService.GetUserAsync(userSettings.DiscordUserId);