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());
|
||||
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 {
|
||||
let first_name = first_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 {
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::game::game_state::PhaseDuration;
|
|||
use crate::game::global_data::GlobalData;
|
||||
use crate::game::player_data::PlayerData;
|
||||
use crate::game::MessageSource;
|
||||
use crate::imgur::Image;
|
||||
use serenity::prelude::SerenityError;
|
||||
|
||||
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,
|
||||
first_name: Option<String>,
|
||||
last_name: Option<String>,
|
||||
profile_pic: Option<Image>,
|
||||
) -> error::Result<PlayerData> {
|
||||
if first_name == None && last_name == None {
|
||||
if first_name.is_none() && last_name.is_none() {
|
||||
return Err(WoxlfError::RanOutOfCodenames);
|
||||
}
|
||||
|
||||
if profile_pic.is_none() {
|
||||
return Err(WoxlfError::RanOutOfProfilePics);
|
||||
}
|
||||
|
||||
let codename = global_data
|
||||
.templates()?
|
||||
.build_name(global_data, first_name, last_name)
|
||||
|
@ -254,7 +260,7 @@ pub async fn add_user_to_game(
|
|||
vote_target: None,
|
||||
codename,
|
||||
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
|
||||
|
|
|
@ -18,6 +18,7 @@ pub enum WoxlfError {
|
|||
ImgurError(ImgurError),
|
||||
RanOutOfCodenames,
|
||||
TemplateError(tera::Error),
|
||||
RanOutOfProfilePics,
|
||||
}
|
||||
|
||||
impl std::error::Error for WoxlfError {}
|
||||
|
@ -39,6 +40,7 @@ impl Display for WoxlfError {
|
|||
.to_string()
|
||||
}
|
||||
WoxlfError::TemplateError(e) => format!("Template error: {}", e),
|
||||
WoxlfError::RanOutOfProfilePics => "Ran out of user profile pics".to_string(),
|
||||
};
|
||||
|
||||
write!(f, "Woxlf Error: {}", msg)
|
||||
|
|
|
@ -11,7 +11,6 @@ use crate::game::Phase;
|
|||
use crate::imgur::{get_album_images, Image};
|
||||
use crate::messages::MessageTemplates;
|
||||
use chrono::Duration;
|
||||
use rand::prelude::SliceRandom;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GlobalData {
|
||||
|
@ -127,14 +126,12 @@ impl GlobalData {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_profile_pic_url(&self) -> Result<String> {
|
||||
let images: Vec<Image> = get_album_images(
|
||||
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?;
|
||||
|
||||
Ok(images.choose(&mut rand::thread_rng()).unwrap().link.clone())
|
||||
.await?)
|
||||
}
|
||||
|
||||
pub fn get_phase_name(&self) -> Result<String> {
|
||||
|
|
Loading…
Reference in New Issue