Merge pull request #102 from polyphony-chat/feature/permissions-and-roles

Feature/permissions and roles
This commit is contained in:
Flori 2023-06-11 19:32:04 +02:00 committed by GitHub
commit 076df001ef
39 changed files with 1605 additions and 1071 deletions

View File

@ -17,7 +17,7 @@ pub struct ExampleObserver {}
// One struct can be an observer of multiple websocketevents, if needed
impl Observer<GatewayReady> for ExampleObserver {
// After we subscribe to an event this function is called every time we receive it
fn update(&self, _data: &GatewayReady) {
fn update(&mut self, _data: &GatewayReady) {
println!("Observed Ready!");
}
}

View File

@ -1,44 +1,35 @@
use reqwest::Client;
use serde_json::{from_str, to_string};
use serde_json::to_string;
use crate::{
api::common,
errors::ChorusLibError,
instance::UserMeta,
limit::LimitedRequester,
types::{Channel, ChannelModifySchema},
};
impl Channel {
pub async fn get(user: &mut UserMeta, channel_id: &str) -> Result<Channel, ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let belongs_to = user.belongs_to.borrow_mut();
let url = belongs_to.urls.get_api().to_string();
drop(belongs_to);
let request = Client::new()
.get(format!(
"{}/channels/{}/",
belongs_to.urls.get_api(),
channel_id
))
.get(format!("{}/channels/{}/", url, channel_id))
.bearer_auth(user.token());
let mut requester = LimitedRequester::new().await;
let result = match requester
.send_request(
let result = common::deserialize_response::<Channel>(
request,
crate::api::limits::LimitType::Guild,
&mut belongs_to.limits,
&mut user.limits,
user,
crate::api::limits::LimitType::Channel,
)
.await
{
Ok(result) => result,
Err(e) => return Err(e),
};
let result_text = result.text().await.unwrap();
match from_str::<Channel>(&result_text) {
Ok(object) => Ok(object),
Err(e) => Err(ChorusLibError::RequestErrorError {
url: format!("{}/channels/{}/", belongs_to.urls.get_api(), channel_id),
error: e.to_string(),
}),
.await;
if result.is_err() {
return Err(ChorusLibError::RequestErrorError {
url: format!("{}/channels/{}/", url, channel_id),
error: result.err().unwrap().to_string(),
});
}
Ok(result.unwrap())
}
/// Deletes a channel.
@ -55,7 +46,7 @@ impl Channel {
///
/// An `Option` that contains an `ChorusLibError` if an error occurred during the request, or `None` if the request was successful.
pub async fn delete(self, user: &mut UserMeta) -> Option<ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let belongs_to = user.belongs_to.borrow_mut();
let request = Client::new()
.delete(format!(
"{}/channels/{}/",
@ -63,18 +54,13 @@ impl Channel {
self.id.to_string()
))
.bearer_auth(user.token());
match LimitedRequester::new()
.await
.send_request(
request,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
.await
{
Ok(_) => None,
Err(e) => return Some(e),
drop(belongs_to);
let response =
common::handle_request(request, user, crate::api::limits::LimitType::Channel).await;
if response.is_err() {
return Some(response.err().unwrap());
} else {
return None;
}
}
@ -97,7 +83,7 @@ impl Channel {
channel_id: &str,
user: &mut UserMeta,
) -> Result<Channel, ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let belongs_to = user.belongs_to.borrow();
let request = Client::new()
.patch(format!(
"{}/channels/{}/",
@ -106,19 +92,14 @@ impl Channel {
))
.bearer_auth(user.token())
.body(to_string(&modify_data).unwrap());
let channel = match LimitedRequester::new()
.await
.send_request(
drop(belongs_to);
let channel = common::deserialize_response::<Channel>(
request,
user,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
.await
{
Ok(channel) => from_str::<Channel>(&channel.text().await.unwrap()).unwrap(),
Err(e) => return Err(e),
};
.unwrap();
Ok(channel)
}
}

View File

@ -3,8 +3,8 @@ use http::HeaderMap;
use reqwest::{multipart, Client};
use serde_json::to_string;
use crate::api::deserialize_response;
use crate::instance::UserMeta;
use crate::limit::LimitedRequester;
use crate::types::{Message, MessageSendSchema, PartialDiscordFileAttachment};
impl Message {
@ -24,23 +24,17 @@ impl Message {
channel_id: String,
message: &mut MessageSendSchema,
files: Option<Vec<PartialDiscordFileAttachment>>,
) -> Result<reqwest::Response, crate::errors::ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let url_api = belongs_to.urls.get_api();
let mut requester = LimitedRequester::new().await;
) -> Result<Message, crate::errors::ChorusLibError> {
let belongs_to = user.belongs_to.borrow_mut();
let url_api = belongs_to.urls.get_api().to_string();
drop(belongs_to);
if files.is_none() {
let message_request = Client::new()
let request = Client::new()
.post(format!("{}/channels/{}/messages/", url_api, channel_id))
.bearer_auth(user.token())
.body(to_string(message).unwrap());
requester
.send_request(
message_request,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
deserialize_response::<Message>(request, user, crate::api::limits::LimitType::Channel)
.await
} else {
for (index, attachment) in message.attachments.iter_mut().enumerate() {
@ -70,18 +64,12 @@ impl Message {
form = form.part(part_name, part);
}
let message_request = Client::new()
let request = Client::new()
.post(format!("{}/channels/{}/messages/", url_api, channel_id))
.bearer_auth(user.token())
.multipart(form);
requester
.send_request(
message_request,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
deserialize_response::<Message>(request, user, crate::api::limits::LimitType::Channel)
.await
}
}
@ -105,7 +93,7 @@ impl UserMeta {
message: &mut MessageSendSchema,
channel_id: String,
files: Option<Vec<PartialDiscordFileAttachment>>,
) -> Result<reqwest::Response, crate::errors::ChorusLibError> {
) -> Result<Message, crate::errors::ChorusLibError> {
Message::send(self, channel_id, message, files).await
}
}

View File

@ -2,6 +2,7 @@ use reqwest::Client;
use serde_json::to_string;
use crate::{
api::handle_request,
errors::ChorusLibError,
instance::UserMeta,
limit::LimitedRequester,
@ -25,13 +26,14 @@ impl types::Channel {
channel_id: &str,
overwrite: PermissionOverwrite,
) -> Option<ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let belongs_to = user.belongs_to.borrow_mut();
let url = format!(
"{}/channels/{}/permissions/{}",
belongs_to.urls.get_api(),
channel_id,
overwrite.id
);
drop(belongs_to);
let body = match to_string(&overwrite) {
Ok(string) => string,
Err(e) => {
@ -41,17 +43,12 @@ impl types::Channel {
}
};
let request = Client::new().put(url).bearer_auth(user.token()).body(body);
LimitedRequester::new()
.await
.send_request(
request,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
.await
.unwrap();
None
match handle_request(request, user, crate::api::limits::LimitType::Channel).await {
Ok(_) => None,
Err(e) => Some(ChorusLibError::InvalidResponseError {
error: e.to_string(),
}),
}
}
/// Deletes a permission overwrite for a channel.
@ -70,26 +67,20 @@ impl types::Channel {
channel_id: &str,
overwrite_id: &str,
) -> Option<ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let belongs_to = user.belongs_to.borrow_mut();
let url = format!(
"{}/channels/{}/permissions/{}",
belongs_to.urls.get_api(),
channel_id,
overwrite_id
);
drop(belongs_to);
let request = Client::new().delete(url).bearer_auth(user.token());
let response = LimitedRequester::new()
.await
.send_request(
request,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
.await;
if response.is_err() {
return Some(response.err().unwrap());
}
None
match handle_request(request, user, crate::api::limits::LimitType::Channel).await {
Ok(_) => None,
Err(e) => Some(ChorusLibError::InvalidResponseError {
error: e.to_string(),
}),
}
}
}

61
src/api/common.rs Normal file
View File

@ -0,0 +1,61 @@
use reqwest::RequestBuilder;
use serde::Deserialize;
use serde_json::from_str;
use crate::{errors::ChorusLibError, instance::UserMeta, limit::LimitedRequester};
use super::limits::LimitType;
/// Sends a request to wherever it needs to go and performs some basic error
/// handling.
pub async fn handle_request(
request: RequestBuilder,
user: &mut UserMeta,
limit_type: LimitType,
) -> Result<reqwest::Response, crate::errors::ChorusLibError> {
let mut belongs_to = user.belongs_to.borrow_mut();
match LimitedRequester::new()
.await
.send_request(
request,
limit_type,
&mut belongs_to.limits,
&mut user.limits,
)
.await
{
Ok(response) => return Ok(response),
Err(e) => return Err(e),
}
}
pub async fn deserialize_response<T: for<'a> Deserialize<'a>>(
request: RequestBuilder,
user: &mut UserMeta,
limit_type: LimitType,
) -> Result<T, ChorusLibError> {
let response = handle_request(request, user, limit_type).await.unwrap();
let response_text = match response.text().await {
Ok(string) => string,
Err(e) => {
return Err(ChorusLibError::InvalidResponseError {
error: format!(
"Error while trying to process the HTTP response into a String: {}",
e.to_string()
),
});
}
};
let object = match from_str::<T>(&response_text) {
Ok(object) => object,
Err(e) => {
return Err(ChorusLibError::InvalidResponseError {
error: format!(
"Error while trying to deserialize the JSON response into T: {}",
e.to_string()
),
})
}
};
Ok(object)
}

View File

@ -1,10 +1,12 @@
pub use channels::messages::*;
pub use common::*;
pub use guilds::*;
pub use policies::instance::instance::*;
pub use policies::instance::limits::*;
pub mod auth;
pub mod channels;
pub mod common;
pub mod guilds;
pub mod policies;
pub mod users;

View File

@ -32,3 +32,35 @@ custom_error! {
pub ObserverError
AlreadySubscribedError = "Each event can only be subscribed to once."
}
custom_error! {
/// For errors we receive from the gateway, see https://discord-userdoccers.vercel.app/topics/opcodes-and-status-codes#gateway-close-event-codes;
///
/// Supposed to be sent as numbers, though they are sent as string most of the time?
///
/// Also includes errors when initiating a connection and unexpected opcodes
#[derive(PartialEq, Eq)]
pub GatewayError
// Errors we have received from the gateway
UnknownError = "We're not sure what went wrong. Try reconnecting?",
UnknownOpcodeError = "You sent an invalid Gateway opcode or an invalid payload for an opcode",
DecodeError = "Gateway server couldn't decode payload",
NotAuthenticatedError = "You sent a payload prior to identifying",
AuthenticationFailedError = "The account token sent with your identify payload is invalid",
AlreadyAuthenticatedError = "You've already identified, no need to reauthenticate",
InvalidSequenceNumberError = "The sequence number sent when resuming the session was invalid. Reconnect and start a new session",
RateLimitedError = "You are being rate limited!",
SessionTimedOutError = "Your session timed out. Reconnect and start a new one",
InvalidShardError = "You sent us an invalid shard when identifying",
ShardingRequiredError = "The session would have handled too many guilds - you are required to shard your connection in order to connect",
InvalidAPIVersionError = "You sent an invalid Gateway version",
InvalidIntentsError = "You sent an invalid intent",
DisallowedIntentsError = "You sent a disallowed intent. You may have tried to specify an intent that you have not enabled or are not approved for",
// Errors when initiating a gateway connection
CannotConnectError{error: String} = "Cannot connect due to a tungstenite error: {error}",
NonHelloOnInitiateError{opcode: u8} = "Received non hello on initial gateway connection ({opcode}), something is definitely wrong",
// Other misc errors
UnexpectedOpcodeReceivedError{opcode: u8} = "Received an opcode we weren't expecting to receive: {opcode}",
}

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ pub struct Attachment {
pub waveform: Option<String>,
#[serde(skip_serializing)]
#[cfg_attr(feature = "sqlx", sqlx(default))]
pub content: Vec<u8>,
pub content: Option<Vec<u8>>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]

View File

@ -34,7 +34,7 @@ pub struct Guild {
pub emojis: Vec<Emoji>,
pub explicit_content_filter: Option<i32>,
//#[cfg_attr(feature = "sqlx", sqlx(try_from = "String"))]
pub features: GuildFeaturesList,
pub features: Option<GuildFeaturesList>,
pub icon: Option<String>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub icon_hash: Option<String>,

View File

@ -15,10 +15,10 @@ pub struct Message {
pub channel_id: Snowflake,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub author: PublicUser,
pub content: String,
pub content: Option<String>,
pub timestamp: String,
pub edited_timestamp: Option<String>,
pub tts: bool,
pub tts: Option<bool>,
pub mention_everyone: bool,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub mentions: Option<Vec<User>>,

View File

@ -1,6 +1,6 @@
use bitflags::bitflags;
use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_option_number_from_string;
use serde_aux::prelude::{deserialize_option_number_from_string, deserialize_string_from_number};
use crate::types::utils::Snowflake;
@ -16,6 +16,7 @@ pub struct RoleObject {
pub unicode_emoji: Option<String>,
pub position: u16,
#[serde(default)]
#[serde(deserialize_with = "deserialize_string_from_number")]
pub permissions: String,
pub managed: bool,
pub mentionable: bool,

View File

@ -13,6 +13,12 @@ pub enum UserStatus {
Invisible,
}
impl std::fmt::Display for UserStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", serde_json::to_string(self).unwrap())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[serde(rename_all = "lowercase")]

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::types::{GuildApplicationCommandPermissions, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#application-command-permissions-update
pub struct ApplicationCommandPermissionsUpdate {
#[serde(flatten)]

View File

@ -5,7 +5,7 @@ use crate::types::{
WebSocketEvent,
};
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create
pub struct AutoModerationRuleCreate {
#[serde(flatten)]
@ -14,7 +14,7 @@ pub struct AutoModerationRuleCreate {
impl WebSocketEvent for AutoModerationRuleCreate {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update
pub struct AutoModerationRuleUpdate {
#[serde(flatten)]
@ -23,7 +23,7 @@ pub struct AutoModerationRuleUpdate {
impl WebSocketEvent for AutoModerationRuleUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-delete
pub struct AutoModerationRuleDelete {
#[serde(flatten)]
@ -32,7 +32,7 @@ pub struct AutoModerationRuleDelete {
impl WebSocketEvent for AutoModerationRuleDelete {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution
pub struct AutoModerationActionExecution {
pub guild_id: Snowflake,

View File

@ -2,10 +2,11 @@ use serde::{Deserialize, Serialize};
use crate::types::{VoiceState, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented
/// Is sent to a client by the server to signify a new being created
/// {"t":"CALL_CREATE","s":2,"op":0,"d":{"voice_states":[],"ringing":[],"region":"milan","message_id":"1107187514906775613","embedded_activities":[],"channel_id":"837609115475771392"}}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented;
/// Is sent to a client by the server to signify a new call being created;
///
/// Ex: {"t":"CALL_CREATE","s":2,"op":0,"d":{"voice_states":[],"ringing":[],"region":"milan","message_id":"1107187514906775613","embedded_activities":[],"channel_id":"837609115475771392"}}
pub struct CallCreate {
pub voice_states: Vec<VoiceState>,
/// Seems like a vec of channel ids
@ -20,10 +21,11 @@ pub struct CallCreate {
impl WebSocketEvent for CallCreate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented
/// Updates the status of calls
/// {"t":"CALL_UPDATE","s":5,"op":0,"d":{"ringing":["837606544539254834"],"region":"milan","message_id":"1107191540234846308","guild_id":null,"channel_id":"837609115475771392"}}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented;
/// Updates the client on which calls are ringing, along with a specific call?;
///
/// Ex: {"t":"CALL_UPDATE","s":5,"op":0,"d":{"ringing":["837606544539254834"],"region":"milan","message_id":"1107191540234846308","guild_id":null,"channel_id":"837609115475771392"}}
pub struct CallUpdate {
/// Seems like a vec of channel ids
pub ringing: Vec<String>,
@ -36,20 +38,21 @@ pub struct CallUpdate {
impl WebSocketEvent for CallUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented
/// Deletes a ringing call
/// {"t":"CALL_DELETE","s":8,"op":0,"d":{"channel_id":"837609115475771392"}}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented;
/// Deletes a ringing call;
/// Ex: {"t":"CALL_DELETE","s":8,"op":0,"d":{"channel_id":"837609115475771392"}}
pub struct CallDelete {
pub channel_id: String,
}
impl WebSocketEvent for CallDelete {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented
/// See https://unofficial-discord-docs.vercel.app/gateway/op13
/// {"op":13,"d":{"channel_id":"837609115475771392"}}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented;
/// See https://unofficial-discord-docs.vercel.app/gateway/op13;
///
/// Ex: {"op":13,"d":{"channel_id":"837609115475771392"}}
pub struct CallSync {
pub channel_id: String,
}

View File

@ -1,8 +1,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::entities::Channel;
use crate::types::events::WebSocketEvent;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#channel-pins-update
@ -14,7 +13,7 @@ pub struct ChannelPinsUpdate {
impl WebSocketEvent for ChannelPinsUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#channel-create
pub struct ChannelCreate {
#[serde(flatten)]
@ -23,7 +22,7 @@ pub struct ChannelCreate {
impl WebSocketEvent for ChannelCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#channel-update
pub struct ChannelUpdate {
#[serde(flatten)]
@ -32,7 +31,7 @@ pub struct ChannelUpdate {
impl WebSocketEvent for ChannelUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// Officially undocumented.
/// Sends updates to client about a new message with its id
/// {"channel_unread_updates": [{"id": "816412869766938648", "last_message_id": "1085892012085104680"}}
@ -41,7 +40,7 @@ pub struct ChannelUnreadUpdate {
pub guild_id: String,
}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// Contains very few fields from [Channel]
/// See also [ChannelUnreadUpdates]
pub struct ChannelUnreadUpdateObject {
@ -52,7 +51,7 @@ pub struct ChannelUnreadUpdateObject {
impl WebSocketEvent for ChannelUnreadUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#channel-delete
pub struct ChannelDelete {
#[serde(flatten)]

View File

@ -7,15 +7,16 @@ use crate::types::{AuditLogEntry, Emoji, GuildMember, GuildScheduledEvent, RoleO
use super::PresenceUpdate;
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-create
/// This one is particularly painful, it can be a Guild object with an extra field or an unavailable guild object
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-create;
/// Received to give data about a guild;
// This one is particularly painful, it can be a Guild object with an extra field or an unavailable guild object
pub struct GuildCreate {
#[serde(flatten)]
pub d: GuildCreateDataOption,
}
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(untagged)]
pub enum GuildCreateDataOption {
UnavailableGuild(UnavailableGuild),
@ -30,8 +31,9 @@ impl Default for GuildCreateDataOption {
impl WebSocketEvent for GuildCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-ban-add-guild-ban-add-event-fields
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-ban-add-guild-ban-add-event-fields;
/// Received to give info about a user being banned from a guild;
pub struct GuildBanAdd {
pub guild_id: String,
pub user: PublicUser,
@ -39,8 +41,9 @@ pub struct GuildBanAdd {
impl WebSocketEvent for GuildBanAdd {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-ban-remove
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-ban-remove;
/// Received to give info about a user being unbanned from a guild;
pub struct GuildBanRemove {
pub guild_id: String,
pub user: PublicUser,
@ -48,8 +51,9 @@ pub struct GuildBanRemove {
impl WebSocketEvent for GuildBanRemove {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-update
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-update;
/// Received to give info about a guild being updated;
pub struct GuildUpdate {
#[serde(flatten)]
pub guild: Guild,
@ -57,8 +61,9 @@ pub struct GuildUpdate {
impl WebSocketEvent for GuildUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-delete
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-delete;
/// Received to tell the client about a guild being deleted;
pub struct GuildDelete {
#[serde(flatten)]
pub guild: UnavailableGuild,
@ -66,8 +71,9 @@ pub struct GuildDelete {
impl WebSocketEvent for GuildDelete {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-audit-log-entry-create
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-audit-log-entry-create;
/// Received to the client about an audit log entry being added;
pub struct GuildAuditLogEntryCreate {
#[serde(flatten)]
pub entry: AuditLogEntry,
@ -75,8 +81,9 @@ pub struct GuildAuditLogEntryCreate {
impl WebSocketEvent for GuildAuditLogEntryCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-emojis-update
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-emojis-update;
/// Received to tell the client about a change to a guild's emoji list;
pub struct GuildEmojisUpdate {
pub guild_id: String,
pub emojis: Vec<Emoji>,
@ -84,8 +91,9 @@ pub struct GuildEmojisUpdate {
impl WebSocketEvent for GuildEmojisUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-stickers-update
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-stickers-update;
/// Received to tell the client about a change to a guild's sticker list;
pub struct GuildStickersUpdate {
pub guild_id: String,
pub stickers: Vec<Sticker>,
@ -93,7 +101,7 @@ pub struct GuildStickersUpdate {
impl WebSocketEvent for GuildStickersUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-integrations-update
pub struct GuildIntegrationsUpdate {
pub guild_id: String,
@ -101,8 +109,9 @@ pub struct GuildIntegrationsUpdate {
impl WebSocketEvent for GuildIntegrationsUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-member-add
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-member-add;
/// Received to tell the client about a user joining a guild;
pub struct GuildMemberAdd {
#[serde(flatten)]
pub member: GuildMember,
@ -111,8 +120,9 @@ pub struct GuildMemberAdd {
impl WebSocketEvent for GuildMemberAdd {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-member-remove
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-member-remove;
/// Received to tell the client about a user leaving a guild;
pub struct GuildMemberRemove {
pub guild_id: String,
pub user: PublicUser,
@ -120,7 +130,7 @@ pub struct GuildMemberRemove {
impl WebSocketEvent for GuildMemberRemove {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-member-update
pub struct GuildMemberUpdate {
pub guild_id: String,
@ -138,7 +148,7 @@ pub struct GuildMemberUpdate {
impl WebSocketEvent for GuildMemberUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-members-chunk
pub struct GuildMembersChunk {
pub guild_id: String,
@ -152,7 +162,7 @@ pub struct GuildMembersChunk {
impl WebSocketEvent for GuildMembersChunk {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-role-create
pub struct GuildRoleCreate {
pub guild_id: String,
@ -161,7 +171,7 @@ pub struct GuildRoleCreate {
impl WebSocketEvent for GuildRoleCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-role-update
pub struct GuildRoleUpdate {
pub guild_id: String,
@ -170,7 +180,7 @@ pub struct GuildRoleUpdate {
impl WebSocketEvent for GuildRoleUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-role-delete
pub struct GuildRoleDelete {
pub guild_id: String,
@ -179,7 +189,7 @@ pub struct GuildRoleDelete {
impl WebSocketEvent for GuildRoleDelete {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-create
pub struct GuildScheduledEventCreate {
#[serde(flatten)]
@ -188,7 +198,7 @@ pub struct GuildScheduledEventCreate {
impl WebSocketEvent for GuildScheduledEventCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-update
pub struct GuildScheduledEventUpdate {
#[serde(flatten)]
@ -197,7 +207,7 @@ pub struct GuildScheduledEventUpdate {
impl WebSocketEvent for GuildScheduledEventUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-delete
pub struct GuildScheduledEventDelete {
#[serde(flatten)]
@ -206,7 +216,7 @@ pub struct GuildScheduledEventDelete {
impl WebSocketEvent for GuildScheduledEventDelete {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-add
pub struct GuildScheduledEventUserAdd {
pub guild_scheduled_event_id: String,
@ -216,7 +226,7 @@ pub struct GuildScheduledEventUserAdd {
impl WebSocketEvent for GuildScheduledEventUserAdd {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-remove
pub struct GuildScheduledEventUserRemove {
pub guild_scheduled_event_id: String,

View File

@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::types::events::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct GatewayHeartbeat {
@ -10,7 +9,7 @@ pub struct GatewayHeartbeat {
impl WebSocketEvent for GatewayHeartbeat {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct GatewayHeartbeatAck {
pub op: i32,
}

View File

@ -1,7 +1,7 @@
use crate::types::WebSocketEvent;
use serde::{Deserialize, Serialize};
use crate::types::events::WebSocketEvent;
/// Received on gateway init, tells the client how often to send heartbeats;
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct GatewayHello {
pub op: i32,
@ -10,8 +10,11 @@ pub struct GatewayHello {
impl WebSocketEvent for GatewayHello {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// Contains info on how often the client should send heartbeats to the server;
pub struct HelloData {
/// How often a client should send heartbeats, in milliseconds
// u128 because std used u128s for milliseconds
pub heartbeat_interval: u128,
}

View File

@ -1,8 +1,7 @@
use crate::types::events::{PresenceUpdate, WebSocketEvent};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use crate::types::events::{PresenceUpdate, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize)]
pub struct GatewayIdentifyPayload {
pub token: String,
@ -67,7 +66,7 @@ impl GatewayIdentifyPayload {
impl WebSocketEvent for GatewayIdentifyPayload {}
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde_as]
pub struct GatewayIdentifyConnectionProps {
/// Almost always sent

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::types::{Integration, WebSocketEvent};
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#integration-create
pub struct IntegrationCreate {
#[serde(flatten)]
@ -12,7 +12,7 @@ pub struct IntegrationCreate {
impl WebSocketEvent for IntegrationCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#integration-update
pub struct IntegrationUpdate {
#[serde(flatten)]
@ -22,7 +22,7 @@ pub struct IntegrationUpdate {
impl WebSocketEvent for IntegrationUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#integration-delete
pub struct IntegrationDelete {
pub id: String,

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::types::{Interaction, WebSocketEvent};
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#interaction-create
pub struct InteractionCreate {
#[serde(flatten)]

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::types::{GuildInvite, WebSocketEvent};
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#invite-create
pub struct InviteCreate {
#[serde(flatten)]
@ -11,7 +11,7 @@ pub struct InviteCreate {
impl WebSocketEvent for InviteCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#invite-delete
pub struct InviteDelete {
pub channel_id: String,

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented
///
/// Sent to the server to signify lazy loading of a guild;

View File

@ -4,7 +4,7 @@ use crate::types::entities::{Emoji, GuildMember, Message, PublicUser};
use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct TypingStartEvent {
pub channel_id: String,
pub guild_id: Option<String>,
@ -15,7 +15,7 @@ pub struct TypingStartEvent {
impl WebSocketEvent for TypingStartEvent {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#message-create
pub struct MessageCreate {
#[serde(flatten)]
@ -25,7 +25,7 @@ pub struct MessageCreate {
mentions: Option<Vec<MessageCreateUser>>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#message-create-message-create-extra-fields
pub struct MessageCreateUser {
#[serde(flatten)]
@ -35,7 +35,7 @@ pub struct MessageCreateUser {
impl WebSocketEvent for MessageCreate {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct MessageUpdate {
#[serde(flatten)]
message: Message,
@ -46,7 +46,7 @@ pub struct MessageUpdate {
impl WebSocketEvent for MessageUpdate {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct MessageDelete {
id: String,
channel_id: String,
@ -55,7 +55,7 @@ pub struct MessageDelete {
impl WebSocketEvent for MessageDelete {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct MessageDeleteBulk {
ids: Vec<String>,
channel_id: String,
@ -64,7 +64,7 @@ pub struct MessageDeleteBulk {
impl WebSocketEvent for MessageDeleteBulk {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct MessageReactionAdd {
user_id: String,
channel_id: String,
@ -76,7 +76,7 @@ pub struct MessageReactionAdd {
impl WebSocketEvent for MessageReactionAdd {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct MessageReactionRemove {
user_id: String,
channel_id: String,
@ -87,7 +87,7 @@ pub struct MessageReactionRemove {
impl WebSocketEvent for MessageReactionRemove {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct MessageReactionRemoveAll {
channel_id: String,
message_id: String,
@ -96,7 +96,7 @@ pub struct MessageReactionRemoveAll {
impl WebSocketEvent for MessageReactionRemoveAll {}
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct MessageReactionRemoveEmoji {
channel_id: String,
message_id: String,
@ -106,7 +106,7 @@ pub struct MessageReactionRemoveEmoji {
impl WebSocketEvent for MessageReactionRemoveEmoji {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented
///
/// Not documented anywhere unofficially

View File

@ -1,8 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::types::{GuildMember, VoiceState};
use super::{ChannelUnreadUpdateObject, WebSocketEvent};
use crate::types::{GuildMember, VoiceState};
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented

View File

@ -1,15 +1,27 @@
use crate::types::{events::WebSocketEvent, UserStatus};
use crate::types::{Activity, PublicUser, Snowflake};
use serde::{Deserialize, Serialize};
use crate::types::events::WebSocketEvent;
use crate::types::interfaces::Activity;
use crate::types::PublicUser;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Sent by the client to update its status and presence;
/// See https://discord.com/developers/docs/topics/gateway-events#update-presence
pub struct UpdatePresence {
/// unix time of when the client went idle, or none if client is not idle
pub since: Option<u128>,
/// the client's status (online, invisible, offline, dnd, idle..)
pub status: UserStatus,
pub activities: Vec<Activity>,
pub afk: bool,
}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Received to tell the client that a user updated their presence / status
/// See https://discord.com/developers/docs/topics/gateway-events#presence-update-presence-update-event-fields
pub struct PresenceUpdate {
pub user: PublicUser,
pub guild_id: Option<String>,
pub status: String,
#[serde(default)]
pub guild_id: Option<Snowflake>,
pub status: UserStatus,
pub activities: Vec<Activity>,
pub client_status: ClientStatusObject,
}

View File

@ -5,10 +5,10 @@ use crate::types::events::{Session, WebSocketEvent};
use crate::types::interfaces::ClientStatusObject;
use crate::types::{Activity, GuildMember, PresenceUpdate, VoiceState};
#[derive(Debug, Deserialize, Serialize, Default)]
/// Sort of documented, though most fields are left out
/// For a full example see https://gist.github.com/kozabrada123/a347002b1fb8825a5727e40746d4e199
/// to:do add all undocumented fields
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// 1/2 half documented;
/// Received after identifying, provides initial user info;
/// See https://discord.com/developers/docs/topics/gateway-events#ready;
pub struct GatewayReady {
pub analytics_token: Option<String>,
pub auth_session_id_hash: Option<String>,
@ -28,10 +28,9 @@ pub struct GatewayReady {
impl WebSocketEvent for GatewayReady {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// Officially Undocumented
/// Sent after the READY event when a client is a user
/// {"t":"READY_SUPPLEMENTAL","s":2,"op":0,"d":{"merged_presences":{"guilds":[[{"user_id":"463640391196082177","status":"online","game":null,"client_status":{"web":"online"},"activities":[]}]],"friends":[{"user_id":"463640391196082177","status":"online","last_modified":1684053508443,"client_status":{"web":"online"},"activities":[]}]},"merged_members":[[{"user_id":"463640391196082177","roles":[],"premium_since":null,"pending":false,"nick":"pog","mute":false,"joined_at":"2021-05-30T15:24:08.763000+00:00","flags":0,"deaf":false,"communication_disabled_until":null,"avatar":null}]],"lazy_private_channels":[],"guilds":[{"voice_states":[],"id":"848582562217590824","embedded_activities":[]}],"disclose":["pomelo"]}}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented;
/// Sent after the READY event when a client is a user, seems to somehow add onto the ready event;
pub struct GatewayReadySupplemental {
pub merged_presences: MergedPresences,
pub merged_members: Vec<Vec<GuildMember>>,
@ -44,13 +43,13 @@ pub struct GatewayReadySupplemental {
impl WebSocketEvent for GatewayReadySupplemental {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct MergedPresences {
pub guilds: Vec<Vec<MergedPresenceGuild>>,
pub friends: Vec<MergedPresenceFriend>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct MergedPresenceFriend {
pub user_id: String,
pub status: String,
@ -60,7 +59,7 @@ pub struct MergedPresenceFriend {
pub activities: Vec<Activity>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct MergedPresenceGuild {
pub user_id: String,
pub status: String,
@ -70,7 +69,7 @@ pub struct MergedPresenceGuild {
pub activities: Vec<Activity>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct SupplementalGuild {
pub voice_states: Option<Vec<VoiceState>>,
pub id: String,

View File

@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::types::{events::WebSocketEvent, Relationship, RelationshipType, Snowflake};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://github.com/spacebarchat/server/issues/204
@ -12,7 +11,7 @@ pub struct RelationshipAdd {
impl WebSocketEvent for RelationshipAdd {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://github.com/spacebarchat/server/issues/203
pub struct RelationshipRemove {
pub id: Snowflake,

View File

@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::types::events::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#request-guild-members-request-guild-members-structure

View File

@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::types::events::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct GatewayResume {

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::types::{Activity, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Officially Undocumented
/// Seems like it sends active session info to users on connect
/// [{"activities":[],"client_info":{"client":"web","os":"other","version":0},"session_id":"ab5941b50d818b1f8d93b4b1b581b192","status":"online"}]
@ -10,7 +10,7 @@ pub struct SessionsReplace {
pub sessions: Vec<Session>,
}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Session info for the current user
pub struct Session {
pub activities: Vec<Activity>,
@ -19,7 +19,7 @@ pub struct Session {
pub status: String,
}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// Another Client info object
/// {"client":"web","os":"other","version":0}
// Note: I don't think this one exists yet? Though I might've made a mistake and this might be a duplicate

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use crate::types::{StageInstance, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-create
pub struct StageInstanceCreate {
#[serde(flatten)]
@ -11,7 +11,7 @@ pub struct StageInstanceCreate {
impl WebSocketEvent for StageInstanceCreate {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-update
pub struct StageInstanceUpdate {
#[serde(flatten)]
@ -20,7 +20,7 @@ pub struct StageInstanceUpdate {
impl WebSocketEvent for StageInstanceUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-delete
pub struct StageInstanceDelete {
#[serde(flatten)]

View File

@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use crate::types::entities::{Channel, ThreadMember};
use crate::types::events::WebSocketEvent;
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#thread-create
pub struct ThreadCreate {
#[serde(flatten)]
@ -12,7 +12,7 @@ pub struct ThreadCreate {
impl WebSocketEvent for ThreadCreate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#thread-update
pub struct ThreadUpdate {
#[serde(flatten)]
@ -21,7 +21,7 @@ pub struct ThreadUpdate {
impl WebSocketEvent for ThreadUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#thread-delete
pub struct ThreadDelete {
#[serde(flatten)]
@ -30,7 +30,7 @@ pub struct ThreadDelete {
impl WebSocketEvent for ThreadDelete {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#thread-list-sync
pub struct ThreadListSync {
pub guild_id: String,
@ -41,7 +41,7 @@ pub struct ThreadListSync {
impl WebSocketEvent for ThreadListSync {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#thread-member-update
/// The inner payload is a thread member object with an extra field.
pub struct ThreadMemberUpdate {
@ -52,7 +52,7 @@ pub struct ThreadMemberUpdate {
impl WebSocketEvent for ThreadMemberUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#thread-members-update
pub struct ThreadMembersUpdate {
pub id: String,

View File

@ -4,8 +4,9 @@ use crate::types::entities::PublicUser;
use crate::types::events::WebSocketEvent;
use crate::types::utils::Snowflake;
#[derive(Debug, Default, Deserialize, Serialize)]
/// See https://discord.com/developers/docs/topics/gateway-events#user-update
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#user-update;
/// Sent to indicate updates to a user object; (name changes, discriminator changes, etc);
pub struct UserUpdate {
#[serde(flatten)]
pub user: PublicUser,
@ -13,12 +14,12 @@ pub struct UserUpdate {
impl WebSocketEvent for UserUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// Undocumented
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// Undocumented;
///
/// Possibly an update for muted guild / channel settings for the current user
/// Possibly an update for muted guild / channel settings for the current user;
///
/// {"version":2,"suppress_roles":false,"suppress_everyone":false,"notify_highlights":0,"muted":false,"mute_scheduled_events":false,"mute_config":null,"mobile_push":true,"message_notifications":1,"hide_muted_channels":false,"guild_id":"848582562217590824","flags":0,"channel_overrides":[{"muted":false,"mute_config":null,"message_notifications":3,"flags":4096,"collapsed":false,"channel_id":"1042689182893604885"}]}
/// Ex: {"version":2,"suppress_roles":false,"suppress_everyone":false,"notify_highlights":0,"muted":false,"mute_scheduled_events":false,"mute_config":null,"mobile_push":true,"message_notifications":1,"hide_muted_channels":false,"guild_id":"848582562217590824","flags":0,"channel_overrides":[{"muted":false,"mute_config":null,"message_notifications":3,"flags":4096,"collapsed":false,"channel_id":"1042689182893604885"}]}
pub struct UserGuildSettingsUpdate {
pub version: u8,
pub suppress_roles: bool,
@ -38,12 +39,12 @@ pub struct UserGuildSettingsUpdate {
impl WebSocketEvent for UserGuildSettingsUpdate {}
#[derive(Debug, Default, Deserialize, Serialize)]
/// Undocumented
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// Undocumented;
///
/// Received in [UserGuildSettingsUpdate]
/// Received in [UserGuildSettingsUpdate];
///
/// {"muted":false,"mute_config":null,"message_notifications":3,"flags":4096,"collapsed":false,"channel_id":"1042689182893604885"}
/// Ex: {"muted":false,"mute_config":null,"message_notifications":3,"flags":4096,"collapsed":false,"channel_id":"1042689182893604885"}
pub struct UserGuildSettingsChannelOverride {
pub muted: bool,
/// ??

View File

@ -1,13 +1,11 @@
use crate::types::{events::WebSocketEvent, VoiceState};
use serde::{Deserialize, Serialize};
use crate::types::{events::WebSocketEvent, VoiceState};
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#update-voice-state
///
/// Sent to the server
/// Sent to the server to indicate an update of the voice state (leave voice channel, join voice channel, mute, deafen);
///
/// Not to be confused with [VoiceStateUpdate]
/// Not to be confused with [VoiceStateUpdate];
pub struct UpdateVoiceState {
pub guild_id: Option<String>,
pub channel_id: Option<String>,
@ -17,12 +15,12 @@ pub struct UpdateVoiceState {
impl WebSocketEvent for UpdateVoiceState {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#voice-state-update
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#voice-state-update;
///
/// Received from the server
/// Received from the server to indicate an update in a user's voice state (leave voice channel, join voice channel, mute, deafen, etc);
///
/// Not to be confused with [UpdateVoiceState]
/// Not to be confused with [UpdateVoiceState];
pub struct VoiceStateUpdate {
#[serde(flatten)]
pub state: VoiceState,
@ -30,8 +28,10 @@ pub struct VoiceStateUpdate {
impl WebSocketEvent for VoiceStateUpdate {}
#[derive(Debug, Deserialize, Serialize, Default)]
/// See https://discord.com/developers/docs/topics/gateway-events#voice-server-update
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#voice-server-update;
///
/// Received to indicate which voice endpoint, token and guild_id to use;
pub struct VoiceServerUpdate {
pub token: String,
pub guild_id: String,

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See https://discord.com/developers/docs/topics/gateway-events#webhooks-update
pub struct WebhooksUpdate {
pub guild_id: String,

24
tests/gateway.rs Normal file
View File

@ -0,0 +1,24 @@
mod common;
use chorus::gateway::*;
use chorus::types;
#[tokio::test]
/// Tests establishing a connection (hello and heartbeats) on the local gateway;
async fn test_gateway_establish() {
let bundle = common::setup().await;
Gateway::new(bundle.urls.wss).await.unwrap();
}
#[tokio::test]
/// Tests establishing a connection and authenticating
async fn test_gateway_authenticate() {
let bundle = common::setup().await;
let gateway = Gateway::new(bundle.urls.wss).await.unwrap();
let mut identify = types::GatewayIdentifyPayload::common();
identify.token = bundle.user.token;
gateway.send_identify(identify).await;
}