From 0794eb6eda202643008d8d8a9c190b8aec89588e Mon Sep 17 00:00:00 2001 From: Plerx <50530305+Plerx2493@users.noreply.github.com> Date: Mon, 22 Apr 2024 19:38:35 +0200 Subject: [PATCH] Update D#+ --- .../AutoCompletion/ReminderAutoCompletion.cs | 16 ++----- .../Commands/ContextMenu/StealEmojiMessage.cs | 5 +-- .../Commands/ContextMenu/TranslateMessage.cs | 7 ++-- .../Commands/ContextMenu/UserInfoUser.cs | 2 +- .../Commands/Slash/About.cs | 7 ++-- .../Commands/Slash/Jumpad.cs | 11 +++-- .../Commands/Slash/MessageSnipe.cs | 2 +- .../Commands/Slash/Purge.cs | 5 +-- .../Commands/Slash/RoleSelection.cs | 9 ++-- .../Commands/Slash/StarboardConfig.cs | 3 +- .../Commands/Slash/Translation.cs | 5 +-- .../Commands/Slash/VoiceAlerts.cs | 5 +-- .../Commands/Slash/moveEmoji.cs | 8 ++-- .../Commands/Text/Base/ExitGuild.cs | 4 +- .../CustomComponents/ActionDiscordButton.cs | 3 +- .../EventListener.ActionButtons.cs | 42 +++++++++---------- .../EventListeners/EventListener.Dms.cs | 2 +- .../EventListeners/EventListener.Errors.cs | 2 +- .../EventListener.GuildDownload.cs | 1 - .../EventListener.RoleSelection.cs | 2 +- .../ModularAssistentForDiscordServer.csproj | 11 +++-- .../Services/DiscordClientService.cs | 4 +- .../Services/LoggingService.cs | 8 ++-- 23 files changed, 72 insertions(+), 92 deletions(-) diff --git a/ModularAssistentForDiscordServer/Commands/AutoCompletion/ReminderAutoCompletion.cs b/ModularAssistentForDiscordServer/Commands/AutoCompletion/ReminderAutoCompletion.cs index 86db041..c91aca3 100644 --- a/ModularAssistentForDiscordServer/Commands/AutoCompletion/ReminderAutoCompletion.cs +++ b/ModularAssistentForDiscordServer/Commands/AutoCompletion/ReminderAutoCompletion.cs @@ -31,22 +31,14 @@ public ReminderAutoCompletion(IServiceProvider services) public async Task> Provider(AutocompleteContext ctx) { - //TODO Userinput is not working (The input string '' was not in a correct format.) - /*long currentInput = (long?) ctx.OptionValue ?? 0; - string currentInputString = currentInput.ToString(); - if (currentInputString == "0") - { - currentInputString = ""; - } - */ - await using MadsContext db = await _factory.CreateDbContextAsync(); IEnumerable choices = db.Reminders .Where(x => x.UserId == ctx.User.Id) .Select(x => x.Id.ToString()) - .ToList() - //.Where(x => x.StartsWith(currentInputString)) - .Select(x => new DiscordAutoCompleteChoice(x, x)); + .Take(25) + .Select(x => new DiscordAutoCompleteChoice(x, x)) + .ToList(); + return choices; } } \ No newline at end of file diff --git a/ModularAssistentForDiscordServer/Commands/ContextMenu/StealEmojiMessage.cs b/ModularAssistentForDiscordServer/Commands/ContextMenu/StealEmojiMessage.cs index 9b241ac..7c75c87 100644 --- a/ModularAssistentForDiscordServer/Commands/ContextMenu/StealEmojiMessage.cs +++ b/ModularAssistentForDiscordServer/Commands/ContextMenu/StealEmojiMessage.cs @@ -13,7 +13,6 @@ // limitations under the License. using System.Text.RegularExpressions; -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; @@ -30,8 +29,8 @@ public StealEmojiMessage(HttpClient httpClient) _httpClient = httpClient; } - [ContextMenu(ApplicationCommandType.MessageContextMenu, "Steal emoji(s)"), - SlashRequirePermissions(Permissions.ManageEmojis)] + [ContextMenu(DiscordApplicationCommandType.MessageContextMenu, "Steal emoji(s)"), + SlashRequirePermissions(DiscordPermissions.ManageEmojis)] public async Task YoinkAsync(ContextMenuContext ctx) { await ctx.DeferAsync(true); diff --git a/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs b/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs index 6daf0c5..6b79ff5 100644 --- a/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs +++ b/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs @@ -14,7 +14,6 @@ using DeepL; using DeepL.Model; -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using MADS.CustomComponents; @@ -35,7 +34,7 @@ public TranslateMessage(TranslateInformationService translateInformationService, _translator = translator; } - [ContextMenu(ApplicationCommandType.MessageContextMenu, "Translate message")] + [ContextMenu(DiscordApplicationCommandType.MessageContextMenu, "Translate message")] public async Task TranslateAsync(ContextMenuContext ctx) { await ctx.DeferAsync(true); @@ -84,8 +83,8 @@ public async Task TranslateAsync(ContextMenuContext ctx) DiscordFollowupMessageBuilder followUpMessage = new DiscordFollowupMessageBuilder() .WithContent("⚠️ You haven't set a preferred language yet. Default is english.") - .AddComponents(new DiscordButtonComponent(ButtonStyle.Primary, "setLanguage", "Set language").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage)) - .AddComponents(new DiscordButtonComponent(ButtonStyle.Primary, "setLanguage", "Set your language to en-US").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage, "en-US")) + .AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Primary, "setLanguage", "Set language").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage)) + .AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Primary, "setLanguage", "Set your language to en-US").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage, "en-US")) .AsEphemeral(); diff --git a/ModularAssistentForDiscordServer/Commands/ContextMenu/UserInfoUser.cs b/ModularAssistentForDiscordServer/Commands/ContextMenu/UserInfoUser.cs index 2ce3f74..c272b07 100644 --- a/ModularAssistentForDiscordServer/Commands/ContextMenu/UserInfoUser.cs +++ b/ModularAssistentForDiscordServer/Commands/ContextMenu/UserInfoUser.cs @@ -23,7 +23,7 @@ namespace MADS.Commands.ContextMenu; public class UserInfoUser : MadsBaseApplicationCommand { - [ContextMenu(ApplicationCommandType.UserContextMenu, "Info")] + [ContextMenu(DiscordApplicationCommandType.UserContextMenu, "Info")] public async Task GetUserInfo(ContextMenuContext ctx) { DiscordUser user = ctx.TargetUser; diff --git a/ModularAssistentForDiscordServer/Commands/Slash/About.cs b/ModularAssistentForDiscordServer/Commands/Slash/About.cs index 617245b..8350734 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/About.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/About.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using Humanizer; @@ -27,7 +26,7 @@ public async Task AboutCommand(InteractionContext ctx) { DiscordEmbedBuilder discordEmbedBuilder = new(); DiscordInteractionResponseBuilder discordMessageBuilder = new(); - string inviteUri = ctx.Client.CurrentApplication.GenerateOAuthUri(null, Permissions.Administrator, DiscordOAuthScope.Bot, + string inviteUri = ctx.Client.CurrentApplication.GenerateOAuthUri(null, DiscordPermissions.Administrator, DiscordOAuthScope.Bot, DiscordOAuthScope.ApplicationsCommands); string addMe = $"[Click here!]({inviteUri.Replace(" ", "%20")})"; @@ -49,10 +48,10 @@ public async Task AboutCommand(InteractionContext ctx) .AddField("Add me", addMe); discordMessageBuilder.AddEmbed(discordEmbedBuilder.Build()); - discordMessageBuilder.AddComponents(new DiscordButtonComponent(ButtonStyle.Success, "feedback-button", + discordMessageBuilder.AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Success, "feedback-button", "Feedback")); discordMessageBuilder.AsEphemeral(); - await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, discordMessageBuilder); + await ctx.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, discordMessageBuilder); } } \ No newline at end of file diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs b/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs index 33d11c2..1b09bf4 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using MADS.CustomComponents; @@ -24,26 +23,26 @@ namespace MADS.Commands.Slash; [GuildOnly] public sealed class Jumppad : MadsBaseApplicationCommand { - [SlashCommand("jumppad", "Create a jumppad button"), SlashCommandPermissions(Permissions.MoveMembers)] + [SlashCommand("jumppad", "Create a jumppad button"), SlashCommandPermissions(DiscordPermissions.MoveMembers)] public async Task Test ( InteractionContext ctx, - [Option("originChannel", "Channel where the users will be moved out"), ChannelTypes(ChannelType.Voice)] + [Option("originChannel", "Channel where the users will be moved out"), ChannelTypes(DiscordChannelType.Voice)] DiscordChannel originChannel, - [Option("targetChannel", "Channel where the users will be put in"), ChannelTypes(ChannelType.Voice)] + [Option("targetChannel", "Channel where the users will be put in"), ChannelTypes(DiscordChannelType.Voice)] DiscordChannel targetChannel, [Option("message", "Message to be sent")] string? content = null ) { DiscordInteractionResponseBuilder message = new(); - DiscordButtonComponent newButton = new(ButtonStyle.Success, "Placeholder", "Jump"); + DiscordButtonComponent newButton = new(DiscordButtonStyle.Success, "Placeholder", "Jump"); newButton = newButton.AsActionButton( ActionDiscordButtonEnum.MoveVoiceChannel, originChannel.Id, targetChannel.Id); message.AddComponents(newButton); message.WithContent(!content.IsNullOrWhiteSpace() ? content! : "Jumppad"); - await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, message); + await ctx.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, message); } } \ No newline at end of file diff --git a/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs b/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs index f04227a..d8da93f 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs @@ -100,7 +100,7 @@ private async Task DoSnipeAsync(InteractionContext ctx, bool edit) DiscordWebhookBuilder response = new DiscordWebhookBuilder() .AddEmbeds(embeds.Prepend(embed).Select(x => x.Build())); - DiscordButtonComponent btn = new(ButtonStyle.Danger, "placeholder", "Delete (Author only)", + DiscordButtonComponent btn = new(DiscordButtonStyle.Danger, "placeholder", "Delete (Author only)", emoji: new DiscordComponentEmoji("🗑")); btn = btn.AsActionButton(ActionDiscordButtonEnum.DeleteOneUserOnly, message.Author!.Id); diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs b/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs index c8d7a94..ae131d3 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Purge.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; @@ -23,7 +22,7 @@ namespace MADS.Commands.Slash; public sealed class Purge : MadsBaseApplicationCommand { [SlashCommand("purge", "Purges messages"), - SlashRequirePermissions(Permissions.ManageMessages), + SlashRequirePermissions(DiscordPermissions.ManageMessages), SlashRequireGuild] public async Task PurgeMessages ( @@ -36,7 +35,7 @@ public async Task PurgeMessages return; } - await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, + await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder()); DiscordMessage response = await ctx.GetOriginalResponseAsync(); diff --git a/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs b/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs index 0edf4fb..e96e303 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/RoleSelection.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.EventArgs; using DSharpPlus.Interactivity; @@ -26,7 +25,7 @@ namespace MADS.Commands.Slash; public sealed class RoleSelection : MadsBaseApplicationCommand { [SlashCommand("RoleSelection", "Use this command in the channel the message should be posted"), - SlashRequirePermissions(Permissions.ManageRoles), + SlashRequirePermissions(DiscordPermissions.ManageRoles), SlashRequireGuild] public async Task RoleSelectionCreation ( @@ -36,7 +35,7 @@ public async Task RoleSelectionCreation ) { //show we are processing - await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, + await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral()); //check if the command was not triggered in a guild and if so abort @@ -47,7 +46,7 @@ await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWith } //check if the user has the required permissons - if (!ctx.Member.Permissions.HasPermission(Permissions.ManageRoles)) + if (!ctx.Member.Permissions.HasPermission(DiscordPermissions.ManageRoles)) { await ctx.EditResponseAsync( new DiscordWebhookBuilder().WithContent( @@ -89,7 +88,7 @@ await ctx.EditResponseAsync(new DiscordWebhookBuilder } //acknowledge interaction and edit first response to delete the select menu - await selectResponse.Result.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate); + await selectResponse.Result.Interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate); await ctx.EditResponseAsync(new DiscordWebhookBuilder { Content = "Submitted" diff --git a/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs b/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs index 30ee824..fbca794 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs @@ -13,7 +13,6 @@ // limitations under the License. using System.Text.RegularExpressions; -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; @@ -36,7 +35,7 @@ public StarboardConfig(IDbContextFactory contextFactory) } [SlashCommand("Starboard", "Configure Starboard"), - SlashRequirePermissions(Permissions.ManageGuild), + SlashRequirePermissions(DiscordPermissions.ManageGuild), SlashRequireGuild] public async Task StarboardConfigCommand ( diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs b/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs index a80817f..ecb2270 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs @@ -14,7 +14,6 @@ using DeepL; using DeepL.Model; -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using MADS.Commands.AutoCompletion; @@ -45,7 +44,7 @@ public async Task SetLanguageAsync { if (string.IsNullOrWhiteSpace(language)) { - await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await ctx.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder() .WithContent("⚠️ Language can't be empty!")); return; @@ -55,7 +54,7 @@ await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, _translationUserInfo.SetPreferredLanguage(ctx.User.Id, code); - await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await ctx.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder() .WithContent($"✅ Language set to {code}")); } diff --git a/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs b/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs index dd2cd0b..9d76ce8 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/VoiceAlerts.cs @@ -13,7 +13,6 @@ // limitations under the License. using System.Text; -using DSharpPlus; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using MADS.Commands.AutoCompletion; @@ -37,7 +36,7 @@ public VoiceAlerts(VoiceAlertService voiceAlertService) public async Task AddAlert ( InteractionContext ctx, - [Option("channel", "channel which will be monitored")] + [Option("channel", "channel which will be monitored"), ChannelTypes(DiscordChannelType.Voice, DiscordChannelType.Stage)] DiscordChannel channel, [Option("minTimeBetween", "time which has to pass between alerts")] TimeSpan? minTimeBetween, @@ -45,7 +44,7 @@ public async Task AddAlert bool repeat = false ) { - if (channel.Type is not (ChannelType.Voice or ChannelType.Stage)) + if (channel.Type is not (DiscordChannelType.Voice or DiscordChannelType.Stage)) { await CreateResponse_Error($"<#{channel.Id}> is not a voice channel", true); return; diff --git a/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs b/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs index 445a30e..c5092c8 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs @@ -27,11 +27,11 @@ namespace MADS.Commands.Slash; public sealed partial class MoveEmoji : MadsBaseApplicationCommand { - [SlashCommand("MoveEmoji", "Move emoji to your guild"), SlashRequirePermissions(Permissions.ManageEmojis)] + [SlashCommand("MoveEmoji", "Move emoji to your guild"), SlashRequirePermissions(DiscordPermissions.ManageEmojis)] public async Task MoveEmojiAsync (InteractionContext ctx, [Option("Emoji", "Emoji which should be moved")] string pEmoji) { - await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, + await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral()); MatchCollection matches = EmojiRegex().Matches(pEmoji); @@ -59,7 +59,7 @@ await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWith try { DiscordMember member = await guild.GetMemberAsync(ctx.User.Id); - if (member.Permissions.HasFlag(Permissions.ManageEmojis)) + if (member.Permissions.HasFlag(DiscordPermissions.ManageEmojis)) { guilds.Add(guild); } @@ -98,7 +98,7 @@ await ctx.EditResponseAsync(new DiscordWebhookBuilder } //acknowledge interaction and edit first response to delete the select menu - await selectResponse.Result.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await selectResponse.Result.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Submitted").AsEphemeral()); await ctx.EditResponseAsync(new DiscordWebhookBuilder { diff --git a/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs b/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs index a62400d..158a529 100644 --- a/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs +++ b/ModularAssistentForDiscordServer/Commands/Text/Base/ExitGuild.cs @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -using DSharpPlus; using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; +using DSharpPlus.Entities; using MADS.Extensions; namespace MADS.Commands.Text.Base; public class ExitGuild : MadsBaseCommand { - [Command("exit"), Description("Exit the bot"), RequirePermissions(Permissions.ManageGuild), RequireGuild] + [Command("exit"), Description("Exit the bot"), RequirePermissions(DiscordPermissions.ManageGuild), RequireGuild] public async Task ExitGuildCommand(CommandContext ctx) { await ctx.RespondAsync("Leaving server..."); diff --git a/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs b/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs index 8489072..f2e5069 100644 --- a/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs +++ b/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using DSharpPlus; using DSharpPlus.Entities; namespace MADS.CustomComponents; @@ -161,7 +160,7 @@ params object[] args } string label = button.Label; - ButtonStyle style = button.Style; + DiscordButtonStyle style = button.Style; DiscordButtonComponent commandButton = new(style, customId, label); return commandButton; diff --git a/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs b/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs index 93955fe..c8dee82 100644 --- a/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs +++ b/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs @@ -107,10 +107,10 @@ private static async Task SetTranslationLanguage(ComponentInteractionCreateEvent DiscordInteractionResponseBuilder modal = new DiscordInteractionResponseBuilder() .WithTitle("Set your preferred language:") .WithCustomId($"setLanguage-{args.User.Id}") - .AddComponents(new TextInputComponent("Please enter your preferred language:", "answer-text", + .AddComponents(new DiscordTextInputComponent("Please enter your preferred language:", "answer-text", required: true, - style: TextInputStyle.Paragraph)); - await args.Interaction.CreateResponseAsync(InteractionResponseType.Modal, modal); + style: DiscordTextInputStyle.Paragraph)); + await args.Interaction.CreateResponseAsync(DiscordInteractionResponseType.Modal, modal); InteractivityExtension interactive = sender.GetInteractivity(); InteractivityResult result = await interactive.WaitForModalAsync($"setLanguage-{args.User.Id}"); @@ -128,14 +128,14 @@ await args.Interaction.CreateFollowupMessageAsync( if (substring.Length != 2) { - await args.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await args.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("400 - Bad Request").AsEphemeral()); return; } translationService.SetPreferredLanguage(args.User.Id, substring[2]); - await args.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await args.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AddEmbed(langSetEmbed).AsEphemeral()); } @@ -144,7 +144,7 @@ private static async Task AnswerDmChannel(ComponentInteractionCreateEventArgs e, { if (!(client.CurrentApplication.Owners?.Contains(e.User) ?? false)) { - await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("401 - Unauthorized").AsEphemeral()); return; } @@ -152,9 +152,9 @@ await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWi DiscordInteractionResponseBuilder modal = new DiscordInteractionResponseBuilder() .WithTitle("Answer to user:") .WithCustomId($"AnswerDM-{substring[1]}") - .AddComponents(new TextInputComponent("Please enter your answer:", "answer-text", required: true, - style: TextInputStyle.Paragraph)); - await e.Interaction.CreateResponseAsync(InteractionResponseType.Modal, modal); + .AddComponents(new DiscordTextInputComponent("Please enter your answer:", "answer-text", required: true, + style: DiscordTextInputStyle.Paragraph)); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.Modal, modal); InteractivityExtension interactive = client.GetInteractivity(); @@ -162,7 +162,7 @@ await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWi if (result.TimedOut) { - await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("408 - Request Timeout").AsEphemeral()); return; } @@ -195,7 +195,7 @@ await result.Result.Interaction.EditOriginalResponseAsync( DiscordMessageBuilder editedMessage = new(e.Message); editedMessage.ClearComponents(); editedMessage.AddComponents( - new DiscordButtonComponent(ButtonStyle.Success, "invalid", "Already answered", true)); + new DiscordButtonComponent(DiscordButtonStyle.Success, "invalid", "Already answered", true)); await e.Message.ModifyAsync(editedMessage); @@ -208,7 +208,7 @@ private static async Task DeleteOneUserOnly(ComponentInteractionCreateEventArgs return; } - await e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate); await e.Message.DeleteAsync(); } @@ -218,10 +218,10 @@ private static async Task MoveVoiceChannelUser IReadOnlyList substring ) { - await e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate); DiscordMember member = await e.Guild.GetMemberAsync(e.User.Id); - if (!member.Permissions.HasPermission(Permissions.MoveMembers)) + if (!member.Permissions.HasPermission(DiscordPermissions.MoveMembers)) { return; } @@ -237,9 +237,9 @@ IReadOnlyList substring private static async Task BanUser(ComponentInteractionCreateEventArgs e, IReadOnlyList substring) { - await e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate); DiscordMember member = await e.Guild.GetMemberAsync(e.User.Id); - if (!member.Permissions.HasPermission(Permissions.BanMembers)) + if (!member.Permissions.HasPermission(DiscordPermissions.BanMembers)) { return; } @@ -251,14 +251,14 @@ private static async Task BanUser(ComponentInteractionCreateEventArgs e, IReadOn private static async Task KickUser(ComponentInteractionCreateEventArgs e, IReadOnlyList substring) { DiscordMember member = await e.Guild.GetMemberAsync(e.User.Id); - if (!member.Permissions.HasPermission(Permissions.KickMembers)) + if (!member.Permissions.HasPermission(DiscordPermissions.KickMembers)) { return; } ulong userId = ulong.Parse(substring[1]); await e.Guild.BanMemberAsync(userId); - await e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate); } private static async Task GetUserId(InteractionCreateEventArgs e, IReadOnlyList substring) @@ -268,7 +268,7 @@ private static async Task GetUserId(InteractionCreateEventArgs e, IReadOnlyList< response.WithContent("User id: " + ulong.Parse(substring[1])) .AsEphemeral(); - await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, response); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, response); } private static async Task GetGuildId(InteractionCreateEventArgs e, IReadOnlyList substring) @@ -278,7 +278,7 @@ private static async Task GetGuildId(InteractionCreateEventArgs e, IReadOnlyList response.WithContent("Guild id: " + ulong.Parse(substring[1])) .AsEphemeral(); - await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, response); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, response); } private static async Task GetChannelId(InteractionCreateEventArgs e, IReadOnlyList substring) @@ -288,7 +288,7 @@ private static async Task GetChannelId(InteractionCreateEventArgs e, IReadOnlyLi response.WithContent("Channel id: " + ulong.Parse(substring[1])) .AsEphemeral(); - await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, response); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, response); } [GeneratedRegex("^CMD:\\d{1,4}(?::\\d{1,20}){0,3}$", RegexOptions.Compiled)] diff --git a/ModularAssistentForDiscordServer/EventListeners/EventListener.Dms.cs b/ModularAssistentForDiscordServer/EventListeners/EventListener.Dms.cs index 8dbcd33..0238583 100644 --- a/ModularAssistentForDiscordServer/EventListeners/EventListener.Dms.cs +++ b/ModularAssistentForDiscordServer/EventListeners/EventListener.Dms.cs @@ -71,7 +71,7 @@ internal static async Task DmHandler(DiscordClient client, MessageCreateEventArg .WithDescription(e.Message.Content); DiscordButtonComponent button = - new DiscordButtonComponent(ButtonStyle.Success, "Placeholder", "Respond to User").AsActionButton( + new DiscordButtonComponent(DiscordButtonStyle.Success, "Placeholder", "Respond to User").AsActionButton( ActionDiscordButtonEnum.AnswerDmChannel, e.Channel.Id); DiscordChannel channel = await client.GetChannelAsync(WebhookClient.Webhooks[0].ChannelId); diff --git a/ModularAssistentForDiscordServer/EventListeners/EventListener.Errors.cs b/ModularAssistentForDiscordServer/EventListeners/EventListener.Errors.cs index fb0529b..2da2a27 100644 --- a/ModularAssistentForDiscordServer/EventListeners/EventListener.Errors.cs +++ b/ModularAssistentForDiscordServer/EventListeners/EventListener.Errors.cs @@ -50,7 +50,7 @@ internal static async Task OnSlashCommandErrored(SlashCommandsExtension sender, try { - await e.Context.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await e.Context.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AddEmbed(discordEmbed).AsEphemeral()); return; } diff --git a/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs b/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs index 03cc62a..66d0e22 100644 --- a/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs +++ b/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs @@ -69,7 +69,6 @@ IDbContextFactory dbFactory { Id = user.Id, Username = user.Username, - Discriminator = Convert.ToInt32(user.Discriminator), PreferedLanguage = "en-US" }; diff --git a/ModularAssistentForDiscordServer/EventListeners/EventListener.RoleSelection.cs b/ModularAssistentForDiscordServer/EventListeners/EventListener.RoleSelection.cs index 5e4cb72..b064866 100644 --- a/ModularAssistentForDiscordServer/EventListeners/EventListener.RoleSelection.cs +++ b/ModularAssistentForDiscordServer/EventListeners/EventListener.RoleSelection.cs @@ -33,7 +33,7 @@ internal static async Task OnRoleSelection(DiscordClient client, ComponentIntera } //TODO Test if "await e.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate);" is possible - await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Roles granted/revoked").AsEphemeral()); DiscordMember member = await e.Guild.GetMemberAsync(e.User.Id); diff --git a/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj b/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj index c2549b3..fcca0b4 100644 --- a/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj +++ b/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj @@ -25,12 +25,11 @@ - - - - - - + + + + + diff --git a/ModularAssistentForDiscordServer/Services/DiscordClientService.cs b/ModularAssistentForDiscordServer/Services/DiscordClientService.cs index f0ed9f3..5d68b9d 100644 --- a/ModularAssistentForDiscordServer/Services/DiscordClientService.cs +++ b/ModularAssistentForDiscordServer/Services/DiscordClientService.cs @@ -140,10 +140,10 @@ public async Task StartAsync(CancellationToken cancellationToken) _logger.Warning("Applied pending migrations in {Time} ms", sw.ElapsedMilliseconds); } - DiscordActivity act = new("Messing with code", ActivityType.Custom); + DiscordActivity act = new("Messing with code", DiscordActivityType.Custom); //connect client - await DiscordClient.ConnectAsync(act, UserStatus.Online); + await DiscordClient.ConnectAsync(act, DiscordUserStatus.Online); } public Task StopAsync(CancellationToken cancellationToken) diff --git a/ModularAssistentForDiscordServer/Services/LoggingService.cs b/ModularAssistentForDiscordServer/Services/LoggingService.cs index e9d5716..b07420f 100644 --- a/ModularAssistentForDiscordServer/Services/LoggingService.cs +++ b/ModularAssistentForDiscordServer/Services/LoggingService.cs @@ -139,10 +139,10 @@ private void SetupFeedback() modal .WithTitle("Feedback") .WithCustomId("feedback-modal") - .AddComponents(new TextInputComponent("Please enter your feedback:", "feedback-text", required: true, - style: TextInputStyle.Paragraph)); + .AddComponents(new DiscordTextInputComponent("Please enter your feedback:", "feedback-text", required: true, + style: DiscordTextInputStyle.Paragraph)); - await e.Interaction.CreateResponseAsync(InteractionResponseType.Modal, modal); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.Modal, modal); }; //Modal processing @@ -164,7 +164,7 @@ private void SetupFeedback() .AddEmbed(embedBuilder) .AsEphemeral(); - await e.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, responseBuilder); + await e.Interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, responseBuilder); // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract string guildName =