Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add joinwatch slash command #183

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Commands/InteractionCommands/JoinwatchInteractions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Cliptok.Commands.InteractionCommands
{
internal class JoinwatchInteractions : ApplicationCommandModule
{
[SlashCommand("joinwatch", "Watch for joins and leaves of a given user. Output goes to #investigations.", defaultPermission: false)]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)]
public async Task JoinwatchSlashCmd(InteractionContext ctx,
[Option("user", "The user to watch for joins and leaves of.")] DiscordUser user,
[Option("note", "An optional note for context.")] string note = "")
{
var joinWatchlist = await Program.db.ListRangeAsync("joinWatchedUsers");

if (joinWatchlist.Contains(user.Id))
{
if (note != "")
{
// User is already joinwatched, just update note
await Program.db.HashSetAsync("joinWatchedUsersNotes", user.Id, note);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully updated the note for {user.Mention}. Run again with no note to unwatch.");
return;
}

// User is already joinwatched, unwatch
Program.db.ListRemove("joinWatchedUsers", joinWatchlist.First(x => x == user.Id));
await Program.db.HashDeleteAsync("joinWatchedUsersNotes", user.Id);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully unwatched {user.Mention}, since they were already in the list.");
}
else
{
// User is not joinwatched, watch
await Program.db.ListRightPushAsync("joinWatchedUsers", user.Id);
if (note != "")
await Program.db.HashSetAsync("joinWatchedUsersNotes", user.Id, note);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Now watching for joins/leaves of {user.Mention} to send to the investigations channel"
+ (note == "" ? "!" : $" with the following note:\n>>> {note}"));
}
}
}

}
Loading