Make id(&self) return Option<Snowflake>

This commit is contained in:
bitfl0wer 2023-08-18 23:34:00 +02:00
parent 1144b77fbb
commit 86b1149565
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
5 changed files with 23 additions and 9 deletions

View File

@ -1,11 +1,13 @@
use std::sync::{Arc, RwLock};
use crate::gateway::Updateable;
use chorus_macros::Updateable;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
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>
pub struct AutoModerationRule {
pub id: Snowflake,

View File

@ -1,3 +1,5 @@
use crate::types::JsonField;
use chorus_macros::JsonField;
use serde::{Deserialize, Serialize};
use crate::types::{
@ -5,6 +7,8 @@ use crate::types::{
WebSocketEvent,
};
use super::UpdateMessage;
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
/// See <https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create>
pub struct AutoModerationRuleCreate {
@ -14,11 +18,19 @@ pub struct 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>
pub struct AutoModerationRuleUpdate {
#[serde(flatten)]
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 {}

View File

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

View File

@ -180,8 +180,8 @@ pub struct GuildRoleCreate {
impl WebSocketEvent for GuildRoleCreate {}
impl UpdateMessage<Guild> for GuildRoleCreate {
fn id(&self) -> Snowflake {
self.guild_id
fn id(&self) -> Option<Snowflake> {
Some(self.guild_id)
}
fn update(&mut self, object_to_update: Arc<RwLock<Guild>>) {
@ -210,8 +210,8 @@ pub struct GuildRoleUpdate {
impl WebSocketEvent for GuildRoleUpdate {}
impl UpdateMessage<RoleObject> for GuildRoleUpdate {
fn id(&self) -> Snowflake {
self.role.id
fn id(&self) -> Option<Snowflake> {
Some(self.role.id)
}
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>>) {
update_object(self.get_json(), object_to_update)
}
fn id(&self) -> Snowflake;
fn id(&self) -> Option<Snowflake>;
}
pub(crate) trait JsonField: Clone {