Changed get_bot_info to return error

This commit is contained in:
2025-01-01 14:54:21 -05:00
parent a3b087688b
commit 70963def92

View File

@@ -9,6 +9,7 @@ use reqwest::Client as HttpClient;
use serenity::all::{Cache, ShardManager, UserId}; use serenity::all::{Cache, ShardManager, UserId};
use crate::api::App; use crate::api::App;
use crate::bot::handler::BotHandler; use crate::bot::handler::BotHandler;
use crate::error::{Error, SirenResult};
mod api; mod api;
mod bot; mod bot;
@@ -57,7 +58,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await .await
.expect("Error creating client"); .expect("Error creating client");
let (bot_owner, bot_id) = get_bot_info(&client.http).await; let (bot_owner, bot_id) = get_bot_info(&client.http).await?;
let client_secret: String = let client_secret: String =
env::var("DISCORD_SECRET").expect("Expected a secret in the environment"); env::var("DISCORD_SECRET").expect("Expected a secret in the environment");
@@ -118,7 +119,7 @@ fn initialize_environment() -> std::io::Result<()> {
Ok(()) Ok(())
} }
async fn get_bot_info(http: &Http) -> (Option<UserId>, UserId) { async fn get_bot_info(http: &Http) -> SirenResult<(Option<UserId>, UserId)> {
match http.get_current_application_info().await { match http.get_current_application_info().await {
Ok(info) => { Ok(info) => {
let bot_owner; let bot_owner;
@@ -130,11 +131,11 @@ async fn get_bot_info(http: &Http) -> (Option<UserId>, UserId) {
bot_owner = None; bot_owner = None;
} }
match http.get_current_user().await { match http.get_current_user().await {
Ok(bot) => (bot_owner, bot.id), Ok(bot) => Ok((bot_owner, bot.id)),
Err(why) => panic!("Could not access the bot id: {why:?}"), Err(why) => Err(Error::new(500, format!("Could not access the bot id: {why:?}"))),
} }
} }
Err(why) => panic!("Could not access application info: {why:?}"), Err(why) => Err(Error::new(500, format!("Could not access application info: {why:?}"))),
} }
} }