-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathRoleInteractions.cs
122 lines (106 loc) · 6.13 KB
/
RoleInteractions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
namespace Cliptok.Commands.InteractionCommands
{
internal class RoleInteractions : ApplicationCommandModule
{
[SlashCommand("grant", "Grant a user Tier 1, bypassing any verification requirements.", defaultPermission: false)]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator), SlashCommandPermissions(permissions: DiscordPermission.ModerateMembers)]
public async Task SlashGrant(InteractionContext ctx, [Option("user", "The user to grant Tier 1 to.")] DiscordUser _)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command is deprecated and no longer works. Please right click (or tap and hold on mobile) the user and click \"Verify Member\" if available.");
}
[HomeServer]
[SlashCommandGroup("roles", "Opt in/out of roles.")]
internal class RoleSlashCommands
{
[SlashCommand("grant", "Opt into a role.")]
public async Task GrantRole(
InteractionContext ctx,
[Autocomplete(typeof(RolesAutocompleteProvider))]
[Option("role", "The role to opt into.")] string role)
{
DiscordMember member = ctx.Member;
ulong roleId = role switch
{
"insiderCanary" => Program.cfgjson.UserRoles.InsiderCanary,
"insiderDev" => Program.cfgjson.UserRoles.InsiderDev,
"insiderBeta" => Program.cfgjson.UserRoles.InsiderBeta,
"insiderRP" => Program.cfgjson.UserRoles.InsiderRP,
"insider10RP" => Program.cfgjson.UserRoles.Insider10RP,
"patchTuesday" => Program.cfgjson.UserRoles.PatchTuesday,
"giveaways" => Program.cfgjson.UserRoles.Giveaways,
"cts" => Program.cfgjson.CommunityTechSupportRoleID,
_ => 0
};
if (roleId == 0)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Invalid role! Please choose from the list.", ephemeral: true);
return;
}
if (roleId == Program.cfgjson.CommunityTechSupportRoleID && await GetPermLevelAsync(ctx.Member) < ServerPermLevel.TechnicalQueriesSlayer)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.NoPermissions} You must be a TQS member to get the CTS role!", ephemeral: true);
return;
}
var roleData = await ctx.Guild.GetRoleAsync(roleId);
await member.GrantRoleAsync(roleData, $"/roles grant used by {DiscordHelpers.UniqueUsername(ctx.User)}");
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} The role {roleData.Mention} has been successfully granted!", ephemeral: true, mentions: false);
}
[SlashCommand("remove", "Opt out of a role.")]
public async Task RemoveRole(
InteractionContext ctx,
[Autocomplete(typeof(RolesAutocompleteProvider))]
[Option("role", "The role to opt out of.")] string role)
{
DiscordMember member = ctx.Member;
ulong roleId = role switch
{
"insiderCanary" => Program.cfgjson.UserRoles.InsiderCanary,
"insiderDev" => Program.cfgjson.UserRoles.InsiderDev,
"insiderBeta" => Program.cfgjson.UserRoles.InsiderBeta,
"insiderRP" => Program.cfgjson.UserRoles.InsiderRP,
"insider10RP" => Program.cfgjson.UserRoles.Insider10RP,
"patchTuesday" => Program.cfgjson.UserRoles.PatchTuesday,
"giveaways" => Program.cfgjson.UserRoles.Giveaways,
"cts" => Program.cfgjson.CommunityTechSupportRoleID,
_ => 0
};
if (roleId == 0)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Invalid role! Please choose from the list.", ephemeral: true);
return;
}
var roleData = await ctx.Guild.GetRoleAsync(roleId);
await member.RevokeRoleAsync(roleData, $"/roles remove used by {DiscordHelpers.UniqueUsername(ctx.User)}");
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} The role {roleData.Mention} has been successfully removed!", ephemeral: true, mentions: false);
}
}
internal class RolesAutocompleteProvider : IAutocompleteProvider
{
public async Task<IEnumerable<DiscordAutoCompleteChoice>> Provider(AutocompleteContext ctx)
{
Dictionary<string, string> options = new()
{
{ "Windows 11 Insiders (Canary)", "insiderCanary" },
{ "Windows 11 Insiders (Dev)", "insiderDev" },
{ "Windows 11 Insiders (Beta)", "insiderBeta" },
{ "Windows 11 Insiders (Release Preview)", "insiderRP" },
{ "Windows 10 Insiders (Release Preview)", "insider10RP" },
{ "Patch Tuesday", "patchTuesday" },
{ "Giveaways", "giveaways" },
{ "Community Tech Support (CTS)", "cts" }
};
var memberHasTqs = await GetPermLevelAsync(ctx.Member) >= ServerPermLevel.TechnicalQueriesSlayer;
List<DiscordAutoCompleteChoice> list = new();
foreach (var option in options)
{
if (ctx.FocusedOption.Value.ToString() == "" || option.Key.Contains(ctx.FocusedOption.Value.ToString(), StringComparison.OrdinalIgnoreCase))
{
if (option.Value == "cts" && !memberHasTqs) continue;
list.Add(new DiscordAutoCompleteChoice(option.Key, option.Value));
}
}
return list;
}
}
}
}