Ensure profile pics are random

+ Clippy + fmt
This commit is contained in:
2022-06-19 14:55:52 -06:00
parent dbaa622eb7
commit 0f70ac5f51
4 changed files with 28 additions and 9 deletions
+15 -1
View File
@@ -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 {
+8 -2
View File
@@ -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