add command to claim daily tokens

This commit is contained in:
2024-12-07 23:16:26 -05:00
parent 3bc51c858f
commit 6219dd8175
4 changed files with 47 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
use crate::{Context, Error};
use std::time::{Duration, Instant};
use poise::serenity_prelude as serenity;
/// Redeem 50 daily tokens.
#[poise::command(slash_command, prefix_command)]
pub async fn daily(ctx: Context<'_>) -> Result<(), Error> {
let data = ctx.data();
let mut db = data.database.lock().await;
let db = db.as_mut();
let id = ctx.author().id;
let mut dailies = data.dailies.lock().await;
match dailies.get_mut(&id) {
Some(daily) => {
if daily.elapsed() >= Duration::from_secs(24 * 60 * 60) {
*daily = Instant::now();
super::add_balance(id, 50, db).await?;
ctx.reply("Added **50** credits to your account!").await?;
} else {
let until_next_daily = Duration::from_secs(10) - daily.elapsed();
ctx.reply(format!("Your daily will be available in {:?}.", until_next_daily)).await?;
}
},
None => {
dailies.insert(id.clone(), Instant::now());
super::add_balance(id, 50, db).await?;
ctx.reply("Added **50** credits to your account!").await?;
}
}
Ok(())
}