$players command returns the discord username for the host

+ clippy + fmt
msg_refactor
Joey Hines 2022-03-13 16:09:05 -06:00
parent e4b98b7796
commit a72fb8a899
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
3 changed files with 41 additions and 15 deletions

View File

@ -1,11 +1,13 @@
use serenity::framework::standard::macros::help;
use serenity::framework::standard::macros::{command, group}; use serenity::framework::standard::macros::{command, group};
use serenity::framework::standard::{Args, CommandResult, HelpOptions, CommandGroup, help_commands}; use serenity::framework::standard::{
help_commands, Args, CommandGroup, CommandResult, HelpOptions,
};
use serenity::framework::StandardFramework; use serenity::framework::StandardFramework;
use serenity::model::id::ChannelId; use serenity::model::id::ChannelId;
use serenity::model::prelude::{Message, UserId}; use serenity::model::prelude::{Message, UserId};
use serenity::prelude::Context; use serenity::prelude::Context;
use serenity::utils::MessageBuilder; use serenity::utils::MessageBuilder;
use serenity::framework::standard::macros::help;
use crate::data::{GlobalData, MessageSource, Phase}; use crate::data::{GlobalData, MessageSource, Phase};
use crate::helper; use crate::helper;
@ -101,7 +103,16 @@ async fn say(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let msg = format!("**wOxlf **> {}", args.rest()); let msg = format!("**wOxlf **> {}", args.rest());
send_msg_to_player_channels(ctx, &guild, &global_data, MessageSource::Host, &msg, None, false).await; send_msg_to_player_channels(
ctx,
&guild,
&global_data,
MessageSource::Host,
&msg,
None,
false,
)
.await;
Ok(()) Ok(())
} }
@ -118,7 +129,16 @@ async fn broadcast(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let msg = build_system_message(args.rest()); let msg = build_system_message(args.rest());
send_msg_to_player_channels(ctx, &guild, &global_data, MessageSource::Host, &msg, None,true).await; send_msg_to_player_channels(
ctx,
&guild,
&global_data,
MessageSource::Host,
&msg,
None,
true,
)
.await;
Ok(()) Ok(())
} }
@ -392,7 +412,6 @@ async fn status(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
Ok(()) Ok(())
} }
#[command] #[command]
#[only_in(guilds)] #[only_in(guilds)]
#[description = "Get the other players in the game. $status"] #[description = "Get the other players in the game. $status"]
@ -407,9 +426,15 @@ async fn players(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
msg_builder.push_line("Test Subjects:"); msg_builder.push_line("Test Subjects:");
for player in &global_data.game_state.player_data { for player in &global_data.game_state.player_data {
msg_builder msg_builder.push("* ").push(&player.codename);
.push("* ")
.push_line(&player.codename); if msg.channel_id.0 == global_data.cfg.host_channel {
let guild = msg.guild(&ctx.cache).await.unwrap();
let member = guild.members.get(&UserId::from(player.discord_id)).unwrap();
msg_builder.push_line(format!(" ({})", member.display_name()));
} else {
msg_builder.push_line("");
}
} }
msg.reply(&ctx.http, msg_builder.build()).await.unwrap(); msg.reply(&ctx.http, msg_builder.build()).await.unwrap();

View File

@ -13,8 +13,8 @@ use serenity::prelude::Context;
use serenity::utils::MessageBuilder; use serenity::utils::MessageBuilder;
use crate::data::{BotConfig, GameState, GlobalData, MessageSource, PlayerData}; use crate::data::{BotConfig, GameState, GlobalData, MessageSource, PlayerData};
use std::time::UNIX_EPOCH;
use serenity::http::AttachmentType; use serenity::http::AttachmentType;
use std::time::UNIX_EPOCH;
pub async fn send_msg_to_player_channels( pub async fn send_msg_to_player_channels(
ctx: &Context, ctx: &Context,
@ -88,8 +88,7 @@ pub async fn send_msg_to_player_channels(
} }
m m
} })
)
.await .await
.unwrap(); .unwrap();
} }

View File

@ -7,11 +7,11 @@ use crate::data::{Args, BotConfig, GlobalData, MessageSource};
use crate::helper::{get_game_state, send_msg_to_player_channels}; use crate::helper::{get_game_state, send_msg_to_player_channels};
use serenity::async_trait; use serenity::async_trait;
use serenity::client::bridge::gateway::GatewayIntents; use serenity::client::bridge::gateway::GatewayIntents;
use serenity::http::AttachmentType;
use serenity::model::prelude::{Message, Ready}; use serenity::model::prelude::{Message, Ready};
use serenity::prelude::*; use serenity::prelude::*;
use std::sync::Arc; use std::sync::Arc;
use structopt::StructOpt; use structopt::StructOpt;
use serenity::http::AttachmentType;
struct Handler {} struct Handler {}
@ -39,9 +39,11 @@ impl EventHandler for Handler {
let guild = msg.guild(&ctx.cache).await.unwrap(); let guild = msg.guild(&ctx.cache).await.unwrap();
let user_msg = format!("{} > {}", player_data.codename, msg.content); let user_msg = format!("{} > {}", player_data.codename, msg.content);
let attachments: Vec<AttachmentType> = msg.attachments.iter().map(|a| { let attachments: Vec<AttachmentType> = msg
AttachmentType::Image(&a.url) .attachments
}).collect(); .iter()
.map(|a| AttachmentType::Image(&a.url))
.collect();
send_msg_to_player_channels( send_msg_to_player_channels(
&ctx, &ctx,