Skip to content

Commit

Permalink
Run Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Jul 1, 2024
1 parent 07abf53 commit 1796e3d
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 131 deletions.
9 changes: 3 additions & 6 deletions Commands/Debug.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Serilog.Events;
using Serilog.Formatting;

namespace Cliptok.Commands
namespace Cliptok.Commands
{
internal class Debug : BaseCommandModule
{
Expand Down Expand Up @@ -251,8 +248,8 @@ public async Task MostWarningsCmd(CommandContext ctx)
if (ulong.TryParse(key.ToString(), out ulong number))
{
var warnings = Program.db.HashGetAll(key);
Dictionary<long, MemberPunishment> warningdict = new();
foreach(var warning in warnings)
Dictionary<long, MemberPunishment> warningdict = new();
foreach (var warning in warnings)
{
var warnobject = JsonConvert.DeserializeObject<MemberPunishment>(warning.Value);
warningdict[(long)warning.Name] = warnobject;
Expand Down
6 changes: 2 additions & 4 deletions Commands/InteractionCommands/AnnouncementInteractions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Linq;

namespace Cliptok.Commands.InteractionCommands
namespace Cliptok.Commands.InteractionCommands
{
internal class AnnouncementInteractions : ApplicationCommandModule
{
Expand Down Expand Up @@ -182,7 +180,7 @@ public async Task AnnounceBuildSlashCommand(InteractionContext ctx,
{
noPingMsgString += $"\n\nDiscuss it here: {threadChannel.Mention}";
}
else if (insiderChannel1 == "Canary" && insiderChannel2 == "" && Program.cfgjson.InsiderCanaryThread != 0 && autothreadName == "Build {0} ({1})" && !canaryCreateNewThread)
else if (insiderChannel1 == "Canary" && insiderChannel2 == "" && Program.cfgjson.InsiderCanaryThread != 0 && autothreadName == "Build {0} ({1})" && !canaryCreateNewThread)
{
threadChannel = await ctx.Client.GetChannelAsync(Program.cfgjson.InsiderCanaryThread);
noPingMsgString += $"\n\nDiscuss it here: {threadChannel.Mention}";
Expand Down
2 changes: 1 addition & 1 deletion Commands/InteractionCommands/ContextCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task ContextAvatar(ContextMenuContext ctx)

await ctx.RespondAsync(null, embed, ephemeral: true);
}

[ContextMenu(DiscordApplicationCommandType.UserContextMenu, "Show Notes", defaultPermission: false)]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator), SlashCommandPermissions(DiscordPermissions.ModerateMembers)]
public async Task ShowNotes(ContextMenuContext ctx)
Expand Down
4 changes: 2 additions & 2 deletions Commands/InteractionCommands/DebugInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task UserInfoSlashCommand(InteractionContext ctx, [Option("user", "
{
await ctx.RespondAsync(embed: await DiscordHelpers.GenerateUserEmbed(user, ctx.Guild), ephemeral: !publicMessage);
}

[SlashCommand("muteinfo", "Show information about the mute for a user.")]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)]
[SlashCommandPermissions(DiscordPermissions.ModerateMembers)]
Expand All @@ -119,7 +119,7 @@ public async Task MuteInfoSlashCommand(
{
await ctx.RespondAsync(embed: await MuteHelpers.MuteStatusEmbed(targetUser, ctx.Guild), ephemeral: !isPublic);
}

[SlashCommand("baninfo", "Show information about the ban for a user.")]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)]
[SlashCommandPermissions(DiscordPermissions.ModerateMembers)]
Expand Down
16 changes: 8 additions & 8 deletions Commands/InteractionCommands/JoinwatchInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public async Task JoinwatchAdd(InteractionContext ctx,
if (joinWatchlist.Contains(user.Id))
{
// User is already watched

// Get current note; if it's the same, do nothing
var currentNote = await Program.db.HashGetAsync("joinWatchedUsersNotes", user.Id);
if (currentNote == note || (string.IsNullOrWhiteSpace(currentNote) && string.IsNullOrWhiteSpace(note)))
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {user.Mention} is already being watched with the same note! Nothing to do.");
return;
}

// If note is different, update it

// If new note is empty, remove instead of changing to empty string!
if (string.IsNullOrWhiteSpace(note))
{
Expand All @@ -36,7 +36,7 @@ public async Task JoinwatchAdd(InteractionContext ctx,
else
{
await Program.db.HashSetAsync("joinWatchedUsersNotes", user.Id, note);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully updated the note for {user.Mention}:\n> {note}");
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully updated the note for {user.Mention}:\n> {note}");
}
}
else
Expand All @@ -55,14 +55,14 @@ public async Task JoinwatchRemove(InteractionContext ctx,
[Option("user", "The user to stop watching for joins and leaves of.")] DiscordUser user)
{
var joinWatchlist = await Program.db.ListRangeAsync("joinWatchedUsers");

// Check user watch status first; error if not watched
if (!joinWatchlist.Contains(user.Id))
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {user.Mention} is not being watched! Nothing to do.");
return;
}

Program.db.ListRemove("joinWatchedUsers", joinWatchlist.First(x => x == user.Id));
await Program.db.HashDeleteAsync("joinWatchedUsersNotes", user.Id);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully unwatched {user.Mention}!");
Expand All @@ -73,11 +73,11 @@ public async Task JoinwatchStatus(InteractionContext ctx,
[Option("user", "The user whose joinwatch status to check.")] DiscordUser user)
{
var joinWatchlist = await Program.db.ListRangeAsync("joinWatchedUsers");

if (joinWatchlist.Contains(user.Id))
{
var note = await Program.db.HashGetAsync("joinWatchedUsersNotes", user.Id);

if (string.IsNullOrWhiteSpace(note))
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Information} {user.Mention} is currently being watched, but no note is set.");
else
Expand Down
10 changes: 5 additions & 5 deletions Commands/InteractionCommands/MuteInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task TqsMuteSlashCommand(
[Option("reason", "The reason for the mute.")] string reason)
{
await ctx.DeferAsync(ephemeral: true);

// Only allow usage in #tech-support, #tech-support-forum, and their threads
if (ctx.Channel.Id != Program.cfgjson.TechSupportChannel &&
ctx.Channel.Id != Program.cfgjson.SupportForumId &&
Expand All @@ -108,18 +108,18 @@ public async Task TqsMuteSlashCommand(
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} This command can only be used in <#{Program.cfgjson.TechSupportChannel}>, <#{Program.cfgjson.SupportForumId}>, and threads in those channels!"));
return;
}

// 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);

if (await Program.db.HashExistsAsync("mutes", targetUser.Id) || ctx.Member.Roles.Contains(mutedRole) || ctx.Member.Roles.Contains(tqsMutedRole))
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, that user is already muted."));
return;
}

// Get member
DiscordMember targetMember = default;
try
Expand Down
10 changes: 5 additions & 5 deletions Commands/InteractionCommands/SecurityActionInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public async Task SlashPauseDMs(InteractionContext ctx, [Option("time", "The amo
return;
}
var dmsDisabledUntil = t.ToUniversalTime().ToString("o");

// get current security actions to avoid unintentionally resetting invites_disabled_until
var currentActions = await SecurityActionHelpers.GetCurrentSecurityActions(ctx.Guild.Id);
JToken invitesDisabledUntil;
if (currentActions is null || !currentActions.HasValues)
invitesDisabledUntil = null;
else
invitesDisabledUntil = currentActions["invites_disabled_until"];

// create json body
var newSecurityActions = JsonConvert.SerializeObject(new
{
Expand All @@ -55,7 +55,7 @@ public async Task SlashPauseDMs(InteractionContext ctx, [Option("time", "The amo
public async Task SlashUnpauseDMs(InteractionContext ctx)
{
// need to make our own api calls because D#+ can't do this natively?

// get current security actions to avoid unintentionally resetting invites_disabled_until
var currentActions = await SecurityActionHelpers.GetCurrentSecurityActions(ctx.Guild.Id);
JToken dmsDisabledUntil, invitesDisabledUntil;
Expand All @@ -76,14 +76,14 @@ public async Task SlashUnpauseDMs(InteractionContext ctx)
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} DMs are already unpaused!");
return;
}

// create json body
var newSecurityActions = JsonConvert.SerializeObject(new
{
invites_disabled_until = invitesDisabledUntil,
dms_disabled_until = (object)null,
});

// set actions
var setActionsResponse = await SecurityActionHelpers.SetCurrentSecurityActions(ctx.Guild.Id, newSecurityActions);

Expand Down
Loading

0 comments on commit 1796e3d

Please sign in to comment.