diff --git a/src/commands/api.rs b/src/commands/api.rs index 4a1ec37..582525b 100644 --- a/src/commands/api.rs +++ b/src/commands/api.rs @@ -1,10 +1,10 @@ -use chrono; use md5::Digest; use rand::seq::SliceRandom; use reqwest::{Error, Response}; use serde::Deserialize; #[derive(Deserialize, Debug)] +#[allow(dead_code)] struct Session { ret_msg: String, session_id: String, @@ -12,6 +12,7 @@ struct Session { } #[derive(Deserialize, Debug)] +#[allow(dead_code)] pub struct God { #[serde(rename = "Name")] name: String, @@ -20,7 +21,7 @@ pub struct God { async fn get_utc_timestamp() -> Result { let timestamp: String = chrono::Utc::now().format("%Y%m%d%H%M%S").to_string(); - return Ok(timestamp); + Ok(timestamp) } async fn get_signature( @@ -31,16 +32,15 @@ async fn get_signature( ) -> Result { let hash: Digest = md5::compute(format!("{}{}{}{}", dev_id, method, auth_key, timestamp)); let signature: String = format!("{:x}", hash); - return Ok(signature); + Ok(signature) } async fn create_session() -> Result { let dev_id: String = std::env::var("DEV_ID").expect("Missing DEV_ID"); let auth_key: String = std::env::var("AUTH_KEY").expect("Missing AUTH_KEY"); - let method: &str = "createsession"; let timestamp: String = get_utc_timestamp().await?; - let signature: String = get_signature(&dev_id, &method, &auth_key, ×tamp).await?; + let signature: String = get_signature(&dev_id, "createsession", &auth_key, ×tamp).await?; let request: String = format!( "https://api.smitegame.com/smiteapi.svc/createsessionJson/{dev_id}/{signature}/{timestamp}", @@ -51,18 +51,17 @@ async fn create_session() -> Result { let response: Response = reqwest::get(&request).await?; let session: Session = response.json().await?; - return Ok(session); + Ok(session) } async fn get_gods() -> Result, Error> { let dev_id: String = std::env::var("DEV_ID").expect("Missing DEV_ID"); let auth_key: String = std::env::var("AUTH_KEY").expect("Missing AUTH_KEY"); - let method: &str = "getgods"; let session_id: String = create_session().await?.session_id; let timestamp: String = get_utc_timestamp().await?; - let signature: String = get_signature(&dev_id, &method, &auth_key, ×tamp).await?; + let signature: String = get_signature(&dev_id, "getgods", &auth_key, ×tamp).await?; let request: String = format!( "https://api.smitegame.com/smiteapi.svc/getgodsJson/{id}/{signature}/{session}/{timestamp}/1", @@ -74,7 +73,7 @@ async fn get_gods() -> Result, Error> { let response: Response = reqwest::get(&request).await?; let gods: Vec = response.json().await?; - return Ok(gods); + Ok(gods) } pub async fn get_random_god() -> Result { @@ -83,5 +82,5 @@ pub async fn get_random_god() -> Result { .choose(&mut rand::thread_rng()) .expect("Couldn't pick random god."); let name: String = god.name.clone(); - return Ok(name); + Ok(name) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d6aa859..17f3f8d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,5 +1,6 @@ // Group all commands for registration mod api; pub mod random; +pub mod register; pub mod slur; pub mod team; diff --git a/src/commands/random.rs b/src/commands/random.rs index b8f1aca..64b94c0 100644 --- a/src/commands/random.rs +++ b/src/commands/random.rs @@ -11,18 +11,6 @@ pub async fn random(_ctx: Context<'_>) -> Result<(), Error> { /// Picks a random god #[poise::command(slash_command)] pub async fn god(ctx: Context<'_>) -> Result<(), Error> { - if ctx.author().id == serenity::UserId(310437480216395777) { - ctx.send(|f| { - f.embed(|f| { - f.title("Random God") - .description(format!("You main **Aphrodite**, idiot.")) - .color(serenity::Colour::from_rgb(227, 28, 121)) - }) - }) - .await?; - return Ok(()); - } - let god: String = get_random_god().await?; ctx.send(|f| { f.embed(|f| { diff --git a/src/commands/register.rs b/src/commands/register.rs new file mode 100644 index 0000000..d785a34 --- /dev/null +++ b/src/commands/register.rs @@ -0,0 +1,7 @@ +use crate::{Context, Error}; + +#[poise::command(prefix_command, owners_only)] +pub async fn register(ctx: Context<'_>) -> Result<(), Error> { + poise::builtins::register_application_commands_buttons(ctx).await?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 11befb5..4df5668 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ async fn main() { commands::slur::slur(), commands::team::team(), commands::random::random(), + commands::register::register(), ], // IntelliJ doesn't like this, but it's fine. ..Default::default() }) @@ -22,23 +23,10 @@ async fn main() { .intents(serenity::GatewayIntents::non_privileged()) // Set intents for Discord dev portal .setup(|ctx, _ready, framework| { Box::pin(async move { - poise::builtins::register_in_guild( - ctx, - &framework.options().commands, - serenity::GuildId( - std::env::var("GUILD_ID") - .expect("Missing GUILD_ID") // Get GID from env and parse - .parse::() - .unwrap(), - ), - ) - .await?; // Update slash commands in GID - + poise::builtins::register_globally(ctx, &framework.options().commands).await?; // Update slash commands ctx.set_activity(serenity::Activity::playing("SMITE")).await; - Ok(Data {}) }) }); - framework.run().await.unwrap(); }