use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
- struct NatsConfigurationClientCert {
- cert: String,
- key: String,
+ pub struct NatsConfigurationClientCert {
+ pub cert: String,
+ pub key: String,
}
++
#[derive(Clone, Debug, Deserialize)]
- struct NatsConfigurationTls {
- mtu: Option<usize>,
+ pub struct NatsConfigurationTls {
+ pub mtu: Option<usize>,
}
#[derive(Clone, Debug, Deserialize)]
pub struct NatsConfiguration {
- client_cert: Option<NatsConfigurationClientCert>,
- root_cert: Option<Vec<String>>,
- jetstream_api_prefix: Option<String>,
- max_reconnects: Option<usize>,
- reconnect_buffer_size: Option<usize>,
- tls: Option<NatsConfigurationTls>,
- client_name: Option<String>,
- tls_required: Option<bool>,
- host: String,
+ pub client_cert: Option<NatsConfigurationClientCert>,
+ pub root_cert: Option<Vec<String>>,
+ pub jetstream_api_prefix: Option<String>,
+ pub max_reconnects: Option<usize>,
+ pub reconnect_buffer_size: Option<usize>,
+ pub tls: Option<NatsConfigurationTls>,
+ pub client_name: Option<String>,
+ pub tls_required: Option<bool>,
+ pub host: String,
}
- ///
+// todo: Prefer From since it automatically gives a free Into implementation
+ // Allows the configuration to directly create a nats connection
impl Into<Connection> for NatsConfiguration {
fn into(self) -> Connection {
let mut options = Options::new();
use serde::{Deserialize, Serialize};
+ use std::fmt::Debug;
-/// Data structure sent to the cache component
-/// by the gateway & webhook.
-#[derive(Serialize, Deserialize, Debug)]
-#[serde(bound(deserialize = "T: Deserialize<'de> + Debug"))]
-pub struct CachePayload<T> {
+use crate::discord_models::{
+ application::Application,
+ channel::{Channel, Message, ThreadMember},
+ emoji::Emoji,
+ gateway::PresenceUpdate,
+ guild::{Guild, GuildMember, Integration},
+ invite::InviteTargetTypes,
+ permissions::Role,
+ slash_commands::{ApplicationCommand, Interaction},
+ stage_instance::StageInstance,
+ user::User,
+ voice::VoiceState,
+};
- #[serde(rename = "tr")]
+/// Payload send to the nova cache queues
+#[derive(Serialize, Deserialize, Debug, Clone)]
+// #[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))]
+pub struct CachePayload {
pub tracing: Tracing,
-
- #[serde(rename = "d")]
- pub data: T,
-
- #[serde(rename = "o")]
- pub operation: String,
+ pub data: CacheData,
}
- #[derive(Serialize, Deserialize, Debug, Clone)]
+ #[derive(Serialize, Deserialize, Debug)]
pub struct Tracing {
pub node_id: String,
- pub span: Option<String>
+ pub span: Option<String>,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub enum CacheData {
+ Ready {
+ version: u8,
+ user: User,
+ guilds: Vec<Guild>,
+ session_id: String,
+ shard: Option<Vec<i64>>,
+ application: Application,
+ },
+ ApplicationCommandCreate {
+ guild_id: Option<String>,
+ command: ApplicationCommand,
+ },
+ ApplicationCommandUpdate {
+ guild_id: Option<String>,
+ command: ApplicationCommand,
+ },
+ ApplicationCommandDelete {
+ guild_id: Option<String>,
+ command: ApplicationCommand,
+ },
+ ChannelCreate {
+ channel: Channel,
+ },
+ ChannelUpdate {
+ channel: Channel,
+ },
+ ChannelDelete {
+ channel: Channel,
+ },
+ ThreadCreate {
+ channel: Channel,
+ },
+ ThreadUpdate {
+ channel: Channel,
+ },
+ ThreadDelete {
+ channel: Channel,
+ },
+ ThreadListSync {
+ guild_id: String,
+ channel_ids: Option<Vec<String>>,
+ threads: Vec<Channel>,
+ members: Vec<ThreadMember>,
+ },
+ ThreadMemberUpdate {
+ member: ThreadMember,
+ },
+ ThreadMembersUpdate {
+ id: String,
+ guild_id: String,
+ member_count: i64,
+ added_members: Option<Vec<ThreadMember>>,
+ removed_member_ids: Option<Vec<String>>,
+ },
+ ChannelPinsUpdate {
+ guild_id: Option<String>,
+ channel_id: String,
+ last_pin_timestamp: Option<String>,
+ },
+ GuildCreate {
+ guild: Guild,
+ },
+ GuildUpdate {
+ guild: Guild,
+ },
+ GuildDelete {
+ guild: Guild,
+ },
+ GuildBanAdd {
+ guild_id: String,
+ user: User,
+ },
+ GuildBanRemove {
+ guild_id: String,
+ user: User,
+ },
+ GuildEmojisUpdate {
+ guild_id: String,
+ emojis: Vec<Emoji>,
+ },
+ GuildIntegrationsUpdate {
+ guild_id: String,
+ },
+ GuildMemberAdd {
+ guild_id: String,
+ member: GuildMember,
+ },
+ GuildMemberRemove {
+ guild_id: String,
+ user: User,
+ },
+ GuildMemberUpdate {
+ guild_id: String,
+ roles: Vec<String>,
+ user: User,
+ nick: Option<String>,
+ joined_at: Option<String>,
+ premium_since: Option<String>,
+ deaf: Option<bool>,
+ mute: Option<bool>,
+ pending: Option<bool>,
+ },
+ GuildMembersChunk {
+ guild_id: String,
+ members: Vec<GuildMember>,
+ chunk_index: i64,
+ chunk_count: i64,
+ not_found: Option<Vec<String>>,
+ presences: Option<Vec<PresenceUpdate>>,
+ nonce: Option<String>,
+ },
+ GuildRoleCreate {
+ guild_id: String,
+ role: Role,
+ },
+ GuildRoleUpdate {
+ guild_id: String,
+ role: Role,
+ },
+ GuildRoleDelete {
+ guild_id: String,
+ role_id: String,
+ },
+ IntegrationCreate {
+ guild_id: String,
+ integration: Integration,
+ },
+ IntegrationUpdate {
+ guild_id: String,
+ integration: Integration,
+ },
+ IntegrationDelete {
+ id: String,
+ guild_id: String,
+ application_id: Option<String>,
+ },
+ InviteCreate {
+ channel_id: String,
+ code: String,
+ created_at: String,
+ guild_id: Option<String>,
+ inviter: Option<User>,
+ max_age: i64,
+ max_uses: i64,
+ target_type: Option<InviteTargetTypes>,
+ target_user: Option<User>,
+ target_application: Option<Application>,
+ temporary: bool,
+ uses: i64,
+ },
+ InviteDelete {
+ channel_id: String,
+ guild_id: Option<String>,
+ code: String,
+ },
+ InteractionCreate {
+ // boxed to avoid a large difference size between variants (https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant)
+ interaction: Box<Interaction>,
+ },
+ MessageCreate {
+ message: Message,
+ },
+ MessageUpdate {
+ message: Message,
+ },
+ MessageDelete {
+ id: String,
+ channel_id: String,
+ guild_id: Option<String>,
+ },
+ MessageDeleteBulk {
+ ids: Vec<String>,
+ channel_id: String,
+ guild_id: Option<String>,
+ },
+ MessageReactionAdd {
+ user_id: String,
+ channel_id: String,
+ message_id: String,
+ guild_id: Option<String>,
+ member: Option<GuildMember>,
+ emoji: Emoji,
+ },
+ MessageReactionRemove {
+ user_id: String,
+ channel_id: String,
+ message_id: String,
+ guild_id: Option<String>,
+ emoji: Emoji,
+ },
+ MessageReactionRemoveAll {
+ channel_id: String,
+ message_id: String,
+ guild_id: Option<String>,
+ },
+ MessageReactionRemoveEmoji {
+ channel_id: String,
+ message_id: String,
+ guild_id: Option<String>,
+ emoji: Emoji,
+ },
+ PresenceUpdate {
+ presence: PresenceUpdate,
+ },
+ TypingStart {
+ channel_id: String,
+ guild_id: Option<String>,
+ user_id: String,
+ timestamp: i64,
+ member: Option<GuildMember>,
+ },
+ UserUpdate {
+ user: User,
+ },
+ VoiceStateUpdate {
+ state: VoiceState,
+ },
+ VoiceServerUpdate {
+ token: String,
+ guild_id: String,
+ endpoint: Option<String>,
+ },
+ WebhookUpdate {
+ guild_id: String,
+ channel_id: String,
+ },
+ StageInstanceCreate {
+ instance: StageInstance,
+ },
+ StageInstanceUpdate {
+ instance: StageInstance,
+ },
+ StageInstanceDelete {
+ instance: StageInstance,
+ },
}