Skip to content

Commit 6ca7474

Browse files
committed
Run Code Cleanup
1 parent 9942c86 commit 6ca7474

40 files changed

+275
-274
lines changed

Checks/ListChecks.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public class ListChecks
7979
{ "υ", "y" },
8080
{ "ζ", "z" },
8181
};
82-
82+
8383
public static (bool success, string? flaggedWord) CheckForNaughtyWords(string input, WordListJson naughtyWordList)
8484
{
8585
// Replace any lookalike letters found in message with Latin characters, if in the dictionary
8686
foreach (var letter in lookalikeAlphabetMap)
8787
input = input.Replace(letter.Key, letter.Value);
88-
88+
8989
string[] naughtyWords = naughtyWordList.Words;
9090
input = input.Replace("\0", "");
9191
if (naughtyWordList.WholeWord)

Commands/AnnouncementCmds.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
4545
await ctx.RespondAsync(text: $"{Program.cfgjson.Emoji.Error} Windows 10 only has a Release Preview Channel.", ephemeral: true);
4646
return;
4747
}
48-
48+
4949
// Avoid duplicate announcements
5050
if (await Program.db.SetContainsAsync("announcedInsiderBuilds", buildNumber) && !forceReannounce)
5151
{

Commands/BanCmds.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public async Task BanSlashCommand(SlashCommandContext ctx,
105105
return;
106106
}
107107
}
108-
108+
109109
webhookOut.Content = $"{Program.cfgjson.Emoji.Success} User was successfully bonked.";
110110
await ctx.EditResponseAsync(webhookOut);
111111
}
@@ -163,7 +163,7 @@ public async Task MassBanCmd(TextCommandContext ctx, [RemainingText] string inpu
163163
reason += $"{word} ";
164164
}
165165
reason = reason.Trim();
166-
166+
167167
if (users.Count == 1 || users.Count == 0)
168168
{
169169
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Not accepting a massban with a single user. Please use `!ban`.");

Commands/DebugCmds.cs

+17-16
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public async Task WarningCacheCmd(TextCommandContext ctx)
323323
await ctx.RespondAsync(await StringHelpers.CodeOrHasteBinAsync(JsonConvert.SerializeObject(WarningHelpers.mostRecentWarning, Formatting.Indented), "json"));
324324
}
325325
}
326-
326+
327327
class OverridesCmd
328328
{
329329
// This is outside of the debug class/group to avoid issues caused by DSP.Commands that are out of our control
@@ -370,7 +370,7 @@ await ctx.RespondAsync(
370370
{
371371
var allowedPermissions = string.IsNullOrWhiteSpace(overwrite.Value.Allowed.ToString("name")) ? "none" : overwrite.Value.Allowed.ToString("name");
372372
var deniedPermissions = string.IsNullOrWhiteSpace(overwrite.Value.Denied.ToString("name")) ? "none" : overwrite.Value.Denied.ToString("name");
373-
373+
374374
response +=
375375
$"<#{overwrite.Key}>:\n**Allowed**: {allowedPermissions}\n**Denied**: {deniedPermissions}\n\n";
376376
}
@@ -441,11 +441,11 @@ public async Task Add(TextCommandContext ctx,
441441
// Confirm permission overrides before we do anything.
442442
var parsedAllowedPerms = new DiscordPermissions(allowedPermissions);
443443
var parsedDeniedPerms = new DiscordPermissions(deniedPermissions);
444-
444+
445445
var allowedPermsStr = parsedAllowedPerms.ToString("name");
446446
if (string.IsNullOrWhiteSpace(allowedPermsStr))
447447
allowedPermsStr = "None";
448-
448+
449449
var deniedPermsStr = parsedDeniedPerms.ToString("name");
450450
if (string.IsNullOrWhiteSpace(deniedPermsStr))
451451
deniedPermsStr = "None";
@@ -566,7 +566,7 @@ public async Task Apply(TextCommandContext ctx,
566566

567567
await msg.ModifyAsync(x => x.Content = $"{Program.cfgjson.Emoji.Success} Successfully applied {numAppliedOverrides}/{dictionary.Count} overrides for {user.Mention}!");
568568
}
569-
569+
570570
[Command("dump")]
571571
[Description("Dump all of a channel's overrides from Discord or the database.")]
572572
[IsBotOwner]
@@ -589,7 +589,7 @@ public async Task DumpFromDiscord(TextCommandContext ctx,
589589

590590
await ctx.RespondAsync($"Dump from Discord:\n{await StringHelpers.CodeOrHasteBinAsync(output, "json")}");
591591
}
592-
592+
593593
[Command("db")]
594594
[TextAlias("database")]
595595
[Description("Dump all of a channel's overrides as they are stored in the db.")]
@@ -600,7 +600,8 @@ public async Task DumpFromDb(TextCommandContext ctx,
600600
try
601601
{
602602
var allOverwrites = await Program.db.HashGetAllAsync("overrides");
603-
foreach (var overwrite in allOverwrites) {
603+
foreach (var overwrite in allOverwrites)
604+
{
604605
var overwriteDict = JsonConvert.DeserializeObject<Dictionary<ulong, DiscordOverwrite>>(overwrite.Value);
605606
if (overwriteDict is null) continue;
606607
if (overwriteDict.TryGetValue(channel.Id, out var value))
@@ -611,18 +612,18 @@ public async Task DumpFromDb(TextCommandContext ctx,
611612
{
612613
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Something went wrong while trying to fetch the overrides for {channel.Mention}!" +
613614
" There are overrides in the database but I could not parse them. Check the database manually for details.");
614-
615+
615616
Program.discord.Logger.LogError(ex, "Failed to read overrides from db for 'debug overrides dump'!");
616-
617+
617618
return;
618619
}
619-
620+
620621
if (overwrites.Count == 0)
621622
{
622623
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} No overrides found for {channel.Mention} in the database!");
623624
return;
624625
}
625-
626+
626627
string output = "";
627628
foreach (var overwrite in overwrites)
628629
{
@@ -632,7 +633,7 @@ public async Task DumpFromDb(TextCommandContext ctx,
632633
await ctx.RespondAsync($"Dump from db:\n{await StringHelpers.CodeOrHasteBinAsync(output, "json")}");
633634
}
634635
}
635-
636+
636637
[Command("cleanup")]
637638
[TextAlias("clean", "prune")]
638639
[Description("Removes overrides from the db for channels that no longer exist.")]
@@ -642,7 +643,7 @@ public async Task CleanUpOverrides(CommandContext ctx)
642643
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Loading} Working on it...");
643644
var msg = await ctx.GetResponseAsync();
644645
var removedOverridesCount = 0;
645-
646+
646647
var dbOverwrites = await Program.db.HashGetAllAsync("overrides");
647648
foreach (var userOverwrites in dbOverwrites)
648649
{
@@ -658,7 +659,7 @@ public async Task CleanUpOverrides(CommandContext ctx)
658659
removedOverridesCount++;
659660
}
660661
}
661-
662+
662663
// Write back to db
663664
// If the user now has no overrides, remove them from the db entirely
664665
if (overwriteDict.Count == 0)
@@ -671,11 +672,11 @@ public async Task CleanUpOverrides(CommandContext ctx)
671672
await Program.db.HashSetAsync("overrides", userOverwrites.Name, JsonConvert.SerializeObject(overwriteDict));
672673
}
673674
}
674-
675+
675676
await msg.ModifyAsync($"{Program.cfgjson.Emoji.Success} Done! Cleaned up {removedOverridesCount} overrides.");
676677
}
677678
}
678-
679+
679680
private static async Task<(bool success, ulong failedOverwrite)> ImportOverridesFromChannelAsync(DiscordChannel channel)
680681
{
681682
// Imports overrides from the specified channel to the database. See 'debug overrides import' and 'debug overrides importall'

Commands/DehoistCmds.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task DehoistCmd(CommandContext ctx, [Parameter("member"), Descripti
2424
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {member.Mention} is already dehoisted!", ephemeral: true);
2525
return;
2626
}
27-
27+
2828
if (member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedUsername))
2929
{
3030
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {member.Mention} is quarantined because their name is in violation of AutoMod rules! Discord will not let me dehoist them. Please change their nickname manually.", ephemeral: true);
@@ -94,7 +94,7 @@ await ctx.RespondAsync(new DiscordMessageBuilder()
9494
}
9595

9696
[Command("enable")]
97-
[Description("Permanently dehoist a member. They will be automatically dehoisted until disabled.")]
97+
[Description("Permanently dehoist a member. They will be automatically dehoisted until disabled.")]
9898
public async Task PermadehoistEnableSlashCmd(CommandContext ctx, [Parameter("member"), Description("The member to permadehoist.")] DiscordUser discordUser)
9999
{
100100
var (success, isPermissionError) = await DehoistHelpers.PermadehoistMember(discordUser, ctx.User, ctx.Guild);
@@ -110,7 +110,7 @@ public async Task PermadehoistEnableSlashCmd(CommandContext ctx, [Parameter("mem
110110
}
111111

112112
[Command("disable")]
113-
[Description("Disable permadehoist for a member.")]
113+
[Description("Disable permadehoist for a member.")]
114114
public async Task PermadehoistDisableSlashCmd(CommandContext ctx, [Parameter("member"), Description("The member to remove the permadehoist for.")] DiscordUser discordUser)
115115
{
116116
var (success, isPermissionError) = await DehoistHelpers.UnpermadehoistMember(discordUser, ctx.User, ctx.Guild);
@@ -126,7 +126,7 @@ public async Task PermadehoistDisableSlashCmd(CommandContext ctx, [Parameter("me
126126
}
127127

128128
[Command("status")]
129-
[Description("Check the status of permadehoist for a member.")]
129+
[Description("Check the status of permadehoist for a member.")]
130130
public async Task PermadehoistStatusSlashCmd(CommandContext ctx, [Parameter("member"), Description("The member whose permadehoist status to check.")] DiscordUser discordUser)
131131
{
132132
if (await Program.db.SetContainsAsync("permadehoists", discordUser.Id))

Commands/GlobalCmds.cs

+30-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Cliptok.Commands
55
public class GlobalCmds
66
{
77
// These commands will be registered outside of the home server and can be used anywhere, even in DMs.
8-
8+
99
// Most of this is taken from DSharpPlus.CommandsNext and adapted to fit here.
1010
// https://github.com/DSharpPlus/DSharpPlus/blob/1c1aa15/DSharpPlus.CommandsNext/CommandsNextExtension.cs#L829
1111
[Command("helptextcmd"), Description("Displays command help.")]
@@ -14,21 +14,21 @@ public class GlobalCmds
1414
public async Task Help(CommandContext ctx, [Description("Command to provide help for."), RemainingText] string command = "")
1515
{
1616
var commandSplit = command.Split(' ');
17-
17+
1818
DiscordEmbedBuilder helpEmbed = new()
1919
{
2020
Title = "Help",
2121
Color = new DiscordColor("#0080ff")
2222
};
23-
24-
IEnumerable<Command> cmds = ctx.Extension.Commands.Values.Where(cmd =>
25-
cmd.Attributes.Any(attr => attr is AllowedProcessorsAttribute apAttr
26-
&& apAttr.Processors.Contains(typeof(TextCommandProcessor))));
27-
23+
24+
IEnumerable<Command> cmds = ctx.Extension.Commands.Values.Where(cmd =>
25+
cmd.Attributes.Any(attr => attr is AllowedProcessorsAttribute apAttr
26+
&& apAttr.Processors.Contains(typeof(TextCommandProcessor))));
27+
2828
if (commandSplit.Length != 0 && commandSplit[0] != "")
2929
{
3030
commandSplit[0] += "textcmd";
31-
31+
3232
Command? cmd = null;
3333
IEnumerable<Command>? searchIn = cmds;
3434
for (int i = 0; i < commandSplit.Length; i++)
@@ -69,11 +69,11 @@ public async Task Help(CommandContext ctx, [Description("Command to provide help
6969
await ctx.RespondAsync(
7070
$"{Program.cfgjson.Emoji.NoPermissions} Invalid permissions to use command **{command.Replace("textcmd", "")}**!\n" +
7171
$"Required: `{att.TargetLvl}`\nYou have: `{levelText}`");
72-
72+
7373
return;
7474
}
7575
}
76-
76+
7777
return;
7878
}
7979
}
@@ -85,30 +85,30 @@ await ctx.RespondAsync(
8585
{
8686
throw new CommandNotFoundException(string.Join(" ", commandSplit));
8787
}
88-
88+
8989
helpEmbed.Description = $"`{cmd.Name.Replace("textcmd", "")}`: {cmd.Description ?? "No description provided."}";
90-
91-
90+
91+
9292
if (cmd.Subcommands.Count > 0 && cmd.Subcommands.Any(subCommand => subCommand.Attributes.Any(attr => attr is DefaultGroupCommandAttribute)))
9393
{
9494
helpEmbed.Description += "\n\nThis group can be executed as a standalone command.";
9595
}
96-
97-
var aliases = cmd.Method?.GetCustomAttributes<TextAliasAttribute>().FirstOrDefault()?.Aliases ?? (cmd.Attributes.FirstOrDefault(x => x is TextAliasAttribute) as TextAliasAttribute)?.Aliases ?? null;
96+
97+
var aliases = cmd.Method?.GetCustomAttributes<TextAliasAttribute>().FirstOrDefault()?.Aliases ?? (cmd.Attributes.FirstOrDefault(x => x is TextAliasAttribute) as TextAliasAttribute)?.Aliases ?? null;
9898
if (aliases is not null && (aliases.Length > 1 || (aliases.Length == 1 && aliases[0] != cmd.Name.Replace("textcmd", ""))))
9999
{
100100
var aliasStr = "";
101101
foreach (var alias in aliases)
102102
{
103103
if (alias == cmd.Name.Replace("textcmd", ""))
104104
continue;
105-
105+
106106
aliasStr += $"`{alias}`, ";
107107
}
108108
aliasStr = aliasStr.TrimEnd(',', ' ');
109109
helpEmbed.AddField("Aliases", aliasStr);
110110
}
111-
111+
112112
var arguments = cmd.Method?.GetParameters();
113113
if (arguments is not null && arguments.Length > 0)
114114
{
@@ -117,21 +117,21 @@ await ctx.RespondAsync(
117117
{
118118
if (arg.ParameterType == typeof(CommandContext) || arg.ParameterType.IsSubclassOf(typeof(CommandContext)))
119119
continue;
120-
120+
121121
bool isCatchAll = arg.GetCustomAttribute<RemainingTextAttribute>() != null;
122122
argumentsStr += $"{(arg.IsOptional || isCatchAll ? " [" : " <")}{arg.Name}{(isCatchAll ? "..." : "")}{(arg.IsOptional || isCatchAll ? "]" : ">")}";
123123
}
124-
124+
125125
argumentsStr += "`\n";
126-
126+
127127
foreach (var arg in arguments)
128128
{
129129
if (arg.ParameterType == typeof(CommandContext) || arg.ParameterType.IsSubclassOf(typeof(CommandContext)))
130130
continue;
131-
131+
132132
argumentsStr += $"`{arg.Name} ({arg.ParameterType.Name})`: {arg.GetCustomAttribute<DescriptionAttribute>()?.Description ?? "No description provided."}\n";
133133
}
134-
134+
135135
helpEmbed.AddField("Arguments", argumentsStr.Trim());
136136
}
137137
//helpBuilder.WithCommand(cmd);
@@ -143,7 +143,7 @@ await ctx.RespondAsync(
143143
foreach (Command? candidateCommand in commandsToSearch)
144144
{
145145
var executionChecks = candidateCommand.Attributes.Where(x => x is ContextCheckAttribute);
146-
146+
147147
if (executionChecks == null || !executionChecks.Any())
148148
{
149149
eligibleCommands.Add(candidateCommand);
@@ -209,7 +209,7 @@ await ctx.RespondAsync(
209209

210210
await ctx.RespondAsync(builder);
211211
}
212-
212+
213213
[Command("pingtextcmd")]
214214
[TextAlias("ping")]
215215
[Description("Pong? This command lets you know whether I'm working well.")]
@@ -225,7 +225,7 @@ await return_message.ModifyAsync($"P{letter}ng! 🏓\n" +
225225
$"• It took me `{ping}ms` to reply to your message!\n" +
226226
$"• Last Websocket Heartbeat took `{Math.Round(ctx.Client.GetConnectionLatency(0).TotalMilliseconds, 0)}ms`!");
227227
}
228-
228+
229229
[Command("userinfo")]
230230
[TextAlias("user-info", "whois")]
231231
[Description("Show info about a user.")]
@@ -283,7 +283,7 @@ public async Task RemindMe(
283283
await Program.db.ListRightPushAsync("reminders", JsonConvert.SerializeObject(reminderObject));
284284
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} I'll try my best to remind you about that on <t:{TimeHelpers.ToUnixTimestamp(t)}:f> (<t:{TimeHelpers.ToUnixTimestamp(t)}:R>)"); // (In roughly **{TimeHelpers.TimeToPrettyFormat(t.Subtract(ctx.Message.Timestamp.DateTime), false)}**)");
285285
}
286-
286+
287287
public class Reminder
288288
{
289289
[JsonProperty("userID")]
@@ -307,7 +307,7 @@ public class Reminder
307307
[JsonProperty("originalTime")]
308308
public DateTime OriginalTime { get; set; }
309309
}
310-
310+
311311
// Runs command context checks manually. Returns a list of failed checks.
312312
// Unfortunately DSharpPlus.Commands does not provide a way to execute a command's context checks manually,
313313
// so this will have to do. This may not include all checks, but it includes everything I could think of. -Milkshake
@@ -344,7 +344,7 @@ private async Task<IEnumerable<ContextCheckAttribute>> CheckPermissionsAsync(Com
344344
{
345345
failedChecks.Add(homeServerAttribute);
346346
}
347-
347+
348348
if (check is RequireHomeserverPermAttribute requireHomeserverPermAttribute)
349349
{
350350
// Fail if guild is wrong but this command does not work outside of the home server
@@ -377,15 +377,15 @@ private async Task<IEnumerable<ContextCheckAttribute>> CheckPermissionsAsync(Com
377377
failedChecks.Add(requirePermissionsAttribute);
378378
}
379379
}
380-
380+
381381
if (check is IsBotOwnerAttribute isBotOwnerAttribute)
382382
{
383383
if (!Program.cfgjson.BotOwners.Contains(ctx.User.Id))
384384
{
385385
failedChecks.Add(isBotOwnerAttribute);
386386
}
387387
}
388-
388+
389389
if (check is UserRolesPresentAttribute userRolesPresentAttribute)
390390
{
391391
if (Program.cfgjson.UserRoles is null)

0 commit comments

Comments
 (0)