Fixed pings and debugs in messages
+ Also added more logging to ensure spy is working okay + clippy + fmtmain
parent
6ebf9e0ad2
commit
f86ef6fc21
|
@ -245,7 +245,7 @@ dependencies = [
|
||||||
"rust-ini",
|
"rust-ini",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"toml",
|
"toml 0.5.8",
|
||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
|
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"hashbrown 0.12.3",
|
"hashbrown",
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot_core",
|
"parking_lot_core",
|
||||||
|
@ -577,12 +577,6 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.11.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.12.3"
|
version = "0.12.3"
|
||||||
|
@ -731,12 +725,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.8.0"
|
version = "1.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"hashbrown 0.11.2",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -924,6 +918,15 @@ dependencies = [
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom8"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ntapi"
|
name = "ntapi"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
|
@ -1023,7 +1026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a"
|
checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dlv-list",
|
"dlv-list",
|
||||||
"hashbrown 0.12.3",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1488,6 +1491,15 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_urlencoded"
|
name = "serde_urlencoded"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
|
@ -1847,6 +1859,40 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_edit",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_datetime"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.19.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"nom8",
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
@ -2316,7 +2362,7 @@ dependencies = [
|
||||||
"structopt",
|
"structopt",
|
||||||
"tera",
|
"tera",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
"toml 0.7.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -11,7 +11,7 @@ structopt = "0.3.26"
|
||||||
chrono = {version="0.4.19", features=["serde"]}
|
chrono = {version="0.4.19", features=["serde"]}
|
||||||
serde = "1.0.136"
|
serde = "1.0.136"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
toml = "0.5.8"
|
toml = "0.7.2"
|
||||||
regex = "1.5.5"
|
regex = "1.5.5"
|
||||||
futures = "0.3.21"
|
futures = "0.3.21"
|
||||||
reqwest = "0.11.10"
|
reqwest = "0.11.10"
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub async fn add_user_to_game(
|
||||||
|
|
||||||
let channel = guild
|
let channel = guild
|
||||||
.create_channel(&ctx.http, |c| {
|
.create_channel(&ctx.http, |c| {
|
||||||
c.category(&ChannelId::from(global_data.cfg.discord_config.category))
|
c.category(ChannelId::from(global_data.cfg.discord_config.category))
|
||||||
.name(format!("{}'s Channel", discord_user.display_name()))
|
.name(format!("{}'s Channel", discord_user.display_name()))
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -199,6 +199,8 @@ async fn broadcast(ctx: &Context, _msg: &Message, args: Args) -> CommandResult {
|
||||||
.dest(MessageDest::Broadcast)
|
.dest(MessageDest::Broadcast)
|
||||||
.content(&broadcast)
|
.content(&broadcast)
|
||||||
.median(Median::Webhook)
|
.median(Median::Webhook)
|
||||||
|
.ping()
|
||||||
|
.pin()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
dispatch_message(ctx, &mut global_data, woxlf_msg).await?;
|
dispatch_message(ctx, &mut global_data, woxlf_msg).await?;
|
||||||
|
@ -235,6 +237,8 @@ async fn next_phase(ctx: &Context, msg: &Message, mut args: Args) -> CommandResu
|
||||||
.dest(MessageDest::Broadcast)
|
.dest(MessageDest::Broadcast)
|
||||||
.median(Median::Webhook)
|
.median(Median::Webhook)
|
||||||
.content(&broadcast)
|
.content(&broadcast)
|
||||||
|
.pin()
|
||||||
|
.ping()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
dispatch_message(ctx, &mut global_data, woxlf_msg).await?;
|
dispatch_message(ctx, &mut global_data, woxlf_msg).await?;
|
||||||
|
@ -475,6 +479,8 @@ async fn add_time(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
||||||
.dest(MessageDest::Broadcast)
|
.dest(MessageDest::Broadcast)
|
||||||
.median(Median::Webhook)
|
.median(Median::Webhook)
|
||||||
.content(&broadcast)
|
.content(&broadcast)
|
||||||
|
.ping()
|
||||||
|
.pin()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
dispatch_message(ctx, &mut global_data, woxlf_msg).await?;
|
dispatch_message(ctx, &mut global_data, woxlf_msg).await?;
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub enum WoxlfError {
|
||||||
UnsupportedMsgMedium,
|
UnsupportedMsgMedium,
|
||||||
RanOutOfRoles,
|
RanOutOfRoles,
|
||||||
ConfigNotfound,
|
ConfigNotfound,
|
||||||
|
WebhookMsgError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for WoxlfError {}
|
impl std::error::Error for WoxlfError {}
|
||||||
|
@ -49,6 +50,7 @@ impl Display for WoxlfError {
|
||||||
}
|
}
|
||||||
WoxlfError::RanOutOfRoles => "Ran out of user roles".to_string(),
|
WoxlfError::RanOutOfRoles => "Ran out of user roles".to_string(),
|
||||||
WoxlfError::ConfigNotfound => "Config not found".to_string(),
|
WoxlfError::ConfigNotfound => "Config not found".to_string(),
|
||||||
|
WoxlfError::WebhookMsgError => "Webhook returned is None".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "Woxlf Error: {}", msg)
|
write!(f, "Woxlf Error: {}", msg)
|
||||||
|
|
|
@ -8,7 +8,8 @@ use serenity::client::Context;
|
||||||
use serenity::http::{CacheHttp, Http};
|
use serenity::http::{CacheHttp, Http};
|
||||||
use serenity::model::guild::Guild;
|
use serenity::model::guild::Guild;
|
||||||
use serenity::model::id::{ChannelId, UserId};
|
use serenity::model::id::{ChannelId, UserId};
|
||||||
use serenity::model::prelude::{AttachmentType, WebhookId};
|
use serenity::model::prelude::{AttachmentType, Message, WebhookId};
|
||||||
|
use serenity::prelude::Mentionable;
|
||||||
use serenity::utils::MessageBuilder;
|
use serenity::utils::MessageBuilder;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -56,6 +57,7 @@ bitflags! {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MsgFlags: u32 {
|
pub struct MsgFlags: u32 {
|
||||||
const PIN_MSG = 0b00000001;
|
const PIN_MSG = 0b00000001;
|
||||||
|
const PING = 0b00000010;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +124,11 @@ impl<'a> WoxlfMessage<'a> {
|
||||||
self.flags |= MsgFlags::PIN_MSG;
|
self.flags |= MsgFlags::PIN_MSG;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ping(mut self) -> Self {
|
||||||
|
self.flags |= MsgFlags::PING;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_source_channel(player_data: &&PlayerData, msg_source: &MessageSource) -> bool {
|
fn filter_source_channel(player_data: &&PlayerData, msg_source: &MessageSource) -> bool {
|
||||||
|
@ -140,12 +147,12 @@ pub async fn send_webhook_msg(
|
||||||
profile_pic_url: Option<String>,
|
profile_pic_url: Option<String>,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
attachments: &Option<Vec<AttachmentType<'_>>>,
|
attachments: &Option<Vec<AttachmentType<'_>>>,
|
||||||
) -> error::Result<()> {
|
) -> error::Result<Message> {
|
||||||
let webhook = http.get_webhook(webhook_id.0).await?;
|
let webhook = http.get_webhook(webhook_id.0).await?;
|
||||||
|
|
||||||
webhook
|
let sent_msg = webhook
|
||||||
.execute(http, false, move |w| {
|
.execute(http, true, move |w| {
|
||||||
w.content(&msg).username(username);
|
w.content(msg).username(username);
|
||||||
|
|
||||||
if let Some(profile_pic_url) = profile_pic_url {
|
if let Some(profile_pic_url) = profile_pic_url {
|
||||||
w.avatar_url(profile_pic_url);
|
w.avatar_url(profile_pic_url);
|
||||||
|
@ -159,7 +166,11 @@ pub async fn send_webhook_msg(
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
if let Some(sent_msg) = sent_msg {
|
||||||
|
Ok(sent_msg)
|
||||||
|
} else {
|
||||||
|
Err(WoxlfError::WebhookMsgError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_private_message(
|
pub async fn send_private_message(
|
||||||
|
@ -167,10 +178,10 @@ pub async fn send_private_message(
|
||||||
dest: UserId,
|
dest: UserId,
|
||||||
msg_content: &str,
|
msg_content: &str,
|
||||||
attachments: &Option<Vec<AttachmentType<'_>>>,
|
attachments: &Option<Vec<AttachmentType<'_>>>,
|
||||||
) -> error::Result<()> {
|
) -> error::Result<Message> {
|
||||||
let dest_user = dest.to_user(http).await?;
|
let dest_user = dest.to_user(http).await?;
|
||||||
|
|
||||||
dest_user
|
let msg = dest_user
|
||||||
.dm(http, |msg| {
|
.dm(http, |msg| {
|
||||||
msg.content(msg_content);
|
msg.content(msg_content);
|
||||||
|
|
||||||
|
@ -182,7 +193,7 @@ pub async fn send_private_message(
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_to_host_channel(
|
pub async fn send_to_host_channel(
|
||||||
|
@ -190,7 +201,7 @@ pub async fn send_to_host_channel(
|
||||||
guild: &Guild,
|
guild: &Guild,
|
||||||
global_data: &GlobalData,
|
global_data: &GlobalData,
|
||||||
msg: WoxlfMessage<'_>,
|
msg: WoxlfMessage<'_>,
|
||||||
) -> error::Result<()> {
|
) -> error::Result<Message> {
|
||||||
let source = match &msg.source {
|
let source = match &msg.source {
|
||||||
MessageSource::Player(player_data) => {
|
MessageSource::Player(player_data) => {
|
||||||
let name = guild
|
let name = guild
|
||||||
|
@ -221,11 +232,7 @@ pub async fn send_to_host_channel(
|
||||||
_ => "".to_string(),
|
_ => "".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let host_channel_username = format!(
|
let host_channel_username = format!("{} ({})", msg.get_message_username(global_data)?, source,);
|
||||||
"{} ({})",
|
|
||||||
msg.get_message_username(global_data)?,
|
|
||||||
source,
|
|
||||||
);
|
|
||||||
|
|
||||||
let content = format!("{}{}", dest, msg.content);
|
let content = format!("{}{}", dest, msg.content);
|
||||||
|
|
||||||
|
@ -237,8 +244,7 @@ pub async fn send_to_host_channel(
|
||||||
&content,
|
&content,
|
||||||
&msg.attachments,
|
&msg.attachments,
|
||||||
)
|
)
|
||||||
.await?;
|
.await
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_message(
|
pub async fn send_message(
|
||||||
|
@ -247,17 +253,28 @@ pub async fn send_message(
|
||||||
msg: &WoxlfMessage<'_>,
|
msg: &WoxlfMessage<'_>,
|
||||||
dest_player: &PlayerData,
|
dest_player: &PlayerData,
|
||||||
) -> Result<(), WoxlfError> {
|
) -> Result<(), WoxlfError> {
|
||||||
match &msg.median {
|
let content = if msg.flags.contains(MsgFlags::PING) {
|
||||||
|
let dest_player_id = UserId::from(dest_player.discord_id);
|
||||||
|
|
||||||
|
MessageBuilder::new()
|
||||||
|
.push_line(dest_player_id.mention())
|
||||||
|
.push(msg.content.clone())
|
||||||
|
.build()
|
||||||
|
} else {
|
||||||
|
msg.content.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
let send_msg = match &msg.median {
|
||||||
Median::Webhook => {
|
Median::Webhook => {
|
||||||
send_webhook_msg(
|
send_webhook_msg(
|
||||||
&ctx.http,
|
&ctx.http,
|
||||||
WebhookId::from(dest_player.channel_webhook_id),
|
WebhookId::from(dest_player.channel_webhook_id),
|
||||||
&msg.get_message_username(global_data)?,
|
&msg.get_message_username(global_data)?,
|
||||||
Some(msg.get_profile_pic(global_data)?),
|
Some(msg.get_profile_pic(global_data)?),
|
||||||
&msg.content,
|
&content,
|
||||||
&msg.attachments,
|
&msg.attachments,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?
|
||||||
}
|
}
|
||||||
Median::DirectMessage => {
|
Median::DirectMessage => {
|
||||||
let dm_msg = MessageBuilder::new()
|
let dm_msg = MessageBuilder::new()
|
||||||
|
@ -265,7 +282,7 @@ pub async fn send_message(
|
||||||
"{} has sent you a private message:",
|
"{} has sent you a private message:",
|
||||||
&msg.get_message_username(global_data)?
|
&msg.get_message_username(global_data)?
|
||||||
))
|
))
|
||||||
.push(&msg.content)
|
.push(content)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
send_private_message(
|
send_private_message(
|
||||||
|
@ -274,14 +291,18 @@ pub async fn send_message(
|
||||||
&dm_msg,
|
&dm_msg,
|
||||||
&msg.attachments,
|
&msg.attachments,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?
|
||||||
}
|
}
|
||||||
Median::StandardMessage => {
|
Median::StandardMessage => {
|
||||||
let channel = ChannelId::from(dest_player.channel);
|
let channel = ChannelId::from(dest_player.channel);
|
||||||
channel.say(&ctx.http(), &msg.content).await?;
|
channel.say(&ctx.http(), &content).await?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if msg.flags.contains(MsgFlags::PIN_MSG) {
|
||||||
|
send_msg.pin(&ctx.http).await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,9 @@ impl Role {
|
||||||
pub fn register_role_listener(&self, listeners: &mut Listeners) {
|
pub fn register_role_listener(&self, listeners: &mut Listeners) {
|
||||||
match self {
|
match self {
|
||||||
Role::Spy => listeners.add_listener(Box::new(SpyListener { role: Role::Spy })),
|
Role::Spy => listeners.add_listener(Box::new(SpyListener { role: Role::Spy })),
|
||||||
Role::WolfAgent => listeners.add_listener(Box::new(SpyListener {role: Role::WolfAgent})),
|
Role::WolfAgent => listeners.add_listener(Box::new(SpyListener {
|
||||||
|
role: Role::WolfAgent,
|
||||||
|
})),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use serenity::utils::MessageBuilder;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SpyListener {
|
pub struct SpyListener {
|
||||||
pub role: Role
|
pub role: Role,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -32,6 +32,8 @@ impl Listener for SpyListener {
|
||||||
return Ok(EventStatus::Okay);
|
return Ok(EventStatus::Okay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("{} is processing {:?}", self.name(), msg);
|
||||||
|
|
||||||
let src_player = if let MessageSource::Player(p) = &msg.source {
|
let src_player = if let MessageSource::Player(p) = &msg.source {
|
||||||
p
|
p
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,7 +78,7 @@ impl Listener for SpyListener {
|
||||||
&msg_content,
|
&msg_content,
|
||||||
&None,
|
&None,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue