$players command returns the discord username for the host
+ clippy + fmtmsg_refactor
parent
e4b98b7796
commit
a72fb8a899
|
@ -1,11 +1,13 @@
|
|||
use serenity::framework::standard::macros::help;
|
||||
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::model::id::ChannelId;
|
||||
use serenity::model::prelude::{Message, UserId};
|
||||
use serenity::prelude::Context;
|
||||
use serenity::utils::MessageBuilder;
|
||||
use serenity::framework::standard::macros::help;
|
||||
|
||||
use crate::data::{GlobalData, MessageSource, Phase};
|
||||
use crate::helper;
|
||||
|
@ -101,7 +103,16 @@ async fn say(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||
|
||||
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(())
|
||||
}
|
||||
|
@ -118,7 +129,16 @@ async fn broadcast(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
|||
|
||||
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(())
|
||||
}
|
||||
|
@ -392,7 +412,6 @@ async fn status(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
#[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:");
|
||||
|
||||
for player in &global_data.game_state.player_data {
|
||||
msg_builder
|
||||
.push("* ")
|
||||
.push_line(&player.codename);
|
||||
msg_builder.push("* ").push(&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();
|
||||
|
|
|
@ -13,8 +13,8 @@ use serenity::prelude::Context;
|
|||
use serenity::utils::MessageBuilder;
|
||||
|
||||
use crate::data::{BotConfig, GameState, GlobalData, MessageSource, PlayerData};
|
||||
use std::time::UNIX_EPOCH;
|
||||
use serenity::http::AttachmentType;
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
pub async fn send_msg_to_player_channels(
|
||||
ctx: &Context,
|
||||
|
@ -88,8 +88,7 @@ pub async fn send_msg_to_player_channels(
|
|||
}
|
||||
|
||||
m
|
||||
}
|
||||
)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -7,11 +7,11 @@ use crate::data::{Args, BotConfig, GlobalData, MessageSource};
|
|||
use crate::helper::{get_game_state, send_msg_to_player_channels};
|
||||
use serenity::async_trait;
|
||||
use serenity::client::bridge::gateway::GatewayIntents;
|
||||
use serenity::http::AttachmentType;
|
||||
use serenity::model::prelude::{Message, Ready};
|
||||
use serenity::prelude::*;
|
||||
use std::sync::Arc;
|
||||
use structopt::StructOpt;
|
||||
use serenity::http::AttachmentType;
|
||||
|
||||
struct Handler {}
|
||||
|
||||
|
@ -39,9 +39,11 @@ impl EventHandler for Handler {
|
|||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
||||
let user_msg = format!("{} > {}", player_data.codename, msg.content);
|
||||
|
||||
let attachments: Vec<AttachmentType> = msg.attachments.iter().map(|a| {
|
||||
AttachmentType::Image(&a.url)
|
||||
}).collect();
|
||||
let attachments: Vec<AttachmentType> = msg
|
||||
.attachments
|
||||
.iter()
|
||||
.map(|a| AttachmentType::Image(&a.url))
|
||||
.collect();
|
||||
|
||||
send_msg_to_player_channels(
|
||||
&ctx,
|
||||
|
|
Loading…
Reference in New Issue