Skip to content

Commit

Permalink
WIP: Update DSharpPlus to 5.0.0-nightly-02379
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Oct 25, 2024
1 parent 1a60926 commit 0c92f38
Show file tree
Hide file tree
Showing 49 changed files with 961 additions and 705 deletions.
5 changes: 2 additions & 3 deletions Cliptok.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

<ItemGroup>
<PackageReference Include="Abyssal.HumanDateParser" Version="2.0.0-20191113.1" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02357" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-02357" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02357" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02379" />
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-02379" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
Expand Down
14 changes: 7 additions & 7 deletions CommandChecks/HomeServerPerms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static async Task<ServerPermLevel> GetPermLevelAsync(DiscordMember target
}

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class RequireHomeserverPermAttribute : CheckBaseAttribute
public class RequireHomeserverPermAttribute : ContextCheckAttribute // TODO(#202): checks changed!! see the checks section of https://dsharpplus.github.io/DSharpPlus/articles/migration/slashcommands_to_commands.html
{
public ServerPermLevel TargetLvl { get; set; }
public bool WorkOutside { get; set; }
Expand All @@ -80,7 +80,7 @@ public RequireHomeserverPermAttribute(ServerPermLevel targetlvl, bool workOutsid
TargetLvl = targetlvl;
}

public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
public async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
{
// If the command is supposed to stay within the server and its being used outside, fail silently
if (!WorkOutside && (ctx.Channel.IsPrivate || ctx.Guild.Id != Program.cfgjson.ServerID))
Expand Down Expand Up @@ -112,7 +112,7 @@ public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help
if (level >= TargetLvl)
return true;

else if (!help && ctx.Command.QualifiedName != "edit")
else if (!help && ctx.Command.FullName != "edit")
{
var levelText = level.ToString();
if (level == ServerPermLevel.Nothing && Program.rand.Next(1, 100) == 69)
Expand All @@ -126,22 +126,22 @@ await ctx.RespondAsync(
}
}

public class HomeServerAttribute : CheckBaseAttribute
public class HomeServerAttribute : ContextCheckAttribute
{
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
public async Task<bool> ExecuteCheckAsync(CommandContext ctx)
{
return !ctx.Channel.IsPrivate && ctx.Guild.Id == Program.cfgjson.ServerID;
}
}

public class SlashRequireHomeserverPermAttribute : SlashCheckBaseAttribute
public class SlashRequireHomeserverPermAttribute : ContextCheckAttribute
{
public ServerPermLevel TargetLvl;

public SlashRequireHomeserverPermAttribute(ServerPermLevel targetlvl)
=> TargetLvl = targetlvl;

public override async Task<bool> ExecuteChecksAsync(InteractionContext ctx)
public async Task<bool> ExecuteChecksAsync(CommandContext ctx)
{
if (ctx.Guild.Id != Program.cfgjson.ServerID)
return false;
Expand Down
4 changes: 2 additions & 2 deletions CommandChecks/OwnerChecks.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Cliptok.CommandChecks
{
public class IsBotOwnerAttribute : CheckBaseAttribute
public class IsBotOwnerAttribute : ContextCheckAttribute
{
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
public async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
{
if (Program.cfgjson.BotOwners.Contains(ctx.User.Id))
{
Expand Down
4 changes: 2 additions & 2 deletions CommandChecks/UserRoleChecks.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Cliptok.CommandChecks
{
public class UserRolesPresentAttribute : CheckBaseAttribute
public class UserRolesPresentAttribute : ContextCheckAttribute
{
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
public async Task<bool> ExecuteCheckAsync(CommandContext ctx)
{
return Program.cfgjson.UserRoles is not null;
}
Expand Down
8 changes: 5 additions & 3 deletions Commands/Announcements.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
namespace Cliptok.Commands
{
internal class Announcements : BaseCommandModule
internal class Announcements
{

[Command("editannounce")]
[Description("Edit an announcement, preserving the ping highlight.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task EditAnnounce(
CommandContext ctx,
TextCommandContext ctx,
[Description("The ID of the message to edit.")] ulong messageId,
[Description("The short name for the role to ping.")] string roleName,
[RemainingText, Description("The new message content, excluding the ping.")] string content
Expand Down Expand Up @@ -40,8 +41,9 @@ public async Task EditAnnounce(

[Command("announce")]
[Description("Announces something in the current channel, pinging an Insider role in the process.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task AnnounceCmd(CommandContext ctx, [Description("'canary', 'dev', 'beta', 'beta10', 'rp', 'rp10', 'patch', 'rpbeta', 'rpbeta10', 'betadev', 'candev'")] string roleName, [RemainingText, Description("The announcement message to send.")] string announcementMessage)
public async Task AnnounceCmd(TextCommandContext ctx, [Description("'canary', 'dev', 'beta', 'beta10', 'rp', 'rp10', 'patch', 'rpbeta', 'rpbeta10', 'betadev', 'candev'")] string roleName, [RemainingText, Description("The announcement message to send.")] string announcementMessage)
{
DiscordRole discordRole;

Expand Down
23 changes: 14 additions & 9 deletions Commands/Bans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Cliptok.Commands
{
class Bans : BaseCommandModule
class Bans
{
[Command("massban")]
[Aliases("bigbonk")]
[TextAlias("bigbonk")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task MassBanCmd(CommandContext ctx, [RemainingText] string input)
public async Task MassBanCmd(TextCommandContext ctx, [RemainingText] string input)
{

List<string> usersString = input.Replace("\n", " ").Replace("\r", "").Split(' ').ToList();
Expand All @@ -21,7 +22,8 @@ public async Task MassBanCmd(CommandContext ctx, [RemainingText] string input)
List<Task<bool>> taskList = new();
int successes = 0;

var loading = await ctx.RespondAsync("Processing, please wait.");
await ctx.RespondAsync("Processing, please wait.");
var loading = await ctx.GetResponseAsync();

foreach (ulong user in users)
{
Expand All @@ -41,10 +43,11 @@ public async Task MassBanCmd(CommandContext ctx, [RemainingText] string input)
}

[Command("ban")]
[Aliases("tempban", "bonk", "isekaitruck")]
[TextAlias("tempban", "bonk", "isekaitruck")]
[Description("Bans a user that you have permission to ban, deleting all their messages in the process. See also: bankeep.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator), RequirePermissions(DiscordPermissions.BanMembers)]
public async Task BanCmd(CommandContext ctx,
public async Task BanCmd(TextCommandContext ctx,
[Description("The user you wish to ban. Accepts many formats")] DiscordUser targetMember,
[RemainingText, Description("The time and reason for the ban. e.g. '14d trolling' NOTE: Add 'appeal' to the start of the reason to include an appeal link")] string timeAndReason = "No reason specified.")
{
Expand Down Expand Up @@ -133,9 +136,10 @@ public async Task BanCmd(CommandContext ctx,
/// I CANNOT find a way to do this as alias so I made it a separate copy of the command.
/// Sue me, I beg you.
[Command("bankeep")]
[Aliases("bansave")]
[TextAlias("bansave")]
[Description("Bans a user but keeps their messages around."), HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator), RequirePermissions(DiscordPermissions.BanMembers)]
public async Task BankeepCmd(CommandContext ctx,
[AllowedProcessors(typeof(TextCommandProcessor))]
public async Task BankeepCmd(TextCommandContext ctx,
[Description("The user you wish to ban. Accepts many formats")] DiscordUser targetMember,
[RemainingText, Description("The time and reason for the ban. e.g. '14d trolling' NOTE: Add 'appeal' to the start of the reason to include an appeal link")] string timeAndReason = "No reason specified.")
{
Expand Down Expand Up @@ -216,8 +220,9 @@ public async Task BankeepCmd(CommandContext ctx,

[Command("unban")]
[Description("Unbans a user who has been previously banned.")]
[AllowedProcessors(typeof(TextCommandProcessor))]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator), RequirePermissions(DiscordPermissions.BanMembers)]
public async Task UnbanCmd(CommandContext ctx, [Description("The user to unban, usually a mention or ID")] DiscordUser targetUser, [Description("Used in audit log only currently")] string reason = "No reason specified.")
public async Task UnbanCmd(TextCommandContext ctx, [Description("The user to unban, usually a mention or ID")] DiscordUser targetUser, [Description("Used in audit log only currently")] string reason = "No reason specified.")
{
if ((await Program.db.HashExistsAsync("bans", targetUser.Id)))
{
Expand Down
Loading

0 comments on commit 0c92f38

Please sign in to comment.