Added basic role handling
+ Games now have a config for which roles they have + Roles are assigned at game start + Roles don't function within the bot, except the spy + Added a spy listener + Clippy + fmt
This commit is contained in:
+25
-5
@@ -21,6 +21,7 @@ use crate::game::message_router::{
|
||||
dispatch_message, Median, MessageDest, MessageSource, WoxlfMessage,
|
||||
};
|
||||
use crate::game::player_data::PlayerData;
|
||||
use crate::game::role::Role;
|
||||
use crate::game::Phase;
|
||||
use crate::messages::DiscordUser;
|
||||
|
||||
@@ -93,10 +94,15 @@ async fn start(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
|
||||
profile_pics.shuffle(&mut thread_rng());
|
||||
|
||||
let mut roles = global_data.game_cfg()?.roles.clone();
|
||||
|
||||
roles.shuffle(&mut thread_rng());
|
||||
|
||||
for player in players {
|
||||
let first_name = first_names.pop();
|
||||
let last_name = last_names.pop();
|
||||
let profile_pic_url = profile_pics.pop();
|
||||
let role = roles.pop();
|
||||
add_user_to_game(
|
||||
ctx,
|
||||
&guild,
|
||||
@@ -105,6 +111,7 @@ async fn start(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
first_name,
|
||||
last_name,
|
||||
profile_pic_url,
|
||||
role,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@@ -369,6 +376,7 @@ async fn test_theme(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
profile_pic_url: "".to_string(),
|
||||
channel_webhook_id: 0,
|
||||
alive: true,
|
||||
role: Role::Villager,
|
||||
};
|
||||
|
||||
let player_1_discord = DiscordUser {
|
||||
@@ -384,6 +392,7 @@ async fn test_theme(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
profile_pic_url: "".to_string(),
|
||||
channel_webhook_id: 0,
|
||||
alive: false,
|
||||
role: Role::Villager,
|
||||
};
|
||||
|
||||
let mut players = vec![test_player_1.clone(), test_player_2.clone()];
|
||||
@@ -623,7 +632,12 @@ async fn players(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
||||
if msg.channel_id.0 == global_data.cfg.discord_config.host_channel {
|
||||
let guild = msg.guild(&ctx.cache).unwrap();
|
||||
let member = guild.members.get(&UserId::from(player.discord_id)).unwrap();
|
||||
msg_builder.push_line(format!(" ({})", member.display_name()));
|
||||
msg_builder.push_line(format!(
|
||||
" ({}) [{} {}]",
|
||||
member.display_name(),
|
||||
player.role,
|
||||
player.role.seer_color()
|
||||
));
|
||||
} else {
|
||||
msg_builder.push_line("");
|
||||
}
|
||||
@@ -638,14 +652,20 @@ async fn players(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
||||
#[aliases("pm", "w")]
|
||||
#[description = "Send a private message to another player."]
|
||||
async fn whisper(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
let data = ctx.data.read().await;
|
||||
let global_data = data.get::<GlobalData>().unwrap();
|
||||
let mut global_data = global_data.lock().await;
|
||||
|
||||
if !global_data.game_cfg()?.whispers_allowed {
|
||||
msg.reply(&ctx.http, "No private messages are allowed in this game")
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if args.len() < 2 {
|
||||
msg.reply(&ctx.http, "Need a recipient and message!")
|
||||
.await?;
|
||||
} else {
|
||||
let data = ctx.data.read().await;
|
||||
let global_data = data.get::<GlobalData>().unwrap();
|
||||
let mut global_data = global_data.lock().await;
|
||||
|
||||
let target = args.single::<String>()?;
|
||||
let pm = args.rest();
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@ use crate::error::WoxlfError;
|
||||
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(
|
||||
ctx: &Context,
|
||||
guild: &Guild,
|
||||
@@ -20,6 +22,7 @@ pub async fn add_user_to_game(
|
||||
first_name: Option<String>,
|
||||
last_name: Option<String>,
|
||||
profile_pic: Option<Image>,
|
||||
role: Option<Role>,
|
||||
) -> error::Result<PlayerData> {
|
||||
if first_name.is_none() && last_name.is_none() {
|
||||
return Err(WoxlfError::RanOutOfCodenames);
|
||||
@@ -29,6 +32,10 @@ pub async fn add_user_to_game(
|
||||
return Err(WoxlfError::RanOutOfProfilePics);
|
||||
}
|
||||
|
||||
if role.is_none() {
|
||||
return Err(WoxlfError::RanOutOfRoles);
|
||||
}
|
||||
|
||||
let codename = global_data
|
||||
.templates()?
|
||||
.build_name(global_data, first_name, last_name)
|
||||
@@ -67,6 +74,7 @@ pub async fn add_user_to_game(
|
||||
channel_webhook_id: webhook.id.0,
|
||||
profile_pic_url: profile_pic.unwrap().link,
|
||||
alive: true,
|
||||
role: role.unwrap(),
|
||||
};
|
||||
|
||||
global_data
|
||||
|
||||
Reference in New Issue
Block a user