-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConfigCommands.cs
388 lines (328 loc) · 18.3 KB
/
ConfigCommands.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Voidway_Bot
{
[SlashCommandGroup("config", "Modify or retrieve configuration values")]
internal class ConfigCommands : ApplicationCommandModule
{
[SlashCommandGroup("discordlog", "Values relating to D#+'s annoying ass log spamming")]
private class Miscellaneous : ApplicationCommandModule
{
[SlashCommand(nameof(Config.ConfigValues.logDiscordDebug), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task LogDiscordDebug(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] bool? value = default)
{
if (value.HasValue)
{
Config.ModifyConfig(cv => cv.logDiscordDebug = value.Value);
return ctx.CreateResponseAsync("Done!", true);
}
return ctx.CreateResponseAsync(Config.GetLogDiscordDebug().ToString(), true);
}
[SlashCommand(nameof(Config.ConfigValues.ignoreDSharpPlusLogsWith), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task IgnoreDiscordLogs(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, or nothing to remove the value at the given index")] string value = "")
{
if (!idx.HasValue)
{
string[] summaries = Array.Empty<string>();
Config.ModifyConfig(cv => summaries = cv.ignoreDSharpPlusLogsWith);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", summaries)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.ignoreDSharpPlusLogsWith = ModifyOrExpand(cv.ignoreDSharpPlusLogsWith, (int)idx.Value, value, string.IsNullOrEmpty(value));
});
return ctx.CreateResponseAsync("Done!", true);
}
}
[SlashCommandGroup("hoist", "hoist hoisthoist. hoist.")]
private class Hoist : ApplicationCommandModule
{
[SlashCommand(nameof(Config.ConfigValues.hoistCharacters), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task HoistCharacters(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] string value = "")
{
if (!string.IsNullOrEmpty(value))
{
Config.ModifyConfig(cv => cv.hoistCharacters = value);
return ctx.CreateResponseAsync("Done!", true);
}
string hoistChars = "";
Config.ModifyConfig(cv => hoistChars = cv.hoistCharacters);
return ctx.CreateResponseAsync("`" + hoistChars + "`", true);
}
[SlashCommand(nameof(Config.ConfigValues.hoistServers), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task HoistServers(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, or nothing to remove the value at the given index")] string _value = "")
{
bool parseSuccess = ulong.TryParse(_value, out ulong value);
if (!idx.HasValue)
{
ulong[] summaries = Array.Empty<ulong>();
Config.ModifyConfig(cv => summaries = cv.hoistServers);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", summaries)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.hoistServers = ModifyOrExpand(cv.hoistServers, (int)idx.Value, value, !parseSuccess);
});
return ctx.CreateResponseAsync("Done!", true);
}
}
[SlashCommandGroup("modio", "Values related to modio announcements")]
private class ModAnnouncements : ApplicationCommandModule
{
[SlashCommand("trimAnnouncementsWithSummaries", "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task AnnouncementCensorSummary(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, or nothing to remove the value at the given index")] string value = "")
{
if (!idx.HasValue)
{
string[] summaries = Array.Empty<string>();
Config.ModifyConfig(cv => summaries = cv.censorModsWithSummaryContaining);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", summaries)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.censorModsWithSummaryContaining = ModifyOrExpand(cv.censorModsWithSummaryContaining, (int)idx.Value, value, string.IsNullOrEmpty(value));
});
return ctx.CreateResponseAsync("Done!", true);
}
[SlashCommand("trimAnnouncementsWithTitles", "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task AnnouncementCensorTitles(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, if it exists")] string value = "")
{
if (!idx.HasValue)
{
string[] titles = Array.Empty<string>();
Config.ModifyConfig(cv => titles = cv.censorModsWithTitlesContaining);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", titles)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.censorModsWithTitlesContaining = ModifyOrExpand(cv.censorModsWithTitlesContaining, (int)idx.Value, value, string.IsNullOrEmpty(value));
});
return ctx.CreateResponseAsync("Done!", true);
}
[SlashCommand("trimAnnouncementsWithTag", "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task AnnouncementCensorTags(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, if it exists")] string value = "")
{
if (!idx.HasValue)
{
string[] titles = Array.Empty<string>();
Config.ModifyConfig(cv => titles = cv.censorModsWithTag);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", titles)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.censorModsWithTag = ModifyOrExpand(cv.censorModsWithTag, (int)idx.Value, value, string.IsNullOrEmpty(value));
});
return ctx.CreateResponseAsync("Done!", true);
}
[SlashCommand(nameof(Config.ConfigValues.ignoreTagspamMods), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task IgnoreTagspamMods(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] bool? value = default)
{
if (value.HasValue)
{
Config.ModifyConfig(cv => cv.logDiscordDebug = value.Value);
return ctx.CreateResponseAsync("Done!", true);
}
return ctx.CreateResponseAsync(Config.GetIgnoreTagspam().ToString(), true);
}
}
[SlashCommandGroup("msgFilter", "Values related to game invite (e.g. Fusion / BLMP) filtering")]
public class MessageFiltering : ApplicationCommandModule
{
[SlashCommand(nameof(Config.ConfigValues.msgFilterServers), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task FilterServers(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, or nothing to remove the value at the given index")] string _value = "")
{
bool parseSuccess = ulong.TryParse(_value, out ulong value);
if (!idx.HasValue)
{
ulong[] summaries = Array.Empty<ulong>();
Config.ModifyConfig(cv => summaries = cv.msgFilterServers);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", summaries)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.msgFilterServers = ModifyOrExpand(cv.msgFilterServers, (int)idx.Value, value, !parseSuccess);
});
return ctx.CreateResponseAsync("Done!", true);
}
[SlashCommand(nameof(Config.ConfigValues.msgFilterExceptions), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task FilterExceptions(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, or nothing to remove the value at the given index")] string _value = "")
{
bool parseSuccess = ulong.TryParse(_value, out ulong value);
if (!idx.HasValue)
{
ulong[] summaries = Array.Empty<ulong>();
Config.ModifyConfig(cv => summaries = cv.msgFilterExceptions);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", summaries)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.msgFilterExceptions = ModifyOrExpand(cv.msgFilterExceptions, (int)idx.Value, value, !parseSuccess);
});
return ctx.CreateResponseAsync("Done!", true);
}
[SlashCommand(nameof(Config.ConfigValues.sendWhenFilterMessage), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task ReactionInvites(InteractionContext ctx,
[Option("index", "List idx to replace, or nothing to read vals. Use a num >= list length to append value")] long? idx = default,
[Option("value", "value to set, if it exists")] string value = "")
{
if (!idx.HasValue)
{
string[] titles = Array.Empty<string>();
Config.ModifyConfig(cv => titles = cv.sendWhenFilterMessage);
return ctx.CreateResponseAsync($"[\n\t{string.Join("\n\t", titles)}\n]", true);
}
Config.ModifyConfig(cv =>
{
cv.sendWhenFilterMessage = ModifyOrExpand(cv.sendWhenFilterMessage, (int)idx.Value, value, string.IsNullOrEmpty(value));
});
return ctx.CreateResponseAsync("Done!", true);
}
[SlashCommand(nameof(Config.ConfigValues.msgFilterMessageTimeout), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task FilterResponseTimeout(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] long? value = default)
{
if (value.HasValue)
{
Config.ModifyConfig(cv => cv.msgFilterMessageTimeout = (int)value.Value);
return ctx.CreateResponseAsync("Done!", true);
}
return ctx.CreateResponseAsync(Config.GetFilterResponseTimeout().ToString(), true);
}
[SlashCommand(nameof(Config.ConfigValues.msgFilterMessageStayTime), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task FilterResponseStayTime(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] long? value = default)
{
if (value.HasValue)
{
Config.ModifyConfig(cv => cv.msgFilterMessageStayTime = (int)value.Value);
return ctx.CreateResponseAsync("Done!", true);
}
return ctx.CreateResponseAsync(Config.GetFilterResponseTimeout().ToString(), true);
}
}
[SlashCommandGroup("threadCreator", "Values related to actions thread owners can perform")]
private class ThreadCreator : ApplicationCommandModule
{
[SlashCommand(nameof(Config.ConfigValues.threadCreatorDeleteMessages), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task ThreadCreatorDeleteMessages(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] bool? value = default)
{
if (value.HasValue)
{
Config.ModifyConfig(cv => cv.threadCreatorDeleteMessages = value.Value);
return ctx.CreateResponseAsync("Done!", true);
}
return ctx.CreateResponseAsync(Config.GetThreadCreatorDeleteMessages().ToString(), true);
}
[SlashCommand(nameof(Config.ConfigValues.threadCreatorPinMessages), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public Task ThreadCreatorPinMessages(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] bool? value = default)
{
if (value.HasValue)
{
Config.ModifyConfig(cv => cv.threadCreatorPinMessages = value.Value);
return ctx.CreateResponseAsync("Done!", true);
}
return ctx.CreateResponseAsync(Config.GetThreadCreatorPinMessages().ToString(), true);
}
}
[SlashCommandGroup("sanityCheck", "Double check runtime values")]
private class SanityCheck : ApplicationCommandModule
{
[SlashCommand(nameof(Config.ConfigValues.moderationChannels), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public async Task ModerationChannel(InteractionContext ctx, [Option("Value", "Some switch or something. Check source.")] bool value = false)
{
ulong id = Config.FetchModerationChannel(ctx.Guild.Id);
string channelName = $"<none found, ID supposedly {id}>";
try
{
DiscordChannel channel = ctx.Guild.Channels[id] ?? throw new NullReferenceException();
channelName = channel.ToString();
}
catch { }
await ctx.CreateResponseAsync("The moderation channel for this server is: " + channelName, true);
}
[SlashCommand(nameof(Config.ConfigValues.messageChannels), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public async Task MessageChannel(InteractionContext ctx, [Option("Value", "Some switch or something. Check source.")] bool value = false)
{
ulong id = Config.FetchMessagesChannel(ctx.Guild.Id);
string channelName = $"<none found, ID supposedly {id}>";
try
{
DiscordChannel channel = ctx.Guild.Channels[id] ?? throw new NullReferenceException();
channelName = channel.ToString();
}
catch { }
await ctx.CreateResponseAsync("The msg channel for this server is: " + channelName, true);
}
}
[SlashCommandGroup("moderation", "Double check runtime values")]
private class Moderation : ApplicationCommandModule
{
[SlashCommand(nameof(Config.ConfigValues.serverModNotesChannels), "Get / set a config value")]
[SlashRequireVoidwayOwner]
public async Task ModNotesChannel(InteractionContext ctx, [Option("Value", "The value to assign, or nothing to retrieve the value.")] long value = 0)
{
if (value != 0)
{
await Config.ModifyConfig(cv => cv.serverModNotesChannels[ctx.Guild.Id.ToString()] = (ulong)value);
await ctx.CreateResponseAsync("Done!", true);
return;
}
string noChannelStr = $"<none found>";
DiscordChannel? channel = await Config.GetModNotesChannel(ctx.Client, ctx.Guild.Id);
await ctx.CreateResponseAsync("The mod notes channel for this server is: " + (channel?.Name ?? noChannelStr), true);
}
}
private static T[] ModifyOrExpand<T>(T[] arr, int idx, T value, bool remove)
{
if (idx >= arr.Length)
{
arr = arr.Append(value).ToArray();
return arr;
}
// THIS IS SO WASTEFUL BRUH
if (idx < arr.Length && remove)
{
List<T> list = arr.ToList();
list.RemoveAt(idx);
return list.ToArray();
}
arr[idx] = value;
return arr;
}
}
}