Skip to content

Commit

Permalink
Add ability to store notes for joinwatched users
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Jul 24, 2023
1 parent b56f4e0 commit 756c618
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Commands/Lists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,34 @@ public async Task ScamCheck(CommandContext ctx, [RemainingText, Description("Dom
[HomeServer, RequireHomeserverPerm(ServerPermLevel.TrialModerator)]
public async Task JoinWatch(
CommandContext ctx,
[Description("The user to watch for joins and leaves of.")] DiscordUser user
[Description("The user to watch for joins and leaves of.")] DiscordUser user,
[Description("An optional note for context."), RemainingText] 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);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Now watching for joins/leaves of {user.Mention} to send to the investigations channel!");
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}"));
}
}

Expand Down
10 changes: 10 additions & 0 deletions Events/MemberEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public static async Task GuildMemberAdded(DiscordClient client, GuildMemberAddEv

if (joinWatchlist.Contains(e.Member.Id))
{
if (await db.HashExistsAsync("joinWatchedUsersNotes", e.Member.Id))
{
embed.AddField($"Joinwatch Note", await db.HashGetAsync("joinWatchedUsersNotes", e.Member.Id));
}

LogChannelHelper.LogMessageAsync("investigations", $"{cfgjson.Emoji.Warning} Watched user {e.Member.Mention} just joined the server!", embed);
}

Expand Down Expand Up @@ -176,6 +181,11 @@ public static async Task GuildMemberRemoved(DiscordClient client, GuildMemberRem

if (joinWatchlist.Contains(e.Member.Id))
{
if (await db.HashExistsAsync("joinWatchedUsersNotes", e.Member.Id))
{
embed.AddField($"Joinwatch Note", await db.HashGetAsync("joinWatchedUsersNotes", e.Member.Id));
}

LogChannelHelper.LogMessageAsync("investigations", $"{cfgjson.Emoji.Warning} Watched user {e.Member.Mention} just left the server!", embed);
}
}
Expand Down

0 comments on commit 756c618

Please sign in to comment.