|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace Cliptok.Commands.InteractionCommands |
| 8 | +{ |
| 9 | + public class NicknameLockInteraction : ApplicationCommandModule |
| 10 | + { |
| 11 | + [SlashCommandGroup("nicknamelock", "Prevent a member from changing their nickname.", defaultPermission: false)] |
| 12 | + [SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator), SlashCommandPermissions(DiscordPermissions.ManageNicknames)] |
| 13 | + public class NicknameLockSlashCommands |
| 14 | + { |
| 15 | + [SlashCommand("enable", "Prevent a member from changing their nickname.")] |
| 16 | + public async Task NicknameLockEnableSlashCmd(InteractionContext ctx, [Option("member", "The member to nickname lock.")] DiscordUser discordUser) |
| 17 | + { |
| 18 | + DiscordMember member = default; |
| 19 | + |
| 20 | + try |
| 21 | + { |
| 22 | + member = await ctx.Guild.GetMemberAsync(discordUser.Id); |
| 23 | + } catch (Exception e) |
| 24 | + { |
| 25 | + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Failed to find {discordUser.Mention} as a member! Are they in the server?\n```\n{e.Message}```", ephemeral: true); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + var currentValue = await Program.db.HashGetAsync($"nicknamelock", discordUser.Id); |
| 30 | + |
| 31 | + if (currentValue.HasValue) |
| 32 | + { |
| 33 | + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {discordUser.Mention} is already nickname locked!", mentions: false); |
| 34 | + } else |
| 35 | + { |
| 36 | + await Program.db.HashSetAsync("nicknamelock", discordUser.Id, member.DisplayName); |
| 37 | + var msg = $"{Program.cfgjson.Emoji.On} Nickname locked {discordUser.Mention} as `{member.DisplayName}`!"; |
| 38 | + await ctx.RespondAsync(msg, mentions: false); |
| 39 | + await LogChannelHelper.LogMessageAsync("nicknames", msg); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + [SlashCommand("disable", "Allow a member to change their nickname again.")] |
| 44 | + public async Task NicknameLockDisableSlashCmd(InteractionContext ctx, [Option("member", "The member to remove the nickname lock for.")] DiscordUser discordUser) |
| 45 | + { |
| 46 | + DiscordMember member = default; |
| 47 | + |
| 48 | + try |
| 49 | + { |
| 50 | + member = await ctx.Guild.GetMemberAsync(discordUser.Id); |
| 51 | + } |
| 52 | + catch (Exception e) |
| 53 | + { |
| 54 | + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Failed to find {discordUser.Mention} as a member! Are they in the server?\n```\n{e.Message}```", ephemeral: true); |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + var currentValue = await Program.db.HashGetAsync($"nicknamelock", discordUser.Id); |
| 59 | + |
| 60 | + if (currentValue.HasValue) |
| 61 | + { |
| 62 | + await Program.db.HashDeleteAsync("nicknamelock", discordUser.Id); |
| 63 | + var msg = $"{Program.cfgjson.Emoji.Off} Removed nickname lock for {discordUser.Mention}!"; |
| 64 | + await ctx.RespondAsync(msg, mentions: false); |
| 65 | + await LogChannelHelper.LogMessageAsync("nicknames", msg); |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {discordUser.Mention} is not nickname locked!", mentions: false); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + [SlashCommand("status", "Check the status of nickname lock for a member.")] |
| 74 | + public async Task NicknameLockStatusSlashCmd(InteractionContext ctx, [Option("member", "The member whose nickname lock status to check.")] DiscordUser discordUser) |
| 75 | + { |
| 76 | + if ((await Program.db.HashGetAsync("nicknamelock", discordUser.Id)).HasValue) |
| 77 | + await ctx.RespondAsync($"{Program.cfgjson.Emoji.On} {discordUser.Mention} is nickname locked.", mentions: false); |
| 78 | + else |
| 79 | + await ctx.RespondAsync($"{Program.cfgjson.Emoji.Off} {discordUser.Mention} is not nickname locked.", mentions: false); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments