only send a subsect of the webhook in a message
This commit is contained in:
@@ -10,7 +10,6 @@ use revolt_quark::{
|
|||||||
|
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
/// # Send Message
|
/// # Send Message
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -981,7 +981,7 @@ pub async fn req(db: &Db, target: Ref, token: String, event: EventHeader<'_>, da
|
|||||||
author: webhook.id.clone(),
|
author: webhook.id.clone(),
|
||||||
channel: webhook.channel.clone(),
|
channel: webhook.channel.clone(),
|
||||||
embeds: Some(vec![embed]),
|
embeds: Some(vec![embed]),
|
||||||
webhook: Some(webhook.clone()),
|
webhook: Some(webhook.clone().into_message_webhook()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ impl Channel {
|
|||||||
masquerade: data.masquerade,
|
masquerade: data.masquerade,
|
||||||
interactions: data.interactions.unwrap_or_default(),
|
interactions: data.interactions.unwrap_or_default(),
|
||||||
author: author_id,
|
author: author_id,
|
||||||
webhook,
|
webhook: webhook.map(|w| w.into_message_webhook()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
events::client::EventV1,
|
events::client::EventV1,
|
||||||
models::{
|
models::{
|
||||||
webhook::{Webhook, PartialWebhook, FieldsWebhook}
|
webhook::{Webhook, PartialWebhook, FieldsWebhook},
|
||||||
|
message::MessageWebhook
|
||||||
},
|
},
|
||||||
Database, Result
|
Database, Result
|
||||||
};
|
};
|
||||||
@@ -56,9 +57,17 @@ impl Webhook {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove(&mut self, field: &FieldsWebhook) {
|
pub fn remove(&mut self, field: &FieldsWebhook) {
|
||||||
match field {
|
match field {
|
||||||
FieldsWebhook::Avatar => self.avatar = None
|
FieldsWebhook::Avatar => self.avatar = None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_message_webhook(self) -> MessageWebhook {
|
||||||
|
MessageWebhook {
|
||||||
|
id: self.id,
|
||||||
|
name: self.name,
|
||||||
|
avatar: self.avatar.map(|f| f.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::Webhook, util::regex::RE_COLOUR};
|
use crate::util::regex::RE_COLOUR;
|
||||||
|
|
||||||
use indexmap::{IndexMap, IndexSet};
|
use indexmap::{IndexMap, IndexSet};
|
||||||
use iso8601_timestamp::Timestamp;
|
use iso8601_timestamp::Timestamp;
|
||||||
@@ -109,6 +109,17 @@ pub struct Interactions {
|
|||||||
pub restrict_reactions: bool,
|
pub restrict_reactions: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Information about the webhook which
|
||||||
|
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, Validate, Default)]
|
||||||
|
pub struct MessageWebhook {
|
||||||
|
// Id of Webhook
|
||||||
|
pub id: String,
|
||||||
|
// The name of the webhook - 1 to 32 chars
|
||||||
|
pub name: String,
|
||||||
|
// The id of the avatar of the webhook, if it has one
|
||||||
|
pub avatar: Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
/// Representation of a Message on Revolt
|
/// Representation of a Message on Revolt
|
||||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, OptionalStruct, Default)]
|
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, OptionalStruct, Default)]
|
||||||
#[optional_derive(Serialize, Deserialize, JsonSchema, Debug, Default, Clone)]
|
#[optional_derive(Serialize, Deserialize, JsonSchema, Debug, Default, Clone)]
|
||||||
@@ -126,9 +137,9 @@ pub struct Message {
|
|||||||
pub channel: String,
|
pub channel: String,
|
||||||
/// Id of the user or webhook that sent this message
|
/// Id of the user or webhook that sent this message
|
||||||
pub author: String,
|
pub author: String,
|
||||||
/// Id of the webhook that sent this message, mutually exclusive with `author`
|
/// The webhook that sent this message, mutually exclusive with `author`
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub webhook: Option<Webhook>,
|
pub webhook: Option<MessageWebhook>,
|
||||||
/// Message content
|
/// Message content
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub content: Option<String>,
|
pub content: Option<String>,
|
||||||
|
|||||||
Reference in New Issue
Block a user