Removed imgur support
parent
6dd12fd561
commit
34cb744091
|
@ -2348,7 +2348,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "woxlf"
|
name = "woxlf"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "woxlf"
|
name = "woxlf"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct GameConfig {
|
||||||
pub vote_phase_name: String,
|
pub vote_phase_name: String,
|
||||||
pub enemy_phase_name: String,
|
pub enemy_phase_name: String,
|
||||||
pub player_group_name: String,
|
pub player_group_name: String,
|
||||||
pub profile_album_hash: String,
|
pub profile_album: Vec<String>,
|
||||||
pub whispers_allowed: bool,
|
pub whispers_allowed: bool,
|
||||||
pub roles: Vec<Role>,
|
pub roles: Vec<Role>,
|
||||||
pub first_name: Vec<String>,
|
pub first_name: Vec<String>,
|
||||||
|
|
|
@ -11,7 +11,6 @@ use crate::game::game_state::PhaseDuration;
|
||||||
use crate::game::global_data::GlobalData;
|
use crate::game::global_data::GlobalData;
|
||||||
use crate::game::player_data::PlayerData;
|
use crate::game::player_data::PlayerData;
|
||||||
use crate::game::role::Role;
|
use crate::game::role::Role;
|
||||||
use crate::imgur::Image;
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn add_user_to_game(
|
pub async fn add_user_to_game(
|
||||||
|
@ -21,7 +20,7 @@ pub async fn add_user_to_game(
|
||||||
discord_user: &Member,
|
discord_user: &Member,
|
||||||
first_name: Option<String>,
|
first_name: Option<String>,
|
||||||
last_name: Option<String>,
|
last_name: Option<String>,
|
||||||
profile_pic: Option<Image>,
|
profile_pic: Option<String>,
|
||||||
role: Option<Role>,
|
role: Option<Role>,
|
||||||
) -> error::Result<PlayerData> {
|
) -> error::Result<PlayerData> {
|
||||||
if first_name.is_none() && last_name.is_none() {
|
if first_name.is_none() && last_name.is_none() {
|
||||||
|
@ -72,7 +71,7 @@ pub async fn add_user_to_game(
|
||||||
vote_target: None,
|
vote_target: None,
|
||||||
codename,
|
codename,
|
||||||
channel_webhook_id: webhook.id.0,
|
channel_webhook_id: webhook.id.0,
|
||||||
profile_pic_url: profile_pic.unwrap().link,
|
profile_pic_url: profile_pic.unwrap(),
|
||||||
alive: true,
|
alive: true,
|
||||||
role: role.unwrap(),
|
role: role.unwrap(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -83,7 +83,7 @@ async fn start(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
first_names.shuffle(&mut thread_rng());
|
first_names.shuffle(&mut thread_rng());
|
||||||
last_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());
|
profile_pics.shuffle(&mut thread_rng());
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::imgur::ImgurError;
|
|
||||||
use serenity::prelude::SerenityError;
|
use serenity::prelude::SerenityError;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
use tera::Error;
|
use tera::Error;
|
||||||
|
@ -15,7 +14,6 @@ pub enum WoxlfError {
|
||||||
DiscordIdParseError(String),
|
DiscordIdParseError(String),
|
||||||
GameNotInProgress,
|
GameNotInProgress,
|
||||||
HostWebhookError,
|
HostWebhookError,
|
||||||
ImgurError(ImgurError),
|
|
||||||
RanOutOfCodenames,
|
RanOutOfCodenames,
|
||||||
TemplateError(tera::Error),
|
TemplateError(tera::Error),
|
||||||
RanOutOfProfilePics,
|
RanOutOfProfilePics,
|
||||||
|
@ -38,7 +36,6 @@ impl Display for WoxlfError {
|
||||||
WoxlfError::DiscordIdParseError(e) => format!("Unable to parse player id {}", e),
|
WoxlfError::DiscordIdParseError(e) => format!("Unable to parse player id {}", e),
|
||||||
WoxlfError::GameNotInProgress => "A game is not currently in progress".to_string(),
|
WoxlfError::GameNotInProgress => "A game is not currently in progress".to_string(),
|
||||||
WoxlfError::HostWebhookError => "Unable to communicate to the host webhook".to_string(),
|
WoxlfError::HostWebhookError => "Unable to communicate to the host webhook".to_string(),
|
||||||
WoxlfError::ImgurError(err) => format!("Imgur module error: {}", err),
|
|
||||||
WoxlfError::RanOutOfCodenames => {
|
WoxlfError::RanOutOfCodenames => {
|
||||||
"Ran out of codename combinations, add more first/last names to the config"
|
"Ran out of codename combinations, add more first/last names to the config"
|
||||||
.to_string()
|
.to_string()
|
||||||
|
@ -81,12 +78,6 @@ impl From<toml::ser::Error> for WoxlfError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ImgurError> for WoxlfError {
|
|
||||||
fn from(err: ImgurError) -> Self {
|
|
||||||
Self::ImgurError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<tera::Error> for WoxlfError {
|
impl From<tera::Error> for WoxlfError {
|
||||||
fn from(err: Error) -> Self {
|
fn from(err: Error) -> Self {
|
||||||
Self::TemplateError(err)
|
Self::TemplateError(err)
|
||||||
|
|
|
@ -9,7 +9,6 @@ use crate::config::{BotConfig, GameConfig};
|
||||||
use crate::error::{Result, WoxlfError};
|
use crate::error::{Result, WoxlfError};
|
||||||
use crate::game::game_state::GameState;
|
use crate::game::game_state::GameState;
|
||||||
use crate::game::Phase;
|
use crate::game::Phase;
|
||||||
use crate::imgur::{get_album_images, Image};
|
|
||||||
use crate::messages::MessageTemplates;
|
use crate::messages::MessageTemplates;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -129,14 +128,6 @@ impl GlobalData {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_profile_pic_album(&self) -> Result<Vec<Image>> {
|
|
||||||
Ok(get_album_images(
|
|
||||||
&self.cfg.imgur_client_id,
|
|
||||||
&self.game_cfg()?.profile_album_hash,
|
|
||||||
)
|
|
||||||
.await?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_phase_name(&self) -> Result<String> {
|
pub fn get_phase_name(&self) -> Result<String> {
|
||||||
let game_cfg = self.game_cfg()?;
|
let game_cfg = self.game_cfg()?;
|
||||||
let state = self.game_state()?;
|
let state = self.game_state()?;
|
||||||
|
|
|
@ -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<reqwest::Error> 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<Vec<Image>>,
|
|
||||||
error: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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<String>,
|
|
||||||
pub description: Option<String>,
|
|
||||||
#[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<Vec<Image>, 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(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,9 +15,8 @@ mod config;
|
||||||
mod discord;
|
mod discord;
|
||||||
mod error;
|
mod error;
|
||||||
mod game;
|
mod game;
|
||||||
mod imgur;
|
|
||||||
mod messages;
|
|
||||||
|
|
||||||
|
mod messages;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let args: Args = Args::from_args();
|
let args: Args = Args::from_args();
|
||||||
|
|
Loading…
Reference in New Issue