File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -251,6 +251,28 @@ await ctx.FollowupAsync(new DiscordFollowupMessageBuilder()
251251 [ Description ( "Commands for managing which guilds the bot is in." ) ]
252252 public static class DebugGuildsCommands
253253 {
254+ [ Command ( "lastuse" ) ]
255+ [ Description ( "Show the last time one of the bot's commands was used in a guild." ) ]
256+ public static async Task DebugGuildsLastUseCommandAsync ( SlashCommandContext ctx ,
257+ [ SlashAutoCompleteProvider ( typeof ( DebugGuildsGuildSearchAutoCompleteProvider ) ) ]
258+ [ Parameter ( "guild" ) , Description ( "The guild to show the last use time for. Accepts names or IDs." ) ] string guildId )
259+ {
260+ await ctx . DeferResponseAsync ( ephemeral : ctx . Interaction . ShouldUseEphemeralResponse ( false ) ) ;
261+
262+ var lastUse = await Setup . Storage . Redis . HashGetAsync ( "lastCommandUse" , guildId ) ;
263+ if ( ! lastUse . HasValue )
264+ {
265+ await ctx . FollowupAsync ( new DiscordFollowupMessageBuilder ( )
266+ . WithContent ( "Nothing stored for that guild." )
267+ . AsEphemeral ( ephemeral : ctx . Interaction . ShouldUseEphemeralResponse ( false ) ) ) ;
268+ return ;
269+ }
270+
271+ await ctx . FollowupAsync ( new DiscordFollowupMessageBuilder ( )
272+ . WithContent ( $ "<t:{ JsonConvert . DeserializeObject < DateTime > ( lastUse ) . ToUnixTimeSeconds ( ) } :F>")
273+ . AsEphemeral ( ephemeral : ctx . Interaction . ShouldUseEphemeralResponse ( false ) ) ) ;
274+ }
275+
254276 [ Command ( "info" ) ]
255277 [ Description ( "Get information about a guild." ) ]
256278 public static async Task DebugGuildsInfoCommandAsync ( SlashCommandContext ctx ,
Original file line number Diff line number Diff line change @@ -602,6 +602,13 @@ await Setup.State.Discord.Channels.Home.SendMessageAsync(new DiscordEmbedBuilder
602602 internal static async Task HandleCommandExecutedEventAsync ( CommandsExtension _ , CommandExecutedEventArgs e )
603603 {
604604 await LogInteractionCommandUsageAsync ( e . Context ) ;
605+ if ( e . Context . Guild is not null )
606+ await SaveGuildLastCommandUseAsync ( e . Context . Guild . Id ) ;
607+ }
608+
609+ private static async Task SaveGuildLastCommandUseAsync ( ulong guildId )
610+ {
611+ await Setup . Storage . Redis . HashSetAsync ( "lastCommandUse" , guildId . ToString ( ) , JsonConvert . SerializeObject ( DateTime . UtcNow ) ) ;
605612 }
606613
607614 private static async Task LogInteractionCommandUsageAsync ( CommandContext context )
You can’t perform that action at this time.
0 commit comments