From 03e37fbebc92a0e5952bb041138cf43a18750dae Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Tue, 31 Dec 2024 09:06:13 +0100 Subject: [PATCH] Add clear_cache command --- youmubot-osu/src/discord/commands.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/youmubot-osu/src/discord/commands.rs b/youmubot-osu/src/discord/commands.rs index 7e26cc7..e1233b3 100644 --- a/youmubot-osu/src/discord/commands.rs +++ b/youmubot-osu/src/discord/commands.rs @@ -21,7 +21,8 @@ use serenity::all::User; "beatmap", "check", "ranks", - "leaderboard" + "leaderboard", + "clear_cache" ) )] pub async fn osu(_ctx: CmdContext<'_, U>) -> Result<()> { @@ -642,6 +643,24 @@ async fn leaderboard( Ok(()) } +/// Clear youmu's cache. +#[poise::command(slash_command, owners_only)] +pub async fn clear_cache( + ctx: CmdContext<'_, U>, + #[description = "Also clear oppai cache"] clear_oppai: bool, +) -> Result<()> { + let env = ctx.data().osu_env(); + ctx.defer_ephemeral().await?; + + env.beatmaps.clear().await?; + + if clear_oppai { + env.oppai.clear().await?; + } + ctx.reply("Beatmap cache cleared!").await?; + Ok(()) +} + fn arg_from_username_or_discord( username: Option, discord_name: Option,