From 0dd80808bc118873253767c78e45854ba8d4797d Mon Sep 17 00:00:00 2001 From: Ryo Takahashi Date: Sat, 13 Apr 2024 00:41:43 +0900 Subject: [PATCH] Refactor clean_cache function to use clean_cache_inner helper function --- ssspam-bot/src/command.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ssspam-bot/src/command.rs b/ssspam-bot/src/command.rs index 7190301..33f9915 100644 --- a/ssspam-bot/src/command.rs +++ b/ssspam-bot/src/command.rs @@ -290,8 +290,12 @@ pub async fn stop(ctx: Context<'_>) -> anyhow::Result<()> { #[poise::command(prefix_command)] pub async fn clean_cache(ctx: Context<'_>) -> anyhow::Result<()> { - ctx.serenity_context() - .data + clean_cache_inner(ctx.serenity_context()).await?; + Ok(()) +} + +async fn clean_cache_inner(ctx: &SerenityContext) -> anyhow::Result<()> { + ctx.data .read() .await .get::() @@ -487,7 +491,7 @@ pub async fn upload(ctx: Context<'_>, files: Vec) -> anyhow::Result< storage.write().reload(); - clean_cache(); + clean_cache_inner(ctx.serenity_context()).await?; ctx.reply(format!("Successfully uploaded {count} sounds")) .await @@ -525,7 +529,7 @@ pub async fn delete(ctx: Context<'_>, #[rest] rest: String) -> anyhow::Result<() tokio::spawn(update_sounds_bin(storage.read().dir.clone())); - clean_cache(); + clean_cache_inner(ctx.serenity_context()).await?; if deleted.is_empty() { ctx.reply("The given saysounds were not found").await.ok();