Skip to content

Commit 1a03dee

Browse files
Merge branch 'main' into floatingmilkshake/dsp-command-migration
2 parents 08c424a + 50b1a0f commit 1a03dee

11 files changed

+384
-313
lines changed

Commands/JoinwatchCmds.cs

+4-100
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,7 @@ public async Task JoinwatchToggle(CommandContext ctx,
1616
[Parameter("user"), Description("The user to watch for joins and leaves of.")] DiscordUser user,
1717
[Parameter("note"), Description("An optional note for context.")] string note = "")
1818
{
19-
var joinWatchlist = await Program.db.ListRangeAsync("joinWatchedUsers");
20-
21-
if (joinWatchlist.Contains(user.Id))
22-
{
23-
if (note != "")
24-
{
25-
// User is already joinwatched, just update note
26-
27-
// Get current note; if it's the same, do nothing
28-
var currentNote = await Program.db.HashGetAsync("joinWatchedUsersNotes", user.Id);
29-
if (currentNote == note || (string.IsNullOrWhiteSpace(currentNote) && string.IsNullOrWhiteSpace(note)))
30-
{
31-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {user.Mention} is already being watched with the same note! Nothing to do.");
32-
return;
33-
}
34-
35-
// If note is different, update it
36-
await Program.db.HashSetAsync("joinWatchedUsersNotes", user.Id, note);
37-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully updated the note for {user.Mention} (run again with no note to unwatch):\n> {note}");
38-
return;
39-
}
40-
41-
// User is already joinwatched, unwatch
42-
Program.db.ListRemove("joinWatchedUsers", joinWatchlist.First(x => x == user.Id));
43-
await Program.db.HashDeleteAsync("joinWatchedUsersNotes", user.Id);
44-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully unwatched {user.Mention}, since they were already in the list.");
45-
}
46-
else
47-
{
48-
// User is not joinwatched, watch
49-
await Program.db.ListRightPushAsync("joinWatchedUsers", user.Id);
50-
if (note != "")
51-
await Program.db.HashSetAsync("joinWatchedUsersNotes", user.Id, note);
52-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Now watching for joins/leaves of {user.Mention} to send to the investigations channel"
53-
+ (note == "" ? "!" : $" with the following note:\n>>> {note}"));
54-
}
19+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command is deprecated and no longer works; all joinwatches have been converted to notes. To add a note for this user, please use `/note add user:{user.Id} note:{(string.IsNullOrEmpty(note) ? "<context>" : note)} show_on_join_and_leave:True`; to remove one, use `/note delete user:{user.Id} note:<note>`.");
5520
}
5621

5722
[Command("add")]
@@ -60,84 +25,23 @@ public async Task JoinwatchAdd(CommandContext ctx,
6025
[Parameter("user"), Description("The user to watch for joins and leaves of.")] DiscordUser user,
6126
[Parameter("note"), Description("An optional note for context.")] string note = "")
6227
{
63-
var joinWatchlist = await Program.db.ListRangeAsync("joinWatchedUsers");
64-
65-
if (joinWatchlist.Contains(user.Id))
66-
{
67-
// User is already watched
68-
69-
// Get current note; if it's the same, do nothing
70-
var currentNote = await Program.db.HashGetAsync("joinWatchedUsersNotes", user.Id);
71-
if (currentNote == note || (string.IsNullOrWhiteSpace(currentNote) && string.IsNullOrWhiteSpace(note)))
72-
{
73-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {user.Mention} is already being watched with the same note! Nothing to do.");
74-
return;
75-
}
76-
77-
// If note is different, update it
78-
79-
// If new note is empty, remove instead of changing to empty string!
80-
if (string.IsNullOrWhiteSpace(note))
81-
{
82-
await Program.db.HashDeleteAsync("joinWatchedUsersNotes", user.Id);
83-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully removed the note for {user.Mention}! They are still being watched.");
84-
}
85-
else
86-
{
87-
await Program.db.HashSetAsync("joinWatchedUsersNotes", user.Id, note);
88-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully updated the note for {user.Mention}:\n> {note}");
89-
}
90-
}
91-
else
92-
{
93-
// User is not joinwatched, watch
94-
await Program.db.ListRightPushAsync("joinWatchedUsers", user.Id);
95-
if (note != "")
96-
await Program.db.HashSetAsync("joinWatchedUsersNotes", user.Id, note);
97-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Now watching for joins/leaves of {user.Mention} to send to the investigations channel"
98-
+ (note == "" ? "!" : $" with the following note:\n>>> {note}"));
99-
}
28+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command is deprecated and no longer works; all joinwatches have been converted to notes. Please use `/note add` instead, like this: `/note add user:{user.Id} note:{(string.IsNullOrEmpty(note) ? "<context>" : note)} show_on_join_and_leave:True`");
10029
}
10130

