add an optional user arg to /daily streak
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
use poise::serenity_prelude::UserId;
|
use poise::serenity_prelude::{UserId, User};
|
||||||
use sqlx::{types::chrono::{DateTime, Utc, TimeZone}, PgExecutor, Row};
|
use sqlx::{types::chrono::{DateTime, Utc, TimeZone}, PgExecutor, Row};
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -59,10 +59,14 @@ where
|
|||||||
|
|
||||||
/// Tells you what your current daily streak is
|
/// Tells you what your current daily streak is
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn streak(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn streak(ctx: Context<'_>, user: Option<User>) -> Result<(), Error> {
|
||||||
let db = &ctx.data().database;
|
let db = &ctx.data().database;
|
||||||
|
let (user, name) = match user {
|
||||||
|
Some(user) => (user.id, user.display_name().to_string()),
|
||||||
|
None => (ctx.author().id, "You".to_string()),
|
||||||
|
};
|
||||||
|
|
||||||
ctx.reply(format!("You have a daily streak of **{}**", get_streak(db, ctx.author().id).await?.unwrap_or(0))).await?;
|
ctx.reply(format!("{name} have a daily streak of **{}**", get_streak(db, user).await?.unwrap_or(0))).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ async fn display_leaderboard(ctx: Context<'_>, t: LeaderboardType) -> Result<(),
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// DIsplay users with the top highest balances
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn tokens(ctx: Context<'_>, count: Option<usize>) -> Result<(), Error> {
|
pub async fn tokens(ctx: Context<'_>, count: Option<usize>) -> Result<(), Error> {
|
||||||
let count = count.unwrap_or(10);
|
let count = count.unwrap_or(10);
|
||||||
@@ -67,6 +68,7 @@ pub async fn tokens(ctx: Context<'_>, count: Option<usize>) -> Result<(), Error>
|
|||||||
display_leaderboard(ctx, LeaderboardType::Tokens(count)).await
|
display_leaderboard(ctx, LeaderboardType::Tokens(count)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Display users with the top highest daily streaks
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn dailies(ctx: Context<'_>, count: Option<usize>) -> Result<(), Error> {
|
pub async fn dailies(ctx: Context<'_>, count: Option<usize>) -> Result<(), Error> {
|
||||||
let count = count.unwrap_or(10);
|
let count = count.unwrap_or(10);
|
||||||
|
|||||||
Reference in New Issue
Block a user