* WOxlf now supports a number of game themes * Each theme can have custom messages, profile pics, phrasing, etc * Messages are defined as tera templates * Couple small improvements + Clippy + fmt
		
			
				
	
	
		
			83 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
use crate::imgur::ImgurError;
 | 
						|
use serenity::prelude::SerenityError;
 | 
						|
use std::fmt::{Display, Formatter};
 | 
						|
use tera::Error;
 | 
						|
 | 
						|
pub type Result<T> = std::result::Result<T, WoxlfError>;
 | 
						|
 | 
						|
#[derive(Debug)]
 | 
						|
pub enum WoxlfError {
 | 
						|
    IOError(std::io::Error),
 | 
						|
    GameStateParseError(toml::de::Error),
 | 
						|
    GameStateSerializeError(toml::ser::Error),
 | 
						|
    DurationParseError,
 | 
						|
    SerenityError(serenity::Error),
 | 
						|
    DiscordIdParseError(String),
 | 
						|
    GameNotInProgress,
 | 
						|
    HostWebhookError,
 | 
						|
    ImgurError(ImgurError),
 | 
						|
    RanOutOfCodenames,
 | 
						|
    TemplateError(tera::Error),
 | 
						|
}
 | 
						|
 | 
						|
impl std::error::Error for WoxlfError {}
 | 
						|
 | 
						|
impl Display for WoxlfError {
 | 
						|
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
 | 
						|
        let msg = match self {
 | 
						|
            WoxlfError::IOError(e) => format!("IO Error: {}", e),
 | 
						|
            WoxlfError::GameStateParseError(e) => format!("Game State Parse Error: {}", e),
 | 
						|
            WoxlfError::GameStateSerializeError(e) => format!("Game State Serialize Error: {}", e),
 | 
						|
            WoxlfError::DurationParseError => "Unable to parse duration".to_string(),
 | 
						|
            WoxlfError::SerenityError(e) => format!("Serenity error: {}", e),
 | 
						|
            WoxlfError::DiscordIdParseError(e) => format!("Unable to parse player id {}", e),
 | 
						|
            WoxlfError::GameNotInProgress => "A game is not currently in progress".to_string(),
 | 
						|
            WoxlfError::HostWebhookError => "Unable to communicate to the host webhook".to_string(),
 | 
						|
            WoxlfError::ImgurError(err) => format!("Imgur module error: {}", err),
 | 
						|
            WoxlfError::RanOutOfCodenames => {
 | 
						|
                "Ran out of codename combinations, add more first/last names to the config"
 | 
						|
                    .to_string()
 | 
						|
            }
 | 
						|
            WoxlfError::TemplateError(e) => format!("Template error: {}", e),
 | 
						|
        };
 | 
						|
 | 
						|
        write!(f, "Woxlf Error: {}", msg)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl From<SerenityError> for WoxlfError {
 | 
						|
    fn from(err: SerenityError) -> Self {
 | 
						|
        Self::SerenityError(err)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl From<std::io::Error> for WoxlfError {
 | 
						|
    fn from(err: std::io::Error) -> Self {
 | 
						|
        Self::IOError(err)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl From<toml::de::Error> for WoxlfError {
 | 
						|
    fn from(err: toml::de::Error) -> Self {
 | 
						|
        Self::GameStateParseError(err)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl From<toml::ser::Error> for WoxlfError {
 | 
						|
    fn from(err: toml::ser::Error) -> Self {
 | 
						|
        Self::GameStateSerializeError(err)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl From<ImgurError> for WoxlfError {
 | 
						|
    fn from(err: ImgurError) -> Self {
 | 
						|
        Self::ImgurError(err)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
impl From<tera::Error> for WoxlfError {
 | 
						|
    fn from(err: Error) -> Self {
 | 
						|
        Self::TemplateError(err)
 | 
						|
    }
 | 
						|
}
 |