Skip to content

Commit

Permalink
Update D#+
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed Jan 24, 2025
1 parent d7c1f09 commit 60eaac7
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 66 deletions.
2 changes: 1 addition & 1 deletion libs/DSharpPlus
Submodule DSharpPlus updated 147 files
2 changes: 1 addition & 1 deletion src/Commands/Common/AvatarCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace OoLunar.Tomoe.Commands.Common
/// <summary>
/// A command module for retrieving avatars from different sources. <see cref="AvatarCommand"/> is a top-level command.
/// </summary>
[Command("avatar"), TextAlias("pfp"), RequirePermissions(DiscordPermissions.EmbedLinks, DiscordPermissions.None)]
[Command("avatar"), TextAlias("pfp"), RequirePermissions([DiscordPermission.EmbedLinks], [])]
public sealed class AvatarCommand
{
private readonly ImageUtilities imageUtilitiesService;
Expand Down
22 changes: 10 additions & 12 deletions src/Commands/Common/DoctorCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -18,14 +17,14 @@ namespace OoLunar.Tomoe.Commands.Common
/// </summary>
public static class DoctorCommand
{
private const string AdministratorWarning = "⚠️ I have the `Administrator` permission; I can execute all of my commands without issue. It is advised you re-invite me with the proper permissions - for a boost in security. The `invite` command will give you the link with the correct permissions. ⚠️";
private const string AdministratorWarning = "⚠️ I have the `Administrator` permission; I can execute all of my commands without issue. It is advised you re-invite me with the proper permissions for a boost in security. The `invite` command will give you the link with the correct permissions. ⚠️";
private const string MissingRequiredPermissionsWarning = "❌ The following permissions are required for all commands to work properly: `Send Messages`, `Send Messages in Threads`, and `Access Channels`. Please re-invite me with the proper permissions. The `invite` command will give you the link with the correct permissions. ❌";
private const string DiffExplanation = "The red permissions are the permissions that I do not have. The green permissions are the ones I do have. If a command has a red permission, that means I cannot execute it.";

/// <summary>
/// Helps diagnose permission issues with the bot.
/// </summary>
[Command("doctor"), RequirePermissions(DiscordPermissions.AccessChannels | DiscordPermissions.SendMessages | DiscordPermissions.SendMessagesInThreads | DiscordPermissions.EmbedLinks, DiscordPermissions.None)]
[Command("doctor"), RequirePermissions([DiscordPermission.ViewChannel, DiscordPermission.SendMessages, DiscordPermission.SendThreadMessages, DiscordPermission.EmbedLinks], [])]
public static async ValueTask ExecuteAsync(CommandContext context)
{
DiscordEmbedBuilder embedBuilder = new()
Expand All @@ -41,17 +40,16 @@ public static async ValueTask ExecuteAsync(CommandContext context)
foreach (Command command in context.Extension.Commands.Values.OrderBy(x => x.Name))
{
DiscordPermissions permissions = GetCommandPermissions(command);
if (permissions == default)
if (permissions == DiscordPermissions.None)
{
continue;
}

StringBuilder stringBuilder = new();
stringBuilder.AppendLine(HelpCommandDocumentationMapperEventHandler.CommandDocumentation.TryGetValue(command, out string? documentation) ? documentation : "No description provided.");
stringBuilder.AppendLine("```diff");
for (ulong i = 0; i < (sizeof(ulong) * 8); i++)
foreach (DiscordPermission permission in DiscordPermissions.All.EnumeratePermissions())
{
DiscordPermissions permission = (DiscordPermissions)Math.Pow(2, i);
if (!permissions.HasFlag(permission))
{
continue;
Expand All @@ -65,26 +63,26 @@ public static async ValueTask ExecuteAsync(CommandContext context)
stringBuilder.Append("- ");
}

stringBuilder.AppendLine(permission.Humanize(LetterCasing.Title));
stringBuilder.AppendLine(permission.ToStringFast());
}

stringBuilder.AppendLine("```");
embedBuilder.AddField(command.Name.Titleize(), stringBuilder.ToString());
}

if (context.Guild.CurrentMember.Permissions.HasFlag(DiscordPermissions.Administrator))
if (context.Guild.CurrentMember.Permissions.HasFlag(DiscordPermission.Administrator))
{
embedBuilder.WithDescription(AdministratorWarning);
}
else if (!botPermissions.HasFlag(DiscordPermissions.SendMessages) || !botPermissions.HasFlag(DiscordPermissions.SendMessagesInThreads) || !botPermissions.HasFlag(DiscordPermissions.AccessChannels))
else if (!botPermissions.HasAllPermissions(DiscordPermission.SendMessages, DiscordPermission.SendThreadMessages, DiscordPermission.ViewChannel))
{
embedBuilder.WithDescription(MissingRequiredPermissionsWarning);
}

DiscordPermissions channelPermissions = context.Channel.PermissionsFor(context.Guild.CurrentMember);
if (context is TextCommandContext textCommandContext)
{
if (!channelPermissions.HasFlag(DiscordPermissions.SendMessages))
if (!channelPermissions.HasFlag(DiscordPermission.SendMessages))
{
try
{
Expand All @@ -94,7 +92,7 @@ public static async ValueTask ExecuteAsync(CommandContext context)
catch (DiscordException)
{
// Try to react to the message
if (channelPermissions.HasFlag(DiscordPermissions.AddReactions))
if (channelPermissions.HasFlag(DiscordPermission.AddReactions))
{
try
{
Expand All @@ -106,7 +104,7 @@ public static async ValueTask ExecuteAsync(CommandContext context)

return;
}
else if (!channelPermissions.HasFlag(DiscordPermissions.EmbedLinks))
else if (!channelPermissions.HasFlag(DiscordPermission.EmbedLinks))
{
embedBuilder.WithDescription("❌ This command requires the `Embed Links` permission to function. ❌");
await context.RespondAsync(embedBuilder);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/FlipCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class FlipCommand
/// <summary>
/// Heads or tails?
/// </summary>
[Command("flip"), TextAlias("random"), RequirePermissions(DiscordPermissions.EmbedLinks, DiscordPermissions.None)]
[Command("flip"), TextAlias("random"), RequirePermissions([DiscordPermission.EmbedLinks], [])]
public static async ValueTask ExecuteAsync(CommandContext context)
{
await context.DeferResponseAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/GuildIconCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class GuildIconCommand
/// <param name="imageFormat">The image format of the icon to get.</param>
/// <param name="imageDimensions">The maximum size of the icon. Must be a power of two, minimum 16, maximum 4096.</param>
/// <param name="guildId">The ID of the guild to get the icon from. Defaults to the current server.</param>
[Command("guild_icon"), TextAlias("guild_picture"), RequirePermissions(DiscordPermissions.EmbedLinks, DiscordPermissions.None)]
[Command("guild_icon"), TextAlias("guild_picture"), RequirePermissions([DiscordPermission.EmbedLinks], [])]
public static async ValueTask ExecuteAsync(CommandContext context, ImageFormat imageFormat = ImageFormat.Auto, ushort imageDimensions = 0, [SlashAutoCompleteProvider<SharedGuildsAutoCompleteProvider>] ulong guildId = 0)
{
if (guildId == 0)
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Common/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ private static DiscordMessageBuilder GetHelpMessage(CommandContext context, Cult
StringBuilder builder = new();
if (commonPermissions != default)
{
builder.AppendLine(commonPermissions.ToPermissionString());
builder.AppendLine(commonPermissions.EnumeratePermissions().Select(x => x.ToStringFast()).Humanize());
}

if (botUniquePermissions != default)
{
builder.Append("**Bot**: ");
builder.AppendLine((permissions.BotPermissions ^ commonPermissions).ToPermissionString());
builder.AppendLine((permissions.BotPermissions ^ commonPermissions).EnumeratePermissions().Select(x => x.ToStringFast()).Humanize());
}

if (userUniquePermissions != default)
{
builder.Append("**User**: ");
builder.AppendLine(permissions.UserPermissions.ToPermissionString());
builder.AppendLine(permissions.UserPermissions.EnumeratePermissions().Select(x => x.ToStringFast()).Humanize());
}

embed.AddField("Required Permissions", builder.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/HexCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class HexCommand
/// Returns information about the provided hex color code.
/// </summary>
/// <param name="hexCode">Which HTML hex code to get information about.</param>
[Command("hex"), RequirePermissions(DiscordPermissions.EmbedLinks | DiscordPermissions.AttachFiles, DiscordPermissions.None)]
[Command("hex"), RequirePermissions([DiscordPermission.EmbedLinks, DiscordPermission.AttachFiles], [])]
public static ValueTask ExecuteAsync(CommandContext context, string hexCode)
{
if (!IsValidHex(hexCode))
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/Common/InfoCommand/InfoCommand.Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using DSharpPlus;
using DSharpPlus.Commands;
using DSharpPlus.Entities;
using Humanizer;
using OoLunar.Tomoe.Database.Models;

namespace OoLunar.Tomoe.Commands.Common
Expand Down Expand Up @@ -38,7 +39,7 @@ public static async Task RoleInfoAsync(CommandContext context, DiscordRole role)
embedBuilder.AddField("Role Id", Formatter.InlineCode(role.Id.ToString(CultureInfo.InvariantCulture)), true);
embedBuilder.AddField("Role Name", role.Name, true);
embedBuilder.AddField("Role Position", role.Position.ToString("N0", await context.GetCultureAsync()), true);
embedBuilder.AddField("Permissions", role.Permissions == DiscordPermissions.None ? "No permissions." : role.Permissions.ToPermissionString() + ".", false);
embedBuilder.AddField("Permissions", role.Permissions == DiscordPermissions.None ? "No permissions." : role.Permissions.EnumeratePermissions().Select(x => x.ToStringFast()).Humanize() + ".", false);

int fieldCharCount = 0;
List<string> memberMentions = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/InfoCommand/InfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OoLunar.Tomoe.Commands.Common
/// <summary>
/// Shows general information about whatever the user wants.
/// </summary>
[Command("info"), RequirePermissions(DiscordPermissions.EmbedLinks, DiscordPermissions.None)]
[Command("info"), RequirePermissions([DiscordPermission.EmbedLinks], [])]
public sealed partial class InfoCommand
{
private readonly AllocationRateTracker _allocationRateTracker = new();
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Common/InviteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public static ValueTask InviteAsync(CommandContext context)
stringBuilder.Append("<https://discord.com/api/oauth2/authorize?client_id=");
stringBuilder.Append(context.Client.CurrentUser.Id);
stringBuilder.Append("&scope=bot%20applications.commands");
if (requiredPermissions != 0)
if (requiredPermissions != DiscordPermissions.None)
{
stringBuilder.Append("&permissions=");
stringBuilder.Append((long)requiredPermissions);
stringBuilder.Append(requiredPermissions.ToString());
}

stringBuilder.Append('>');
Expand All @@ -38,7 +38,7 @@ public static ValueTask InviteAsync(CommandContext context)

private static DiscordPermissions GetSubcommandsPermissions(IEnumerable<Command> subCommands)
{
DiscordPermissions permissions = 0;
DiscordPermissions permissions = DiscordPermissions.None;
foreach (Command subCommand in subCommands)
{
if (subCommand.Subcommands.Count != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/PollCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class PollCommand
/// <param name="question">What question to ask everyone.</param>
/// <param name="expiresAt">When the poll should end.</param>
/// <param name="options">The choices to choose from.</param>
[Command("poll"), Description("Create a poll."), RequirePermissions(DiscordPermissions.EmbedLinks, DiscordPermissions.None)]
[Command("poll"), Description("Create a poll."), RequirePermissions([DiscordPermission.EmbedLinks], [])]
public async ValueTask ExecuteAsync(CommandContext context, string question, TimeSpan expiresAt, params string[] options)
{
DateTimeOffset now = DateTimeOffset.UtcNow;
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Common/QuoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public static class QuoteCommand
/// Links a message from another channel.
/// </summary>
/// <param name="message">The message to repeat.</param>
[Command("quote"), TextAlias("rat", "mock", "q", "tattle-tale", "tattle"), RequirePermissions(DiscordPermissions.EmbedLinks | DiscordPermissions.ReadMessageHistory, DiscordPermissions.None)]
[Command("quote"), TextAlias("rat", "mock", "q", "tattle-tale", "tattle"), RequirePermissions([DiscordPermission.EmbedLinks, DiscordPermission.ReadMessageHistory], [])]
public static ValueTask ExecuteAsync(CommandContext context, DiscordMessage message)
{
if (!message.Channel!.PermissionsFor(context.Member!).HasPermission(DiscordPermissions.AccessChannels))
if (!message.Channel!.PermissionsFor(context.Member!).HasPermission(DiscordPermission.ViewChannel))
{
return context.RespondAsync("You don't have access to that message!");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/RawCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class RawCommand
/// </summary>
/// <param name="message">The message to get the raw content of.</param>
/// <param name="jsonfied">Whether to return the raw content as JSON.</param>
[Command("raw"), TextAlias("print"), DisplayName("Raw"), SlashCommandTypes(DiscordApplicationCommandType.SlashCommand, DiscordApplicationCommandType.MessageContextMenu), RequirePermissions(DiscordPermissions.ReadMessageHistory | DiscordPermissions.EmbedLinks, DiscordPermissions.None)]
[Command("raw"), TextAlias("print"), DisplayName("Raw"), SlashCommandTypes(DiscordApplicationCommandType.SlashCommand, DiscordApplicationCommandType.MessageContextMenu), RequirePermissions([DiscordPermission.ReadMessageHistory, DiscordPermission.EmbedLinks], [])]
public static ValueTask ExecuteAsync(CommandContext context, DiscordMessage? message = null, bool jsonfied = false)
{
if (context is TextCommandContext textContext && message is null)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/ReminderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public sealed class ReminderCommand
/// </summary>
/// <param name="expiresAt">When you should be notified.</param>
/// <param name="content">What you want to be reminded about.</param>
[Command("set"), DefaultGroupCommand, RequirePermissions(DiscordPermissions.AttachFiles, DiscordPermissions.None)]
[Command("set"), DefaultGroupCommand, RequirePermissions([DiscordPermission.AttachFiles], [])]
public async ValueTask SetAsync(CommandContext context, string expiresAt, [RemainingText] string? content = null)
{
DateTimeOffset now = DateTimeOffset.UtcNow;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/RotateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class RotateCommand
/// </summary>
/// <param name="attachment">The image to rotate.</param>
/// <param name="degrees">The degrees to rotate the image by. Defaults to 90. Only supports increments of 90.</param>
[Command("rotate"), Description("Rotates the image by the specified degrees."), RequirePermissions(DiscordPermissions.AttachFiles, DiscordPermissions.None)]
[Command("rotate"), Description("Rotates the image by the specified degrees."), RequirePermissions([DiscordPermission.AttachFiles], [])]
public async ValueTask ExecuteAsync(CommandContext context, DiscordAttachment attachment, float degrees = 90.0f)
{
// Download the image, rotate it, and send it back
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/TagCommand/TagCommand.Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static bool TryVerifyTagContent(ref string content, [NotNullWhen(false)]

private static bool TryVerifyTagOwnership(CommandContext context, CultureInfo cultureInfo, TagModel tag, [NotNullWhen(false)] out string? errorMessage)
{
if (tag.OwnerId != context.User.Id && !context.Member!.Permissions.HasPermission(DiscordPermissions.ManageMessages))
if (tag.OwnerId != context.User.Id && !context.Member!.Permissions.HasPermission(DiscordPermission.ManageMessages))
{
errorMessage = string.Format(cultureInfo, TAG_MODIFY_PERMISSIONS, Formatter.Sanitize(tag.Name), tag.OwnerId);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/BanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class BanCommand
/// </remarks>
/// <param name="user">Who to ban.</param>
/// <param name="reason">Why they're being banned.</param>
[Command("ban"), RequirePermissions(DiscordPermissions.BanMembers)]
[Command("ban"), RequirePermissions(DiscordPermission.BanMembers)]
public static async ValueTask ExecuteAsync(CommandContext context, DiscordUser user, [RemainingText] string? reason = null)
{
if (await GuildMemberModel.IsUserBannedAsync(user.Id, context.Guild!.Id))
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Moderation/ClearCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class ClearCommand
/// <param name="firstMessage">Removes any messages after this message.</param>
/// <param name="lastMessage">Removes any messages before this message.</param>
/// <param name="reason">Why the messages are being deleted.</param>
[Command("clear"), Description("Clears messages from chat."), RequirePermissions(DiscordPermissions.ManageMessages | DiscordPermissions.ReadMessageHistory)]
[Command("clear"), Description("Clears messages from chat."), RequirePermissions(DiscordPermission.ManageMessages, DiscordPermission.ReadMessageHistory)]
public static async ValueTask ExecuteAsync(CommandContext context, DiscordMessage firstMessage, DiscordMessage? lastMessage = null, [RemainingText] string? reason = null)
{
List<DiscordMessage> messages = [];
Expand Down
Loading

0 comments on commit 60eaac7

Please sign in to comment.