change how webhook information is in the webhook
This commit is contained in:
@@ -9,7 +9,7 @@ impl AbstractMessage for DummyDb {
|
||||
Ok(Message {
|
||||
id: id.into(),
|
||||
channel: "channel".into(),
|
||||
author: Some("author".into()),
|
||||
author: "author".into(),
|
||||
content: Some("message content".into()),
|
||||
|
||||
..Default::default()
|
||||
|
||||
@@ -22,7 +22,7 @@ impl AbstractWebhook for DummyDb {
|
||||
name: "".to_string(),
|
||||
avatar: None,
|
||||
channel: "0".to_string(),
|
||||
token: "".to_owned(),
|
||||
token: Some("".to_owned()),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -428,6 +428,11 @@ impl Channel {
|
||||
}
|
||||
}
|
||||
|
||||
let (author_id, webhook) = match &author {
|
||||
MessageAuthor::User(user) => (user.id.clone(), None),
|
||||
MessageAuthor::Webhook(webhook) => (webhook.id.clone(), Some((*webhook).clone()))
|
||||
};
|
||||
|
||||
// Start constructing the message
|
||||
let message_id = Ulid::new().to_string();
|
||||
let mut message = Message {
|
||||
@@ -435,14 +440,11 @@ impl Channel {
|
||||
channel: self.id().to_string(),
|
||||
masquerade: data.masquerade,
|
||||
interactions: data.interactions.unwrap_or_default(),
|
||||
author: author_id,
|
||||
webhook,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
match &author {
|
||||
MessageAuthor::User(user) => message.author = Some(user.id.clone()),
|
||||
MessageAuthor::Webhook(webhook) => message.webhook = Some(webhook.id.clone()),
|
||||
}
|
||||
|
||||
// Parse mentions in message.
|
||||
let mut mentions = HashSet::new();
|
||||
if let Some(content) = &data.content {
|
||||
@@ -464,7 +466,7 @@ impl Channel {
|
||||
let message = Ref::from_unchecked(id).as_message(db).await?;
|
||||
|
||||
if mention {
|
||||
mentions.insert(message.author_id().to_owned());
|
||||
mentions.insert(message.author.to_owned());
|
||||
}
|
||||
|
||||
replies.insert(message.id);
|
||||
|
||||
@@ -272,12 +272,8 @@ impl Message {
|
||||
db.clear_reaction(&self.id, emoji).await
|
||||
}
|
||||
|
||||
/// Gets either the user or the webhook id which sent this message
|
||||
pub fn author_id(&self) -> &str {
|
||||
match &self.author {
|
||||
Some(id) => id,
|
||||
None => self.webhook.as_deref().unwrap()
|
||||
}
|
||||
pub fn is_webhook(&self) -> bool {
|
||||
self.webhook.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,8 +285,8 @@ impl IntoUsers for Message {
|
||||
fn get_user_ids(&self) -> Vec<String> {
|
||||
let mut ids = Vec::new();
|
||||
|
||||
if let Some(author) = &self.author {
|
||||
ids.push(author.clone());
|
||||
if !self.is_webhook() {
|
||||
ids.push(self.author.clone());
|
||||
};
|
||||
|
||||
if let Some(msg) = &self.system {
|
||||
@@ -331,7 +327,7 @@ impl SystemMessage {
|
||||
Message {
|
||||
id: Ulid::new().to_string(),
|
||||
channel,
|
||||
author: Some("00000000000000000000000000".to_string()),
|
||||
author: "00000000000000000000000000".to_string(),
|
||||
system: Some(self),
|
||||
|
||||
..Default::default()
|
||||
|
||||
Reference in New Issue
Block a user