Changed get_bot_info to return error
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -9,6 +9,7 @@ use reqwest::Client as HttpClient;
|
||||
use serenity::all::{Cache, ShardManager, UserId};
|
||||
use crate::api::App;
|
||||
use crate::bot::handler::BotHandler;
|
||||
use crate::error::{Error, SirenResult};
|
||||
|
||||
mod api;
|
||||
mod bot;
|
||||
@@ -57,7 +58,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.await
|
||||
.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 =
|
||||
env::var("DISCORD_SECRET").expect("Expected a secret in the environment");
|
||||
@@ -118,7 +119,7 @@ fn initialize_environment() -> std::io::Result<()> {
|
||||
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 {
|
||||
Ok(info) => {
|
||||
let bot_owner;
|
||||
@@ -130,11 +131,11 @@ async fn get_bot_info(http: &Http) -> (Option<UserId>, UserId) {
|
||||
bot_owner = None;
|
||||
}
|
||||
match http.get_current_user().await {
|
||||
Ok(bot) => (bot_owner, bot.id),
|
||||
Err(why) => panic!("Could not access the bot id: {why:?}"),
|
||||
Ok(bot) => Ok((bot_owner, bot.id)),
|
||||
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:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user