10231
[Command("remove")]
10332
[Description("Stop watching for joins and leaves of a user.")]
10433
public async Task JoinwatchRemove(CommandContext ctx,
10534
[Parameter("user"), Description("The user to stop watching for joins and leaves of.")] DiscordUser user)
10635
{
107-
var joinWatchlist = await Program.db.ListRangeAsync("joinWatchedUsers");
108-
109-
// Check user watch status first; error if not watched
110-
if (!joinWatchlist.Contains(user.Id))
111-
{
112-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {user.Mention} is not being watched! Nothing to do.");
113-
return;
114-
}
115-
116-
Program.db.ListRemove("joinWatchedUsers", joinWatchlist.First(x => x == user.Id));
117-
await Program.db.HashDeleteAsync("joinWatchedUsersNotes", user.Id);
118-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully unwatched {user.Mention}!");
36+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command is deprecated and no longer works; all joinwatches have been converted to notes. Please use `/note delete` instead, like this: `/note delete user:{user.Id} note:<note>`");
11937
}
12038

12139
[Command("status")]
12240
[Description("Check the joinwatch status for a user.")]
12341
public async Task JoinwatchStatus(CommandContext ctx,
12442
[Parameter("user"), Description("The user whose joinwatch status to check.")] DiscordUser user)
12543
{
126-
var joinWatchlist = await Program.db.ListRangeAsync("joinWatchedUsers");
127-
128-
if (joinWatchlist.Contains(user.Id))
129-
{
130-
var note = await Program.db.HashGetAsync("joinWatchedUsersNotes", user.Id);
131-
132-
if (string.IsNullOrWhiteSpace(note))
133-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Information} {user.Mention} is currently being watched, but no note is set.");
134-
else
135-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Information} {user.Mention} is currently being watched with the following note:\n> {note}");
136-
}
137-
else
138-
{
139-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {user.Mention} is not being watched!");
140-
}
44+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command is deprecated and no longer works; all joinwatches have been converted to notes. Please use `/note list user:{user.Id}` to show all of this user's notes, or `/note details user:{user.Id} note:<note>` for details on a specific note, instead. Notes with \"Show on Join & Leave\" enabled will behave like joinwatches.");
14145
}
14246
}
14347
}

Commands/LockdownCmds.cs

+14-12
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ await thread.ModifyAsync(a =>
7979
if (ctx is TextCommandContext)
8080
await ctx.As<TextCommandContext>().Message.DeleteAsync();
8181

82-
bool success = await LockdownHelpers.LockChannelAsync(user: ctx.User, channel: currentChannel, duration: lockDuration, reason: reason, lockThreads: lockThreads);
83-
if (ctx is SlashCommandContext)
82+
try
8483
{
85-
if (success)
86-
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Channel locked successfully.").AsEphemeral(true));
87-
else
88-
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to lock this channel!").AsEphemeral(true));
84+
await LockdownHelpers.LockChannelAsync(user: ctx.User, channel: currentChannel, duration: lockDuration, reason: reason, lockThreads: lockThreads);
85+
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Channel locked successfully.").AsEphemeral(true));
86+
}
87+
catch (ArgumentException)
88+
{
89+
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to lock this channel!").AsEphemeral(true));
8990
}
9091
}
9192

@@ -171,13 +172,14 @@ public class UnlockCmds
171172
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} A mass lockdown or unlock is already ongoing. Refusing your request. sorry.");
172173
return;
173174
}
174-
bool success = await LockdownHelpers.UnlockChannel(currentChannel, ctx.Member);
175-
if (ctx is SlashCommandContext)
175+
try
176176
{
177-
if (success)
178-
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Channel unlocked successfully.").AsEphemeral(true));
179-
else
180-
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to unlock this channel!").AsEphemeral(true));
177+
await LockdownHelpers.UnlockChannel(currentChannel, ctx.Member);
178+
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Channel locked successfully.").AsEphemeral(true));
179+
}
180+
catch (ArgumentException)
181+
{
182+
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent("Failed to lock this channel!").AsEphemeral(true));
181183
}
182184
}
183185

