diff --git a/LDTTeam Authentication.sln.DotSettings.user b/LDTTeam Authentication.sln.DotSettings.user index 345530d..ded7dca 100644 --- a/LDTTeam Authentication.sln.DotSettings.user +++ b/LDTTeam Authentication.sln.DotSettings.user @@ -1,6 +1,12 @@  ForceIncluded + ForceIncluded ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file diff --git a/LDTTeam.Authentication.Modules.Api/LDTTeam.Authentication.Modules.Api.csproj b/LDTTeam.Authentication.Modules.Api/LDTTeam.Authentication.Modules.Api.csproj index 0627256..d7fb441 100644 --- a/LDTTeam.Authentication.Modules.Api/LDTTeam.Authentication.Modules.Api.csproj +++ b/LDTTeam.Authentication.Modules.Api/LDTTeam.Authentication.Modules.Api.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/LDTTeam.Authentication.Server/LDTTeam.Authentication.Server.csproj b/LDTTeam.Authentication.Server/LDTTeam.Authentication.Server.csproj index f0fd764..86e1a75 100644 --- a/LDTTeam.Authentication.Server/LDTTeam.Authentication.Server.csproj +++ b/LDTTeam.Authentication.Server/LDTTeam.Authentication.Server.csproj @@ -9,19 +9,19 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - + + + diff --git a/Modules/LDTTeam.Authentication.Modules.Discord/Commands/MyRewardsCommands.cs b/Modules/LDTTeam.Authentication.Modules.Discord/Commands/MyRewardsCommands.cs index 37866a3..fe288d3 100644 --- a/Modules/LDTTeam.Authentication.Modules.Discord/Commands/MyRewardsCommands.cs +++ b/Modules/LDTTeam.Authentication.Modules.Discord/Commands/MyRewardsCommands.cs @@ -6,10 +6,9 @@ using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; -using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Objects; using Remora.Discord.Commands.Contexts; -using Remora.Discord.Core; +using Remora.Discord.Commands.Feedback.Services; using Remora.Results; namespace LDTTeam.Authentication.Modules.Discord.Commands @@ -17,34 +16,52 @@ namespace LDTTeam.Authentication.Modules.Discord.Commands public class MyRewardsCommands : CommandGroup { private readonly InteractionContext _context; - private readonly IDiscordRestWebhookAPI _channelApi; + private readonly IFeedbackService _feedbackService; private readonly IConditionService _conditionService; - public MyRewardsCommands(InteractionContext context, IDiscordRestWebhookAPI channelApi, + public MyRewardsCommands(InteractionContext context, + IFeedbackService feedbackService, IConditionService conditionService) { _context = context; - _channelApi = channelApi; + _feedbackService = feedbackService; _conditionService = conditionService; } [Command("myrewards")] [Description("Lists your LDTTeam Auth rewards")] - public async Task MyRewardsCommand() + public async Task MyRewardsCommand() { - Dictionary? rewards = - await _conditionService.GetRewardsForUser("discord", _context.User.ID.ToString(), CancellationToken); + var member = _context.Interaction.Member; + if (!member.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + var user = member.Value.User; + if (!user.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var rewards = + await _conditionService.GetRewardsForUser("discord", user.Value.ID.ToString(), CancellationToken); Result reply; if (rewards == null) { - reply = await Reply(new Embed - { - Title = "User not found", - Description = - $"User {_context.User.Username} was not found in our system, are you sure you've signed up?", - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "User not found", + Description = + $"User {user.Value.Username} was not found in our system, are you sure you've signed up?", + Colour = Color.Red + } + ); } else { @@ -55,31 +72,19 @@ public async Task MyRewardsCommand() fields.Add(new EmbedField(reward, has.ToString(), true)); } - Embed embed = new() - { - Title = $"{_context.User.Username}'s rewards", - Colour = Color.Green, - Fields = fields - }; - - reply = await Reply(embed, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = $"{user.Value.Username}'s rewards", + Colour = Color.Green, + Fields = fields + } + ); } return !reply.IsSuccess ? Result.FromError(reply) : Result.FromSuccess(); } - - private async Task> Reply(Embed embed, Optional> components) - { - return await _channelApi.CreateFollowupMessageAsync - ( - _context.ApplicationID, - _context.Token, - embeds: new[] {embed}, - components: components, - ct: CancellationToken - ); - } } } \ No newline at end of file diff --git a/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RefreshCommand.cs b/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RefreshCommand.cs index 1c5a047..a8f90c4 100644 --- a/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RefreshCommand.cs +++ b/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RefreshCommand.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Threading.Tasks; @@ -7,9 +6,9 @@ using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; -using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Objects; using Remora.Discord.Commands.Contexts; +using Remora.Discord.Commands.Feedback.Services; using Remora.Results; namespace LDTTeam.Authentication.Modules.Discord.Commands @@ -17,15 +16,15 @@ namespace LDTTeam.Authentication.Modules.Discord.Commands public class RefreshCommand : CommandGroup { private readonly InteractionContext _context; - private readonly IDiscordRestWebhookAPI _channelApi; + private readonly IFeedbackService _feedbackService; private readonly IBackgroundEventsQueue _eventsQueue; - public RefreshCommand(InteractionContext context, IDiscordRestWebhookAPI channelApi, - IBackgroundEventsQueue eventsQueue) + public RefreshCommand(InteractionContext context, + IBackgroundEventsQueue eventsQueue, IFeedbackService feedbackService) { _context = context; - _channelApi = channelApi; _eventsQueue = eventsQueue; + _feedbackService = feedbackService; } [Command("refresh")] @@ -33,42 +32,48 @@ public RefreshCommand(InteractionContext context, IDiscordRestWebhookAPI channel public async Task RemoveRewardConditionCommand([Description("Optional provider to refresh")] string? provider = null) { - if (!_context.Member.Value.Permissions.Value.HasPermission(DiscordPermission.Administrator)) + var member = _context.Interaction.Member; + if (!member.HasValue) { - return await _channelApi.CreateFollowupMessageAsync - ( - _context.ApplicationID, - _context.Token, - embeds: new[] - { - new Embed - { - Title = "No Permission", - Description = - "You require Administrator permissions for this command", - Colour = Color.DarkRed - } - }, - flags: MessageFlags.Ephemeral, - ct: CancellationToken + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var permissions = member.Value.Permissions; + if (!permissions.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" ); } + + if (!permissions.Value.HasPermission(DiscordPermission.Administrator)) + { + return await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "No Permission", + Description = + "You require Administrator permissions for this command", + Colour = Color.DarkRed + }); + } await _eventsQueue.QueueBackgroundWorkItemAsync(async (events, scope, _) => { await events._refreshContentEvent.InvokeAsync(scope, - provider == null ? null : new List {provider}); + provider == null ? null : [provider]); await events._postRefreshContentEvent.InvokeAsync(scope); }, CancellationToken); - return await _channelApi.CreateFollowupMessageAsync - ( - _context.ApplicationID, - _context.Token, - "done!", - flags: MessageFlags.Ephemeral, - ct: CancellationToken - ); + return await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Refreshed", + Description = "Refreshed provider(s)", + Colour = Color.Green + }); } } } \ No newline at end of file diff --git a/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RewardsCommands.cs b/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RewardsCommands.cs index a374779..6744602 100644 --- a/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RewardsCommands.cs +++ b/Modules/LDTTeam.Authentication.Modules.Discord/Commands/RewardsCommands.cs @@ -8,10 +8,9 @@ using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; -using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Objects; using Remora.Discord.Commands.Contexts; -using Remora.Discord.Core; +using Remora.Discord.Commands.Feedback.Services; using Remora.Results; namespace LDTTeam.Authentication.Modules.Discord.Commands @@ -20,34 +19,51 @@ namespace LDTTeam.Authentication.Modules.Discord.Commands public class RewardsCommands : CommandGroup { private readonly InteractionContext _context; - private readonly IDiscordRestWebhookAPI _channelApi; + private readonly IFeedbackService _feedbackService; private readonly IConditionService _conditionService; private readonly IRewardService _rewardService; - public RewardsCommands(InteractionContext context, IDiscordRestWebhookAPI channelApi, + public RewardsCommands(InteractionContext context, IFeedbackService feedbackService, IConditionService conditionService, IRewardService rewardService) { _context = context; - _channelApi = channelApi; + _feedbackService = feedbackService; _conditionService = conditionService; _rewardService = rewardService; } [Command("user")] [Description("Lists a user's LDTTeam Auth rewards")] - public async Task UserRewardsCommand([Description("User to get rewards for")] + public async Task UserRewardsCommand([Description("User to get rewards for")] IUser user) { + var member = _context.Interaction.Member; + if (!member.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var permissions = member.Value.Permissions; + if (!permissions.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + Result reply; - if (!_context.Member.Value.Permissions.Value.HasPermission(DiscordPermission.Administrator)) + if (!permissions.Value.HasPermission(DiscordPermission.Administrator)) { - reply = await Reply(new Embed - { - Title = "No Permission", - Description = - "You require Administrator permissions for this command", - Colour = Color.DarkRed - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "No Permission", + Description = + "You require Administrator permissions for this command", + Colour = Color.DarkRed + }); } else { @@ -56,13 +72,14 @@ public async Task UserRewardsCommand([Description("User to get rewards f if (rewards == null) { - reply = await Reply(new Embed - { - Title = "User not found", - Description = - $"User {user.Username} was not found in our system, are you sure they've signed up?", - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "User not found", + Description = + $"User {user.Username} was not found in our system, are you sure they've signed up?", + Colour = Color.Red + }); } else { @@ -73,14 +90,13 @@ public async Task UserRewardsCommand([Description("User to get rewards f fields.Add(new EmbedField(reward, has.ToString(), true)); } - Embed embed = new() - { - Title = $"{user.Username}'s rewards", - Colour = Color.Green, - Fields = fields - }; - - reply = await Reply(embed, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = $"{user.Username}'s rewards", + Colour = Color.Green, + Fields = fields + }); } } @@ -91,42 +107,61 @@ public async Task UserRewardsCommand([Description("User to get rewards f [Command("add")] [Description("Adds new reward")] - public async Task AddRewardCommand([Description("The new reward's ID")] string rewardId) + public async Task AddRewardCommand([Description("The new reward's ID")] string rewardId) { + var member = _context.Interaction.Member; + if (!member.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var permissions = member.Value.Permissions; + if (!permissions.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + Result reply; - if (!_context.Member.Value.Permissions.Value.HasPermission(DiscordPermission.Administrator)) + if (!permissions.Value.HasPermission(DiscordPermission.Administrator)) { - reply = await Reply(new Embed - { - Title = "No Permission", - Description = - "You require Administrator permissions for this command", - Colour = Color.DarkRed - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "No Permission", + Description = + "You require Administrator permissions for this command", + Colour = Color.DarkRed + }); } else { if (await _rewardService.GetReward(rewardId) != null) { - reply = await Reply(new Embed - { - Title = "Duplicate Reward", - Description = - $"Reward {rewardId} already exists in our system", - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Existing Reward", + Description = + $"Reward {rewardId} already exists in our system", + Colour = Color.Red + }); } else { await _rewardService.AddReward(rewardId); - reply = await Reply(new Embed - { - Title = "New Reward Added", - Description = - $"Reward {rewardId} has been added to our system", - Colour = Color.Green - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Reward Added", + Description = + $"Reward {rewardId} has been added to our system", + Colour = Color.Green + }); } } @@ -137,18 +172,35 @@ public async Task UserRewardsCommand([Description("User to get rewards f [Command("get")] [Description("Gets all rewards or a single reward")] - public async Task GetRewardsCommand([Description("An optional reward ID")] string? rewardId = null) + public async Task GetRewardsCommand([Description("An optional reward ID")] string? rewardId = null) { + var member = _context.Interaction.Member; + if (!member.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var permissions = member.Value.Permissions; + if (!permissions.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + Result reply; - if (!_context.Member.Value.Permissions.Value.HasPermission(DiscordPermission.Administrator)) + if (!permissions.Value.HasPermission(DiscordPermission.Administrator)) { - reply = await Reply(new Embed - { - Title = "No Permission", - Description = - "You require Administrator permissions for this command", - Colour = Color.DarkRed - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "No Permission", + Description = + "You require Administrator permissions for this command", + Colour = Color.DarkRed + }); } else { @@ -158,22 +210,23 @@ public async Task GetRewardsCommand([Description("An optional reward ID" if (reward == null) { - reply = await Reply(new Embed - { - Title = "Missing Reward", - Description = - $"Reward {rewardId} does not exist in our system", - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Missing Reward", + Description = + $"Reward {rewardId} does not exist in our system", + Colour = Color.Red + }); } else { - List fields = new() - { + List fields = + [ new EmbedField("Module", "\u200b", true), new EmbedField("Condition", "\u200b", true), - new EmbedField("Lambda", "\u200b", true), - }; + new EmbedField("Lambda", "\u200b", true) + ]; foreach (ConditionInstance condition in reward.Conditions) { @@ -182,12 +235,13 @@ public async Task GetRewardsCommand([Description("An optional reward ID" fields.Add(new EmbedField("\u200b", condition.LambdaString, true)); } - reply = await Reply(new Embed - { - Title = $"Reward {reward}", - Fields = fields, - Colour = Color.Green - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = $"Reward {rewardId}", + Fields = fields, + Colour = Color.Green + }); } } else @@ -197,12 +251,13 @@ public async Task GetRewardsCommand([Description("An optional reward ID" select new EmbedField("\u200b", reward.Id, true)) .Cast().ToList(); - reply = await Reply(new Embed - { - Title = "Rewards", - Fields = fields, - Colour = Color.Green - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Rewards", + Fields = fields, + Colour = Color.Green + }); } } @@ -213,43 +268,62 @@ public async Task GetRewardsCommand([Description("An optional reward ID" [Command("remove")] [Description("Removes a reward")] - public async Task RemoveRewardCommand([Description("The to be removed reward's ID")] + public async Task RemoveRewardCommand([Description("The to be removed reward's ID")] string rewardId) { + var member = _context.Interaction.Member; + if (!member.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var permissions = member.Value.Permissions; + if (!permissions.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + Result reply; - if (!_context.Member.Value.Permissions.Value.HasPermission(DiscordPermission.Administrator)) + if (!permissions.Value.HasPermission(DiscordPermission.Administrator)) { - reply = await Reply(new Embed - { - Title = "No Permission", - Description = - "You require Administrator permissions for this command", - Colour = Color.DarkRed - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "No Permission", + Description = + "You require Administrator permissions for this command", + Colour = Color.DarkRed + }); } else { if (await _rewardService.GetReward(rewardId) == null) { - reply = await Reply(new Embed - { - Title = "Missing Reward", - Description = - $"Reward {rewardId} does not exist in our system", - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Missing Reward", + Description = + $"Reward {rewardId} does not exist in our system", + Colour = Color.Red + }); } else { await _rewardService.AddReward(rewardId); - reply = await Reply(new Embed - { - Title = "Reward Removed", - Description = - $"Reward {rewardId} has been removed from our system", - Colour = Color.Green - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Reward Removed", + Description = + $"Reward {rewardId} has been removed from our system", + Colour = Color.Green + }); } } @@ -262,22 +336,22 @@ public async Task RemoveRewardCommand([Description("The to be removed re public class RewardConditionsCommands : CommandGroup { private readonly InteractionContext _context; - private readonly IDiscordRestWebhookAPI _channelApi; + private readonly IFeedbackService _feedbackService; private readonly IConditionService _conditionService; private readonly IRewardService _rewardService; - public RewardConditionsCommands(InteractionContext context, IDiscordRestWebhookAPI channelApi, + public RewardConditionsCommands(InteractionContext context, IFeedbackService feedbackService, IConditionService conditionService, IRewardService rewardService) { _context = context; - _channelApi = channelApi; + _feedbackService = feedbackService; _conditionService = conditionService; _rewardService = rewardService; } [Command("add")] [Description("Adds condition to reward")] - public async Task AddRewardConditionCommand( + public async Task AddRewardConditionCommand( [Description("Reward to add condition to")] string rewardId, [Description("Module Name for condition")] @@ -286,16 +360,34 @@ public async Task AddRewardConditionCommand( string conditionName, [Description("Module Lambda")] string lambda) { + var member = _context.Interaction.Member; + if (!member.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var permissions = member.Value.Permissions; + if (!permissions.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + Result reply; - if (!_context.Member.Value.Permissions.Value.HasPermission(DiscordPermission.Administrator)) + if (!permissions.Value.HasPermission(DiscordPermission.Administrator)) { - reply = await Reply(new Embed - { - Title = "No Permission", - Description = - "You require Administrator permissions for this command", - Colour = Color.DarkRed - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "No Permission", + Description = + "You require Administrator permissions for this command", + Colour = Color.DarkRed + }); } else { @@ -303,13 +395,14 @@ public async Task AddRewardConditionCommand( if (reward == null) { - reply = await Reply(new Embed - { - Title = "Missing Reward", - Description = - $"Reward {rewardId} does not exist in our system", - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Missing Reward", + Description = + $"Reward {rewardId} does not exist in our system", + Colour = Color.Red + }); } else { @@ -317,20 +410,22 @@ public async Task AddRewardConditionCommand( { await _conditionService.AddConditionToReward(rewardId, moduleName, conditionName, lambda, CancellationToken); - reply = await Reply(new Embed - { - Title = "Condition Added", - Description = "Condition instance was successfully added to reward" - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Condition Added", + Description = "Condition instance was successfully added to reward" + }); } catch (AddConditionException e) { - reply = await Reply(new Embed - { - Title = "Add Failed", - Description = e.Message, - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Add Failed", + Description = e.Message, + Colour = Color.Red + }); } } } @@ -342,7 +437,7 @@ public async Task AddRewardConditionCommand( [Command("remove")] [Description("Removes condition from reward")] - public async Task RemoveRewardConditionCommand( + public async Task RemoveRewardConditionCommand( [Description("Reward to remove condition from")] string rewardId, [Description("Module Name for condition")] @@ -350,16 +445,34 @@ public async Task RemoveRewardConditionCommand( [Description("Module's Condition Name")] string conditionName) { + var member = _context.Interaction.Member; + if (!member.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + var permissions = member.Value.Permissions; + if (!permissions.HasValue) + { + return await _feedbackService.SendContextualErrorAsync( + "Command needs a user to run" + ); + } + + Result reply; - if (!_context.Member.Value.Permissions.Value.HasPermission(DiscordPermission.Administrator)) + if (!permissions.Value.HasPermission(DiscordPermission.Administrator)) { - reply = await Reply(new Embed - { - Title = "No Permission", - Description = - "You require Administrator permissions for this command", - Colour = Color.DarkRed - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "No Permission", + Description = + "You require Administrator permissions for this command", + Colour = Color.DarkRed + }); } else { @@ -367,13 +480,14 @@ public async Task RemoveRewardConditionCommand( if (reward == null) { - reply = await Reply(new Embed - { - Title = "Missing Reward", - Description = - $"Reward {rewardId} does not exist in our system", - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Missing Reward", + Description = + $"Reward {rewardId} does not exist in our system", + Colour = Color.Red + }); } else { @@ -381,20 +495,22 @@ public async Task RemoveRewardConditionCommand( { await _conditionService.RemoveConditionFromReward(rewardId, moduleName, conditionName, CancellationToken); - reply = await Reply(new Embed - { - Title = "Condition Remoed", - Description = "Condition instance was successfully removed from reward" - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Condition Removed", + Description = "Condition instance was successfully removed from reward" + }); } - catch (AddConditionException e) + catch (RemoveConditionException e) { - reply = await Reply(new Embed - { - Title = "Remove Failed", - Description = e.Message, - Colour = Color.Red - }, new Optional>()); + reply = await _feedbackService.SendContextualEmbedAsync( + new Embed + { + Title = "Remove Failed", + Description = e.Message, + Colour = Color.Red + }); } } } @@ -403,31 +519,6 @@ public async Task RemoveRewardConditionCommand( ? Result.FromError(reply) : Result.FromSuccess(); } - - private async Task> Reply(Embed embed, - Optional> components) - { - return await _channelApi.CreateFollowupMessageAsync - ( - _context.ApplicationID, - _context.Token, - embeds: new[] {embed}, - components: components, - ct: CancellationToken - ); - } - } - - private async Task> Reply(Embed embed, Optional> components) - { - return await _channelApi.CreateFollowupMessageAsync - ( - _context.ApplicationID, - _context.Token, - embeds: new[] {embed}, - components: components, - ct: CancellationToken - ); } } } \ No newline at end of file diff --git a/Modules/LDTTeam.Authentication.Modules.Discord/DiscordModule.cs b/Modules/LDTTeam.Authentication.Modules.Discord/DiscordModule.cs index f335685..01cb3d8 100644 --- a/Modules/LDTTeam.Authentication.Modules.Discord/DiscordModule.cs +++ b/Modules/LDTTeam.Authentication.Modules.Discord/DiscordModule.cs @@ -17,8 +17,8 @@ using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.Caching.Extensions; using Remora.Discord.Commands.Extensions; -using Remora.Discord.Core; using Remora.Discord.Gateway.Extensions; +using Remora.Rest.Core; using Remora.Results; namespace LDTTeam.Authentication.Modules.Discord diff --git a/Modules/LDTTeam.Authentication.Modules.Discord/LDTTeam.Authentication.Modules.Discord.csproj b/Modules/LDTTeam.Authentication.Modules.Discord/LDTTeam.Authentication.Modules.Discord.csproj index f21bbf4..e0fb02c 100644 --- a/Modules/LDTTeam.Authentication.Modules.Discord/LDTTeam.Authentication.Modules.Discord.csproj +++ b/Modules/LDTTeam.Authentication.Modules.Discord/LDTTeam.Authentication.Modules.Discord.csproj @@ -10,10 +10,10 @@ - - - - + + + + diff --git a/Modules/LDTTeam.Authentication.Modules.Discord/Services/DiscordStartupTask.cs b/Modules/LDTTeam.Authentication.Modules.Discord/Services/DiscordStartupTask.cs index d3cd9b2..c6bd34b 100644 --- a/Modules/LDTTeam.Authentication.Modules.Discord/Services/DiscordStartupTask.cs +++ b/Modules/LDTTeam.Authentication.Modules.Discord/Services/DiscordStartupTask.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Remora.Discord.Commands.Services; -using Remora.Discord.Core; +using Remora.Rest.Core; using Remora.Results; namespace LDTTeam.Authentication.Modules.Discord.Services @@ -24,14 +24,14 @@ public DiscordStartupTask(SlashService slashService, ILogger(); if (discordConfig == null) throw new Exception("discord not set in configuration!"); - - Result checkSlashSupport = _slashService.SupportsSlashCommands(); + + Result checkSlashSupport = await _slashService.UpdateSlashCommandsAsync(ct: cancellationToken); if (!checkSlashSupport.IsSuccess) { _logger.LogWarning @@ -45,15 +45,14 @@ public Task ExecuteAsync(CancellationToken cancellationToken) foreach (string server in discordConfig.RoleMappings.Keys) { if (!ulong.TryParse(server, out ulong serverId)) continue; - Result updateSlash = _slashService.UpdateSlashCommandsAsync(new Snowflake(serverId), cancellationToken).Result; + + Result updateSlash = await _slashService.UpdateSlashCommandsAsync(new Snowflake(serverId), ct: cancellationToken); if (!updateSlash.IsSuccess) { _logger.LogWarning("Failed to update slash commands: {Reason}", updateSlash.Error.Message); } } } - - return Task.CompletedTask; } } } \ No newline at end of file diff --git a/Modules/LDTTeam.Authentication.Modules.Discord/Services/WebhookLoggingQueueService.cs b/Modules/LDTTeam.Authentication.Modules.Discord/Services/WebhookLoggingQueueService.cs index 113887b..3751597 100644 --- a/Modules/LDTTeam.Authentication.Modules.Discord/Services/WebhookLoggingQueueService.cs +++ b/Modules/LDTTeam.Authentication.Modules.Discord/Services/WebhookLoggingQueueService.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Hosting; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Objects; -using Remora.Discord.Core; +using Remora.Rest.Core; namespace LDTTeam.Authentication.Modules.Discord.Services { diff --git a/Modules/LDTTeam.Authentication.Modules.GitHub/EventHandlers/GithubRefreshEventHandler.cs b/Modules/LDTTeam.Authentication.Modules.GitHub/EventHandlers/GithubRefreshEventHandler.cs index 7af1b0f..362269d 100644 --- a/Modules/LDTTeam.Authentication.Modules.GitHub/EventHandlers/GithubRefreshEventHandler.cs +++ b/Modules/LDTTeam.Authentication.Modules.GitHub/EventHandlers/GithubRefreshEventHandler.cs @@ -58,11 +58,11 @@ public async Task ExecuteAsync() _db.Teams.Remove(dbTeam); _logger.LogDebug($"GitHub team removed: {dbTeam.Slug}"); - List fields = new() - { - new EmbedField("Team Id", dbTeam.Id.ToString(), true), - new EmbedField("Team Slug", dbTeam.Slug, true) - }; + List fields = + [ + new("Team Id", dbTeam.Id.ToString(), true), + new("Team Slug", dbTeam.Slug, true) + ]; await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed { @@ -79,14 +79,14 @@ await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed continue; // team already sync with db // team added to github - _db.Teams.Add(new DbGitHubTeam(team.Id, team.Slug)); + _db.Teams.Add(new DbGitHubTeam((int) team.Id, team.Slug)); _logger.LogDebug($"GitHub team added: {team.Slug}"); - List fields = new() - { - new EmbedField("Team Id", team.Id.ToString(), true), - new EmbedField("Team Slug", team.Slug, true) - }; + List fields = + [ + new("Team Id", team.Id.ToString(), true), + new("Team Slug", team.Slug, true) + ]; await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed { @@ -110,7 +110,7 @@ await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed foreach (User user in users.Where(x => dbUsers.All(y => y.Id != x.Id))) { - await _db.Users.AddAsync(new DbGitHubUser(user.Id)); + await _db.Users.AddAsync(new DbGitHubUser((int) user.Id)); } await _db.SaveChangesAsync(); @@ -121,12 +121,12 @@ await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed dbTeam.UserRelationships.Remove(teamRelationship); // user deleted from team _logger.LogDebug($"GitHub user {teamRelationship.UserId} removed from team {dbTeam.Slug}"); - List fields = new() - { - new EmbedField("Team Id", dbTeam.Id.ToString(), true), - new EmbedField("Team Slug", dbTeam.Slug, true), - new EmbedField("User Id", teamRelationship.UserId.ToString(), true) - }; + List fields = + [ + new("Team Id", dbTeam.Id.ToString(), true), + new("Team Slug", dbTeam.Slug, true), + new("User Id", teamRelationship.UserId.ToString(), true) + ]; await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed { @@ -143,16 +143,16 @@ await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed continue; // user already synced with db // user added to team - dbTeam.UserRelationships.Add(new DbGithubTeamUser(user.Id, + dbTeam.UserRelationships.Add(new DbGithubTeamUser((int) user.Id, dbTeam.Id)); _logger.LogDebug($"GitHub user {user.Login} added to team {dbTeam.Slug}"); - List fields = new() - { - new EmbedField("Team Id", dbTeam.Id.ToString(), true), - new EmbedField("Team Slug", dbTeam.Slug, true), - new EmbedField("User Id", user.Id.ToString(), true) - }; + List fields = + [ + new("Team Id", dbTeam.Id.ToString(), true), + new("Team Slug", dbTeam.Slug, true), + new("User Id", user.Id.ToString(), true) + ]; await _loggingQueue.QueueBackgroundWorkItemAsync(new Embed { diff --git a/Modules/LDTTeam.Authentication.Modules.GitHub/LDTTeam.Authentication.Modules.GitHub.csproj b/Modules/LDTTeam.Authentication.Modules.GitHub/LDTTeam.Authentication.Modules.GitHub.csproj index ed44133..957652f 100644 --- a/Modules/LDTTeam.Authentication.Modules.GitHub/LDTTeam.Authentication.Modules.GitHub.csproj +++ b/Modules/LDTTeam.Authentication.Modules.GitHub/LDTTeam.Authentication.Modules.GitHub.csproj @@ -10,19 +10,19 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/Modules/LDTTeam.Authentication.Modules.Patreon/LDTTeam.Authentication.Modules.Patreon.csproj b/Modules/LDTTeam.Authentication.Modules.Patreon/LDTTeam.Authentication.Modules.Patreon.csproj index 3453eb7..d6fdea0 100644 --- a/Modules/LDTTeam.Authentication.Modules.Patreon/LDTTeam.Authentication.Modules.Patreon.csproj +++ b/Modules/LDTTeam.Authentication.Modules.Patreon/LDTTeam.Authentication.Modules.Patreon.csproj @@ -10,14 +10,14 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/OAuth/AspNet.Security.OAuth.BuyMeACoffee/AspNet.Security.OAuth.BuyMeACoffee.csproj b/OAuth/AspNet.Security.OAuth.BuyMeACoffee/AspNet.Security.OAuth.BuyMeACoffee.csproj index f18c460..2d4fa29 100644 --- a/OAuth/AspNet.Security.OAuth.BuyMeACoffee/AspNet.Security.OAuth.BuyMeACoffee.csproj +++ b/OAuth/AspNet.Security.OAuth.BuyMeACoffee/AspNet.Security.OAuth.BuyMeACoffee.csproj @@ -6,7 +6,7 @@ - + diff --git a/OAuth/AspNet.Security.OAuth.Minecraft/AspNet.Security.OAuth.Minecraft.csproj b/OAuth/AspNet.Security.OAuth.Minecraft/AspNet.Security.OAuth.Minecraft.csproj index 529717f..00b75d6 100644 --- a/OAuth/AspNet.Security.OAuth.Minecraft/AspNet.Security.OAuth.Minecraft.csproj +++ b/OAuth/AspNet.Security.OAuth.Minecraft/AspNet.Security.OAuth.Minecraft.csproj @@ -6,7 +6,7 @@ - +