diff --git a/Cargo.lock b/Cargo.lock index bdd0f3b..84ca8b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -800,7 +800,7 @@ dependencies = [ [[package]] name = "kon" -version = "0.1.8" +version = "0.1.9" dependencies = [ "cargo_toml", "gamedig", diff --git a/Cargo.toml b/Cargo.toml index aabe0ea..0bbbf4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kon" -version = "0.1.8" +version = "0.1.9" rust-version = "1.74" edition = "2021" @@ -11,7 +11,7 @@ cargo_toml = "0.18.0" gamedig = "0.4.1" once_cell = "1.19.0" poise = "0.6.1" -reqwest = "0.11.23" +reqwest = { version = "0.11.23", features = ["json"] } serde_json = "1.0.111" serenity = "0.12.0" sysinfo = "0.30.5" diff --git a/src/commands/status.rs b/src/commands/status.rs index 6247670..1d8055d 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -18,6 +18,8 @@ use reqwest::{ Client, header::USER_AGENT }; +use poise::CreateReply; +use serenity::builder::CreateEmbed; use once_cell::sync::Lazy; use cargo_toml::Manifest; use serde_json::Value; @@ -79,10 +81,11 @@ pub async fn status(_: poise::Context<'_, (), Error>) -> Result<(), Error> { /// Retrieve the server status from ATS #[poise::command(slash_command)] pub async fn ats(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> { + let embed = CreateEmbed::new().color(EMBED_COLOR); match query_server() { Ok(response) => { - ctx.send(|m| m.embed(|e| - e.color(EMBED_COLOR) + ctx.send(CreateReply::default() + .embed(embed .title("American Truck Simulator Server Status") .fields(vec![ ("Name", format!("{}", response.info.name), true), @@ -101,6 +104,7 @@ pub async fn ats(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> { pub async fn wg(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> { let pms_asia = &PMS_BASE; let pms_eu = PMS_BASE.replace("asia", "eu"); + let embed = CreateEmbed::new().color(EMBED_COLOR); let (servers_asia, servers_eu) = join!(pms_serverstatus(&pms_asia), pms_serverstatus(&pms_eu)); @@ -125,11 +129,7 @@ pub async fn wg(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> { embed_fields.push((name, status, true)); } - ctx.send(|m| m.embed(|e| - e.color(EMBED_COLOR) - .title("World of Tanks Server Status") - .fields(embed_fields) - )).await?; + ctx.send(CreateReply::default().embed(embed.title("World of Tanks Server Status").fields(embed_fields))).await?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 8e62366..0985a75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,12 @@ mod commands; -use poise::serenity_prelude::{self as serenity}; use std::env::var; +use poise::serenity_prelude::{self as serenity}; +use serenity::builder::{ + CreateMessage, + CreateEmbed, + CreateEmbedAuthor +}; type Error = Box; @@ -15,22 +20,19 @@ async fn on_ready( ) -> Result<(), Error> { println!("Connected to API as {}", ready.user.name); - serenity::ChannelId(BOT_READY_NOTIFY).send_message(&ctx.http, |m| m.embed(|e| - e.color(EMBED_COLOR) - .thumbnail(ready.user.avatar_url().unwrap_or_default()) - .author(|a| - a.name(format!("{} is ready!", ready.user.name)) - ) - )).await?; + let message = CreateMessage::new(); + let ready_embed = CreateEmbed::new() + .color(EMBED_COLOR) + .thumbnail(ready.user.avatar_url().unwrap_or_default()) + .author(CreateEmbedAuthor::new(format!("{} is ready!", ready.user.name)).clone()); + + serenity::ChannelId::new(BOT_READY_NOTIFY).send_message(&ctx.http, message.add_embed(ready_embed)).await?; let register_commands = var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::().unwrap_or(true); if register_commands { let builder = poise::builtins::create_application_commands(&framework.options().commands); - let commands = serenity::Command::set_global_application_commands(&ctx.http, |commands| { - *commands = builder.clone(); - commands - }).await; + let commands = serenity::Command::set_global_commands(&ctx.http, builder).await; match commands { Ok(cmdmap) => for command in cmdmap.iter() { @@ -47,8 +49,7 @@ async fn on_ready( async fn main() { let token = var("DISCORD_TOKEN").expect("Expected a \"DISCORD_TOKEN\" in the envvar but none was found"); - let client = poise::Framework::builder().token(token) - .intents(serenity::GatewayIntents::GUILDS) + let framework = poise::Framework::builder() .options(poise::FrameworkOptions { commands: vec![ commands::ping::ping(), @@ -65,7 +66,9 @@ async fn main() { ..Default::default() }) .setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework))) - .build().await.expect("Error while building the client"); + .build(); + + let mut client = serenity::ClientBuilder::new(token, serenity::GatewayIntents::GUILDS).framework(framework).await.expect("Error creating client"); if let Err(why) = client.start().await { println!("Client error: {:?}", why);