Skip to content

Commit

Permalink
tqsunmute: Address PR feedback
Browse files Browse the repository at this point in the history
Allow usage in #bot-commands (adds config.json value), move `else if` into `catch`
  • Loading branch information
FloatingMilkshake committed Mar 1, 2025
1 parent 0e91739 commit 164e767
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 10 additions & 12 deletions Commands/MuteCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,17 @@ public async Task TqsMuteSlashCommand(
return;
}

// Only allow usage in #tech-support, #tech-support-forum, and their threads
// Only allow usage in #tech-support, #tech-support-forum, and their threads + #bot-commands
if (ctx.Channel.Id != Program.cfgjson.TechSupportChannel &&
ctx.Channel.Id != Program.cfgjson.SupportForumId &&
ctx.Channel.Parent.Id != Program.cfgjson.TechSupportChannel &&
ctx.Channel.Parent.Id != Program.cfgjson.SupportForumId)
ctx.Channel.Parent.Id != Program.cfgjson.SupportForumId &&
ctx.Channel.Id != Program.cfgjson.BotCommandsChannel)
{
if (ctx is SlashCommandContext)
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!"));
else
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command can only be used in <#{Program.cfgjson.TechSupportChannel}>, <#{Program.cfgjson.SupportForumId}>, and threads in those channels!");
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command can only be used in <#{Program.cfgjson.TechSupportChannel}>, <#{Program.cfgjson.SupportForumId}>, their threads, and <#{Program.cfgjson.BotCommandsChannel}>!");
return;
}

Expand All @@ -248,7 +249,12 @@ public async Task TqsMuteSlashCommand(
}
catch (DSharpPlus.Exceptions.NotFoundException)
{
// handled below
// couldn't fetch member, fail
if (ctx is SlashCommandContext)
await ctx.EditResponseAsync($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be in the server!");
else
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be in the server!");
return;
}

if (await Program.db.HashExistsAsync("mutes", targetUser.Id) && targetMember is not null && targetMember.Roles.Contains(tqsMutedRole))
Expand All @@ -270,14 +276,6 @@ public async Task TqsMuteSlashCommand(
else
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully unmuted {targetUser.Mention}!");
}
else if (targetMember is null)
{
// couldn't fetch member, fail
if (ctx is SlashCommandContext)
await ctx.EditResponseAsync($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be in the server!");
else
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be in the server!");
}
else
{
// member is not TQS-muted, fail
Expand Down
3 changes: 3 additions & 0 deletions Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ public ulong InsidersChannel

[JsonProperty("githubWorkflowSucessString")]
public string GithubWorkflowSucessString { get; private set; } = "";

[JsonProperty("botCommandsChannel")]
public ulong BotCommandsChannel { get; private set; }
}

public enum Level { Information, Warning, Error, Debug, Verbose }
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,6 @@
450181490345508884
],
"pingBotOwnersOnBadErrors": true,
"githubWorkflowSucessString": "[lists:main] 1 new commit"
"githubWorkflowSucessString": "[lists:main] 1 new commit",
"botCommandsChannel": 740272437719072808
}

0 comments on commit 164e767

Please sign in to comment.