diff options
author | Ashelyn Rose <git@ashen.earth> | 2024-09-30 22:22:52 -0600 |
---|---|---|
committer | Ashelyn Rose <git@ashen.earth> | 2024-09-30 22:22:52 -0600 |
commit | 4fcb9965c09782e7da2c8a316e1980ec192d181f (patch) | |
tree | c501d14fd68439ce43800807a15aa9e194a352cb /src/system.rs | |
parent | 02bfb07c876d86802a723f67f471a4c5e1359a30 (diff) |
Fix ping on reply
Diffstat (limited to 'src/system.rs')
-rw-r--r-- | src/system.rs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/system.rs b/src/system.rs index d1f9dc9..d708074 100644 --- a/src/system.rs +++ b/src/system.rs @@ -4,7 +4,7 @@ use tokio::{sync::mpsc::{channel, Receiver, Sender}, time::{Sleep,sleep}}; use futures::future::join_all; use twilight_gateway::MessageSender; use twilight_http::Client; -use twilight_model::{channel::{message::MessageType, Message}, gateway::{payload::outgoing::{update_presence::UpdatePresencePayload, UpdatePresence}, presence::Status, OpCode}, id::{Id, marker::{ChannelMarker, MessageMarker, UserMarker}}}; +use twilight_model::{channel::{message::{AllowedMentions, MentionType, MessageType}, Message}, gateway::{payload::outgoing::{update_presence::UpdatePresencePayload, UpdatePresence}, presence::Status, OpCode}, id::{Id, marker::{ChannelMarker, MessageMarker, UserMarker}}}; use twilight_model::util::Timestamp; use twilight_model::http::attachment::Attachment; @@ -174,10 +174,32 @@ impl System { let mut create_message = client.create_message(message.channel_id) .content(content)?; + let mut allowed_mentions = AllowedMentions { + parse: Vec::new(), + replied_user: false, + roles: message.mention_roles.clone(), + users: message.mentions.iter().map(|user| user.id).collect(), + }; + + if message.mention_everyone { + allowed_mentions.parse.push(MentionType::Everyone); + } + if message.kind == MessageType::Reply { - create_message = create_message.reply( - message.referenced_message.as_ref().expect("Message was reply but no referenced message").id - ); + if let Some(ref_message) = message.referenced_message.as_ref() { + create_message = create_message.reply(ref_message.id); + + let pings_referenced_author = message.mentions.iter().any(|user| user.id == ref_message.author.id); + + if pings_referenced_author { + allowed_mentions.replied_user = true; + } else { + allowed_mentions.replied_user = false; + } + + } else { + panic!("Cannot proxy message: Was reply but no referenced message"); + } } let attachments = join_all(message.attachments.iter().map(|attachment| async { @@ -200,6 +222,11 @@ impl System { create_message = create_message.attachments(attachments.as_slice())?; } + if let Some(flags) = message.flags { + create_message = create_message.flags(flags); + } + + create_message = create_message.allowed_mentions(Some(&allowed_mentions)); let new_message = create_message.await?.model().await?; Ok(new_message) |