work on implementing message attachment sending
This commit is contained in:
parent
4c83e190b8
commit
7eaa8a96b7
|
@ -143,6 +143,8 @@ pub mod messages {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{AuthUsername, LoginSchema},
|
api::{AuthUsername, LoginSchema},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
|
@ -163,7 +165,6 @@ mod test {
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let mut instance = Instance::new(
|
let mut instance = Instance::new(
|
||||||
crate::URLBundle {
|
crate::URLBundle {
|
||||||
|
@ -194,4 +195,68 @@ mod test {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn send_message_two() {
|
||||||
|
let channel_id = "1104413094102290492".to_string();
|
||||||
|
|
||||||
|
let attachment = crate::api::types::PartialDiscordFileAttachment {
|
||||||
|
id: None,
|
||||||
|
filename: Some("test".to_string()),
|
||||||
|
description: None,
|
||||||
|
content_type: None,
|
||||||
|
size: None,
|
||||||
|
url: None,
|
||||||
|
proxy_url: None,
|
||||||
|
width: None,
|
||||||
|
height: None,
|
||||||
|
ephemeral: Some(false),
|
||||||
|
duration_secs: None,
|
||||||
|
waveform: None,
|
||||||
|
content: vec![8],
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut message = crate::api::schemas::MessageSendSchema::new(
|
||||||
|
None,
|
||||||
|
Some("ashjkdhjksdfgjsdfzjkhsdvhjksdf".to_string()),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(vec![attachment.clone()]),
|
||||||
|
);
|
||||||
|
let mut instance = Instance::new(
|
||||||
|
crate::URLBundle {
|
||||||
|
api: "http://localhost:3001/api".to_string(),
|
||||||
|
wss: "ws://localhost:3001/".to_string(),
|
||||||
|
cdn: "http://localhost:3001".to_string(),
|
||||||
|
},
|
||||||
|
LimitedRequester::new().await,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let login_schema: LoginSchema = LoginSchema::new(
|
||||||
|
AuthUsername::new("user1@gmail.com".to_string()).unwrap(),
|
||||||
|
"user".to_string(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let login_result = instance.login_account(&login_schema).await.unwrap();
|
||||||
|
let token = login_result.token;
|
||||||
|
let settings = login_result.settings;
|
||||||
|
let limits = instance.limits.clone();
|
||||||
|
let mut user = crate::api::types::User::new(&mut instance, token, limits, settings, None);
|
||||||
|
let vec_attach = vec![attachment.clone()];
|
||||||
|
let arg = Some(&vec_attach);
|
||||||
|
let response = user
|
||||||
|
.send_message(&mut message, &channel_id, arg)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,8 +257,6 @@ pub struct MessageSendSchema {
|
||||||
message_reference: Option<super::MessageReference>,
|
message_reference: Option<super::MessageReference>,
|
||||||
components: Option<Vec<super::Component>>,
|
components: Option<Vec<super::Component>>,
|
||||||
sticker_ids: Option<Vec<String>>,
|
sticker_ids: Option<Vec<String>>,
|
||||||
#[serde(flatten)]
|
|
||||||
files: Option<HashMap<String, Vec<u8>>>,
|
|
||||||
attachments: Option<Vec<super::PartialDiscordFileAttachment>>,
|
attachments: Option<Vec<super::PartialDiscordFileAttachment>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +272,6 @@ impl MessageSendSchema {
|
||||||
message_reference: Option<super::MessageReference>,
|
message_reference: Option<super::MessageReference>,
|
||||||
components: Option<Vec<super::Component>>,
|
components: Option<Vec<super::Component>>,
|
||||||
sticker_ids: Option<Vec<String>>,
|
sticker_ids: Option<Vec<String>>,
|
||||||
files: Option<HashMap<String, Vec<u8>>>,
|
|
||||||
attachments: Option<Vec<super::PartialDiscordFileAttachment>>,
|
attachments: Option<Vec<super::PartialDiscordFileAttachment>>,
|
||||||
) -> MessageSendSchema {
|
) -> MessageSendSchema {
|
||||||
MessageSendSchema {
|
MessageSendSchema {
|
||||||
|
@ -287,7 +284,6 @@ impl MessageSendSchema {
|
||||||
message_reference,
|
message_reference,
|
||||||
components,
|
components,
|
||||||
sticker_ids,
|
sticker_ids,
|
||||||
files,
|
|
||||||
attachments,
|
attachments,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -843,21 +843,21 @@ pub struct DiscordFileAttachment {
|
||||||
content: Vec<u8>,
|
content: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
|
||||||
pub struct PartialDiscordFileAttachment {
|
pub struct PartialDiscordFileAttachment {
|
||||||
pub id: Option<i16>,
|
pub id: Option<i16>,
|
||||||
pub filename: Option<String>,
|
pub filename: Option<String>,
|
||||||
description: Option<String>,
|
pub description: Option<String>,
|
||||||
content_type: Option<String>,
|
pub content_type: Option<String>,
|
||||||
size: Option<i64>,
|
pub size: Option<i64>,
|
||||||
url: Option<String>,
|
pub url: Option<String>,
|
||||||
proxy_url: Option<String>,
|
pub proxy_url: Option<String>,
|
||||||
height: Option<i32>,
|
pub height: Option<i32>,
|
||||||
width: Option<i32>,
|
pub width: Option<i32>,
|
||||||
ephemeral: Option<bool>,
|
pub ephemeral: Option<bool>,
|
||||||
duration_secs: Option<f32>,
|
pub duration_secs: Option<f32>,
|
||||||
waveform: Option<String>,
|
pub waveform: Option<String>,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
pub content: Vec<u8>,
|
pub content: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue