Skip to content

Commit

Permalink
Upgrade DSharpPlus to 5.0.0-nightly-02383
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Oct 14, 2024
1 parent 36e49d3 commit 89c1fda
Show file tree
Hide file tree
Showing 50 changed files with 3,251 additions and 3,097 deletions.
38 changes: 20 additions & 18 deletions Commands/AboutCommands.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
namespace MechanicalMilkshake.Commands;

public class AboutCommands : ApplicationCommandModule
public class AboutCommands
{
[SlashCommand("about", "View information about me!")]
public static async Task About(InteractionContext ctx)
[Command("about")]
[Description("View information about me!")]
public static async Task About(SlashCommandContext ctx)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);
await ctx.DeferResponseAsync();

// Set this to an empty string to disable the Privacy Policy notice in /about, or change it to your own
// Privacy Policy URL if you have one.
const string privacyPolicyUrl = "https://floatingmilkshake.com/privacy#MechanicalMilkshake";

// Set this to an empty string to disable the Support Server notice in /about, or change it your own
// Support Server invite if you have one.
const string supportServerInvite = "https://floatingmilkshake.link/bot/support";
const string supportServerInvite = "https://milkshake.wtf/bot/support";

// Create embed
// Description
Expand Down Expand Up @@ -55,35 +56,36 @@ public static async Task About(InteractionContext ctx)
+ "\n- DM the bot itself (DMs are forwarded to owners!)"
+ "\n- DM a bot owner (see above for a list!)");

await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(embed));
await ctx.FollowupAsync(embed);
}

[SlashCommand("version", "Show my version information.")]
public static async Task CommitInfo(InteractionContext ctx,
[Option("extended", "Whether to show extended info. Defaults to False.")] bool extended = false)
[Command("version")]
[Description("Show my version information.")]
public static async Task CommitInfo(SlashCommandContext ctx,
[Parameter("extended"), Description("Whether to show extended info. Defaults to False.")] bool extended = false)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);
await ctx.DeferResponseAsync();

if (extended) {
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(
await DebugInfoHelpers.GenerateDebugInfoEmbed(false)));
await ctx.FollowupAsync(await DebugInfoHelpers.GenerateDebugInfoEmbed(false));
return;
}

var commitHash = await FileHelpers.ReadFileAsync("CommitHash.txt", "dev");
var commitMessage = await FileHelpers.ReadFileAsync("CommitMessage.txt", "dev");
var commitUrl = await FileHelpers.ReadFileAsync("RemoteUrl.txt");

await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder()
await ctx.FollowupAsync(new DiscordEmbedBuilder()
.WithColor(Program.BotColor)
.AddField("Version", commitHash == "dev" ? "`dev`" : $"[`{commitHash}`]({commitUrl}): {commitMessage}")
.AddField("Last updated on", DebugInfoHelpers.GetDebugInfo().CommitTimestamp)));
.AddField("Last updated on", DebugInfoHelpers.GetDebugInfo().CommitTimestamp));
}

[SlashCommand("uptime", "Check my uptime!")]
public static async Task Uptime(InteractionContext ctx)
[Command("uptime")]
[Description("Check my uptime!")]
public static async Task Uptime(SlashCommandContext ctx)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);
await ctx.DeferResponseAsync();

DiscordEmbedBuilder embed = new()
{
Expand All @@ -99,6 +101,6 @@ public static async Task Uptime(InteractionContext ctx)
embed.AddField("Process started at", $"<t:{startUnixTime}:F> (<t:{startUnixTime}:R>)");
embed.AddField("Last connected to Discord at", $"<t:{connectUnixTime}:F> (<t:{connectUnixTime}:R>)");

await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(embed));
await ctx.FollowupAsync(embed);
}
}
18 changes: 9 additions & 9 deletions Commands/Avatar.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace MechanicalMilkshake.Commands;

public class Avatar : ApplicationCommandModule
public class Avatar
{
[SlashCommand("avatar",
"Returns the avatar of the provided user. Defaults to yourself if no user is provided.")]
public static async Task AvatarCommand(InteractionContext ctx,
[Option("user", "The user whose avatar to get.")]
[Command("avatar")]
[Description("Returns the avatar of the provided user. Defaults to yourself if no user is provided.")]
public static async Task AvatarCommand(SlashCommandContext ctx,
[Parameter("user"), Description("The user whose avatar to get.")]
DiscordUser user = null)
{
DiscordButtonComponent serverAvatarButton =
new(ButtonStyle.Primary, "server-avatar-ctx-cmd-button", "Server Avatar");
new(DiscordButtonStyle.Primary, "server-avatar-ctx-cmd-button", "Server Avatar");
DiscordButtonComponent userAvatarButton =
new(ButtonStyle.Primary, "user-avatar-ctx-cmd-button", "User Avatar");
new(DiscordButtonStyle.Primary, "user-avatar-ctx-cmd-button", "User Avatar");

user ??= ctx.User;

Expand All @@ -26,11 +26,11 @@ public static async Task AvatarCommand(InteractionContext ctx,
}

if (member == default || member.GuildAvatarUrl is null)
await ctx.CreateResponseAsync(
await ctx.RespondAsync(
new DiscordInteractionResponseBuilder().WithContent(
$"{user.AvatarUrl}".Replace("size=1024", "size=4096")));
else
await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder()
await ctx.RespondAsync(new DiscordInteractionResponseBuilder()
.WithContent(
$"You requested the avatar for {user.Mention}. Please choose one of the options below.")
.AddComponents(serverAvatarButton, userAvatarButton));
Expand Down
44 changes: 22 additions & 22 deletions Commands/BanCommands.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
namespace MechanicalMilkshake.Commands;

[SlashRequireGuild]
public class BanCommands : ApplicationCommandModule
[RequireGuild]
public class BanCommands
{
[SlashCommand("ban", "Ban a user. They will not be able to rejoin unless unbanned.", false)]
[SlashCommandPermissions(Permissions.BanMembers)]
public static async Task BanCommand(InteractionContext ctx,
[Option("user", "The user to ban.")] DiscordUser userToBan,
[Option("reason", "The reason for the ban.")] [MaximumLength(1500)]
[Command("ban")]
[Description("Ban a user. They will not be able to rejoin unless unbanned.")]
[RequirePermissions(DiscordPermissions.BanMembers)]
public static async Task BanCommand(SlashCommandContext ctx,
[Parameter("user"), Description("The user to ban.")] DiscordUser userToBan,
[Parameter("reason"), Description("The reason for the ban.")] [MinMaxLength(maxLength: 1500)]
string reason = "No reason provided.")
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource,
new DiscordInteractionResponseBuilder().AsEphemeral());
await ctx.DeferResponseAsync(true);

try
{
await ctx.Guild.BanMemberAsync(userToBan.Id, 0, reason);
await ctx.Guild.BanMemberAsync(userToBan.Id, TimeSpan.Zero, reason);
}
catch (UnauthorizedException)
{
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder()
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder()
.WithContent(
$"Something went wrong. You or I may not be allowed to ban **{UserInfoHelpers.GetFullUsername(userToBan)}**! Please check the role hierarchy and permissions.")
.AsEphemeral());
return;
}
catch (Exception e)
{
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent(
$"Hmm, something went wrong while trying to ban that user!\n\nThis was Discord's response:\n> {e.Message}")
.AsEphemeral());
return;
}

await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder()
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder()
.WithContent("User banned successfully.").AsEphemeral());
await ctx.Channel.SendMessageAsync($"{userToBan.Mention} has been banned: **{reason}**");
}

[SlashCommand("unban", "Unban a user.", false)]
[SlashCommandPermissions(Permissions.BanMembers)]
public static async Task UnbanCommand(InteractionContext ctx,
[Option("user", "The user to unban.")] DiscordUser userToUnban)
[Command("unban")]
[Description("Unban a user.")]
[RequirePermissions(DiscordPermissions.BanMembers)]
public static async Task UnbanCommand(SlashCommandContext ctx,
[Parameter("user"), Description("The user to unban.")] DiscordUser userToUnban)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource,
new DiscordInteractionResponseBuilder().AsEphemeral());
await ctx.DeferResponseAsync(true);

try
{
await ctx.Guild.UnbanMemberAsync(userToUnban);
}
catch (UnauthorizedException)
{
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder()
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder()
.WithContent(
$"Something went wrong. You or I may not be allowed to unban **{UserInfoHelpers.GetFullUsername(userToUnban)}**! Please check the role hierarchy and permissions.")
.AsEphemeral());
return;
}
catch (Exception e)
{
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent(
$"Hmm, something went wrong while trying to unban that user!\n\nThis was Discord's response:\n> {e.Message}\n\nIf you'd like to contact the bot owner about this, include this debug info:\n```{e}\n```")
.AsEphemeral());
return;
}

await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder()
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder()
.WithContent("User unbanned successfully.").AsEphemeral());
await ctx.Channel.SendMessageAsync(
$"Successfully unbanned **{UserInfoHelpers.GetFullUsername(userToUnban)}**!");
Expand Down
11 changes: 6 additions & 5 deletions Commands/CharacterCount.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
namespace MechanicalMilkshake.Commands;

public class CharacterCount : ApplicationCommandModule
public class CharacterCount
{
[SlashCommand("charactercount", "Counts the characters in a message.")]
public static async Task CharacterCountCommand(InteractionContext ctx,
[Option("message", "The message to count the characters of.")]
[Command("charactercount")]
[Description("Counts the characters in a message.")]
public static async Task CharacterCountCommand(SlashCommandContext ctx,
[Parameter("message"), Description("The message to count the characters of.")]
string chars)
{
await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder().WithContent(chars.Length.ToString()));
await ctx.RespondAsync(new DiscordInteractionResponseBuilder().WithContent(chars.Length.ToString()));
}
}
Loading

0 comments on commit 89c1fda

Please sign in to comment.