Skip to content

Commit

Permalink
Add opt-in Giveaways role
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Jan 14, 2024
1 parent 62fba80 commit ac872a8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Commands/InteractionCommands/RoleInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public async Task GrantRole(
[Choice("Windows 11 Insiders (Release Preview)", "insiderRP")]
[Choice("Windows 10 Insiders (Release Preview)", "insider10RP")]
[Choice("Patch Tuesday", "patchTuesday")]
[Choice("Giveaways", "giveaways")]
[Option("role", "The role to opt into.")] string role)
{
DiscordMember member = ctx.Member;
Expand All @@ -48,6 +49,7 @@ public async Task GrantRole(
"insiderRP" => Program.cfgjson.UserRoles.InsiderRP,
"insider10RP" => Program.cfgjson.UserRoles.Insider10RP,
"patchTuesday" => Program.cfgjson.UserRoles.PatchTuesday,
"giveaways" => Program.cfgjson.UserRoles.Giveaways,
_ => throw new NotSupportedException()
};

Expand All @@ -66,6 +68,7 @@ public async Task RemoveRole(
[Choice("Windows 11 Insiders (Release Preview)", "insiderRP")]
[Choice("Windows 10 Insiders (Release Preview)", "insider10RP")]
[Choice("Patch Tuesday", "patchTuesday")]
[Choice("Giveaways", "giveaways")]
[Option("role", "The role to opt out of.")] string role)
{
DiscordMember member = ctx.Member;
Expand All @@ -78,6 +81,7 @@ public async Task RemoveRole(
"insiderRP" => Program.cfgjson.UserRoles.InsiderRP,
"insider10RP" => Program.cfgjson.UserRoles.Insider10RP,
"patchTuesday" => Program.cfgjson.UserRoles.PatchTuesday,
"giveaways" => Program.cfgjson.UserRoles.Giveaways,
_ => throw new NotSupportedException()
};

Expand Down
9 changes: 9 additions & 0 deletions Commands/UserRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ public static async Task GiveUserRolesAsync(CommandContext ctx, Func<System.Refl
DiscordGuild guild = await Program.discord.GetGuildAsync(ctx.Guild.Id);
String response = "";
System.Reflection.PropertyInfo[] roleIds = Program.cfgjson.UserRoles.GetType().GetProperties().Where(predicate).ToArray();

for (int i = 0; i < roleIds.Length; i++)
{
// quick patch to exclude giveaways role
if ((ulong)roleIds[i].GetValue(Program.cfgjson.UserRoles, null) == Program.cfgjson.UserRoles.Giveaways)
continue;

DiscordRole roleToGrant = guild.GetRole((ulong)roleIds[i].GetValue(Program.cfgjson.UserRoles, null));
await ctx.Member.GrantRoleAsync(roleToGrant);

Expand Down Expand Up @@ -55,6 +60,10 @@ public static async Task RemoveUserRolesAsync(CommandContext ctx, Func<System.Re
System.Reflection.PropertyInfo[] roleIds = Program.cfgjson.UserRoles.GetType().GetProperties().Where(predicate).ToArray();
foreach (System.Reflection.PropertyInfo roleId in roleIds)
{
// quick patch to exclude giveaways role
if ((ulong)roleId.GetValue(Program.cfgjson.UserRoles, null) == Program.cfgjson.UserRoles.Giveaways)
return;

DiscordRole roleToGrant = guild.GetRole((ulong)roleId.GetValue(Program.cfgjson.UserRoles, null));
await ctx.Member.RevokeRoleAsync(roleToGrant);
}
Expand Down
3 changes: 3 additions & 0 deletions Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ public class UserRoleConfig

[JsonProperty("patchTuesday")]
public ulong PatchTuesday { get; private set; }

[JsonProperty("giveaways")]
public ulong Giveaways { get; private set; }
}

public class PhishingRequestBody
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@
"insiderBeta": 643712828217360394,
"insiderRP": 288729239921098752,
"insider10RP": 910319453491839069,
"patchTuesday": 445773142233710594
"patchTuesday": 445773142233710594,
"giveaways": 1169336992455200820
},
"modmailCategory": 536572162450915340,
"autobanIds": [
Expand Down

0 comments on commit ac872a8

Please sign in to comment.