Fixed issue with automated messages and spying
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details

+ Discord blocks "System Messages" from usersnames because of course it does
main
Joey Hines 2023-02-14 18:46:19 -07:00
parent fa7d78c272
commit 6ebf9e0ad2
Signed by: joeyahines
GPG Key ID: 995E531F7A569DDB
6 changed files with 20 additions and 6 deletions

View File

@ -9,6 +9,10 @@ pub struct HostSnooper {}
#[async_trait] #[async_trait]
impl Listener for HostSnooper { impl Listener for HostSnooper {
fn name(&self) -> String {
"Host Snooper".to_string()
}
fn get_priority(&self) -> Priority { fn get_priority(&self) -> Priority {
Priority::Logging Priority::Logging
} }

View File

@ -39,6 +39,7 @@ impl Listeners {
} }
pub fn add_listener(&mut self, listener: Box<dyn Listener>) { pub fn add_listener(&mut self, listener: Box<dyn Listener>) {
println!("Adding {} listener", listener.name());
self.listeners.push(listener); self.listeners.push(listener);
self.listeners.sort_by_key(|l1| l1.get_priority()); self.listeners.sort_by_key(|l1| l1.get_priority());
@ -89,6 +90,8 @@ pub struct ListenerContext<'a> {
#[async_trait] #[async_trait]
pub trait Listener: Debug + Send + Sync { pub trait Listener: Debug + Send + Sync {
fn name(&self) -> String;
fn get_priority(&self) -> Priority { fn get_priority(&self) -> Priority {
Priority::Medium Priority::Medium
} }

View File

@ -84,7 +84,7 @@ impl<'a> WoxlfMessage<'a> {
Ok(match &self.source { Ok(match &self.source {
MessageSource::Player(p) => p.codename.clone(), MessageSource::Player(p) => p.codename.clone(),
MessageSource::Host => global_data.game_cfg()?.bot_name.clone(), MessageSource::Host => global_data.game_cfg()?.bot_name.clone(),
MessageSource::Automated => "Woxlf System Message".to_string(), MessageSource::Automated => "Woxlf Game Message".to_string(),
}) })
} }
@ -213,7 +213,7 @@ pub async fn send_to_host_channel(
.get(&UserId::from(dest_player.discord_id)) .get(&UserId::from(dest_player.discord_id))
.unwrap() .unwrap()
.display_name(); .display_name();
format!(" to {} ({})", dest_player.codename, name) format!("**[DM to {} ({})]** ", dest_player.codename, name)
} else { } else {
"".to_string() "".to_string()
} }
@ -222,18 +222,19 @@ pub async fn send_to_host_channel(
}; };
let host_channel_username = format!( let host_channel_username = format!(
"{} ({}){}", "{} ({})",
msg.get_message_username(global_data)?, msg.get_message_username(global_data)?,
source, source,
dest
); );
let content = format!("{}{}", dest, msg.content);
send_webhook_msg( send_webhook_msg(
http, http,
WebhookId::from(global_data.cfg.discord_config.host_webhook_id), WebhookId::from(global_data.cfg.discord_config.host_webhook_id),
&host_channel_username, &host_channel_username,
Some(msg.get_profile_pic(global_data)?), Some(msg.get_profile_pic(global_data)?),
&msg.content, &content,
&msg.attachments, &msg.attachments,
) )
.await?; .await?;

View File

@ -134,7 +134,6 @@ impl Role {
} }
pub fn register_role_listener(&self, listeners: &mut Listeners) { pub fn register_role_listener(&self, listeners: &mut Listeners) {
#[allow(clippy::single_match)]
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})),

View File

@ -15,6 +15,10 @@ pub struct SpyListener {
#[async_trait] #[async_trait]
impl Listener for SpyListener { impl Listener for SpyListener {
fn name(&self) -> String {
format!("{} DM Listener", self.role)
}
fn get_priority(&self) -> Priority { fn get_priority(&self) -> Priority {
Priority::Logging Priority::Logging
} }
@ -56,6 +60,8 @@ impl Listener for SpyListener {
// 1/4 chance to intercept message // 1/4 chance to intercept message
if thread_rng().gen_bool(0.25) { if thread_rng().gen_bool(0.25) {
println!("Sending a spy message...");
let msg_content = MessageBuilder::default() let msg_content = MessageBuilder::default()
.push_bold_line_safe(format!( .push_bold_line_safe(format!(
"{} Sent {} a private message:", "{} Sent {} a private message:",

View File

@ -35,6 +35,7 @@ async fn main() {
let mut listeners = Listeners::default(); let mut listeners = Listeners::default();
Role::Spy.register_role_listener(&mut listeners); Role::Spy.register_role_listener(&mut listeners);
Role::WolfAgent.register_role_listener(&mut listeners);
let mut client = Client::builder(&bot_cfg.discord_config.token, GatewayIntents::all()) let mut client = Client::builder(&bot_cfg.discord_config.token, GatewayIntents::all())
.event_handler(Handler {}) .event_handler(Handler {})