From 34cb7440917e71bf040768498a35d90ff5800afe Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Fri, 8 Dec 2023 20:15:32 -0700 Subject: [PATCH] Removed imgur support --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config.rs | 2 +- src/discord/helper.rs | 5 ++- src/discord/host.rs | 2 +- src/error.rs | 9 ----- src/game/global_data.rs | 9 ----- src/imgur/mod.rs | 73 ----------------------------------------- src/main.rs | 3 +- 9 files changed, 7 insertions(+), 100 deletions(-) delete mode 100644 src/imgur/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 5fd7083..f3ed641 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2348,7 +2348,7 @@ dependencies = [ [[package]] name = "woxlf" -version = "0.3.0" +version = "0.3.1" dependencies = [ "bitflags", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 14da5e4..465c03d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "woxlf" -version = "0.3.0" +version = "0.3.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/config.rs b/src/config.rs index e424a08..f523200 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,7 +20,7 @@ pub struct GameConfig { pub vote_phase_name: String, pub enemy_phase_name: String, pub player_group_name: String, - pub profile_album_hash: String, + pub profile_album: Vec, pub whispers_allowed: bool, pub roles: Vec, pub first_name: Vec, diff --git a/src/discord/helper.rs b/src/discord/helper.rs index 620d123..c3658b5 100644 --- a/src/discord/helper.rs +++ b/src/discord/helper.rs @@ -11,7 +11,6 @@ use crate::game::game_state::PhaseDuration; use crate::game::global_data::GlobalData; use crate::game::player_data::PlayerData; use crate::game::role::Role; -use crate::imgur::Image; #[allow(clippy::too_many_arguments)] pub async fn add_user_to_game( @@ -21,7 +20,7 @@ pub async fn add_user_to_game( discord_user: &Member, first_name: Option, last_name: Option, - profile_pic: Option, + profile_pic: Option, role: Option, ) -> error::Result { if first_name.is_none() && last_name.is_none() { @@ -72,7 +71,7 @@ pub async fn add_user_to_game( vote_target: None, codename, channel_webhook_id: webhook.id.0, - profile_pic_url: profile_pic.unwrap().link, + profile_pic_url: profile_pic.unwrap(), alive: true, role: role.unwrap(), }; diff --git a/src/discord/host.rs b/src/discord/host.rs index 87b6583..2245dce 100644 --- a/src/discord/host.rs +++ b/src/discord/host.rs @@ -83,7 +83,7 @@ async fn start(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { first_names.shuffle(&mut thread_rng()); last_names.shuffle(&mut thread_rng()); - let mut profile_pics = global_data.get_profile_pic_album().await?; + let mut profile_pics = global_data.game_cfg()?.profile_album.clone(); profile_pics.shuffle(&mut thread_rng()); diff --git a/src/error.rs b/src/error.rs index 99ad9ab..0176353 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,3 @@ -use crate::imgur::ImgurError; use serenity::prelude::SerenityError; use std::fmt::{Display, Formatter}; use tera::Error; @@ -15,7 +14,6 @@ pub enum WoxlfError { DiscordIdParseError(String), GameNotInProgress, HostWebhookError, - ImgurError(ImgurError), RanOutOfCodenames, TemplateError(tera::Error), RanOutOfProfilePics, @@ -38,7 +36,6 @@ impl Display for WoxlfError { 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() @@ -81,12 +78,6 @@ impl From for WoxlfError { } } -impl From for WoxlfError { - fn from(err: ImgurError) -> Self { - Self::ImgurError(err) - } -} - impl From for WoxlfError { fn from(err: Error) -> Self { Self::TemplateError(err) diff --git a/src/game/global_data.rs b/src/game/global_data.rs index 733bf4d..a5e81a6 100644 --- a/src/game/global_data.rs +++ b/src/game/global_data.rs @@ -9,7 +9,6 @@ use crate::config::{BotConfig, GameConfig}; use crate::error::{Result, WoxlfError}; use crate::game::game_state::GameState; use crate::game::Phase; -use crate::imgur::{get_album_images, Image}; use crate::messages::MessageTemplates; #[derive(Debug, Clone)] @@ -129,14 +128,6 @@ impl GlobalData { Ok(()) } - pub async fn get_profile_pic_album(&self) -> Result> { - Ok(get_album_images( - &self.cfg.imgur_client_id, - &self.game_cfg()?.profile_album_hash, - ) - .await?) - } - pub fn get_phase_name(&self) -> Result { let game_cfg = self.game_cfg()?; let state = self.game_state()?; diff --git a/src/imgur/mod.rs b/src/imgur/mod.rs deleted file mode 100644 index ce0dfd2..0000000 --- a/src/imgur/mod.rs +++ /dev/null @@ -1,73 +0,0 @@ -use reqwest::Client; -use serde::{Deserialize, Serialize}; -use std::fmt::{Display, Formatter}; - -#[derive(Debug)] -pub enum ImgurError { - ReqwestError(reqwest::Error), - ImgurRequestError(String), -} - -impl From for ImgurError { - fn from(e: reqwest::Error) -> Self { - Self::ReqwestError(e) - } -} - -impl Display for ImgurError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - let msg = match self { - ImgurError::ReqwestError(err) => format!("Reqwest error: {}", err), - ImgurError::ImgurRequestError(msg) => format!("Imgur request error: {}", msg), - }; - - write!(f, "{}", msg) - } -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct AlbumData { - images: Option>, - error: Option, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct AlbumResponse { - data: AlbumData, - success: bool, - status: i32, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -pub struct Image { - pub id: String, - pub title: Option, - pub description: Option, - #[serde(rename = "type")] - pub img_type: String, - pub animated: bool, - pub width: i32, - pub height: i32, - pub size: i32, - pub link: String, -} - -pub async fn get_album_images(client_id: &str, album_hash: &str) -> Result, ImgurError> { - let client = Client::new(); - - let res = client - .get(format!("https://api.imgur.com/3/album/{}", album_hash)) - .header("Authorization", format!("Client-ID {}", client_id)) - .send() - .await?; - - let album_response: AlbumResponse = res.json().await?; - - if album_response.success { - Ok(album_response.data.images.unwrap()) - } else { - Err(ImgurError::ImgurRequestError( - album_response.data.error.unwrap(), - )) - } -} diff --git a/src/main.rs b/src/main.rs index ca4ed76..4b261d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,9 +15,8 @@ mod config; mod discord; mod error; mod game; -mod imgur; -mod messages; +mod messages; #[tokio::main] async fn main() { let args: Args = Args::from_args();