Skip to content

Commit

Permalink
Refactor clean_cache function to use clean_cache_inner helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
reiyw committed Apr 12, 2024
1 parent 164bd6b commit 0dd8080
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ssspam-bot/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<SaySoundCache>()
Expand Down Expand Up @@ -487,7 +491,7 @@ pub async fn upload(ctx: Context<'_>, files: Vec<Attachment>) -> anyhow::Result<

storage.write().reload();

clean_cache();
clean_cache_inner(ctx.serenity_context()).await?;

ctx.reply(format!("Successfully uploaded {count} sounds"))
.await
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0dd8080

Please sign in to comment.