Skip to content

Commit d421f33

Browse files
committed
expand RequireSpecificGuildAttribute to work with more than one server and add another server to work with Pirate and PirateBan
1 parent 4e6d709 commit d421f33

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

src/Bot/Helpers/TextCommandHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static bool IsAccessibleToGuild(this Command command, ulong id)
4747
return command.Checks
4848
.TryGetFirst(x => x is RequireSpecificGuildAttribute, out var attr)
4949
&& attr is RequireSpecificGuildAttribute rsga
50-
&& rsga.GuildId == id;
50+
&& rsga.GuildIds.Contains(id);
5151
}
5252

5353
public static async ValueTask<EmbedBuilder> CreateCommandEmbedAsync(Command command, VolteContext ctx)

src/Bot/Systems/Commands/Text/Attributes/Checks/RequireSpecificGuildAttribute.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
namespace Volte.Systems.Commands.Text;
22

3-
public class RequireSpecificGuildAttribute(ulong guildId) : CheckAttribute
3+
public class RequireSpecificGuildAttribute(ulong[] guildIds) : CheckAttribute
44
{
5-
public ulong GuildId => guildId;
5+
public ulong[] GuildIds => guildIds;
66

77
public override ValueTask<CheckResult> CheckAsync(CommandContext context)
88
{
99
var ctx = context.Cast<VolteContext>();
10-
if (ctx.Guild.Id == guildId)
10+
if (GuildIds.Contains(ctx.Guild.Id))
1111
return CheckResult.Successful;
1212

1313
return CheckResult.Failed("Insufficient permission.");

src/Bot/Systems/Commands/Text/Modules/Moderation/PirateBanCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public partial class ModerationModule
44
{
55
[Command("PirateBan", "PBan")]
66
[Description("Bans the user with a very long-winded message as to why piracy is not supported. Content is retrieved from the 'emulationisnotpiracy' tag.")]
7-
[RequireSpecificGuild(1294443224030511104)]
7+
[RequireSpecificGuild([1294443224030511104, 1325735818714943498])]
88
public async Task<ActionResult> PirateBanAsync(
99
[CheckHierarchy, EnsureNotSelf, Description("The target user.")] RestUser user)
1010
{

src/Bot/Systems/Commands/Text/Modules/Moderation/PirateCommand.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,39 @@
22

33
public partial class ModerationModule
44
{
5-
public const ulong VerifiedSwitchOwnerRoleId = 1334992661198930001;
6-
public const ulong NoSupportRoleId = 1298451667863470120;
5+
public readonly Dictionary<Snowflake, Snowflake> GuildsToVerifiedSwitchOwnerRoleIds = new()
6+
{
7+
{ 1294443224030511104, 1334992661198930001 }, // R
8+
{ 1325735818714943498, 1354326584550625460 } // C
9+
};
10+
11+
public readonly Dictionary<Snowflake, Snowflake> GuildsToPirateRoleIds = new()
12+
{
13+
{ 1294443224030511104, 1298451667863470120 }, // R
14+
{ 1325735818714943498, 1405060402362060911 } // C
15+
};
716

817
[Command("Pirate", "NoSupport")]
9-
[Description("Warns the target user for Rule 4, gives them the No Support role, and, if they have it, takes away Verified Switch Owner.")]
10-
[RequireSpecificGuild(1294443224030511104)]
18+
[Description("Warns the target user for piracy, gives them the server's pirate role, and, if they have it, takes away Verified Switch Owner.")]
19+
[RequireSpecificGuild([1294443224030511104, 1325735818714943498])]
1120
public async Task<ActionResult> PirateAsync([CheckHierarchy, EnsureNotSelf, Description("The target user.")] SocketGuildUser member)
1221
{
13-
await member.WarnAsync(Context, "Rule #4");
14-
if (member.HasRole(VerifiedSwitchOwnerRoleId))
15-
await member.RemoveRoleAsync(VerifiedSwitchOwnerRoleId);
22+
await member.WarnAsync(Context, Context.Guild.Id is 1294443224030511104 ? "Rule #4" : "Piracy");
23+
24+
var verifiedRole = GuildsToVerifiedSwitchOwnerRoleIds[Context.Guild.Id];
25+
26+
if (member.HasRole(verifiedRole))
27+
await member.RemoveRoleAsync(verifiedRole);
1628

17-
if (!member.HasRole(NoSupportRoleId))
18-
await member.AddRoleAsync(NoSupportRoleId);
29+
var pirateRole = GuildsToPirateRoleIds[Context.Guild.Id];
30+
31+
if (!member.HasRole(pirateRole))
32+
await member.AddRoleAsync(pirateRole);
1933

20-
return Ok($"Successfully warned **{member}** for piracy, and gave them <@&1298451667863470120>.",
34+
return Ok($"Successfully warned **{member}** for piracy, and gave them <@&{pirateRole.Raw}>.",
2135
_ => ModerationService.OnModActionCompleteAsync(ModActionEventArgs.InContext(Context)
2236
.WithActionType(ModActionType.Warn)
2337
.WithTarget(member)
24-
.WithReason("#rules #4")));
38+
.WithReason(Context.Guild.Id is 1294443224030511104 ? "#rules #4" : "Piracy")));
2539
}
2640
}

0 commit comments

Comments
 (0)