diff --git a/Cargo.lock b/Cargo.lock index cb1a85d..076e8c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,7 +122,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bazooka-bot" -version = "0.7.0" +version = "0.7.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index e0d7b87..6991562 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bazooka-bot" -version = "0.7.0" +version = "0.7.1" edition = "2024" publish = false diff --git a/Shuttle.toml b/Shuttle.toml deleted file mode 100644 index 51db43c..0000000 --- a/Shuttle.toml +++ /dev/null @@ -1 +0,0 @@ -deploy.deny_dirty = true diff --git a/deny.toml b/deny.toml index b1bab53..0c42447 100644 --- a/deny.toml +++ b/deny.toml @@ -3,5 +3,4 @@ ignore = [ # "RUSTSEC-0000-0000", # { id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, { id = "RUSTSEC-2024-0388", reason = "Tracking issue https://github.com/serenity-rs/poise/issues/334" }, - { id = "RUSTSEC-2025-0057", reason = "Tracking issue https://github.com/serenity-rs/serenity/issues/3420" }, ] diff --git a/src/config.rs b/src/config.rs index d09dd57..04dcdc1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,11 +26,12 @@ impl StartupConfig { pub fn try_new(clap_config: &ClapConfig) -> anyhow::Result { let guild_id = clap_config .registration_guild_id - .parse::() - .context("failed to parse guild id") - .map(GuildId::new)?; + .as_ref() + .map(|x| x.parse::().map(GuildId::new)) + .transpose() + .context("failed to parse guild id")?; - // TODO 4 - See if we can split this in clap + // TODO 5 - See if we can split this in clap let owners: HashSet = clap_config .owners .split(',') @@ -41,10 +42,10 @@ impl StartupConfig { }) .collect::>>()?; - let is_production = std::env::var("SHUTTLE").is_ok(); + let is_production = std::env::var("IS_PROD").is_ok(); Ok(Self { - registration_guild_id: Some(guild_id), + registration_guild_id: guild_id, owners, is_production, }) diff --git a/src/lib.rs b/src/lib.rs index 48bd18c..cdb0e8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,7 +92,7 @@ pub struct ClapConfig { /// Used mostly for testing to register the commands directly for the guild #[arg(long, env = "REGISTRATION_GUILD_ID")] - pub registration_guild_id: String, + pub registration_guild_id: Option, /// The RoleId of the role that can run privileged commands #[arg(long, env = "AUTH_ROLE_ID")] diff --git a/src/main.rs b/src/main.rs index ae8a7f1..a59f1fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::Context as _; +use anyhow::{Context as _, bail}; use bazooka_bot::{ClapConfig, Data, SharedConfig, StartupConfig, commands_list, heartbeat}; use poise::serenity_prelude::{ClientBuilder, GatewayIntents}; use secrecy::ExposeSecret; @@ -14,7 +14,7 @@ use version::version; use clap::Parser; #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { tracing_subscriber::registry() .with(fmt::layer().with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)) .with( @@ -27,14 +27,17 @@ async fn main() { // Load setup values info!("Loading environment variables"); - loadenv::load().expect("failed to load .env file"); + match loadenv::load() { + Ok(was_found) => debug!(".env file was found: {was_found}"), + Err(err_msg) => bail!("failed to load .env file: {err_msg:?}"), + } let clap_config = ClapConfig::parse(); debug!("ClapConfig: {:?}", clap_config); let startup_config = - StartupConfig::try_new(&clap_config).expect("failed to create setup config"); + StartupConfig::try_new(&clap_config).context("failed to create setup config")?; let shared_config = - SharedConfig::try_new(&clap_config).expect("failed to created shared_config"); + SharedConfig::try_new(&clap_config).context("failed to created shared_config")?; let discord_token = clap_config.discord_token; let framework = poise::Framework::builder() @@ -101,9 +104,10 @@ async fn main() { ) .framework(framework) .await - .expect("Error creating client"); + .context("Error creating client")?; - if let Err(why) = client.start().await { - error!("Client error: {why:?}"); - } + client + .start() + .await + .context("failed to start discord client") }