Merge 98f42aa03b
into fe8106d2a1
This commit is contained in:
commit
eb679548da
|
@ -36,7 +36,7 @@ impl Message {
|
||||||
chorus_request.deserialize_response::<Message>(user).await
|
chorus_request.deserialize_response::<Message>(user).await
|
||||||
} else {
|
} else {
|
||||||
for (index, attachment) in message.attachments.iter_mut().enumerate() {
|
for (index, attachment) in message.attachments.iter_mut().enumerate() {
|
||||||
attachment.get_mut(index).unwrap().set_id(index as i16);
|
attachment.get_mut(index).unwrap().id = Some(index as i16);
|
||||||
}
|
}
|
||||||
let mut form = reqwest::multipart::Form::new();
|
let mut form = reqwest::multipart::Form::new();
|
||||||
let payload_json = to_string(&message).unwrap();
|
let payload_json = to_string(&message).unwrap();
|
||||||
|
@ -45,8 +45,8 @@ impl Message {
|
||||||
form = form.part("payload_json", payload_field);
|
form = form.part("payload_json", payload_field);
|
||||||
|
|
||||||
for (index, attachment) in message.attachments.unwrap().into_iter().enumerate() {
|
for (index, attachment) in message.attachments.unwrap().into_iter().enumerate() {
|
||||||
let (attachment_content, current_attachment) = attachment.move_content();
|
let attachment_content = attachment.content;
|
||||||
let (attachment_filename, _) = current_attachment.move_filename();
|
let attachment_filename = attachment.filename;
|
||||||
let part_name = format!("files[{}]", index);
|
let part_name = format!("files[{}]", index);
|
||||||
let content_disposition = format!(
|
let content_disposition = format!(
|
||||||
"form-data; name=\"{}\"'; filename=\"{}\"",
|
"form-data; name=\"{}\"'; filename=\"{}\"",
|
||||||
|
|
|
@ -9,7 +9,7 @@ use reqwest::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::errors::ChorusResult;
|
use crate::errors::ChorusResult;
|
||||||
use crate::gateway::{Gateway, GatewayHandle};
|
use crate::gateway::{Gateway, GatewayHandle, Shared};
|
||||||
use crate::ratelimiter::ChorusRequest;
|
use crate::ratelimiter::ChorusRequest;
|
||||||
use crate::types::types::subconfigs::limits::rates::RateLimits;
|
use crate::types::types::subconfigs::limits::rates::RateLimits;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
|
@ -37,8 +37,6 @@ impl PartialEq for Instance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for Instance {}
|
|
||||||
|
|
||||||
impl std::hash::Hash for Instance {
|
impl std::hash::Hash for Instance {
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
self.urls.hash(state);
|
self.urls.hash(state);
|
||||||
|
@ -73,7 +71,6 @@ impl PartialEq for LimitsInformation {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
|
|
||||||
pub(crate) fn clone_limits_if_some(&self) -> Option<HashMap<LimitType, Limit>> {
|
pub(crate) fn clone_limits_if_some(&self) -> Option<HashMap<LimitType, Limit>> {
|
||||||
if self.limits_information.is_some() {
|
if self.limits_information.is_some() {
|
||||||
return Some(self.limits_information.as_ref().unwrap().ratelimits.clone());
|
return Some(self.limits_information.as_ref().unwrap().ratelimits.clone());
|
||||||
|
@ -156,11 +153,11 @@ impl fmt::Display for Token {
|
||||||
/// It is used for most authenticated actions on a Spacebar server.
|
/// It is used for most authenticated actions on a Spacebar server.
|
||||||
/// It also has its own [Gateway] connection.
|
/// It also has its own [Gateway] connection.
|
||||||
pub struct ChorusUser {
|
pub struct ChorusUser {
|
||||||
pub belongs_to: Arc<RwLock<Instance>>,
|
pub belongs_to: Shared<Instance>,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
pub limits: Option<HashMap<LimitType, Limit>>,
|
pub limits: Option<HashMap<LimitType, Limit>>,
|
||||||
pub settings: Arc<RwLock<UserSettings>>,
|
pub settings: Shared<UserSettings>,
|
||||||
pub object: Arc<RwLock<User>>,
|
pub object: Shared<User>,
|
||||||
pub gateway: GatewayHandle,
|
pub gateway: GatewayHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +169,6 @@ impl PartialEq for ChorusUser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for ChorusUser {}
|
|
||||||
|
|
||||||
impl ChorusUser {
|
impl ChorusUser {
|
||||||
pub fn token(&self) -> String {
|
pub fn token(&self) -> String {
|
||||||
self.token.clone()
|
self.token.clone()
|
||||||
|
@ -189,11 +184,11 @@ impl ChorusUser {
|
||||||
/// This isn't the prefered way to create a ChorusUser.
|
/// This isn't the prefered way to create a ChorusUser.
|
||||||
/// See [Instance::login_account] and [Instance::register_account] instead.
|
/// See [Instance::login_account] and [Instance::register_account] instead.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
belongs_to: Arc<RwLock<Instance>>,
|
belongs_to: Shared<Instance>,
|
||||||
token: String,
|
token: String,
|
||||||
limits: Option<HashMap<LimitType, Limit>>,
|
limits: Option<HashMap<LimitType, Limit>>,
|
||||||
settings: Arc<RwLock<UserSettings>>,
|
settings: Shared<UserSettings>,
|
||||||
object: Arc<RwLock<User>>,
|
object: Shared<User>,
|
||||||
gateway: GatewayHandle,
|
gateway: GatewayHandle,
|
||||||
) -> ChorusUser {
|
) -> ChorusUser {
|
||||||
ChorusUser {
|
ChorusUser {
|
||||||
|
@ -211,7 +206,7 @@ impl ChorusUser {
|
||||||
/// registering or logging in to the Instance, where you do not yet have a User object, but still
|
/// registering or logging in to the Instance, where you do not yet have a User object, but still
|
||||||
/// need to make a RateLimited request. To use the [`GatewayHandle`], you will have to identify
|
/// need to make a RateLimited request. To use the [`GatewayHandle`], you will have to identify
|
||||||
/// first.
|
/// first.
|
||||||
pub(crate) async fn shell(instance: Arc<RwLock<Instance>>, token: String) -> ChorusUser {
|
pub(crate) async fn shell(instance: Shared<Instance>, token: String) -> ChorusUser {
|
||||||
let settings = Arc::new(RwLock::new(UserSettings::default()));
|
let settings = Arc::new(RwLock::new(UserSettings::default()));
|
||||||
let object = Arc::new(RwLock::new(User::default()));
|
let object = Arc::new(RwLock::new(User::default()));
|
||||||
let wss_url = instance.read().unwrap().urls.wss.clone();
|
let wss_url = instance.read().unwrap().urls.wss.clone();
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::utils::Snowflake;
|
use crate::types::utils::Snowflake;
|
||||||
use crate::types::{Team, User};
|
use crate::types::{Team, User};
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ pub struct Application {
|
||||||
pub bot_require_code_grant: bool,
|
pub bot_require_code_grant: bool,
|
||||||
pub verify_key: String,
|
pub verify_key: String,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub owner: Arc<RwLock<User>>,
|
pub owner: Shared<User>,
|
||||||
pub flags: u64,
|
pub flags: u64,
|
||||||
#[cfg(feature = "sqlx")]
|
#[cfg(feature = "sqlx")]
|
||||||
pub redirect_uris: Option<sqlx::types::Json<Vec<String>>>,
|
pub redirect_uris: Option<sqlx::types::Json<Vec<String>>>,
|
||||||
|
@ -49,7 +48,7 @@ pub struct Application {
|
||||||
#[cfg(feature = "sqlx")]
|
#[cfg(feature = "sqlx")]
|
||||||
pub install_params: Option<sqlx::types::Json<InstallParams>>,
|
pub install_params: Option<sqlx::types::Json<InstallParams>>,
|
||||||
#[cfg(not(feature = "sqlx"))]
|
#[cfg(not(feature = "sqlx"))]
|
||||||
pub install_params: Option<Arc<RwLock<InstallParams>>>,
|
pub install_params: Option<Shared<InstallParams>>,
|
||||||
pub terms_of_service_url: Option<String>,
|
pub terms_of_service_url: Option<String>,
|
||||||
pub privacy_policy_url: Option<String>,
|
pub privacy_policy_url: Option<String>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
|
@ -142,7 +141,7 @@ pub struct ApplicationCommand {
|
||||||
pub application_id: Snowflake,
|
pub application_id: Snowflake,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub options: Vec<Arc<RwLock<ApplicationCommandOption>>>,
|
pub options: Vec<Shared<ApplicationCommandOption>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@ -154,7 +153,7 @@ pub struct ApplicationCommandOption {
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub required: bool,
|
pub required: bool,
|
||||||
pub choices: Vec<ApplicationCommandOptionChoice>,
|
pub choices: Vec<ApplicationCommandOptionChoice>,
|
||||||
pub options: Arc<RwLock<Vec<ApplicationCommandOption>>>,
|
pub options: Shared<Vec<ApplicationCommandOption>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
@ -190,14 +189,14 @@ pub enum ApplicationCommandOptionType {
|
||||||
pub struct ApplicationCommandInteractionData {
|
pub struct ApplicationCommandInteractionData {
|
||||||
pub id: Snowflake,
|
pub id: Snowflake,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub options: Vec<Arc<RwLock<ApplicationCommandInteractionDataOption>>>,
|
pub options: Vec<Shared<ApplicationCommandInteractionDataOption>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ApplicationCommandInteractionDataOption {
|
pub struct ApplicationCommandInteractionDataOption {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub value: Value,
|
pub value: Value,
|
||||||
pub options: Vec<Arc<RwLock<ApplicationCommandInteractionDataOption>>>,
|
pub options: Vec<Shared<ApplicationCommandInteractionDataOption>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||||
|
@ -206,7 +205,7 @@ pub struct GuildApplicationCommandPermissions {
|
||||||
pub id: Snowflake,
|
pub id: Snowflake,
|
||||||
pub application_id: Snowflake,
|
pub application_id: Snowflake,
|
||||||
pub guild_id: Snowflake,
|
pub guild_id: Snowflake,
|
||||||
pub permissions: Vec<Arc<RwLock<ApplicationCommandPermission>>>,
|
pub permissions: Vec<Shared<ApplicationCommandPermission>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
|
|
@ -55,73 +55,3 @@ pub struct PartialDiscordFileAttachment {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
pub content: Vec<u8>,
|
pub content: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialDiscordFileAttachment {
|
|
||||||
/// Moves `self.content` out of `self` and returns it.
|
|
||||||
pub fn move_content(self) -> (Vec<u8>, PartialDiscordFileAttachment) {
|
|
||||||
let content = self.content;
|
|
||||||
let updated_struct = PartialDiscordFileAttachment {
|
|
||||||
id: self.id,
|
|
||||||
filename: self.filename,
|
|
||||||
description: self.description,
|
|
||||||
content_type: self.content_type,
|
|
||||||
size: self.size,
|
|
||||||
url: self.url,
|
|
||||||
proxy_url: self.proxy_url,
|
|
||||||
height: self.height,
|
|
||||||
width: self.width,
|
|
||||||
ephemeral: self.ephemeral,
|
|
||||||
duration_secs: self.duration_secs,
|
|
||||||
waveform: self.waveform,
|
|
||||||
content: Vec::new(),
|
|
||||||
};
|
|
||||||
(content, updated_struct)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Moves `self.filename` out of `self` and returns it.
|
|
||||||
pub fn move_filename(self) -> (String, PartialDiscordFileAttachment) {
|
|
||||||
let filename = self.filename;
|
|
||||||
let updated_struct = PartialDiscordFileAttachment {
|
|
||||||
id: self.id,
|
|
||||||
filename: String::new(),
|
|
||||||
description: self.description,
|
|
||||||
content_type: self.content_type,
|
|
||||||
size: self.size,
|
|
||||||
url: self.url,
|
|
||||||
proxy_url: self.proxy_url,
|
|
||||||
height: self.height,
|
|
||||||
width: self.width,
|
|
||||||
|
|
||||||
ephemeral: self.ephemeral,
|
|
||||||
duration_secs: self.duration_secs,
|
|
||||||
waveform: self.waveform,
|
|
||||||
content: self.content,
|
|
||||||
};
|
|
||||||
(filename, updated_struct)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Moves `self.content_type` out of `self` and returns it.
|
|
||||||
pub fn move_content_type(self) -> (Option<String>, PartialDiscordFileAttachment) {
|
|
||||||
let content_type = self.content_type;
|
|
||||||
let updated_struct = PartialDiscordFileAttachment {
|
|
||||||
id: self.id,
|
|
||||||
filename: self.filename,
|
|
||||||
description: self.description,
|
|
||||||
content_type: None,
|
|
||||||
size: self.size,
|
|
||||||
url: self.url,
|
|
||||||
proxy_url: self.proxy_url,
|
|
||||||
height: self.height,
|
|
||||||
width: self.width,
|
|
||||||
ephemeral: self.ephemeral,
|
|
||||||
duration_secs: self.duration_secs,
|
|
||||||
waveform: self.waveform,
|
|
||||||
content: self.content,
|
|
||||||
};
|
|
||||||
(content_type, updated_struct)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_id(&mut self, id: i16) {
|
|
||||||
self.id = Some(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::utils::Snowflake;
|
use crate::types::utils::Snowflake;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
|
||||||
/// See <https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object>
|
/// See <https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object>
|
||||||
pub struct AuditLogEntry {
|
pub struct AuditLogEntry {
|
||||||
pub target_id: Option<String>,
|
pub target_id: Option<String>,
|
||||||
pub changes: Option<Vec<Arc<RwLock<AuditLogChange>>>>,
|
pub changes: Option<Vec<Shared<AuditLogChange>>>,
|
||||||
pub user_id: Option<Snowflake>,
|
pub user_id: Option<Snowflake>,
|
||||||
pub id: Snowflake,
|
pub id: Snowflake,
|
||||||
// to:do implement an enum for these types
|
// to:do implement an enum for these types
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::sync::{Arc, RwLock};
|
use crate::gateway::Shared;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use crate::gateway::Updateable;
|
use crate::gateway::Updateable;
|
||||||
|
|
||||||
|
@ -21,8 +20,8 @@ pub struct AutoModerationRule {
|
||||||
pub creator_id: Snowflake,
|
pub creator_id: Snowflake,
|
||||||
pub event_type: AutoModerationRuleEventType,
|
pub event_type: AutoModerationRuleEventType,
|
||||||
pub trigger_type: AutoModerationRuleTriggerType,
|
pub trigger_type: AutoModerationRuleTriggerType,
|
||||||
pub trigger_metadata: Arc<RwLock<AutoModerationRuleTriggerMetadata>>,
|
pub trigger_metadata: Shared<AutoModerationRuleTriggerMetadata>,
|
||||||
pub actions: Vec<Arc<RwLock<AutoModerationAction>>>,
|
pub actions: Vec<Shared<AutoModerationAction>>,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub exempt_roles: Vec<Snowflake>,
|
pub exempt_roles: Vec<Snowflake>,
|
||||||
pub exempt_channels: Vec<Snowflake>,
|
pub exempt_channels: Vec<Snowflake>,
|
||||||
|
@ -99,7 +98,7 @@ pub enum AutoModerationRuleKeywordPresetType {
|
||||||
pub struct AutoModerationAction {
|
pub struct AutoModerationAction {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub action_type: AutoModerationActionType,
|
pub action_type: AutoModerationActionType,
|
||||||
pub metadata: Option<Arc<RwLock<AutoModerationActionMetadata>>>,
|
pub metadata: Option<Shared<AutoModerationActionMetadata>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
|
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_aux::prelude::deserialize_string_from_number;
|
use serde_aux::prelude::deserialize_string_from_number;
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
entities::{GuildMember, User},
|
entities::{GuildMember, User},
|
||||||
utils::Snowflake,
|
utils::Snowflake,
|
||||||
|
@ -71,13 +70,13 @@ pub struct Channel {
|
||||||
pub permission_overwrites: Option<sqlx::types::Json<Vec<PermissionOverwrite>>>,
|
pub permission_overwrites: Option<sqlx::types::Json<Vec<PermissionOverwrite>>>,
|
||||||
#[cfg(not(feature = "sqlx"))]
|
#[cfg(not(feature = "sqlx"))]
|
||||||
#[cfg_attr(feature = "client", observe_option_vec)]
|
#[cfg_attr(feature = "client", observe_option_vec)]
|
||||||
pub permission_overwrites: Option<Vec<Arc<RwLock<PermissionOverwrite>>>>,
|
pub permission_overwrites: Option<Vec<Shared<PermissionOverwrite>>>,
|
||||||
pub permissions: Option<String>,
|
pub permissions: Option<String>,
|
||||||
pub position: Option<i32>,
|
pub position: Option<i32>,
|
||||||
pub rate_limit_per_user: Option<i32>,
|
pub rate_limit_per_user: Option<i32>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
#[cfg_attr(feature = "client", observe_option_vec)]
|
#[cfg_attr(feature = "client", observe_option_vec)]
|
||||||
pub recipients: Option<Vec<Arc<RwLock<User>>>>,
|
pub recipients: Option<Vec<Shared<User>>>,
|
||||||
pub rtc_region: Option<String>,
|
pub rtc_region: Option<String>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub thread_metadata: Option<ThreadMetadata>,
|
pub thread_metadata: Option<ThreadMetadata>,
|
||||||
|
@ -171,7 +170,7 @@ pub struct ThreadMember {
|
||||||
pub user_id: Option<Snowflake>,
|
pub user_id: Option<Snowflake>,
|
||||||
pub join_timestamp: Option<String>,
|
pub join_timestamp: Option<String>,
|
||||||
pub flags: Option<u64>,
|
pub flags: Option<u64>,
|
||||||
pub member: Option<Arc<RwLock<GuildMember>>>,
|
pub member: Option<Shared<GuildMember>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||||
|
|
|
@ -15,20 +15,29 @@ impl ConfigEntity {
|
||||||
let Some(v) = self.value.as_ref() else {
|
let Some(v) = self.value.as_ref() else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
Some(v.as_str().expect("value is not a string").to_string())
|
let Some(v) = v.as_str() else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
Some(v.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bool(&self) -> Option<bool> {
|
pub fn as_bool(&self) -> Option<bool> {
|
||||||
let Some(v) = self.value.as_ref() else {
|
let Some(v) = self.value.as_ref() else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
Some(v.as_bool().expect("value is not a boolean"))
|
let Some(v) = v.as_bool() else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
Some(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_int(&self) -> Option<i64> {
|
pub fn as_int(&self) -> Option<i64> {
|
||||||
let Some(v) = self.value.as_ref() else {
|
let Some(v) = self.value.as_ref() else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
Some(v.as_i64().expect("value is not a number"))
|
let Some(v) = v.as_i64() else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
Some(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::entities::User;
|
use crate::types::entities::User;
|
||||||
use crate::types::Snowflake;
|
use crate::types::Snowflake;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ pub struct Emoji {
|
||||||
#[cfg(not(feature = "sqlx"))]
|
#[cfg(not(feature = "sqlx"))]
|
||||||
pub roles: Option<Vec<Snowflake>>,
|
pub roles: Option<Vec<Snowflake>>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub user: Option<Arc<RwLock<User>>>,
|
pub user: Option<Shared<User>>,
|
||||||
pub require_colons: Option<bool>,
|
pub require_colons: Option<bool>,
|
||||||
pub managed: Option<bool>,
|
pub managed: Option<bool>,
|
||||||
pub animated: Option<bool>,
|
pub animated: Option<bool>,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::types::guild_configuration::GuildFeaturesList;
|
use crate::types::types::guild_configuration::GuildFeaturesList;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
entities::{Channel, Emoji, RoleObject, Sticker, User, VoiceState, Webhook},
|
entities::{Channel, Emoji, RoleObject, Sticker, User, VoiceState, Webhook},
|
||||||
|
@ -45,14 +45,14 @@ pub struct Guild {
|
||||||
pub bans: Option<Vec<GuildBan>>,
|
pub bans: Option<Vec<GuildBan>>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
#[cfg_attr(feature = "client", observe_option_vec)]
|
#[cfg_attr(feature = "client", observe_option_vec)]
|
||||||
pub channels: Option<Vec<Arc<RwLock<Channel>>>>,
|
pub channels: Option<Vec<Shared<Channel>>>,
|
||||||
pub default_message_notifications: Option<MessageNotificationLevel>,
|
pub default_message_notifications: Option<MessageNotificationLevel>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub discovery_splash: Option<String>,
|
pub discovery_splash: Option<String>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
#[cfg_attr(feature = "client", observe_vec)]
|
#[cfg_attr(feature = "client", observe_vec)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub emojis: Vec<Arc<RwLock<Emoji>>>,
|
pub emojis: Vec<Shared<Emoji>>,
|
||||||
pub explicit_content_filter: Option<i32>,
|
pub explicit_content_filter: Option<i32>,
|
||||||
//#[cfg_attr(feature = "sqlx", sqlx(try_from = "String"))]
|
//#[cfg_attr(feature = "sqlx", sqlx(try_from = "String"))]
|
||||||
pub features: Option<GuildFeaturesList>,
|
pub features: Option<GuildFeaturesList>,
|
||||||
|
@ -88,7 +88,7 @@ pub struct Guild {
|
||||||
pub region: Option<String>,
|
pub region: Option<String>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
#[cfg_attr(feature = "client", observe_option_vec)]
|
#[cfg_attr(feature = "client", observe_option_vec)]
|
||||||
pub roles: Option<Vec<Arc<RwLock<RoleObject>>>>,
|
pub roles: Option<Vec<Shared<RoleObject>>>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub rules_channel: Option<String>,
|
pub rules_channel: Option<String>,
|
||||||
pub rules_channel_id: Option<Snowflake>,
|
pub rules_channel_id: Option<Snowflake>,
|
||||||
|
@ -102,10 +102,10 @@ pub struct Guild {
|
||||||
pub verification_level: Option<VerificationLevel>,
|
pub verification_level: Option<VerificationLevel>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
#[cfg_attr(feature = "client", observe_option_vec)]
|
#[cfg_attr(feature = "client", observe_option_vec)]
|
||||||
pub voice_states: Option<Vec<Arc<RwLock<VoiceState>>>>,
|
pub voice_states: Option<Vec<Shared<VoiceState>>>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
#[cfg_attr(feature = "client", observe_option_vec)]
|
#[cfg_attr(feature = "client", observe_option_vec)]
|
||||||
pub webhooks: Option<Vec<Arc<RwLock<Webhook>>>>,
|
pub webhooks: Option<Vec<Shared<Webhook>>>,
|
||||||
#[cfg(feature = "sqlx")]
|
#[cfg(feature = "sqlx")]
|
||||||
pub welcome_screen: Option<sqlx::types::Json<WelcomeScreenObject>>,
|
pub welcome_screen: Option<sqlx::types::Json<WelcomeScreenObject>>,
|
||||||
#[cfg(not(feature = "sqlx"))]
|
#[cfg(not(feature = "sqlx"))]
|
||||||
|
@ -217,8 +217,6 @@ impl std::cmp::PartialEq for Guild {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::cmp::Eq for Guild {}
|
|
||||||
|
|
||||||
/// See <https://docs.spacebar.chat/routes/#get-/guilds/-guild_id-/bans/-user->
|
/// See <https://docs.spacebar.chat/routes/#get-/guilds/-guild_id-/bans/-user->
|
||||||
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
|
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
|
||||||
|
@ -239,11 +237,11 @@ pub struct GuildInvite {
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
pub expires_at: Option<DateTime<Utc>>,
|
pub expires_at: Option<DateTime<Utc>>,
|
||||||
pub guild_id: Snowflake,
|
pub guild_id: Snowflake,
|
||||||
pub guild: Option<Arc<RwLock<Guild>>>,
|
pub guild: Option<Shared<Guild>>,
|
||||||
pub channel_id: Snowflake,
|
pub channel_id: Snowflake,
|
||||||
pub channel: Option<Arc<RwLock<Channel>>>,
|
pub channel: Option<Shared<Channel>>,
|
||||||
pub inviter_id: Option<Snowflake>,
|
pub inviter_id: Option<Snowflake>,
|
||||||
pub inviter: Option<Arc<RwLock<User>>>,
|
pub inviter: Option<Shared<User>>,
|
||||||
pub target_user_id: Option<Snowflake>,
|
pub target_user_id: Option<Snowflake>,
|
||||||
pub target_user: Option<String>,
|
pub target_user: Option<String>,
|
||||||
pub target_user_type: Option<i32>,
|
pub target_user_type: Option<i32>,
|
||||||
|
@ -296,7 +294,7 @@ pub struct GuildScheduledEvent {
|
||||||
pub entity_type: GuildScheduledEventEntityType,
|
pub entity_type: GuildScheduledEventEntityType,
|
||||||
pub entity_id: Option<Snowflake>,
|
pub entity_id: Option<Snowflake>,
|
||||||
pub entity_metadata: Option<GuildScheduledEventEntityMetadata>,
|
pub entity_metadata: Option<GuildScheduledEventEntityMetadata>,
|
||||||
pub creator: Option<Arc<RwLock<User>>>,
|
pub creator: Option<Shared<User>>,
|
||||||
pub user_count: Option<u64>,
|
pub user_count: Option<u64>,
|
||||||
pub image: Option<String>,
|
pub image: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::{entities::PublicUser, Snowflake};
|
use crate::types::{entities::PublicUser, Snowflake};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Default, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Default, Serialize, Clone)]
|
||||||
|
@ -10,7 +9,7 @@ use crate::types::{entities::PublicUser, Snowflake};
|
||||||
/// # Reference
|
/// # Reference
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/guild#guild-member-object>
|
/// See <https://discord-userdoccers.vercel.app/resources/guild#guild-member-object>
|
||||||
pub struct GuildMember {
|
pub struct GuildMember {
|
||||||
pub user: Option<Arc<RwLock<PublicUser>>>,
|
pub user: Option<Shared<PublicUser>>,
|
||||||
pub nick: Option<String>,
|
pub nick: Option<String>,
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
pub roles: Vec<Snowflake>,
|
pub roles: Vec<Snowflake>,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
entities::{Application, User},
|
entities::{Application, User},
|
||||||
utils::Snowflake,
|
utils::Snowflake,
|
||||||
|
@ -23,14 +22,14 @@ pub struct Integration {
|
||||||
pub expire_behaviour: Option<u8>,
|
pub expire_behaviour: Option<u8>,
|
||||||
pub expire_grace_period: Option<u16>,
|
pub expire_grace_period: Option<u16>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub user: Option<Arc<RwLock<User>>>,
|
pub user: Option<Shared<User>>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub account: IntegrationAccount,
|
pub account: IntegrationAccount,
|
||||||
pub synced_at: Option<DateTime<Utc>>,
|
pub synced_at: Option<DateTime<Utc>>,
|
||||||
pub subscriber_count: Option<f64>,
|
pub subscriber_count: Option<f64>,
|
||||||
pub revoked: Option<bool>,
|
pub revoked: Option<bool>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub application: Option<Arc<RwLock<Application>>>,
|
pub application: Option<Shared<Application>>,
|
||||||
pub scopes: Option<Vec<String>>,
|
pub scopes: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::{Snowflake, WelcomeScreenObject};
|
use crate::types::{Snowflake, WelcomeScreenObject};
|
||||||
|
|
||||||
use super::guild::GuildScheduledEvent;
|
use super::guild::GuildScheduledEvent;
|
||||||
|
@ -21,7 +20,7 @@ pub struct Invite {
|
||||||
pub flags: Option<i32>,
|
pub flags: Option<i32>,
|
||||||
pub guild: Option<InviteGuild>,
|
pub guild: Option<InviteGuild>,
|
||||||
pub guild_id: Option<Snowflake>,
|
pub guild_id: Option<Snowflake>,
|
||||||
pub guild_scheduled_event: Option<Arc<RwLock<GuildScheduledEvent>>>,
|
pub guild_scheduled_event: Option<Shared<GuildScheduledEvent>>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub invite_type: Option<i32>,
|
pub invite_type: Option<i32>,
|
||||||
pub inviter: Option<User>,
|
pub inviter: Option<User>,
|
||||||
|
@ -59,7 +58,7 @@ pub struct InviteGuild {
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/invite#invite-stage-instance-object>
|
/// See <https://discord-userdoccers.vercel.app/resources/invite#invite-stage-instance-object>
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct InviteStageInstance {
|
pub struct InviteStageInstance {
|
||||||
pub members: Vec<Arc<RwLock<GuildMember>>>,
|
pub members: Vec<Shared<GuildMember>>,
|
||||||
pub participant_count: i32,
|
pub participant_count: i32,
|
||||||
pub speaker_count: i32,
|
pub speaker_count: i32,
|
||||||
pub topic: String,
|
pub topic: String,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
entities::{
|
entities::{
|
||||||
Application, Attachment, Channel, Emoji, GuildMember, PublicUser, RoleSubscriptionData,
|
Application, Attachment, Channel, Emoji, GuildMember, PublicUser, RoleSubscriptionData,
|
||||||
|
@ -121,7 +120,7 @@ pub struct MessageInteraction {
|
||||||
pub interaction_type: u8,
|
pub interaction_type: u8,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub user: User,
|
pub user: User,
|
||||||
pub member: Option<Arc<RwLock<GuildMember>>>,
|
pub member: Option<Shared<GuildMember>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, Eq, PartialOrd, Ord)]
|
||||||
|
|
|
@ -24,7 +24,6 @@ pub use voice_state::*;
|
||||||
pub use webhook::*;
|
pub use webhook::*;
|
||||||
|
|
||||||
use crate::gateway::Shared;
|
use crate::gateway::Shared;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use crate::gateway::Updateable;
|
use crate::gateway::Updateable;
|
||||||
|
|
||||||
|
@ -36,7 +35,6 @@ use async_trait::async_trait;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::Snowflake;
|
use crate::types::Snowflake;
|
||||||
|
|
||||||
use super::PublicUser;
|
use super::PublicUser;
|
||||||
|
@ -15,7 +14,7 @@ pub struct Relationship {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub relationship_type: RelationshipType,
|
pub relationship_type: RelationshipType,
|
||||||
pub nickname: Option<String>,
|
pub nickname: Option<String>,
|
||||||
pub user: Arc<RwLock<PublicUser>>,
|
pub user: Shared<PublicUser>,
|
||||||
pub since: Option<DateTime<Utc>>,
|
pub since: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::{entities::User, utils::Snowflake};
|
use crate::types::{entities::User, utils::Snowflake};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
|
@ -24,7 +23,7 @@ pub struct Sticker {
|
||||||
pub available: Option<bool>,
|
pub available: Option<bool>,
|
||||||
pub guild_id: Option<Snowflake>,
|
pub guild_id: Option<Snowflake>,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub user: Option<Arc<RwLock<User>>>,
|
pub user: Option<Shared<User>>,
|
||||||
pub sort_value: Option<u8>,
|
pub sort_value: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::entities::User;
|
use crate::types::entities::User;
|
||||||
use crate::types::Snowflake;
|
use crate::types::Snowflake;
|
||||||
|
|
||||||
|
@ -21,5 +20,5 @@ pub struct TeamMember {
|
||||||
pub membership_state: u8,
|
pub membership_state: u8,
|
||||||
pub permissions: Vec<String>,
|
pub permissions: Vec<String>,
|
||||||
pub team_id: Snowflake,
|
pub team_id: Snowflake,
|
||||||
pub user: Arc<RwLock<User>>,
|
pub user: Shared<User>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
entities::{Guild, User},
|
entities::{Guild, User},
|
||||||
utils::Snowflake,
|
utils::Snowflake,
|
||||||
|
@ -18,13 +17,13 @@ pub struct GuildTemplate {
|
||||||
pub usage_count: Option<u64>,
|
pub usage_count: Option<u64>,
|
||||||
pub creator_id: Snowflake,
|
pub creator_id: Snowflake,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub creator: Arc<RwLock<User>>,
|
pub creator: Shared<User>,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
pub source_guild_id: Snowflake,
|
pub source_guild_id: Snowflake,
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub source_guild: Vec<Arc<RwLock<Guild>>>,
|
pub source_guild: Vec<Shared<Guild>>,
|
||||||
// Unsure how a {recursive: Guild} looks like, might be a Vec?
|
// Unsure how a {recursive: Guild} looks like, might be a Vec?
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub serialized_source_guild: Vec<Arc<RwLock<Guild>>>,
|
pub serialized_source_guild: Vec<Shared<Guild>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub struct UserData {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
pub fn to_public_user(self) -> PublicUser {
|
pub fn into_public_user(self) -> PublicUser {
|
||||||
PublicUser::from(self)
|
PublicUser::from(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ use std::sync::{Arc, RwLock};
|
||||||
use chrono::{serde::ts_milliseconds_option, Utc};
|
use chrono::{serde::ts_milliseconds_option, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
|
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
|
@ -77,7 +79,7 @@ pub struct UserSettings {
|
||||||
#[cfg(not(feature = "sqlx"))]
|
#[cfg(not(feature = "sqlx"))]
|
||||||
pub restricted_guilds: Vec<String>,
|
pub restricted_guilds: Vec<String>,
|
||||||
pub show_current_game: bool,
|
pub show_current_game: bool,
|
||||||
pub status: Arc<RwLock<UserStatus>>,
|
pub status: Shared<UserStatus>,
|
||||||
pub stream_notifications_enabled: bool,
|
pub stream_notifications_enabled: bool,
|
||||||
pub theme: UserTheme,
|
pub theme: UserTheme,
|
||||||
pub timezone_offset: i16,
|
pub timezone_offset: i16,
|
||||||
|
@ -153,5 +155,5 @@ pub struct GuildFolder {
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct LoginResult {
|
pub struct LoginResult {
|
||||||
pub token: String,
|
pub token: String,
|
||||||
pub settings: Arc<RwLock<UserSettings>>,
|
pub settings: Shared<UserSettings>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use chorus_macros::Composite;
|
use chorus_macros::Composite;
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use crate::types::Composite;
|
use crate::types::Composite;
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ pub struct VoiceState {
|
||||||
pub guild: Option<Guild>,
|
pub guild: Option<Guild>,
|
||||||
pub channel_id: Option<Snowflake>,
|
pub channel_id: Option<Snowflake>,
|
||||||
pub user_id: Snowflake,
|
pub user_id: Snowflake,
|
||||||
pub member: Option<Arc<RwLock<GuildMember>>>,
|
pub member: Option<Shared<GuildMember>>,
|
||||||
pub session_id: String,
|
pub session_id: String,
|
||||||
pub token: Option<String>,
|
pub token: Option<String>,
|
||||||
pub deaf: bool,
|
pub deaf: bool,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::gateway::Shared;
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use crate::gateway::Updateable;
|
use crate::gateway::Updateable;
|
||||||
|
|
||||||
|
@ -36,10 +36,10 @@ pub struct Webhook {
|
||||||
pub application_id: Snowflake,
|
pub application_id: Snowflake,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub user: Option<Arc<RwLock<User>>>,
|
pub user: Option<Shared<User>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub source_guild: Option<Arc<RwLock<Guild>>>,
|
pub source_guild: Option<Shared<Guild>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::types::events::WebSocketEvent;
|
use crate::types::events::WebSocketEvent;
|
||||||
|
use crate::types::IntoShared;
|
||||||
use crate::types::{entities::Channel, JsonField, Snowflake, SourceUrlField};
|
use crate::types::{entities::Channel, JsonField, Snowflake, SourceUrlField};
|
||||||
use chorus_macros::{JsonField, SourceUrlField};
|
use chorus_macros::{JsonField, SourceUrlField};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
@ -8,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use super::UpdateMessage;
|
use super::UpdateMessage;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use std::sync::{Arc, RwLock};
|
use crate::gateway::Shared;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use crate::types::Guild;
|
use crate::types::Guild;
|
||||||
|
@ -42,9 +43,9 @@ impl UpdateMessage<Guild> for ChannelCreate {
|
||||||
self.channel.guild_id
|
self.channel.guild_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, object_to_update: Arc<RwLock<Guild>>) {
|
fn update(&mut self, object_to_update: Shared<Guild>) {
|
||||||
let mut write = object_to_update.write().unwrap();
|
let mut write = object_to_update.write().unwrap();
|
||||||
let update = Arc::new(RwLock::new(self.channel.clone()));
|
let update = self.channel.clone().into_shared();
|
||||||
if write.channels.is_some() {
|
if write.channels.is_some() {
|
||||||
write.channels.as_mut().unwrap().push(update);
|
write.channels.as_mut().unwrap().push(update);
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,7 +69,7 @@ impl WebSocketEvent for ChannelUpdate {}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<Channel> for ChannelUpdate {
|
impl UpdateMessage<Channel> for ChannelUpdate {
|
||||||
fn update(&mut self, object_to_update: Arc<RwLock<Channel>>) {
|
fn update(&mut self, object_to_update: Shared<Channel>) {
|
||||||
let mut write = object_to_update.write().unwrap();
|
let mut write = object_to_update.write().unwrap();
|
||||||
*write = self.channel.clone();
|
*write = self.channel.clone();
|
||||||
}
|
}
|
||||||
|
@ -114,7 +115,7 @@ impl UpdateMessage<Guild> for ChannelDelete {
|
||||||
self.channel.guild_id
|
self.channel.guild_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, object_to_update: Arc<RwLock<Guild>>) {
|
fn update(&mut self, object_to_update: Shared<Guild>) {
|
||||||
if self.id().is_none() {
|
if self.id().is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize};
|
||||||
use crate::types::entities::{Guild, PublicUser, UnavailableGuild};
|
use crate::types::entities::{Guild, PublicUser, UnavailableGuild};
|
||||||
use crate::types::events::WebSocketEvent;
|
use crate::types::events::WebSocketEvent;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
AuditLogEntry, Emoji, GuildMember, GuildScheduledEvent, JsonField, RoleObject, Snowflake,
|
AuditLogEntry, Emoji, GuildMember, GuildScheduledEvent, IntoShared, JsonField, RoleObject,
|
||||||
SourceUrlField, Sticker,
|
Snowflake, SourceUrlField, Sticker,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::PresenceUpdate;
|
use super::PresenceUpdate;
|
||||||
|
@ -14,7 +14,7 @@ use super::PresenceUpdate;
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use super::UpdateMessage;
|
use super::UpdateMessage;
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use std::sync::{Arc, RwLock};
|
use crate::gateway::Shared;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Default, Clone, SourceUrlField, JsonField)]
|
#[derive(Debug, Deserialize, Serialize, Default, Clone, SourceUrlField, JsonField)]
|
||||||
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-create>;
|
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-create>;
|
||||||
|
@ -38,7 +38,7 @@ impl UpdateMessage<Guild> for GuildCreate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, _: Arc<RwLock<Guild>>) {}
|
fn update(&mut self, _: Shared<Guild>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
|
@ -114,7 +114,7 @@ impl UpdateMessage<Guild> for GuildDelete {
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.guild.id)
|
Some(self.guild.id)
|
||||||
}
|
}
|
||||||
fn update(&mut self, _: Arc<RwLock<Guild>>) {}
|
fn update(&mut self, _: Shared<Guild>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebSocketEvent for GuildDelete {}
|
impl WebSocketEvent for GuildDelete {}
|
||||||
|
@ -229,16 +229,16 @@ impl UpdateMessage<Guild> for GuildRoleCreate {
|
||||||
Some(self.guild_id)
|
Some(self.guild_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, object_to_update: Arc<RwLock<Guild>>) {
|
fn update(&mut self, object_to_update: Shared<Guild>) {
|
||||||
let mut object_to_update = object_to_update.write().unwrap();
|
let mut object_to_update = object_to_update.write().unwrap();
|
||||||
if object_to_update.roles.is_some() {
|
if object_to_update.roles.is_some() {
|
||||||
object_to_update
|
object_to_update
|
||||||
.roles
|
.roles
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.push(Arc::new(RwLock::new(self.role.clone())));
|
.push(self.role.clone().into_shared());
|
||||||
} else {
|
} else {
|
||||||
object_to_update.roles = Some(Vec::from([Arc::new(RwLock::new(self.role.clone()))]));
|
object_to_update.roles = Some(Vec::from([self.role.clone().into_shared()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ impl UpdateMessage<RoleObject> for GuildRoleUpdate {
|
||||||
Some(self.role.id)
|
Some(self.role.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, object_to_update: Arc<RwLock<RoleObject>>) {
|
fn update(&mut self, object_to_update: Shared<RoleObject>) {
|
||||||
let mut write = object_to_update.write().unwrap();
|
let mut write = object_to_update.write().unwrap();
|
||||||
*write = self.role.clone();
|
*write = self.role.clone();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,9 @@ use serde_json::{from_str, from_value, to_value, Value};
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use std::fmt::Debug;
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use std::sync::{Arc, RwLock};
|
use crate::gateway::Shared;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
@ -132,7 +132,7 @@ pub(crate) trait UpdateMessage<T>: Clone + JsonField + SourceUrlField
|
||||||
where
|
where
|
||||||
T: Updateable + Serialize + DeserializeOwned + Clone,
|
T: Updateable + Serialize + DeserializeOwned + Clone,
|
||||||
{
|
{
|
||||||
fn update(&mut self, object_to_update: Arc<RwLock<T>>) {
|
fn update(&mut self, object_to_update: Shared<T>) {
|
||||||
update_object(self.get_json(), object_to_update)
|
update_object(self.get_json(), object_to_update)
|
||||||
}
|
}
|
||||||
fn id(&self) -> Option<Snowflake>;
|
fn id(&self) -> Option<Snowflake>;
|
||||||
|
@ -152,7 +152,7 @@ pub trait SourceUrlField: Clone {
|
||||||
/// Only applicable for events where the Update struct is the same as the Entity struct
|
/// Only applicable for events where the Update struct is the same as the Entity struct
|
||||||
pub(crate) fn update_object(
|
pub(crate) fn update_object(
|
||||||
value: String,
|
value: String,
|
||||||
object: Arc<RwLock<(impl Updateable + Serialize + DeserializeOwned + Clone)>>,
|
object: Shared<(impl Updateable + Serialize + DeserializeOwned + Clone)>,
|
||||||
) {
|
) {
|
||||||
let data_from_event: HashMap<String, Value> = from_str(&value).unwrap();
|
let data_from_event: HashMap<String, Value> = from_str(&value).unwrap();
|
||||||
let mut original_data: HashMap<String, Value> =
|
let mut original_data: HashMap<String, Value> =
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,18 @@
|
||||||
|
use chorus::types::{PublicUser, Snowflake, User};
|
||||||
|
|
||||||
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||||
|
#[cfg_attr(not(target_arch = "wasm32"), test)]
|
||||||
|
fn to_public_user() {
|
||||||
|
let mut user = User::default();
|
||||||
|
let mut public_user = PublicUser {
|
||||||
|
username: Some("".to_string()),
|
||||||
|
discriminator: Some("".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let id: Snowflake = 1_u64.into();
|
||||||
|
user.id = id;
|
||||||
|
public_user.id = id;
|
||||||
|
|
||||||
|
let from_user = user.into_public_user();
|
||||||
|
assert_eq!(public_user, from_user);
|
||||||
|
}
|
Loading…
Reference in New Issue