use serde::Deserialize;
use serde_json::Value;
use crate::{ds, str, types::payloads::ActivityPayload};
#[derive(Debug, Clone, Deserialize)]
pub struct ActivityResponseData {
application_id: Option<String>,
platform: Option<String>,
metadata: Option<Value>,
#[serde(flatten)]
pub activity: ActivityPayload,
}
impl ActivityResponseData {
ds!(application_id, "The ID of the application");
ds!(platform, "The platform of the host.");
#[must_use]
pub fn metadata(&self) -> Option<&Value> {
self.metadata.as_ref()
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct ReadyData {
v: u8,
pub config: ServerConfigurationData,
pub user: DiscordUser,
}
impl ReadyData {
#[must_use]
pub fn version(&self) -> u8 {
self.v
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct ServerConfigurationData {
cdn_host: String,
api_endpoint: String,
environment: String,
}
impl ServerConfigurationData {
str!(cdn_host, "The CDN for the RPC server.");
str!(api_endpoint, "The API endpoint for the RPC server.");
str!(environment, "The environment for the RPC server.");
}
#[derive(Debug, Clone, Deserialize)]
pub struct DiscordUser {
id: String,
username: String,
discriminator: String,
global_name: Option<String>,
avatar: Option<String>,
bot: Option<bool>,
system: Option<bool>,
mfa_enabled: Option<bool>,
banner: Option<String>,
accent_color: Option<isize>,
locale: Option<String>,
verified: Option<bool>,
email: Option<String>,
flags: Option<isize>,
premium_type: Option<isize>,
public_flags: Option<isize>,
pub avatar_decoration_data: Option<AvatarDecorationData>,
pub collectibles: Option<Collectibles>,
pub primary_guild: Option<PrimaryGuild>,
}
impl DiscordUser {
str!(id, "The user's ID.");
str!(
username,
"The user's username, not unique across the platform."
);
str!(discriminator, "The user's Discord-tag.");
ds!(global_name, "The user's display name, if set.");
ds!(avatar, "The user's avatar hash.");
#[must_use]
pub fn bot(&self) -> Option<bool> {
self.bot
}
#[must_use]
pub fn system(&self) -> Option<bool> {
self.system
}
#[must_use]
pub fn mfa_enabled(&self) -> Option<bool> {
self.mfa_enabled
}
ds!(banner, "The user's banner hash.");
ds!(locale, "The user's chosen language option.");
ds!(email, "The user's email.");
#[must_use]
pub fn verified(&self) -> Option<bool> {
self.verified
}
#[must_use]
pub fn accent_color(&self) -> Option<isize> {
self.accent_color
}
#[must_use]
pub fn flags(&self) -> Option<isize> {
self.flags
}
#[must_use]
pub fn premium_type(&self) -> Option<isize> {
self.premium_type
}
#[must_use]
pub fn public_flags(&self) -> Option<isize> {
self.public_flags
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct AvatarDecorationData {
asset: String,
sku_id: String,
}
impl AvatarDecorationData {
str!(
asset,
"The avatar decoration hash. See: <https://docs.discord.com/developers/reference#image-formatting>"
);
str!(sku_id, "ID of the avatar decoration's SKU.");
}
#[derive(Debug, Clone, Deserialize)]
pub struct Collectibles {
pub nameplate: Option<NameplateData>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct NameplateData {
sku_id: String,
asset: String,
label: String,
palette: String,
}
impl NameplateData {
str!(sku_id, "ID of the nameplate SKU.");
str!(
asset,
"Path to the nameplate asset. See: <https://docs.discord.com/developers/reference#image-formatting>"
);
str!(label, "The label of this nameplate. Currently unused.");
str!(
palette,
"Background color of the nameplate, one of: `crimson`, `berry`, `sky`, `teal`, `forest`, `bubble_gum`, `violet`, `cobalt`, `clover`, `lemon`, `white`"
);
}
#[derive(Debug, Clone, Deserialize)]
pub struct PrimaryGuild {
identity_guild_id: Option<String>,
identity_enabled: Option<bool>,
tag: Option<String>,
badge: Option<String>,
}
impl PrimaryGuild {
ds!(identity_guild_id, "The ID of the user's primary guild.");
ds!(
tag,
"The text of the user's server tag. Limited to 4 characters."
);
ds!(badge, "The server tag badge hash.");
#[must_use]
pub fn identity_enabled(&self) -> Option<bool> {
self.identity_enabled
}
}