From 2ff05b1a19154de0f2c729488fa790f82fe886e7 Mon Sep 17 00:00:00 2001 From: toast Date: Sun, 10 Dec 2023 21:03:52 +1100 Subject: [PATCH] Sync and rustify --- src/commands/data.rs | 42 +++++++++++++++++++----------------------- src/commands/ping.rs | 2 +- src/main.rs | 27 +++++++++++++++------------ 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/commands/data.rs b/src/commands/data.rs index a3c16ad..1f2a629 100644 --- a/src/commands/data.rs +++ b/src/commands/data.rs @@ -15,7 +15,6 @@ pub async fn data( // Send a GET request to the provided URL let response = get(&url).await?.json::>().await?; - // println!("{:?}", response); // Extract the required values from the parsed JSON let server = &response["server"]; @@ -28,28 +27,25 @@ pub async fn data( let slot_cap = slots["capacity"].as_i64().unwrap(); let slot_cur = slots["used"].as_i64().unwrap(); - ctx.send(|m| { - m.embed(|e| { - e.color(crate::COLOR) - .author(|a| - a.name(format!("{}/{}", slot_cur, slot_cap)) - ) - .title(name) - .description("*Nobody is playing*") - .fields(vec![ - ("Map", map, true), - ("Version", ver, true), - ("Time", "xx:xx", true), - ("Slot usage", "xx/xx", true), - ("Autosave", "xx", true), - ("Timescale", "0x", true) - ]) - .footer(|f| - f.text("Last updated") - ) - .timestamp(poise::serenity_prelude::Timestamp::now()) - }) - }).await?; + ctx.send(|m| m.embed(|e| e.color(crate::COLOR) + .author(|a| + a.name(format!("{}/{}", slot_cur, slot_cap)) + ) + .title(name) + .description("*Nobody is playing*") + .fields(vec![ + ("Map", map, true), + ("Version", ver, true), + ("Time", "xx:xx", true), + ("Slot usage", "xx/xx", true), + ("Autosave", "xx", true), + ("Timescale", "0x", true) + ]) + .footer(|f| + f.text("Last updated") + ) + .timestamp(poise::serenity_prelude::Timestamp::now()) + )).await?; Ok(()) } diff --git a/src/commands/ping.rs b/src/commands/ping.rs index 03da42d..aa0300e 100644 --- a/src/commands/ping.rs +++ b/src/commands/ping.rs @@ -3,6 +3,6 @@ use crate::Error; /// Check if the bot is alive #[poise::command(slash_command)] pub async fn ping(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> { - ctx.reply(format!("Powong! `{:?}`ms", ctx.ping().await.as_millis())).await?; + ctx.reply(format!("Powong! `{:?}`", ctx.ping().await)).await?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 8f7ae97..610cc19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,15 +13,13 @@ async fn on_ready( ) -> Result<(), Error> { println!("Connected to API as {}", ready.user.name); - serenity::ChannelId(865673694184996888).send_message(&ctx.http, |m| { - m.embed(|e| - e.color(COLOR) - .thumbnail(ready.user.avatar_url().unwrap_or_default()) - .author(|a| - a.name(format!("{} is ready!", ready.user.name)) - ) - ) - }).await?; + serenity::ChannelId(865673694184996888).send_message(&ctx.http, |m| m.embed(|e| + e.color(COLOR) + .thumbnail(ready.user.avatar_url().unwrap_or_default()) + .author(|a| + a.name(format!("{} is ready!", ready.user.name)) + ) + )).await?; let register_commands = std::env::var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::().unwrap_or(true); @@ -58,10 +56,15 @@ async fn main() { commands::data::data() ], pre_command: |ctx| Box::pin(async move { - println!("{} ran /{}", ctx.author().name, ctx.command().name) - }), + let get_guild_name = match ctx.guild() { + Some(guild) => guild.name.clone(), + None => String::from("DM") + }; + println!("[{}] {} ran /{}", get_guild_name, ctx.author().name, ctx.command().qualified_name) + }), ..Default::default() - }).setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework))) + }) + .setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework))) .build().await.expect("Error while building the client"); if let Err(why) = client.start().await {