Skip to content

Commit

Permalink
Upgrade DSharpPlus to 5.0.0-nightly-02356
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Aug 19, 2024
1 parent 89b2e68 commit 70f0ef0
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 89 deletions.
6 changes: 3 additions & 3 deletions Cliptok.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

<ItemGroup>
<PackageReference Include="Abyssal.HumanDateParser" Version="2.0.0-20191113.1" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02351" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-02351" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02351" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02356" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-02356" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02356" />
<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
36 changes: 18 additions & 18 deletions CommandChecks/HomeServerPerms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@ public enum ServerPermLevel
Owner = int.MaxValue
}

public static ServerPermLevel GetPermLevel(DiscordMember target)
public static async Task<ServerPermLevel> GetPermLevelAsync(DiscordMember target)
{
if (target.Guild.Id != Program.cfgjson.ServerID)
return ServerPermLevel.Nothing;

// Torch approved of this.
if (target.IsOwner)
return ServerPermLevel.Owner;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.AdminRole)))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.AdminRole)))
return ServerPermLevel.Admin;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.ModRole)))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.ModRole)))
return ServerPermLevel.Moderator;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.MutedRole)))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.MutedRole)))
return ServerPermLevel.Muted;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TrialModRole)))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TrialModRole)))
return ServerPermLevel.TrialModerator;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TqsRoleId)))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TqsRoleId)))
return ServerPermLevel.TechnicalQueriesSlayer;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[9])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[9])))
return ServerPermLevel.TierX;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[8])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[8])))
return ServerPermLevel.TierS;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[7])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[7])))
return ServerPermLevel.Tier8;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[6])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[6])))
return ServerPermLevel.Tier7;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[5])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[5])))
return ServerPermLevel.Tier6;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[4])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[4])))
return ServerPermLevel.Tier5;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[3])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[3])))
return ServerPermLevel.Tier4;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[2])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[2])))
return ServerPermLevel.Tier3;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[1])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[1])))
return ServerPermLevel.Tier2;
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[0])))
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[0])))
return ServerPermLevel.Tier1;
else
return ServerPermLevel.Nothing;
Expand Down Expand Up @@ -108,7 +108,7 @@ public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help
member = ctx.Member;
}

var level = GetPermLevel(member);
var level = await GetPermLevelAsync(member);
if (level >= TargetLvl)
return true;

Expand Down Expand Up @@ -146,7 +146,7 @@ public override async Task<bool> ExecuteChecksAsync(InteractionContext ctx)
if (ctx.Guild.Id != Program.cfgjson.ServerID)
return false;

var level = GetPermLevel(ctx.Member);
var level = await GetPermLevelAsync(ctx.Member);
if (level >= TargetLvl)
return true;
else
Expand Down
20 changes: 10 additions & 10 deletions Commands/Announcements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task EditAnnounce(

if (Program.cfgjson.AnnouncementRoles.ContainsKey(roleName))
{
discordRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles[roleName]);
discordRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles[roleName]);
await discordRole.ModifyAsync(mentionable: true);
try
{
Expand Down Expand Up @@ -47,7 +47,7 @@ public async Task AnnounceCmd(CommandContext ctx, [Description("'canary', 'dev',

if (Program.cfgjson.AnnouncementRoles.ContainsKey(roleName))
{
discordRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles[roleName]);
discordRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles[roleName]);
await discordRole.ModifyAsync(mentionable: true);
try
{
Expand All @@ -62,8 +62,8 @@ public async Task AnnounceCmd(CommandContext ctx, [Description("'canary', 'dev',
}
else if (roleName == "rpbeta")
{
var rpRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["rp"]);
var betaRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["beta"]);
var rpRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["rp"]);
var betaRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["beta"]);

await rpRole.ModifyAsync(mentionable: true);
await betaRole.ModifyAsync(mentionable: true);
Expand All @@ -84,8 +84,8 @@ public async Task AnnounceCmd(CommandContext ctx, [Description("'canary', 'dev',
// this is rushed pending an actual solution
else if (roleName == "rpbeta10")
{
var rpRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["rp10"]);
var betaRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["beta10"]);
var rpRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["rp10"]);
var betaRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["beta10"]);

await rpRole.ModifyAsync(mentionable: true);
await betaRole.ModifyAsync(mentionable: true);
Expand All @@ -105,8 +105,8 @@ public async Task AnnounceCmd(CommandContext ctx, [Description("'canary', 'dev',
}
else if (roleName == "betadev")
{
var betaRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["beta"]);
var devRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["dev"]);
var betaRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["beta"]);
var devRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["dev"]);

await betaRole.ModifyAsync(mentionable: true);
await devRole.ModifyAsync(mentionable: true);
Expand All @@ -126,8 +126,8 @@ public async Task AnnounceCmd(CommandContext ctx, [Description("'canary', 'dev',
}
else if (roleName == "candev")
{
var canaryRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["canary"]);
var devRole = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles["dev"]);
var canaryRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["canary"]);
var devRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles["dev"]);

await canaryRole.ModifyAsync(mentionable: true);
await devRole.ModifyAsync(mentionable: true);
Expand Down
4 changes: 2 additions & 2 deletions Commands/InteractionCommands/AnnouncementInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task AnnounceBuildSlashCommand(InteractionContext ctx,
roleKey1 = insiderChannel1.ToLower();
}

DiscordRole insiderRole1 = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles[roleKey1]);
DiscordRole insiderRole1 = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles[roleKey1]);
DiscordRole insiderRole2 = default;

