1+ using DiscordIntegration . Bot . Services ;
2+ using DiscordIntegration . Dependency . Database ;
3+
4+ namespace DiscordIntegration . Bot . Commands ;
5+
6+ using Discord ;
7+ using Discord . Interactions ;
8+
9+ [ Group ( "watchlist" , "Commands for managing the watchlist." ) ]
10+ public class WatchlistCommands : InteractionModuleBase < SocketInteractionContext >
11+ {
12+ private readonly Bot bot ;
13+
14+ public WatchlistCommands ( Bot bot ) => this . bot = bot ;
15+
16+ [ SlashCommand ( "add" , "Adds a UserID to the watchlist." ) ]
17+ public async Task AddToWatchlist ( [ Summary ( "UserId" , "The user ID of the player to watch." ) ] string userId , [ Summary ( "Reason" , "The reason they should be watched." ) ] string reason )
18+ {
19+ ErrorCodes canRunCommand = SlashCommandHandler . CanRunCommand ( ( IGuildUser ) Context . User , bot . ServerNumber , "watchlist" ) ;
20+ if ( canRunCommand != ErrorCodes . None )
21+ {
22+ await RespondAsync ( embed : await ErrorHandlingService . GetErrorEmbed ( canRunCommand ) , ephemeral : true ) ;
23+ return ;
24+ }
25+
26+ if ( DatabaseHandler . CheckWatchlist ( userId , out string res ) )
27+ {
28+ await RespondAsync (
29+ embed : await EmbedBuilderService . CreateBasicEmbed ( "User already on Watchlist" ,
30+ $ "The userID { userId } is already on the watchlist for { reason } . If you wish to change the reason, please remove the user first then re-add them.",
31+ Color . Orange ) , ephemeral : true ) ;
32+ return ;
33+ }
34+
35+ DatabaseHandler . AddEntry ( userId , reason ) ;
36+ await RespondAsync (
37+ embed : await EmbedBuilderService . CreateBasicEmbed ( "User added to Watchlist" ,
38+ $ "The userID { userId } has been added to the watchlist for { reason } ", Color . Green ) , ephemeral : true ) ;
39+ }
40+
41+ [ SlashCommand ( "remove" , "Removes a UserID from the watchlist." ) ]
42+ public async Task RemoveFromWatchlist ( [ Summary ( "UserID" , "The user ID of the player to remove from the watchlist." ) ] string userId )
43+ {
44+ ErrorCodes canRunCommand =
45+ SlashCommandHandler . CanRunCommand ( ( IGuildUser ) Context . User , bot . ServerNumber , "watchlist" ) ;
46+ if ( canRunCommand != ErrorCodes . None )
47+ {
48+ await RespondAsync ( embed : await ErrorHandlingService . GetErrorEmbed ( canRunCommand ) , ephemeral : true ) ;
49+ return ;
50+ }
51+
52+ if ( ! DatabaseHandler . CheckWatchlist ( userId , out string _ ) )
53+ {
54+ await RespondAsync ( embed : await ErrorHandlingService . GetErrorEmbed ( ErrorCodes . NoRecordForUserFound ) , ephemeral : true ) ;
55+ return ;
56+ }
57+
58+ DatabaseHandler . RemoveEntry ( userId ) ;
59+ await RespondAsync (
60+ embed : await EmbedBuilderService . CreateBasicEmbed ( "User removed from watchlist." ,
61+ $ "User { userId } has been removed from the watchlist.", Color . Green ) , ephemeral : true ) ;
62+ }
63+ }
0 commit comments