basic leaderboard, %b command
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::common::{self, 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, aliases("bal"))]
|
#[poise::command(slash_command, prefix_command, aliases("bal", "b"))]
|
||||||
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 db = &ctx.data().database;
|
let db = &ctx.data().database;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
use crate::common::{Context, Error};
|
||||||
|
use poise::serenity_prelude::UserId;
|
||||||
|
use sqlx::Row;
|
||||||
|
|
||||||
|
/// Display a leaderboard of the top 10 wealthiest players
|
||||||
|
#[poise::command(slash_command, prefix_command)]
|
||||||
|
pub async fn leaderboard(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let db = &ctx.data().database;
|
||||||
|
|
||||||
|
let rows = sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT id, balance FROM bank
|
||||||
|
ORDER BY balance DESC
|
||||||
|
LIMIT 10
|
||||||
|
"#
|
||||||
|
).fetch_all(db).await?;
|
||||||
|
|
||||||
|
let users: Vec<(_, i32)> = rows.iter().map(|row| (UserId::new(row.get::<i64, _>(0) as u64), row.get(1))).collect();
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
for (id, balance) in users {
|
||||||
|
let user = id.to_user(ctx).await?;
|
||||||
|
output += &format!("{} - {}\n", user.display_name(), balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.reply(format!("```\n{output}```")).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub fn commands() -> Vec<Command<Data, Error>> {
|
|||||||
gambling::give::give(),
|
gambling::give::give(),
|
||||||
gambling::wager::wager(),
|
gambling::wager::wager(),
|
||||||
gambling::daily::daily(),
|
gambling::daily::daily(),
|
||||||
|
gambling::leaderboard::leaderboard(),
|
||||||
eval::eval(),
|
eval::eval(),
|
||||||
self_roles::role(),
|
self_roles::role(),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user