Commands/TrackingCmds.cs

+79-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,89 @@ public class TrackingSlashCommands
1010
{
1111
[Command("add")]
1212
[Description("Track a users messages.")]
13-
public async Task TrackingAddSlashCmd(SlashCommandContext ctx, [Parameter("member"), Description("The member to track.")] DiscordUser discordUser)
13+
public async Task TrackingAddSlashCmd(SlashCommandContext ctx, [Parameter("member"), Description("The member to track.")] DiscordUser discordUser, [Parameter("channels"), Description("Optional channels to filter to. Use IDs or mentions, and separate with commas or spaces.")] string channels = "")
1414
{
1515
await ctx.DeferResponseAsync(ephemeral: false);
16+
17+
var channelsUpdated = false;
18+
19+
// Resolve list of filter channels
20+
List<ulong> filterChannels = new();
21+
if (!string.IsNullOrEmpty(channels))
22+
{
23+
channels = Regex.Replace(channels, ", +", ",").Trim(); // "#general-chat, #lounge" ~> "#general-chat,#lounge" & trim
24+
var channelIds = channels.Split(' ', ',');
25+
foreach (var channel in channelIds)
26+
{
27+
// skip some common obviously-invalid entries
28+
if (channel == "" || channel == " ")
29+
continue;
30+
31+
// If this is a channel mention, get the ID first
32+
var channelId = channel.Replace("<#", "").Replace(">", "");
33+
34+
if (ulong.TryParse(channelId, out var id))
35+
{
36+
if (!filterChannels.Contains(id))
37+
filterChannels.Add(id);
38+
}
39+
else
40+
{
41+
// Invalid ID; couldn't parse as ulong
42+
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} I couldn't parse \"{channel}\" as a channel ID or mention! Please double-check it and try again."));
43+
return;
44+
}
45+
}
46+
}
47+
48+
// If we were passed nothing, filterChannels remains an empty List. Otherwise, it is populated with the parsed channel IDs
49+
50+
// Compare to db; if there is a mismatch, replace whatever is already in the db with what was passed to this command
51+
if (Program.db.HashExists("trackingChannels", discordUser.Id))
52+
{
53+
var dbChannels = Program.db.HashGet("trackingChannels", discordUser.Id).ToString();
54+
string cmdChannels;
55+
if (filterChannels.Count < 1)
56+
{
57+
// No channels were passed. If there are any in the db, remove them
58+
if (await Program.db.HashExistsAsync("trackingChannels", discordUser.Id))
59+
{
60+
await Program.db.HashDeleteAsync("trackingChannels", discordUser.Id);
61+
channelsUpdated = true;
62+
}
63+
}
64+
else
65+
{
66+
cmdChannels = JsonConvert.SerializeObject(filterChannels);
67+
if (dbChannels != cmdChannels)
68+
{
69+
// Passed channels do not match db channels, update db
70+
var newChannels = JsonConvert.SerializeObject(filterChannels);
71+
await Program.db.HashSetAsync("trackingChannels", discordUser.Id, newChannels);
72+
channelsUpdated = true;
73+
}
74+
}
75+
}
76+
else
77+
{
78+
// No channels in db; just add whatever was passed
79+
// If nothing was passed, don't add anything
80+
if (filterChannels.Count > 0)
81+
{
82+
var newChannels = JsonConvert.SerializeObject(filterChannels);
83+
await Program.db.HashSetAsync("trackingChannels", discordUser.Id, newChannels);
84+
channelsUpdated = true;
85+
}
86+
}
1687

1788
if (Program.db.SetContains("trackedUsers", discordUser.Id))
1889
{
90+
if (channelsUpdated)
91+
{
92+
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Success} Successfully updated tracking for {discordUser.Mention}!"));
93+
return;
94+
}
95+
1996
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} This user is already tracked!"));
2097
return;
2198
}
@@ -55,6 +132,7 @@ public async Task TrackingRemoveSlashCmd(SlashCommandContext ctx, [Parameter("me
55132
}
56133

57134
await Program.db.SetRemoveAsync("trackedUsers", discordUser.Id);
135+
await Program.db.HashDeleteAsync("trackingChannels", discordUser.Id);
58136

59137
var channelId = Program.db.HashGet("trackingThreads", discordUser.Id);
60138
DiscordThreadChannel thread = (DiscordThreadChannel)await ctx.Client.GetChannelAsync((ulong)channelId);

0 commit comments

Comments
 (0)