Skip to content

Commit

Permalink
Handle cases where TQS mute role is not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Sep 12, 2024
1 parent e7c3e64 commit 1a60926
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Commands/InteractionCommands/MuteInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public async Task TqsMuteSlashCommand(
{
await ctx.DeferAsync(ephemeral: true);

// only work if TQS mute role is configured
if (Program.cfgjson.TqsMutedRole == 0)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} TQS mutes are not configured, so this command does nothing. Please contact the bot maintainer if this is unexpected."));
return;
}

// 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 Down
10 changes: 9 additions & 1 deletion Commands/Mutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public async Task UnmuteCmd(CommandContext ctx, [Description("The user you're tr

// todo: store per-guild
DiscordRole mutedRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.MutedRole);
DiscordRole tqsMutedRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.TqsMutedRole);
DiscordRole tqsMutedRole = default;
if (Program.cfgjson.TqsMutedRole != 0)
tqsMutedRole = await ctx.Guild.GetRoleAsync(Program.cfgjson.TqsMutedRole);

DiscordMember member = default;
try
Expand Down Expand Up @@ -103,6 +105,12 @@ public async Task TqsMuteCmd(
CommandContext ctx, [Description("The user to mute")] DiscordUser targetUser,
[RemainingText, Description("The reason for the mute")] string reason = "No reason specified.")
{
if (Program.cfgjson.TqsMutedRole == 0)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} TQS mutes are not configured, so this command does nothing. Please contact the bot maintainer if this is unexpected.");
return;
}

// 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 Down
6 changes: 5 additions & 1 deletion Events/MemberEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ public static async Task GuildMemberRemoved(DiscordClient client, GuildMemberRem
return;

var muteRole = await e.Guild.GetRoleAsync(cfgjson.MutedRole);
var tqsMuteRole = await e.Guild.GetRoleAsync(cfgjson.TqsMutedRole);

DiscordRole tqsMuteRole = default;
if (cfgjson.TqsMutedRole != 0)
tqsMuteRole = await e.Guild.GetRoleAsync(cfgjson.TqsMutedRole);

var userMute = await db.HashGetAsync("mutes", e.Member.Id);

if (!userMute.IsNull && !e.Member.Roles.Contains(muteRole) & !e.Member.Roles.Contains(tqsMuteRole))
Expand Down
5 changes: 4 additions & 1 deletion Helpers/MuteHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ public static async Task<bool> UnmuteUserAsync(DiscordUser targetUser, string re

// todo: store per-guild
DiscordRole mutedRole = await guild.GetRoleAsync(Program.cfgjson.MutedRole);
DiscordRole tqsMutedRole = await guild.GetRoleAsync(Program.cfgjson.TqsMutedRole);
DiscordRole tqsMutedRole = default;
if (Program.cfgjson.TqsMutedRole != 0)
tqsMutedRole = await Program.homeGuild.GetRoleAsync(Program.cfgjson.TqsMutedRole);

DiscordMember member = default;
try
{
Expand Down
2 changes: 1 addition & 1 deletion Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public class ConfigJson
public ulong InsiderCanaryThread { get; set; } = 0;

[JsonProperty("tqsMutedRole")]
public ulong TqsMutedRole { get; private set; }
public ulong TqsMutedRole { get; private set; } = 0;

[JsonProperty("tqsMuteDurationHours")]
public int TqsMuteDurationHours { get; private set; }
Expand Down

0 comments on commit 1a60926

Please sign in to comment.