StringBuilder channelString = new();
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task AnnounceBuildSlashCommand(InteractionContext ctx,
roleKey2 = insiderChannel2.ToLower();
}

insiderRole2 = ctx.Guild.GetRole(Program.cfgjson.AnnouncementRoles[roleKey2]);
insiderRole2 = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles[roleKey2]);
}

string pingMsgBareString = $"{insiderRole1.Mention}{(insiderChannel2 != "" ? $" {insiderRole2.Mention}\n" : " - ")}Hi Insiders!\n\n" +
Expand Down
2 changes: 1 addition & 1 deletion Commands/InteractionCommands/BanInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task BanSlashCommand(InteractionContext ctx,
try
{
targetMember = await ctx.Guild.GetMemberAsync(user.Id);
if (GetPermLevel(ctx.Member) == ServerPermLevel.TrialModerator && (GetPermLevel(targetMember) >= ServerPermLevel.TrialModerator))
if ((await GetPermLevelAsync(ctx.Member)) == ServerPermLevel.TrialModerator && ((await GetPermLevelAsync(targetMember)) >= ServerPermLevel.TrialModerator))
{
webhookOut.Content = $"{Program.cfgjson.Emoji.Error} As a Trial Moderator you cannot perform moderation actions on other staff members.";
await ctx.EditResponseAsync(webhookOut);
Expand Down
2 changes: 1 addition & 1 deletion Commands/InteractionCommands/ClearInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public async Task ClearSlashCommand(InteractionContext ctx,
continue;
}

if (GetPermLevel(member) >= ServerPermLevel.TrialModerator)
if ((await GetPermLevelAsync(member)) >= ServerPermLevel.TrialModerator)
{
messagesToClear.Remove(message);
}
Expand Down
10 changes: 5 additions & 5 deletions Commands/InteractionCommands/MuteInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task MuteSlashCommand(
// is this worth logging?
}

if (targetMember != default && GetPermLevel(ctx.Member) == ServerPermLevel.TrialModerator && (GetPermLevel(targetMember) >= ServerPermLevel.TrialModerator || targetMember.IsBot))
if (targetMember != default && (await GetPermLevelAsync(ctx.Member)) == ServerPermLevel.TrialModerator && ((await GetPermLevelAsync(targetMember)) >= ServerPermLevel.TrialModerator || targetMember.IsBot))
{
await ctx.Channel.SendMessageAsync($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, as a Trial Moderator you cannot perform moderation actions on other staff members or bots.");
return;
Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task UnmuteSlashCommand(
reason = $"[Manual unmute by {DiscordHelpers.UniqueUsername(ctx.User)}]: {reason}";

// todo: store per-guild
DiscordRole mutedRole = ctx.Guild.GetRole(Program.cfgjson.MutedRole);
DiscordRole mutedRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.MutedRole);

DiscordMember member = default;
try
Expand Down Expand Up @@ -113,8 +113,8 @@ public async Task TqsMuteSlashCommand(

// Check if the user is already muted; disallow TQS-mute if so

DiscordRole mutedRole = ctx.Guild.GetRole(Program.cfgjson.MutedRole);
DiscordRole tqsMutedRole = ctx.Guild.GetRole(Program.cfgjson.TqsMutedRole);
DiscordRole mutedRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.MutedRole);
DiscordRole tqsMutedRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.TqsMutedRole);

// Get member
DiscordMember targetMember = default;
Expand All @@ -134,7 +134,7 @@ public async Task TqsMuteSlashCommand(
}

// Check if user to be muted is staff or TQS, and disallow if so
if (targetMember != default && GetPermLevel(ctx.Member) == ServerPermLevel.TechnicalQueriesSlayer && (GetPermLevel(targetMember) >= ServerPermLevel.TechnicalQueriesSlayer || targetMember.IsBot))
if (targetMember != default && (await GetPermLevelAsync(ctx.Member)) == ServerPermLevel.TechnicalQueriesSlayer && ((await GetPermLevelAsync(targetMember)) >= ServerPermLevel.TechnicalQueriesSlayer || targetMember.IsBot))
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, you cannot mute other TQS or staff members."));
return;
Expand Down
4 changes: 2 additions & 2 deletions Commands/InteractionCommands/RoleInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task GrantRole(
_ => throw new NotSupportedException()
};

var roleData = ctx.Guild.GetRole(roleId);
var roleData = await ctx.Guild.GetRoleAsync(roleId);

await member.GrantRoleAsync(roleData, $"/roles grant used by {DiscordHelpers.UniqueUsername(ctx.User)}");
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} The role {roleData.Mention} has been successfully granted!", ephemeral: true, mentions: false);
Expand Down Expand Up @@ -75,7 +75,7 @@ public async Task RemoveRole(
_ => throw new NotSupportedException()
};

var roleData = ctx.Guild.GetRole(roleId);
var roleData = await ctx.Guild.GetRoleAsync(roleId);

await member.RevokeRoleAsync(roleData, $"/roles remove used by {DiscordHelpers.UniqueUsername(ctx.User)}");
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} The role {roleData.Mention} has been successfully removed!", ephemeral: true, mentions: false);
Expand Down
6 changes: 3 additions & 3 deletions Commands/InteractionCommands/WarningInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task WarnSlashCommand(InteractionContext ctx,
try
{
targetMember = await ctx.Guild.GetMemberAsync(user.Id);
if (GetPermLevel(ctx.Member) == ServerPermLevel.TrialModerator && (GetPermLevel(targetMember) >= ServerPermLevel.TrialModerator || targetMember.IsBot))
if ((await GetPermLevelAsync(ctx.Member)) == ServerPermLevel.TrialModerator && ((await GetPermLevelAsync(targetMember)) >= ServerPermLevel.TrialModerator || targetMember.IsBot))
{
webhookOut = new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} As a Trial Moderator you cannot perform moderation actions on other staff members or bots.");
await ctx.EditResponseAsync(webhookOut);
Expand Down Expand Up @@ -239,7 +239,7 @@ public async Task DelwarnSlashCommand(InteractionContext ctx,
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That's a note, not a warning! Try using `/note delete` instead, or make sure you've got the right warning ID.", ephemeral: true);
}
else if (GetPermLevel(ctx.Member) == ServerPermLevel.TrialModerator && warning.ModUserId != ctx.User.Id && warning.ModUserId != ctx.Client.CurrentUser.Id)
else if ((await GetPermLevelAsync(ctx.Member)) == ServerPermLevel.TrialModerator && warning.ModUserId != ctx.User.Id && warning.ModUserId != ctx.Client.CurrentUser.Id)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, as a Trial Moderator you cannot edit or delete warnings that aren't issued by you or the bot!", ephemeral: true);
}
Expand Down Expand Up @@ -307,7 +307,7 @@ public async Task EditWarnSlashCommand(InteractionContext ctx,
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That's a note, not a warning! Try using `/note edit` instead, or make sure you've got the right warning ID.", ephemeral: true);
}
else if (GetPermLevel(ctx.Member) == ServerPermLevel.TrialModerator && warningObject.ModUserId != ctx.User.Id && warningObject.ModUserId != ctx.Client.CurrentUser.Id)
else if ((await GetPermLevelAsync(ctx.Member)) == ServerPermLevel.TrialModerator && warningObject.ModUserId != ctx.User.Id && warningObject.ModUserId != ctx.Client.CurrentUser.Id)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, as a Trial Moderator you cannot edit or delete warnings that aren't issued by you or the bot!", ephemeral: true);
}
Expand Down
Loading

0 comments on commit 70f0ef0

Please sign in to comment.