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