Skip to content

Commit 3fe757d

Browse files
Add !tqsmute and /tqsmute
1 parent 85434a9 commit 3fe757d

File tree

5 files changed

+198
-30
lines changed

5 files changed

+198
-30
lines changed

CommandChecks/HomeServerPerms.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Cliptok.CommandChecks
1+
using System.Formats.Tar;
2+
3+
namespace Cliptok.CommandChecks
24
{
35
public class ServerPerms
46
{
@@ -16,6 +18,7 @@ public enum ServerPermLevel
1618
Tier8,
1719
TierS,
1820
TierX,
21+
TechnicalQueriesSlayer,
1922
TrialModerator,
2023
Moderator,
2124
Admin,
@@ -38,6 +41,8 @@ public static ServerPermLevel GetPermLevel(DiscordMember target)
3841
return ServerPermLevel.Muted;
3942
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TrialModRole)))
4043
return ServerPermLevel.TrialModerator;
44+
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TqsRoleId)))
45+
return ServerPermLevel.TechnicalQueriesSlayer;
4146
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[9])))
4247
return ServerPermLevel.TierX;
4348
else if (target.Roles.Contains(target.Guild.GetRole(Program.cfgjson.TierRoles[8])))

Commands/InteractionCommands/MuteInteractions.cs

+42
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,47 @@ public async Task UnmuteSlashCommand(
8989
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be muted, *and* an error occurred while attempting to unmute them anyway. Please contact the bot owner, the error has been logged.");
9090
}
9191
}
92+
93+
[SlashCommand("tqsmute", "Temporarily mute a user in tech support channels.")]
94+
[SlashRequireHomeserverPerm(ServerPermLevel.TechnicalQueriesSlayer)]
95+
public async Task TqsMuteSlashCommand(
96+
InteractionContext ctx,
97+
[Option("user", "The user to mute.")] DiscordUser targetUser,
98+
[Option("reason", "The reason for the mute.")] string reason)
99+
{
100+
await ctx.DeferAsync(ephemeral: true);
101+
102+
// Only allow usage in #tech-support, #tech-support-forum, and their threads
103+
if (ctx.Channel.Id != Program.cfgjson.TechSupportChannel &&
104+
ctx.Channel.Id != Program.cfgjson.SupportForumId &&
105+
ctx.Channel.Parent.Id != Program.cfgjson.TechSupportChannel &&
106+
ctx.Channel.Parent.Id != Program.cfgjson.SupportForumId)
107+
{
108+
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!"));
109+
return;
110+
}
111+
112+
DiscordMember targetMember = default;
113+
try
114+
{
115+
targetMember = await ctx.Guild.GetMemberAsync(targetUser.Id);
116+
}
117+
catch (DSharpPlus.Exceptions.NotFoundException)
118+
{
119+
// blah
120+
}
121+
122+
if (targetMember != default && GetPermLevel(ctx.Member) == ServerPermLevel.TechnicalQueriesSlayer && (GetPermLevel(targetMember) >= ServerPermLevel.TechnicalQueriesSlayer || targetMember.IsBot))
123+
{
124+
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, you cannot mute other TQS or staff members."));
125+
return;
126+
}
127+
128+
// mute duration is static for TQS mutes
129+
TimeSpan muteDuration = TimeSpan.FromHours(Program.cfgjson.TqsMuteDurationHours);
130+
131+
await MuteHelpers.MuteUserAsync(targetUser, reason, ctx.User.Id, ctx.Guild, ctx.Channel, muteDuration, true, true);
132+
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Done. Please open a modmail thread for this user if you haven't already!"));
133+
}
92134
}
93135
}

Commands/Mutes.cs

+44-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public async Task UnmuteCmd(CommandContext ctx, [Description("The user you're tr
1212

1313
// todo: store per-guild
1414
DiscordRole mutedRole = ctx.Guild.GetRole(Program.cfgjson.MutedRole);
15+
DiscordRole tqsMutedRole = ctx.Guild.GetRole(Program.cfgjson.TqsMutedRole);
1516

1617
DiscordMember member = default;
1718
try
@@ -23,7 +24,7 @@ public async Task UnmuteCmd(CommandContext ctx, [Description("The user you're tr
2324
Program.discord.Logger.LogWarning(eventId: Program.CliptokEventID, exception: ex, message: "Failed to unmute {user} in {server} because they weren't in the server.", $"{DiscordHelpers.UniqueUsername(targetUser)}", ctx.Guild.Name);
2425
}
2526

26-
if ((await Program.db.HashExistsAsync("mutes", targetUser.Id)) || (member != default && member.Roles.Contains(mutedRole)))
27+
if ((await Program.db.HashExistsAsync("mutes", targetUser.Id)) || (member != default && (member.Roles.Contains(mutedRole) || member.Roles.Contains(tqsMutedRole))))
2728
{
2829
await MuteHelpers.UnmuteUserAsync(targetUser, reason);
2930
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Information} Successfully unmuted **{DiscordHelpers.UniqueUsername(targetUser)}**.");
@@ -93,5 +94,47 @@ public async Task MuteCmd(
9394

9495
_ = MuteHelpers.MuteUserAsync(targetUser, reason, ctx.User.Id, ctx.Guild, ctx.Channel, muteDuration, true);
9596
}
97+
98+
[Command("tqsmute")]
99+
[Description(
100+
"Temporarily mutes a user, preventing them from sending messages in #tech-support and related channels until they're unmuted.")]
101+
[HomeServer, RequireHomeserverPerm(ServerPermLevel.TechnicalQueriesSlayer)]
102+
public async Task TqsMuteCmd(
103+
CommandContext ctx, [Description("The user to mute")] DiscordUser targetUser,
104+
[RemainingText, Description("The reason for the mute")] string reason = "No reason specified.")
105+
{
106+
// Only allow usage in #tech-support, #tech-support-forum, and their threads
107+
if (ctx.Channel.Id != Program.cfgjson.TechSupportChannel &&
108+
ctx.Channel.Id != Program.cfgjson.SupportForumId &&
109+
ctx.Channel.Parent.Id != Program.cfgjson.TechSupportChannel &&
110+
ctx.Channel.Parent.Id != Program.cfgjson.SupportForumId)
111+
{
112+
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!");
113+
return;
114+
}
115+
116+
DiscordMember targetMember = default;
117+
try
118+
{
119+
targetMember = await ctx.Guild.GetMemberAsync(targetUser.Id);
120+
}
121+
catch (DSharpPlus.Exceptions.NotFoundException)
122+
{
123+
// blah
124+
}
125+
126+
if (targetMember != default && GetPermLevel(ctx.Member) == ServerPermLevel.TechnicalQueriesSlayer && (GetPermLevel(targetMember) >= ServerPermLevel.TechnicalQueriesSlayer || targetMember.IsBot))
127+
{
128+
await ctx.Channel.SendMessageAsync($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, you cannot mute other TQS or staff members.");
129+
return;
130+
}
131+
132+
await ctx.Message.DeleteAsync();
133+
134+
// mute duration is static for TQS mutes
135+
TimeSpan muteDuration = TimeSpan.FromHours(Program.cfgjson.TqsMuteDurationHours);
136+
137+
MuteHelpers.MuteUserAsync(targetUser, reason, ctx.User.Id, ctx.Guild, ctx.Channel, muteDuration, true, true);
138+
}
96139
}
97140
}

0 commit comments

Comments
 (0)