Ensure profile pics are random
+ Clippy + fmtmsg_refactor
parent
dbaa622eb7
commit
0f70ac5f51
|
@ -87,10 +87,24 @@ 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?;
|
||||||
|
|
||||||
|
profile_pics.shuffle(&mut thread_rng());
|
||||||
|
|
||||||
for player in players {
|
for player in players {
|
||||||
let first_name = first_names.pop();
|
let first_name = first_names.pop();
|
||||||
let last_name = last_names.pop();
|
let last_name = last_names.pop();
|
||||||
add_user_to_game(ctx, &guild, &mut global_data, player, first_name, last_name).await?;
|
let profile_pic_url = profile_pics.pop();
|
||||||
|
add_user_to_game(
|
||||||
|
ctx,
|
||||||
|
&guild,
|
||||||
|
&mut global_data,
|
||||||
|
player,
|
||||||
|
first_name,
|
||||||
|
last_name,
|
||||||
|
profile_pic_url,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for player_data in &global_data.game_state()?.player_data {
|
for player_data in &global_data.game_state()?.player_data {
|
||||||
|
|
|
@ -12,6 +12,7 @@ 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::MessageSource;
|
use crate::game::MessageSource;
|
||||||
|
use crate::imgur::Image;
|
||||||
use serenity::prelude::SerenityError;
|
use serenity::prelude::SerenityError;
|
||||||
|
|
||||||
fn filter_source_channel(player_data: &&PlayerData, msg_source: &MessageSource) -> bool {
|
fn filter_source_channel(player_data: &&PlayerData, msg_source: &MessageSource) -> bool {
|
||||||
|
@ -213,11 +214,16 @@ 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>,
|
||||||
) -> error::Result<PlayerData> {
|
) -> error::Result<PlayerData> {
|
||||||
if first_name == None && last_name == None {
|
if first_name.is_none() && last_name.is_none() {
|
||||||
return Err(WoxlfError::RanOutOfCodenames);
|
return Err(WoxlfError::RanOutOfCodenames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if profile_pic.is_none() {
|
||||||
|
return Err(WoxlfError::RanOutOfProfilePics);
|
||||||
|
}
|
||||||
|
|
||||||
let codename = global_data
|
let codename = global_data
|
||||||
.templates()?
|
.templates()?
|
||||||
.build_name(global_data, first_name, last_name)
|
.build_name(global_data, first_name, last_name)
|
||||||
|
@ -254,7 +260,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: global_data.get_profile_pic_url().await?,
|
profile_pic_url: profile_pic.unwrap().link,
|
||||||
};
|
};
|
||||||
|
|
||||||
global_data
|
global_data
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub enum WoxlfError {
|
||||||
ImgurError(ImgurError),
|
ImgurError(ImgurError),
|
||||||
RanOutOfCodenames,
|
RanOutOfCodenames,
|
||||||
TemplateError(tera::Error),
|
TemplateError(tera::Error),
|
||||||
|
RanOutOfProfilePics,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for WoxlfError {}
|
impl std::error::Error for WoxlfError {}
|
||||||
|
@ -39,6 +40,7 @@ impl Display for WoxlfError {
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
WoxlfError::TemplateError(e) => format!("Template error: {}", e),
|
WoxlfError::TemplateError(e) => format!("Template error: {}", e),
|
||||||
|
WoxlfError::RanOutOfProfilePics => "Ran out of user profile pics".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "Woxlf Error: {}", msg)
|
write!(f, "Woxlf Error: {}", msg)
|
||||||
|
|
|
@ -11,7 +11,6 @@ use crate::game::Phase;
|
||||||
use crate::imgur::{get_album_images, Image};
|
use crate::imgur::{get_album_images, Image};
|
||||||
use crate::messages::MessageTemplates;
|
use crate::messages::MessageTemplates;
|
||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use rand::prelude::SliceRandom;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct GlobalData {
|
pub struct GlobalData {
|
||||||
|
@ -127,14 +126,12 @@ impl GlobalData {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_profile_pic_url(&self) -> Result<String> {
|
pub async fn get_profile_pic_album(&self) -> Result<Vec<Image>> {
|
||||||
let images: Vec<Image> = get_album_images(
|
Ok(get_album_images(
|
||||||
&self.cfg.imgur_client_id,
|
&self.cfg.imgur_client_id,
|
||||||
&self.game_cfg()?.profile_album_hash,
|
&self.game_cfg()?.profile_album_hash,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?)
|
||||||
|
|
||||||
Ok(images.choose(&mut rand::thread_rng()).unwrap().link.clone())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_phase_name(&self) -> Result<String> {
|
pub fn get_phase_name(&self) -> Result<String> {
|
||||||
|
|
Loading…
Reference in New Issue