add command to claim daily tokens
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::common::{Context, Error};
|
|||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude as serenity;
|
||||||
|
|
||||||
/// Tells you what your or someone else's balance is
|
/// Tells you what your or someone else's balance is
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command, aliases("bal"))]
|
||||||
pub async fn balance(ctx: Context<'_>, user: Option<serenity::User>) -> Result<(), Error> {
|
pub async fn balance(ctx: Context<'_>, user: Option<serenity::User>) -> Result<(), Error> {
|
||||||
let user = user.as_ref().unwrap_or(ctx.author());
|
let user = user.as_ref().unwrap_or(ctx.author());
|
||||||
let data = ctx.data();
|
let data = ctx.data();
|
||||||
|
|||||||
37
src/commands/gambling/daily.rs
Normal file
37
src/commands/gambling/daily.rs
Normal 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(())
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
pub mod balance;
|
pub mod balance;
|
||||||
pub mod give;
|
pub mod give;
|
||||||
pub mod wager;
|
pub mod wager;
|
||||||
|
pub mod daily;
|
||||||
|
|
||||||
use crate::common::Error;
|
use crate::common::Error;
|
||||||
use poise::serenity_prelude::UserId;
|
use poise::serenity_prelude::UserId;
|
||||||
@@ -28,4 +29,10 @@ pub async fn change_balance(id: UserId, balance: i32, db: &mut PgConnection) ->
|
|||||||
.execute(db).await?;
|
.execute(db).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn add_balance(id: UserId, amount: i32, db: &mut PgConnection) -> Result<(), Error> {
|
||||||
|
let balance = get_balance(id, db).await?;
|
||||||
|
change_balance(id, balance + amount, db).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ mod dox;
|
|||||||
mod yeehaw;
|
mod yeehaw;
|
||||||
mod gambling;
|
mod gambling;
|
||||||
mod eval;
|
mod eval;
|
||||||
|
mod self_roles;
|
||||||
|
|
||||||
pub fn commands() -> Vec<Command<Data, Error>> {
|
pub fn commands() -> Vec<Command<Data, Error>> {
|
||||||
vec![
|
vec![
|
||||||
@@ -15,6 +16,7 @@ pub fn commands() -> Vec<Command<Data, Error>> {
|
|||||||
gambling::balance::balance(),
|
gambling::balance::balance(),
|
||||||
gambling::give::give(),
|
gambling::give::give(),
|
||||||
gambling::wager::wager(),
|
gambling::wager::wager(),
|
||||||
|
gambling::daily::daily(),
|
||||||
eval::eval(),
|
eval::eval(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user