Compare commits

...

3 Commits

Author SHA1 Message Date
kozabrada123 3a5bbb73e0 Merge 'origin/dev' into feat/websocketevent-derive 2024-04-28 07:49:02 +02:00
kozabrada123 c5ba48526a chore: derive WebSocketEvent
use derive macro instead of manual impl blocks
2024-04-28 07:44:50 +02:00
kozabrada123 a710edc2a1
add WebSocketEvent macro derive, bump chorus-macros to 0.3.0 (#490)
* feat: add WebSocketEvent derive, bump to 0.2.1

* change license, version of macros
2024-04-19 17:13:36 +02:00
42 changed files with 135 additions and 284 deletions

4
Cargo.lock generated
View File

@ -252,9 +252,9 @@ dependencies = [
[[package]]
name = "chorus-macros"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a81545a60b926f815517dadbbd40cd502294ae2baea25fa8194d854d607512b0"
checksum = "de4221700bc486c6e6bc261fdea478936d33067a06325895f5d2a8cde5917272"
dependencies = [
"async-trait",
"quote",

View File

@ -43,7 +43,7 @@ thiserror = "1.0.56"
jsonwebtoken = "8.3.0"
log = "0.4.20"
async-trait = "0.1.77"
chorus-macros = "0.2.0"
chorus-macros = "0.3.0"
sqlx = { version = "0.7.3", features = [
"mysql",
"sqlite",

View File

@ -6,6 +6,7 @@
use custom_error::custom_error;
use crate::types::WebSocketEvent;
use chorus_macros::WebSocketEvent;
custom_error! {
#[derive(PartialEq, Eq, Clone, Hash)]
@ -72,7 +73,7 @@ custom_error! {
/// 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, Default, Clone)]
#[derive(PartialEq, Eq, Default, Clone, WebSocketEvent)]
pub GatewayError
// Errors we have received from the gateway
#[default]
@ -99,15 +100,13 @@ custom_error! {
UnexpectedOpcodeReceived{opcode: u8} = "Received an opcode we weren't expecting to receive: {opcode}",
}
impl WebSocketEvent for GatewayError {}
custom_error! {
/// Voice Gateway errors
///
/// Similar to [GatewayError].
///
/// See <https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-close-event-codes>;
#[derive(Clone, Default, PartialEq, Eq)]
#[derive(Clone, Default, PartialEq, Eq, WebSocketEvent)]
pub VoiceGatewayError
// Errors we receive
#[default]
@ -132,11 +131,9 @@ custom_error! {
UnexpectedOpcodeReceived{opcode: u8} = "Received an opcode we weren't expecting to receive: {opcode}",
}
impl WebSocketEvent for VoiceGatewayError {}
custom_error! {
/// Voice UDP errors.
#[derive(Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq, WebSocketEvent)]
pub VoiceUdpError
// General errors
@ -155,4 +152,3 @@ custom_error! {
CannotConnect{error: String} = "Cannot connect due to a UDP error: {error}",
}
impl WebSocketEvent for VoiceUdpError {}

View File

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

View File

@ -2,28 +2,27 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::{JsonField, SourceUrlField};
use chorus_macros::{JsonField, SourceUrlField};
use crate::types::{JsonField, SourceUrlField, WebSocketEvent};
use chorus_macros::{JsonField, SourceUrlField, WebSocketEvent};
use serde::{Deserialize, Serialize};
use crate::types::{
AutoModerationAction, AutoModerationRule, AutoModerationRuleTriggerType, Snowflake,
WebSocketEvent,
};
#[cfg(feature = "client")]
use super::UpdateMessage;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create>
pub struct AutoModerationRuleCreate {
#[serde(flatten)]
pub rule: AutoModerationRule,
}
impl WebSocketEvent for AutoModerationRuleCreate {}
#[derive(Debug, Deserialize, Serialize, Default, Clone, JsonField, SourceUrlField)]
#[derive(
Debug, Deserialize, Serialize, Default, Clone, JsonField, SourceUrlField, WebSocketEvent,
)]
/// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update>
pub struct AutoModerationRuleUpdate {
#[serde(flatten)]
@ -43,18 +42,14 @@ impl UpdateMessage<AutoModerationRule> for AutoModerationRuleUpdate {
}
}
impl WebSocketEvent for AutoModerationRuleUpdate {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-delete>
pub struct AutoModerationRuleDelete {
#[serde(flatten)]
pub rule: AutoModerationRule,
}
impl WebSocketEvent for AutoModerationRuleDelete {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution>
pub struct AutoModerationActionExecution {
pub guild_id: Snowflake,
@ -69,5 +64,3 @@ pub struct AutoModerationActionExecution {
pub matched_keyword: Option<String>,
pub matched_content: Option<String>,
}
impl WebSocketEvent for AutoModerationActionExecution {}

View File

@ -5,8 +5,9 @@
use serde::{Deserialize, Serialize};
use crate::types::{Snowflake, VoiceState, WebSocketEvent};
use chorus_macros::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// Officially Undocumented;
/// Is sent to a client by the server to signify a new call being created;
///
@ -23,9 +24,7 @@ pub struct CallCreate {
pub channel_id: Snowflake,
}
impl WebSocketEvent for CallCreate {}
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq, WebSocketEvent)]
/// Officially Undocumented;
/// Updates the client on which calls are ringing, along with a specific call?;
///
@ -40,9 +39,7 @@ pub struct CallUpdate {
pub channel_id: Snowflake,
}
impl WebSocketEvent for CallUpdate {}
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq, WebSocketEvent)]
/// Officially Undocumented;
/// Deletes a ringing call;
/// Ex: {"t":"CALL_DELETE","s":8,"op":0,"d":{"channel_id":"837609115475771392"}}
@ -50,9 +47,7 @@ pub struct CallDelete {
pub channel_id: Snowflake,
}
impl WebSocketEvent for CallDelete {}
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq, WebSocketEvent)]
/// Officially Undocumented;
/// See <https://unofficial-discord-docs.vercel.app/gateway/op13>;
///
@ -61,4 +56,3 @@ pub struct CallSync {
pub channel_id: Snowflake,
}
impl WebSocketEvent for CallSync {}

View File

@ -18,7 +18,7 @@ use crate::gateway::Shared;
#[cfg(feature = "client")]
use crate::types::Guild;
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#channel-pins-update>
pub struct ChannelPinsUpdate {
pub guild_id: Option<Snowflake>,
@ -26,9 +26,7 @@ pub struct ChannelPinsUpdate {
pub last_pin_timestamp: Option<DateTime<Utc>>,
}
impl WebSocketEvent for ChannelPinsUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#channel-create>
pub struct ChannelCreate {
#[serde(flatten)]
@ -39,8 +37,6 @@ pub struct ChannelCreate {
pub source_url: String,
}
impl WebSocketEvent for ChannelCreate {}
#[cfg(feature = "client")]
impl UpdateMessage<Guild> for ChannelCreate {
#[cfg(not(tarpaulin_include))]
@ -59,7 +55,7 @@ impl UpdateMessage<Guild> for ChannelCreate {
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#channel-update>
pub struct ChannelUpdate {
#[serde(flatten)]
@ -70,8 +66,6 @@ pub struct ChannelUpdate {
pub source_url: String,
}
impl WebSocketEvent for ChannelUpdate {}
#[cfg(feature = "client")]
impl UpdateMessage<Channel> for ChannelUpdate {
fn update(&mut self, object_to_update: Shared<Channel>) {
@ -85,7 +79,7 @@ impl UpdateMessage<Channel> for ChannelUpdate {
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// Officially undocumented.
/// Sends updates to client about a new message with its id
/// {"channel_unread_updates": [{"id": "816412869766938648", "last_message_id": "1085892012085104680"}}
@ -103,9 +97,7 @@ pub struct ChannelUnreadUpdateObject {
pub last_pin_timestamp: Option<String>,
}
impl WebSocketEvent for ChannelUnreadUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#channel-delete>
pub struct ChannelDelete {
#[serde(flatten)]
@ -140,4 +132,3 @@ impl UpdateMessage<Guild> for ChannelDelete {
}
}
impl WebSocketEvent for ChannelDelete {}

View File

@ -20,7 +20,7 @@ use super::UpdateMessage;
#[cfg(feature = "client")]
use crate::gateway::Shared;
#[derive(Debug, Deserialize, Serialize, Default, Clone, SourceUrlField, JsonField)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, SourceUrlField, JsonField, WebSocketEvent)]
/// 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
@ -60,9 +60,7 @@ impl Default for GuildCreateDataOption {
}
}
impl WebSocketEvent for GuildCreate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -70,9 +68,7 @@ pub struct GuildBanAdd {
pub user: PublicUser,
}
impl WebSocketEvent for GuildBanAdd {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -80,9 +76,7 @@ pub struct GuildBanRemove {
pub user: PublicUser,
}
impl WebSocketEvent for GuildBanRemove {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, SourceUrlField, JsonField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, SourceUrlField, JsonField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-update>;
/// Received to give info about a guild being updated;
pub struct GuildUpdate {
@ -94,8 +88,6 @@ pub struct GuildUpdate {
pub json: String,
}
impl WebSocketEvent for GuildUpdate {}
#[cfg(feature = "client")]
impl UpdateMessage<Guild> for GuildUpdate {
#[cfg(not(tarpaulin_include))]
@ -104,7 +96,7 @@ impl UpdateMessage<Guild> for GuildUpdate {
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone, SourceUrlField, JsonField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, SourceUrlField, JsonField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-delete>;
/// Received to tell the client about a guild being deleted;
pub struct GuildDelete {
@ -125,9 +117,7 @@ impl UpdateMessage<Guild> for GuildDelete {
fn update(&mut self, _: Shared<Guild>) {}
}
impl WebSocketEvent for GuildDelete {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -135,9 +125,7 @@ pub struct GuildAuditLogEntryCreate {
pub entry: AuditLogEntry,
}
impl WebSocketEvent for GuildAuditLogEntryCreate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -145,9 +133,7 @@ pub struct GuildEmojisUpdate {
pub emojis: Vec<Emoji>,
}
impl WebSocketEvent for GuildEmojisUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -155,17 +141,13 @@ pub struct GuildStickersUpdate {
pub stickers: Vec<Sticker>,
}
impl WebSocketEvent for GuildStickersUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-integrations-update>
pub struct GuildIntegrationsUpdate {
pub guild_id: Snowflake,
}
impl WebSocketEvent for GuildIntegrationsUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -174,9 +156,7 @@ pub struct GuildMemberAdd {
pub guild_id: Snowflake,
}
impl WebSocketEvent for GuildMemberAdd {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -184,9 +164,7 @@ pub struct GuildMemberRemove {
pub user: PublicUser,
}
impl WebSocketEvent for GuildMemberRemove {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-member-update>
pub struct GuildMemberUpdate {
pub guild_id: Snowflake,
@ -202,9 +180,7 @@ pub struct GuildMemberUpdate {
pub communication_disabled_until: Option<DateTime<Utc>>,
}
impl WebSocketEvent for GuildMemberUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-members-chunk>
pub struct GuildMembersChunk {
pub guild_id: Snowflake,
@ -216,9 +192,7 @@ pub struct GuildMembersChunk {
pub nonce: Option<String>,
}
impl WebSocketEvent for GuildMembersChunk {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-role-create>
pub struct GuildRoleCreate {
pub guild_id: Snowflake,
@ -229,8 +203,6 @@ pub struct GuildRoleCreate {
pub source_url: String,
}
impl WebSocketEvent for GuildRoleCreate {}
#[cfg(feature = "client")]
impl UpdateMessage<Guild> for GuildRoleCreate {
#[cfg(not(tarpaulin_include))]
@ -252,7 +224,7 @@ impl UpdateMessage<Guild> for GuildRoleCreate {
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-role-update>
pub struct GuildRoleUpdate {
pub guild_id: Snowflake,
@ -263,8 +235,6 @@ pub struct GuildRoleUpdate {
pub source_url: String,
}
impl WebSocketEvent for GuildRoleUpdate {}
#[cfg(feature = "client")]
impl UpdateMessage<RoleObject> for GuildRoleUpdate {
#[cfg(not(tarpaulin_include))]
@ -278,43 +248,35 @@ impl UpdateMessage<RoleObject> for GuildRoleUpdate {
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-role-delete>
pub struct GuildRoleDelete {
pub guild_id: Snowflake,
pub role_id: Snowflake,
}
impl WebSocketEvent for GuildRoleDelete {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-create>
pub struct GuildScheduledEventCreate {
#[serde(flatten)]
pub event: GuildScheduledEvent,
}
impl WebSocketEvent for GuildScheduledEventCreate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-update>
pub struct GuildScheduledEventUpdate {
#[serde(flatten)]
pub event: GuildScheduledEvent,
}
impl WebSocketEvent for GuildScheduledEventUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-delete>
pub struct GuildScheduledEventDelete {
#[serde(flatten)]
pub event: GuildScheduledEvent,
}
impl WebSocketEvent for GuildScheduledEventDelete {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-add>
pub struct GuildScheduledEventUserAdd {
pub guild_scheduled_event_id: Snowflake,
@ -322,14 +284,10 @@ pub struct GuildScheduledEventUserAdd {
pub guild_id: Snowflake,
}
impl WebSocketEvent for GuildScheduledEventUserAdd {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-remove>
pub struct GuildScheduledEventUserRemove {
pub guild_scheduled_event_id: Snowflake,
pub user_id: Snowflake,
pub guild_id: Snowflake,
}
impl WebSocketEvent for GuildScheduledEventUserRemove {}

View File

@ -5,17 +5,14 @@
use crate::types::events::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize, WebSocketEvent)]
pub struct GatewayHeartbeat {
pub op: u8,
pub d: Option<u64>,
}
impl WebSocketEvent for GatewayHeartbeat {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
pub struct GatewayHeartbeatAck {
pub op: i32,
}
impl WebSocketEvent for GatewayHeartbeatAck {}

View File

@ -3,22 +3,20 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::WebSocketEvent;
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
/// Received on gateway init, tells the client how often to send heartbeats;
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, WebSocketEvent)]
pub struct GatewayHello {
pub op: i32,
pub d: HelloData,
}
impl WebSocketEvent for GatewayHello {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, Copy, WebSocketEvent)]
/// 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
pub heartbeat_interval: u64,
}
impl WebSocketEvent for HelloData {}

View File

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

View File

@ -5,8 +5,9 @@
use serde::{Deserialize, Serialize};
use crate::types::{Integration, Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#integration-create>
pub struct IntegrationCreate {
#[serde(flatten)]
@ -14,9 +15,7 @@ pub struct IntegrationCreate {
pub guild_id: Snowflake,
}
impl WebSocketEvent for IntegrationCreate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#integration-update>
pub struct IntegrationUpdate {
#[serde(flatten)]
@ -24,9 +23,7 @@ pub struct IntegrationUpdate {
pub guild_id: Snowflake,
}
impl WebSocketEvent for IntegrationUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#integration-delete>
pub struct IntegrationDelete {
pub id: Snowflake,
@ -34,4 +31,3 @@ pub struct IntegrationDelete {
pub application_id: Option<Snowflake>,
}
impl WebSocketEvent for IntegrationDelete {}

View File

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

View File

@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// Your session is now invalid.
///
/// Either reauthenticate and reidentify or resume if possible.
@ -14,4 +14,3 @@ pub struct GatewayInvalidSession {
pub resumable: bool,
}
impl WebSocketEvent for GatewayInvalidSession {}

View File

@ -5,17 +5,16 @@
use serde::{Deserialize, Serialize};
use crate::types::{GuildInvite, Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#invite-create>
pub struct InviteCreate {
#[serde(flatten)]
pub invite: GuildInvite,
}
impl WebSocketEvent for InviteCreate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#invite-delete>
pub struct InviteDelete {
pub channel_id: Snowflake,
@ -23,4 +22,3 @@ pub struct InviteDelete {
pub code: String,
}
impl WebSocketEvent for InviteDelete {}

View File

@ -7,10 +7,9 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::types::Snowflake;
use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// Officially Undocumented
///
/// Sent to the server to signify lazy loading of a guild;
@ -31,4 +30,3 @@ pub struct LazyRequest {
pub channels: Option<HashMap<String, Vec<Vec<u64>>>>,
}
impl WebSocketEvent for LazyRequest {}

View File

@ -6,12 +6,12 @@ use serde::{Deserialize, Serialize};
use crate::types::{
entities::{Emoji, GuildMember, Message, PublicUser},
Snowflake,
Snowflake, WebSocketEvent
};
use super::WebSocketEvent;
use chorus_macros::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#typing-start>
pub struct TypingStartEvent {
@ -22,9 +22,7 @@ pub struct TypingStartEvent {
pub member: Option<GuildMember>,
}
impl WebSocketEvent for TypingStartEvent {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#message-create>
pub struct MessageCreate {
#[serde(flatten)]
@ -34,7 +32,7 @@ pub struct MessageCreate {
pub mentions: Option<Vec<MessageCreateUser>>,
}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#message-create-message-create-extra-fields>
pub struct MessageCreateUser {
#[serde(flatten)]
@ -42,9 +40,7 @@ pub struct MessageCreateUser {
pub member: Option<GuildMember>,
}
impl WebSocketEvent for MessageCreate {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#message-update>
pub struct MessageUpdate {
@ -55,9 +51,7 @@ pub struct MessageUpdate {
pub mentions: Option<Vec<MessageCreateUser>>,
}
impl WebSocketEvent for MessageUpdate {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#message-delete>
pub struct MessageDelete {
@ -66,9 +60,7 @@ pub struct MessageDelete {
pub guild_id: Option<Snowflake>,
}
impl WebSocketEvent for MessageDelete {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#message-delete-bulk>
pub struct MessageDeleteBulk {
@ -77,9 +69,7 @@ pub struct MessageDeleteBulk {
pub guild_id: Option<Snowflake>,
}
impl WebSocketEvent for MessageDeleteBulk {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#message-reaction-add>
pub struct MessageReactionAdd {
@ -91,9 +81,7 @@ pub struct MessageReactionAdd {
pub emoji: Emoji,
}
impl WebSocketEvent for MessageReactionAdd {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove>
pub struct MessageReactionRemove {
@ -104,9 +92,7 @@ pub struct MessageReactionRemove {
pub emoji: Emoji,
}
impl WebSocketEvent for MessageReactionRemove {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-all>
pub struct MessageReactionRemoveAll {
@ -115,9 +101,7 @@ pub struct MessageReactionRemoveAll {
pub guild_id: Option<Snowflake>,
}
impl WebSocketEvent for MessageReactionRemoveAll {}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[derive(Debug, Serialize, Deserialize, Default, Clone, WebSocketEvent)]
/// # Reference
/// See <https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-emoji>
pub struct MessageReactionRemoveEmoji {
@ -127,9 +111,7 @@ pub struct MessageReactionRemoveEmoji {
pub emoji: Emoji,
}
impl WebSocketEvent for MessageReactionRemoveEmoji {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// Officially Undocumented
///
/// Not documented anywhere unofficially
@ -150,4 +132,3 @@ pub struct MessageACK {
pub channel_id: Snowflake,
}
impl WebSocketEvent for MessageACK {}

View File

@ -33,6 +33,8 @@ pub use voice::*;
pub use voice_gateway::*;
pub use webhooks::*;
use chorus_macros::WebSocketEvent;
#[cfg(feature = "client")]
use super::Snowflake;
@ -84,7 +86,7 @@ mod voice_gateway;
pub trait WebSocketEvent: Send + Sync + Debug {}
#[derive(Debug, Default, Serialize, Clone)]
#[derive(Debug, Default, Serialize, Clone, WebSocketEvent)]
/// The payload used for sending events to the gateway
///
/// Similar to [GatewayReceivePayload], except we send a [serde_json::value::Value] for d whilst we receive a [serde_json::value::RawValue]
@ -102,8 +104,6 @@ pub struct GatewaySendPayload {
pub sequence_number: Option<u64>,
}
impl WebSocketEvent for GatewaySendPayload {}
#[derive(Debug, Default, Deserialize, Clone)]
/// The payload used for receiving events from the gateway
pub struct GatewayReceivePayload<'a> {

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use super::{ChannelUnreadUpdateObject, WebSocketEvent};
use crate::types::{GuildMember, Snowflake, VoiceState};
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, WebSocketEvent)]
/// Officially Undocumented
///
/// Seems to be passively set to update the client on guild details (though, why not just send the update events?)
@ -18,4 +18,3 @@ pub struct PassiveUpdateV1 {
pub channels: Vec<ChannelUnreadUpdateObject>,
}
impl WebSocketEvent for PassiveUpdateV1 {}

View File

@ -6,7 +6,7 @@ use crate::types::{events::WebSocketEvent, UserStatus};
use crate::types::{Activity, ClientStatusObject, PublicUser, Snowflake};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// Sent by the client to update its status and presence;
/// See <https://discord.com/developers/docs/topics/gateway-events#update-presence>
pub struct UpdatePresence {
@ -18,7 +18,7 @@ pub struct UpdatePresence {
pub afk: bool,
}
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, WebSocketEvent)]
/// 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 {
@ -30,4 +30,3 @@ pub struct PresenceUpdate {
pub client_status: ClientStatusObject,
}
impl WebSocketEvent for PresenceUpdate {}

View File

@ -9,7 +9,7 @@ use crate::types::events::{Session, WebSocketEvent};
use crate::types::interfaces::ClientStatusObject;
use crate::types::{Activity, GuildMember, PresenceUpdate, VoiceState};
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// 1/2 half documented;
/// Received after identifying, provides initial user info;
/// See <https://discord.com/developers/docs/topics/gateway-events#ready;>
@ -30,9 +30,7 @@ pub struct GatewayReady {
pub shard: Option<(u64, u64)>,
}
impl WebSocketEvent for GatewayReady {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// Officially Undocumented;
/// Sent after the READY event when a client is a user, seems to somehow add onto the ready event;
pub struct GatewayReadySupplemental {
@ -45,8 +43,6 @@ pub struct GatewayReadySupplemental {
pub disclose: Vec<String>,
}
impl WebSocketEvent for GatewayReadySupplemental {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct MergedPresences {
pub guilds: Vec<Vec<MergedPresenceGuild>>,

View File

@ -2,11 +2,10 @@ use serde::{Deserialize, Serialize};
use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// "The reconnect event is dispatched when a client should reconnect to the Gateway (and resume their existing session, if they have one). This event usually occurs during deploys to migrate sessions gracefully off old hosts"
///
/// # Reference
/// See <https://docs.discord.sex/topics/gateway-events#reconnect>
pub struct GatewayReconnect {}
impl WebSocketEvent for GatewayReconnect {}

View File

@ -5,7 +5,7 @@
use crate::types::{events::WebSocketEvent, Relationship, RelationshipType, Snowflake};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, WebSocketEvent)]
/// See <https://github.com/spacebarchat/server/issues/204>
pub struct RelationshipAdd {
#[serde(flatten)]
@ -13,9 +13,7 @@ pub struct RelationshipAdd {
pub should_notify: bool,
}
impl WebSocketEvent for RelationshipAdd {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// See <https://github.com/spacebarchat/server/issues/203>
pub struct RelationshipRemove {
pub id: Snowflake,
@ -23,4 +21,3 @@ pub struct RelationshipRemove {
pub relationship_type: RelationshipType,
}
impl WebSocketEvent for RelationshipRemove {}

View File

@ -5,7 +5,7 @@
use crate::types::{events::WebSocketEvent, Snowflake};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default)]
#[derive(Debug, Deserialize, Serialize, Default, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#request-guild-members-request-guild-members-structure>
pub struct GatewayRequestGuildMembers {
pub guild_id: Snowflake,
@ -17,4 +17,3 @@ pub struct GatewayRequestGuildMembers {
pub nonce: Option<String>,
}
impl WebSocketEvent for GatewayRequestGuildMembers {}

View File

@ -5,11 +5,10 @@
use crate::types::events::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[derive(Debug, Clone, Deserialize, Serialize, Default, WebSocketEvent)]
pub struct GatewayResume {
pub token: String,
pub session_id: String,
pub seq: String,
}
impl WebSocketEvent for GatewayResume {}

View File

@ -2,11 +2,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
use crate::types::{Activity, WebSocketEvent};
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// 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"}]
@ -33,4 +34,3 @@ pub struct ClientInfo {
pub version: u8,
}
impl WebSocketEvent for SessionsReplace {}

View File

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

View File

@ -12,16 +12,14 @@ use crate::types::{JsonField, Snowflake, SourceUrlField};
#[cfg(feature = "client")]
use super::UpdateMessage;
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#thread-create>
pub struct ThreadCreate {
#[serde(flatten)]
pub thread: Channel,
}
impl WebSocketEvent for ThreadCreate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonField, SourceUrlField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#thread-update>
pub struct ThreadUpdate {
#[serde(flatten)]
@ -32,8 +30,6 @@ pub struct ThreadUpdate {
pub source_url: String,
}
impl WebSocketEvent for ThreadUpdate {}
#[cfg(feature = "client")]
impl UpdateMessage<Channel> for ThreadUpdate {
#[cfg(not(tarpaulin_include))]
@ -42,16 +38,14 @@ impl UpdateMessage<Channel> for ThreadUpdate {
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#thread-delete>
pub struct ThreadDelete {
#[serde(flatten)]
pub thread: Channel,
}
impl WebSocketEvent for ThreadDelete {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#thread-list-sync>
pub struct ThreadListSync {
pub guild_id: Snowflake,
@ -60,9 +54,7 @@ pub struct ThreadListSync {
pub members: Option<Vec<ThreadMember>>,
}
impl WebSocketEvent for ThreadListSync {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// 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 {
@ -71,9 +63,7 @@ pub struct ThreadMemberUpdate {
pub guild_id: Snowflake,
}
impl WebSocketEvent for ThreadMemberUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#thread-members-update>
pub struct ThreadMembersUpdate {
pub id: Snowflake,
@ -84,4 +74,3 @@ pub struct ThreadMembersUpdate {
pub removed_members: Option<Vec<Snowflake>>,
}
impl WebSocketEvent for ThreadMembersUpdate {}

View File

@ -8,7 +8,7 @@ use crate::types::entities::PublicUser;
use crate::types::events::WebSocketEvent;
use crate::types::utils::Snowflake;
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, WebSocketEvent)]
/// 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 {
@ -16,9 +16,7 @@ pub struct UserUpdate {
pub user: PublicUser,
}
impl WebSocketEvent for UserUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, WebSocketEvent)]
/// Undocumented;
///
/// Possibly an update for muted guild / channel settings for the current user;
@ -41,8 +39,6 @@ pub struct UserGuildSettingsUpdate {
pub channel_overrides: Vec<UserGuildSettingsChannelOverride>,
}
impl WebSocketEvent for UserGuildSettingsUpdate {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
/// Undocumented;
///

View File

@ -5,7 +5,7 @@
use crate::types::{events::WebSocketEvent, Snowflake, VoiceState};
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, Copy, PartialEq, Eq, WebSocketEvent)]
///
/// Sent to the server to indicate an update of the voice state (leave voice channel, join voice channel, mute, deafen);
///
@ -17,9 +17,7 @@ pub struct UpdateVoiceState {
pub self_deaf: bool,
}
impl WebSocketEvent for UpdateVoiceState {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#voice-state-update>;
///
/// Received from the server to indicate an update in a user's voice state (leave voice channel, join voice channel, mute, deafen, etc);
@ -30,9 +28,7 @@ pub struct VoiceStateUpdate {
pub state: VoiceState,
}
impl WebSocketEvent for VoiceStateUpdate {}
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#voice-server-update>;
///
/// Received to indicate which voice endpoint, token and guild_id to use;
@ -45,4 +41,3 @@ pub struct VoiceServerUpdate {
pub endpoint: Option<String>,
}
impl WebSocketEvent for VoiceServerUpdate {}

View File

@ -3,9 +3,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::{Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy, WebSocketEvent)]
/// Sent when another user connects to the voice server.
///
/// Contains the user id and "flags".
@ -21,9 +22,7 @@ pub struct VoiceClientConnectFlags {
pub flags: Option<u8>,
}
impl WebSocketEvent for VoiceClientConnectFlags {}
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy, WebSocketEvent)]
/// Sent when another user connects to the voice server.
///
/// Contains the user id and "platform".
@ -37,4 +36,3 @@ pub struct VoiceClientConnectPlatform {
pub platform: u8,
}
impl WebSocketEvent for VoiceClientConnectPlatform {}

View File

@ -3,9 +3,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::{Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy, WebSocketEvent)]
/// Sent when another user disconnects from the voice server.
///
/// When received, the SSRC of the user should be discarded.
@ -15,4 +16,3 @@ pub struct VoiceClientDisconnection {
pub user_id: Snowflake,
}
impl WebSocketEvent for VoiceClientDisconnection {}

View File

@ -3,9 +3,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::WebSocketEvent;
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy, WebSocketEvent)]
/// Contains info on how often the client should send heartbeats to the server;
///
/// Differs from the normal hello data in that discord sends heartbeat interval as a float.
@ -21,4 +22,3 @@ pub struct VoiceHelloData {
pub heartbeat_interval: f64,
}
impl WebSocketEvent for VoiceHelloData {}

View File

@ -3,9 +3,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::{Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq, WebSocketEvent)]
/// The identify payload for the voice gateway connection;
///
/// Contains authentication info and context to authenticate to the voice gateway.
@ -22,4 +23,3 @@ pub struct VoiceIdentify {
// TODO: Add video streams
}
impl WebSocketEvent for VoiceIdentify {}

View File

@ -3,9 +3,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::WebSocketEvent;
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Copy, WebSocketEvent)]
/// What does this do?
///
/// {"op":15,"d":{"any":100}}
@ -15,4 +16,3 @@ pub struct VoiceMediaSinkWants {
pub any: u16,
}
impl WebSocketEvent for VoiceMediaSinkWants {}

View File

@ -30,7 +30,7 @@ mod speaking;
mod ssrc_definition;
mod voice_backend_version;
#[derive(Debug, Default, Serialize, Clone)]
#[derive(Debug, Default, Serialize, Clone, WebSocketEvent)]
/// The payload used for sending events to the voice gateway.
///
/// Similar to [VoiceGatewayReceivePayload], except we send a [Value] for d whilst we receive a [serde_json::value::RawValue]
@ -42,8 +42,6 @@ pub struct VoiceGatewaySendPayload {
pub data: Value,
}
impl WebSocketEvent for VoiceGatewaySendPayload {}
#[derive(Debug, Deserialize, Clone)]
/// The payload used for receiving events from the voice gateway.
///

View File

@ -5,11 +5,12 @@
use std::net::Ipv4Addr;
use crate::types::WebSocketEvent;
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
use super::VoiceEncryptionMode;
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, WebSocketEvent)]
/// The voice gateway's ready event;
///
/// Gives the user info about the UDP connection IP and port, srrc to use,
@ -43,4 +44,3 @@ impl Default for VoiceReady {
}
}
impl WebSocketEvent for VoiceReady {}

View File

@ -1,8 +1,9 @@
use super::{AudioCodec, VideoCodec, VoiceEncryptionMode};
use crate::types::WebSocketEvent;
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
#[derive(Debug, Deserialize, Serialize, Clone, Default, WebSocketEvent)]
/// Event that describes our encryption mode and secret key for encryption
///
/// See <https://discord-userdoccers.vercel.app/topics/voice-connections#session-description-structure>
@ -19,9 +20,7 @@ pub struct SessionDescription {
pub keyframe_interval: Option<u64>,
}
impl WebSocketEvent for SessionDescription {}
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
#[derive(Debug, Deserialize, Serialize, Clone, Default, WebSocketEvent)]
/// Event that might be sent to update session parameters
///
/// See <https://discord-userdoccers.vercel.app/topics/voice-connections#session-update-structure>
@ -36,4 +35,3 @@ pub struct SessionUpdate {
pub new_media_session_id: Option<String>,
}
impl WebSocketEvent for SessionUpdate {}

View File

@ -6,13 +6,14 @@ use bitflags::bitflags;
use serde::{Deserialize, Serialize};
use crate::types::{Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
/// Event that tells the server we are speaking;
///
/// Essentially, what allows us to send UDP data and lights up the green circle around your avatar.
///
/// See <https://discord-userdoccers.vercel.app/topics/voice-connections#speaking-structure>
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
#[derive(Debug, Deserialize, Serialize, Clone, Default, WebSocketEvent)]
pub struct Speaking {
/// Data about the audio we're transmitting.
///
@ -27,8 +28,6 @@ pub struct Speaking {
pub delay: u64,
}
impl WebSocketEvent for Speaking {}
bitflags! {
/// Bitflags of speaking types;
///

View File

@ -3,6 +3,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::{Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
/// Defines an event which provides ssrcs for voice and video for a user id.
@ -24,7 +25,7 @@ use serde::{Deserialize, Serialize};
/// ```json
/// {"op":12,"d":{"audio_ssrc":2307250864,"video_ssrc":0,"rtx_ssrc":0,"streams":[{"type":"video","rid":"100","ssrc":26595,"active":false,"quality":100,"rtx_ssrc":26596,"max_bitrate":2500000,"max_framerate":30,"max_resolution":{"type":"fixed","width":1280,"height":720}}]}}
/// ```
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq, WebSocketEvent)]
pub struct SsrcDefinition {
/// The ssrc used for video communications.
///
@ -50,4 +51,3 @@ pub struct SsrcDefinition {
pub streams: Vec<String>,
}
impl WebSocketEvent for SsrcDefinition {}

View File

@ -3,9 +3,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::types::WebSocketEvent;
use chorus_macros::WebSocketEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, WebSocketEvent)]
/// Received from the voice gateway server to describe the backend version.
///
/// See <https://discord-userdoccers.vercel.app/topics/voice-connections#voice-backend-version>
@ -18,4 +19,3 @@ pub struct VoiceBackendVersion {
pub rtc_worker_version: String,
}
impl WebSocketEvent for VoiceBackendVersion {}

View File

@ -4,15 +4,13 @@
use serde::{Deserialize, Serialize};
use crate::types::Snowflake;
use crate::types::{Snowflake, WebSocketEvent};
use chorus_macros::WebSocketEvent;
use super::WebSocketEvent;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
#[derive(Debug, Deserialize, Serialize, Default, Clone, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#webhooks-update>
pub struct WebhooksUpdate {
pub guild_id: Snowflake,
pub channel_id: Snowflake,
}
impl WebSocketEvent for WebhooksUpdate {}