Sync and rustify

This commit is contained in:
toast 2023-12-10 21:03:52 +11:00
parent 3f16bfd086
commit 2ff05b1a19
3 changed files with 35 additions and 36 deletions

View File

@ -15,7 +15,6 @@ pub async fn data(
// Send a GET request to the provided URL
let response = get(&url).await?.json::<HashMap<String, Value>>().await?;
// println!("{:?}", response);
// Extract the required values from the parsed JSON
let server = &response["server"];
@ -28,9 +27,7 @@ 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)
ctx.send(|m| m.embed(|e| e.color(crate::COLOR)
.author(|a|
a.name(format!("{}/{}", slot_cur, slot_cap))
)
@ -48,8 +45,7 @@ pub async fn data(
f.text("Last updated")
)
.timestamp(poise::serenity_prelude::Timestamp::now())
})
}).await?;
)).await?;
Ok(())
}

View File

@ -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(())
}

View File

@ -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|
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?;
)).await?;
let register_commands = std::env::var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().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 {