Skip to content

Commit

Permalink
Update D#+
Browse files Browse the repository at this point in the history
  • Loading branch information
Plerx2493 committed Apr 22, 2024
1 parent 3dcb576 commit 0794eb6
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,14 @@ public ReminderAutoCompletion(IServiceProvider services)

public async Task<IEnumerable<DiscordAutoCompleteChoice>> 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<DiscordAutoCompleteChoice> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using System.Text.RegularExpressions;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using DeepL;
using DeepL.Model;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using MADS.CustomComponents;
Expand All @@ -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);
Expand Down Expand Up @@ -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();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions ModularAssistentForDiscordServer/Commands/Slash/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")})";

Expand All @@ -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);
}
}
11 changes: 5 additions & 6 deletions ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions ModularAssistentForDiscordServer/Commands/Slash/Purge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
(
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
(
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using System.Text.RegularExpressions;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
Expand All @@ -36,7 +35,7 @@ public StarboardConfig(IDbContextFactory<MadsContext> contextFactory)
}

[SlashCommand("Starboard", "Configure Starboard"),
SlashRequirePermissions(Permissions.ManageGuild),
SlashRequirePermissions(DiscordPermissions.ManageGuild),
SlashRequireGuild]
public async Task StarboardConfigCommand
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using DeepL;
using DeepL.Model;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using MADS.Commands.AutoCompletion;
Expand Down Expand Up @@ -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;
Expand All @@ -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}"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using System.Text;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using MADS.Commands.AutoCompletion;
Expand All @@ -37,15 +36,15 @@ 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,
[Option("repeat", "repeat the alert")]
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;
Expand Down
8 changes: 4 additions & 4 deletions ModularAssistentForDiscordServer/Commands/Slash/moveEmoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 0794eb6

Please sign in to comment.