Make id(&self) return Option<Snowflake>

This commit is contained in:
bitfl0wer 2023-08-18 23:34:00 +02:00
parent 82d2151f1b
commit d64004b308
5 changed files with 23 additions and 9 deletions

View File

@ -1,11 +1,13 @@
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use crate::gateway::Updateable;
use chorus_macros::Updateable;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::types::utils::Snowflake; use crate::types::utils::Snowflake;
#[derive(Serialize, Deserialize, Debug, Default, Clone)] #[derive(Serialize, Deserialize, Debug, Default, Clone, Updateable)]
/// See <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object> /// See <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object>
pub struct AutoModerationRule { pub struct AutoModerationRule {
pub id: Snowflake, pub id: Snowflake,

View File

@ -1,3 +1,5 @@
use crate::types::JsonField;
use chorus_macros::JsonField;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::{ use crate::types::{
@ -5,6 +7,8 @@ use crate::types::{
WebSocketEvent, WebSocketEvent,
}; };
use super::UpdateMessage;
#[derive(Debug, Deserialize, Serialize, Default, Clone)] #[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create> /// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create>
pub struct AutoModerationRuleCreate { pub struct AutoModerationRuleCreate {
@ -14,11 +18,19 @@ pub struct AutoModerationRuleCreate {
impl WebSocketEvent for AutoModerationRuleCreate {} impl WebSocketEvent for AutoModerationRuleCreate {}
#[derive(Debug, Deserialize, Serialize, Default, Clone)] #[derive(Debug, Deserialize, Serialize, Default, Clone, JsonField)]
/// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update> /// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update>
pub struct AutoModerationRuleUpdate { pub struct AutoModerationRuleUpdate {
#[serde(flatten)] #[serde(flatten)]
pub rule: AutoModerationRule, pub rule: AutoModerationRule,
#[serde(skip)]
pub json: String,
}
impl UpdateMessage<AutoModerationRule> for AutoModerationRuleUpdate {
fn id(&self) -> Option<Snowflake> {
Some(self.rule.id)
}
} }
impl WebSocketEvent for AutoModerationRuleUpdate {} impl WebSocketEvent for AutoModerationRuleUpdate {}

View File

@ -43,8 +43,8 @@ impl UpdateMessage<Channel> for ChannelUpdate {
let mut write = object_to_update.write().unwrap(); let mut write = object_to_update.write().unwrap();
*write = self.channel.clone(); *write = self.channel.clone();
} }
fn id(&self) -> Snowflake { fn id(&self) -> Option<Snowflake> {
self.channel.id Some(self.channel.id)
} }
} }

View File

@ -180,8 +180,8 @@ pub struct GuildRoleCreate {
impl WebSocketEvent for GuildRoleCreate {} impl WebSocketEvent for GuildRoleCreate {}
impl UpdateMessage<Guild> for GuildRoleCreate { impl UpdateMessage<Guild> for GuildRoleCreate {
fn id(&self) -> Snowflake { fn id(&self) -> Option<Snowflake> {
self.guild_id Some(self.guild_id)
} }
fn update(&mut self, object_to_update: Arc<RwLock<Guild>>) { fn update(&mut self, object_to_update: Arc<RwLock<Guild>>) {
@ -210,8 +210,8 @@ pub struct GuildRoleUpdate {
impl WebSocketEvent for GuildRoleUpdate {} impl WebSocketEvent for GuildRoleUpdate {}
impl UpdateMessage<RoleObject> for GuildRoleUpdate { impl UpdateMessage<RoleObject> for GuildRoleUpdate {
fn id(&self) -> Snowflake { fn id(&self) -> Option<Snowflake> {
self.role.id Some(self.role.id)
} }
fn update(&mut self, object_to_update: Arc<RwLock<RoleObject>>) { fn update(&mut self, object_to_update: Arc<RwLock<RoleObject>>) {

View File

@ -122,7 +122,7 @@ where
fn update(&mut self, object_to_update: Arc<RwLock<T>>) { fn update(&mut self, object_to_update: Arc<RwLock<T>>) {
update_object(self.get_json(), object_to_update) update_object(self.get_json(), object_to_update)
} }
fn id(&self) -> Snowflake; fn id(&self) -> Option<Snowflake>;
} }
pub(crate) trait JsonField: Clone { pub(crate) trait JsonField: Clone {