-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathRaidmodeInteractions.cs
128 lines (106 loc) · 6.25 KB
/
RaidmodeInteractions.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
123
124
125
126
127
128
namespace Cliptok.Commands.InteractionCommands
{
internal class RaidmodeInteractions : ApplicationCommandModule
{
[SlashCommandGroup("raidmode", "Commands relating to Raidmode", defaultPermission: false)]
[SlashRequireHomeserverPerm(ServerPermLevel.Moderator)]
[SlashCommandPermissions(permissions: DiscordPermission.ModerateMembers)]
public class RaidmodeSlashCommands : ApplicationCommandModule
{
[SlashCommand("status", "Check the current state of raidmode.")]
public async Task RaidmodeStatus(InteractionContext ctx)
{
if (Program.db.HashExists("raidmode", ctx.Guild.Id))
{
string output = $"Raidmode is currently **enabled**.";
ulong expirationTimeUnix = (ulong)Program.db.HashGet("raidmode", ctx.Guild.Id);
output += $"\nRaidmode ends <t:{expirationTimeUnix}>";
var newAccountAgeKey = Program.db.StringGet("raidmode-accountage");
if (newAccountAgeKey.HasValue)
output += $"\nAccounts created before <t:{newAccountAgeKey}> are still allowed to join.";
await ctx.RespondAsync(output, ephemeral: true);
}
else
{
await ctx.RespondAsync($" Raidmode is currently **disabled**.", ephemeral: true);
}
}
[SlashCommand("on", "Enable raidmode. Defaults to 3 hour length if not specified.")]
public async Task RaidmodeOnSlash(InteractionContext ctx,
[Option("duration", "How long to keep raidmode enabled for.")] string duration = default,
[Option("allowed_account_age", "How old an account can be to be allowed to bypass raidmode. Relative to right now.")] string allowedAccountAge = ""
)
{
if (Program.db.HashExists("raidmode", ctx.Guild.Id))
{
string output = $"Raidmode is already **enabled**.";
ulong expirationTimeUnix = (ulong)Program.db.HashGet("raidmode", ctx.Guild.Id);
output += $"\nRaidmode ends <t:{expirationTimeUnix}>";
var newAccountAgeKey = Program.db.StringGet("raidmode-accountage");
if (newAccountAgeKey.HasValue)
output += $"\nAccounts created before <t:{newAccountAgeKey}> are still allowed to join.";
await ctx.RespondAsync(output);
}
else
{
DateTime parsedExpiration;
if (duration == default)
parsedExpiration = DateTime.Now.AddHours(3);
else
parsedExpiration = HumanDateParser.HumanDateParser.Parse(duration);
long unixExpiration = TimeHelpers.ToUnixTimestamp(parsedExpiration);
Program.db.HashSet("raidmode", ctx.Guild.Id, unixExpiration);
DateTime allowedAgeTime;
if (allowedAccountAge == "")
Program.db.KeyDelete("raidmode-accountage");
else
{
DateTime anchorTime = DateTime.Now;
DateTime parseResult = HumanDateParser.HumanDateParser.Parse(allowedAccountAge, anchorTime);
TimeSpan timeSpan = parseResult - anchorTime;
allowedAgeTime = anchorTime - timeSpan;
Program.db.StringSet("raidmode-accountage", TimeHelpers.ToUnixTimestamp(allowedAgeTime));
}
string userContent = $"Raidmode is now **enabled** and will end <t:{unixExpiration}:R>.";
string logContent = $"{Program.cfgjson.Emoji.On} Raidmode was **enabled** by {ctx.User.Mention} and ends <t:{unixExpiration}:R>.";
// i dont know why im fetching it back but honestly i get so many weird conditions i just want to be informed on the current state
var newAccountAgeKey = Program.db.StringGet("raidmode-accountage");
if (newAccountAgeKey.HasValue)
{
var stringAdd = $"\nAccounts created before <t:{newAccountAgeKey}> will still be allowed to join.";
userContent += stringAdd;
logContent += stringAdd;
}
await ctx.RespondAsync(userContent);
DiscordMessageBuilder response = new DiscordMessageBuilder()
.WithContent(logContent)
.WithAllowedMentions(Mentions.None);
await LogChannelHelper.LogMessageAsync("mod", response);
}
}
[SlashCommand("off", "Disable raidmode immediately.")]
public async Task RaidmodeOffSlash(InteractionContext ctx)
{
if (Program.db.HashExists("raidmode", ctx.Guild.Id))
{
long expirationTimeUnix = (long)Program.db.HashGet("raidmode", ctx.Guild.Id);
Program.db.HashDelete("raidmode", ctx.Guild.Id);
Program.db.KeyDelete("raidmode-accountage");
string resp = $"Raidmode is now **disabled**.\nIt was supposed to end <t:{expirationTimeUnix}:R>.";
var newAccountAgeKey = Program.db.StringGet("raidmode-accountage");
if (newAccountAgeKey.HasValue)
resp += $"\nAccounts created before <t:{newAccountAgeKey}> were still allowed to join.";
await ctx.RespondAsync(resp);
DiscordMessageBuilder response = new DiscordMessageBuilder()
.WithContent($"{Program.cfgjson.Emoji.Off} Raidmode was **disabled** by {ctx.User.Mention}.\nIt was supposed to end <t:{expirationTimeUnix}:R>.")
.WithAllowedMentions(Mentions.None);
await LogChannelHelper.LogMessageAsync("mod", response);
}
else
{
await ctx.RespondAsync($"Raidmode is already **disabled**.");
}
}
}
}
}