diff --git a/README.md b/README.md index 622bfcd..7e86ebe 100644 --- a/README.md +++ b/README.md @@ -60,27 +60,7 @@ async fn main() { client.set_heartbeat_ack(true); // Send all the permissions you need from your bot to discord - client.add_intents(vec![ - Intent::Guilds, - Intent::GuildMembers, - Intent::GuildModeration, - Intent::GuildEmojisAndStickers, - Intent::GuildIntegrations, - Intent::GuildWebhooks, - Intent::GuildInvites, - Intent::GuildVoiceStates, - Intent::GuildPresences, - Intent::GuildMessages, - Intent::GuildMessageReactions, - Intent::GuildMessageTyping, - Intent::DirectMessages, - Intent::DirectMessageReactions, - Intent::DirectMessageTyping, - Intent::MessageContent, - Intent::GuildScheduledEvents, - Intent::AutoModerationConfiguration, - Intent::AutoModerationExecution, - ]); + client.all_intents(); // The ready event will be launched once your bot is connected client.on_ready(|ready| { diff --git a/adiscord-intents/Cargo.toml b/adiscord-intents/Cargo.toml index 224d4f2..68078af 100644 --- a/adiscord-intents/Cargo.toml +++ b/adiscord-intents/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adiscord-intents" -version = "0.0.3" +version = "0.0.4" authors = ["MoskalykA <100430077+MoskalykA@users.noreply.github.com>"] edition = "2021" description = "Calculate the number of intents from a list of enums" diff --git a/adiscord-intents/src/lib.rs b/adiscord-intents/src/lib.rs index 700539a..123da50 100644 --- a/adiscord-intents/src/lib.rs +++ b/adiscord-intents/src/lib.rs @@ -1,3 +1,4 @@ +#[repr(u32)] pub enum Intent { /// Exhaustive list of events included: /// diff --git a/adiscord-test/Cargo.toml b/adiscord-test/Cargo.toml index 0573455..3e8c927 100644 --- a/adiscord-test/Cargo.toml +++ b/adiscord-test/Cargo.toml @@ -8,5 +8,5 @@ license = "MIT" [dependencies] dotenv_codegen = "0.15.0" tokio = { version = "1", features = ["rt-multi-thread"] } -adiscord = { version = "0.0.7", features = ["gateway"] } -adiscord-intents = "0.0.3" +adiscord = { version = "0.0.8", features = ["gateway"] } +adiscord-intents = "0.0.4" diff --git a/adiscord-types/Cargo.toml b/adiscord-types/Cargo.toml index 2d9ea2a..59dbc47 100644 --- a/adiscord-types/Cargo.toml +++ b/adiscord-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adiscord-types" -version = "0.0.3" +version = "0.0.4" authors = ["MoskalykA <100430077+MoskalykA@users.noreply.github.com>"] edition = "2021" description = "The large list of Discord API types and Gateway types" @@ -10,8 +10,9 @@ repository = "https://github.com/MoskalykA/adiscord" license = "MIT" [dependencies] -serde = { version = "1.0.157", features = ["derive"] } -serde_json = { version = "1.0.95" } +serde = { version = "1.0.163", features = ["derive"] } +serde_json = { version = "1.0.96" } +serde_repr = "0.1.12" [features] gateway = [] diff --git a/adiscord-types/src/api/application.rs b/adiscord-types/src/api/application.rs index cb03d06..505ea7e 100644 --- a/adiscord-types/src/api/application.rs +++ b/adiscord-types/src/api/application.rs @@ -1,9 +1,10 @@ use super::{team::Team, user::User}; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u32)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Flags { None, diff --git a/adiscord-types/src/api/audit.rs b/adiscord-types/src/api/audit.rs index a0def9b..86f0c3a 100644 --- a/adiscord-types/src/api/audit.rs +++ b/adiscord-types/src/api/audit.rs @@ -1,5 +1,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[derive(Deserialize, Serialize, Debug)] pub struct Change { @@ -15,7 +16,7 @@ pub struct Change { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Event { /// Server settings were updated GUILD_UPDATE = 1, diff --git a/adiscord-types/src/api/auto_moderation.rs b/adiscord-types/src/api/auto_moderation.rs index 730228e..fcfb33b 100644 --- a/adiscord-types/src/api/auto_moderation.rs +++ b/adiscord-types/src/api/auto_moderation.rs @@ -1,15 +1,18 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; +use serde_repr::{Deserialize_repr, Serialize_repr}; +#[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum EventType { /// when a member sends or edits a message in the guild MESSAGE_SEND = 1, } +#[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum TriggerType { /// check if content contains words from a user defined list of keywords KEYWORD = 1, @@ -24,8 +27,9 @@ pub enum TriggerType { MENTION_SPAM, } +#[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum KeywordPreset { /// words that may be considered forms of swearing or cursing PROFANITY = 1, @@ -58,8 +62,9 @@ pub struct TriggerMetadata { pub mention_raid_protection_enabled: Option, } +#[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum ActionType { /// blocks a member's message and prevents it from being posted. A custom explanation can be specified and shown to members whenever their message is blocked. BLOCK_MESSAGE = 1, diff --git a/adiscord-types/src/api/channel.rs b/adiscord-types/src/api/channel.rs index 5aa05be..e71bb44 100644 --- a/adiscord-types/src/api/channel.rs +++ b/adiscord-types/src/api/channel.rs @@ -5,6 +5,7 @@ use super::{ user::User, }; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[derive(Deserialize, Serialize, Debug)] pub struct Attachment { @@ -41,7 +42,7 @@ pub struct Attachment { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Flags { None, @@ -54,7 +55,7 @@ pub enum Flags { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum ForumLayout { /// No default has been set for forum channel NOT_SET, @@ -98,7 +99,7 @@ pub struct Overwrite { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum SortOrder { /// Sort forum posts by activity LATEST_ACTIVITY, @@ -109,7 +110,7 @@ pub enum SortOrder { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum ChannelType { /// atext channel within a server GUILD_TEXT, @@ -149,7 +150,7 @@ pub enum ChannelType { } #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum VideoQuality { /// Discord chooses the quality for optimal performance AUTO = 1, diff --git a/adiscord-types/src/api/guild.rs b/adiscord-types/src/api/guild.rs index da8d40a..5036f85 100644 --- a/adiscord-types/src/api/guild.rs +++ b/adiscord-types/src/api/guild.rs @@ -1,9 +1,10 @@ use super::{emoji::Emoji, feature::Feature, role::Role, sticker::Sticker, user::User}; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum MemberFlags { None, @@ -85,7 +86,7 @@ pub struct WelcomeScreen { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum DefaultMessageNotifications { /// members will receive notifications for all messages by default ALL_MESSAGES, @@ -96,7 +97,7 @@ pub enum DefaultMessageNotifications { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum ExplicitContentFilter { /// media content will not be scanned DISABLED, @@ -109,7 +110,7 @@ pub enum ExplicitContentFilter { } #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum MFALevel { /// guild has no MFA/2FA requirement for moderation actions None, @@ -119,7 +120,7 @@ pub enum MFALevel { } #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum NSFWLevel { Default, Explicit, @@ -128,7 +129,7 @@ pub enum NSFWLevel { } #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum PremiumTier { /// guild has not unlocked any Server Boost perks None, @@ -180,7 +181,7 @@ pub struct Preview { } #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum SystemChannelFlags { None, @@ -205,7 +206,7 @@ pub enum SystemChannelFlags { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum VerificationLevel { /// unrestricted NONE, diff --git a/adiscord-types/src/api/integration.rs b/adiscord-types/src/api/integration.rs index 8d24327..25f4c58 100644 --- a/adiscord-types/src/api/integration.rs +++ b/adiscord-types/src/api/integration.rs @@ -1,8 +1,10 @@ use super::{application::Application, user::User}; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; +#[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum ExpireBehavior { RemoveRole = 0, Kick, diff --git a/adiscord-types/src/api/message.rs b/adiscord-types/src/api/message.rs index 5b4ea62..91da329 100644 --- a/adiscord-types/src/api/message.rs +++ b/adiscord-types/src/api/message.rs @@ -6,10 +6,11 @@ use super::{ }; use crate::api::{application::Application, role::Role, user::User}; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum ActivityType { JOIN = 1, SPECTATE, @@ -28,7 +29,7 @@ pub struct Activity { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum InteractionType { PING = 1, APPLICATION_COMMAND, @@ -56,7 +57,7 @@ pub struct Interaction { } #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Component { /// Container for other components ActionRow = 1, @@ -85,7 +86,7 @@ pub enum Component { #[repr(u16)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Flags { None, @@ -152,7 +153,7 @@ pub struct RoleSubscriptionData { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Type { DEFAULT, RECIPIENT_ADD, diff --git a/adiscord-types/src/api/stage.rs b/adiscord-types/src/api/stage.rs index 2da267e..bceaa8d 100644 --- a/adiscord-types/src/api/stage.rs +++ b/adiscord-types/src/api/stage.rs @@ -1,8 +1,9 @@ use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum PrivacyLevel { /// The Stage instance is visible publicly. (deprecated) PUBLIC = 1, diff --git a/adiscord-types/src/api/sticker.rs b/adiscord-types/src/api/sticker.rs index ca42149..92f8ef6 100644 --- a/adiscord-types/src/api/sticker.rs +++ b/adiscord-types/src/api/sticker.rs @@ -1,8 +1,9 @@ use super::user::User; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum FormatType { PNG = 1, APNG, @@ -23,7 +24,7 @@ pub struct Item { } #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Type { /// an official sticker in a pack, part of Nitro or in a removed purchasable pack Standard = 1, diff --git a/adiscord-types/src/api/team.rs b/adiscord-types/src/api/team.rs index b2ff9ae..f6f5396 100644 --- a/adiscord-types/src/api/team.rs +++ b/adiscord-types/src/api/team.rs @@ -1,9 +1,10 @@ use super::user::User; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum MemberState { INVITED = 1, ACCEPTED, diff --git a/adiscord-types/src/api/user.rs b/adiscord-types/src/api/user.rs index ef7e1a2..1262e87 100644 --- a/adiscord-types/src/api/user.rs +++ b/adiscord-types/src/api/user.rs @@ -1,9 +1,12 @@ use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u32)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Flags { + Unknow, + /// Discord Employee STAFF = 1 << 0, @@ -50,8 +53,9 @@ pub enum Flags { ACTIVE_DEVELOPER = 1 << 22, } +#[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum PreniumType { NONE, NITRO_CLASSIC, diff --git a/adiscord-types/src/api/webhook.rs b/adiscord-types/src/api/webhook.rs index 825c366..b86dfe8 100644 --- a/adiscord-types/src/api/webhook.rs +++ b/adiscord-types/src/api/webhook.rs @@ -1,8 +1,9 @@ use super::{channel::Channel, guild::Guild, user::User}; use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Type { /// Incoming Webhooks can post messages to channels with a generated token Incoming = 1, diff --git a/adiscord-types/src/gateway/activity.rs b/adiscord-types/src/gateway/activity.rs index 017affc..41b3a02 100644 --- a/adiscord-types/src/gateway/activity.rs +++ b/adiscord-types/src/gateway/activity.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[derive(Deserialize, Serialize, Debug)] pub struct Assets { @@ -72,7 +73,7 @@ pub struct Timestamps { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Type { Game, Streaming, diff --git a/adiscord-types/src/gateway/guild.rs b/adiscord-types/src/gateway/guild.rs index 6bd798f..3cd22a4 100644 --- a/adiscord-types/src/gateway/guild.rs +++ b/adiscord-types/src/gateway/guild.rs @@ -14,6 +14,7 @@ use crate::api::{ voice::VoiceState, }; use serde::Deserialize; +use serde_repr::Deserialize_repr; #[derive(Deserialize, Debug)] pub struct Unavailable { @@ -26,7 +27,7 @@ pub struct Unavailable { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Debug)] +#[derive(Deserialize_repr, Debug)] pub enum EventStatus { SCHEDULED = 1, ACTIVE, @@ -36,7 +37,7 @@ pub enum EventStatus { #[repr(u8)] #[allow(non_camel_case_types)] -#[derive(Deserialize, Debug)] +#[derive(Deserialize_repr, Debug)] pub enum EventEntityTypes { STAGE_INSTANCE = 1, VOICE, diff --git a/adiscord-types/src/gateway/identify.rs b/adiscord-types/src/gateway/identify.rs index 623aa31..7304644 100644 --- a/adiscord-types/src/gateway/identify.rs +++ b/adiscord-types/src/gateway/identify.rs @@ -53,5 +53,5 @@ pub struct Identify { pub presence: Option, /// Gateway Intents you wish to receive - pub intents: u16, + pub intents: u32, } diff --git a/adiscord-types/src/gateway/opcode.rs b/adiscord-types/src/gateway/opcode.rs index 7f88c94..1affe08 100644 --- a/adiscord-types/src/gateway/opcode.rs +++ b/adiscord-types/src/gateway/opcode.rs @@ -1,7 +1,7 @@ -use serde::{Deserialize, Serialize}; +use serde_repr::{Deserialize_repr, Serialize_repr}; #[repr(u8)] -#[derive(Deserialize, Serialize, Debug)] +#[derive(Deserialize_repr, Serialize_repr, Debug)] pub enum Opcode { /// Receive An event was dispatched. Dispatch, diff --git a/adiscord/Cargo.toml b/adiscord/Cargo.toml index 99dc833..0dcd679 100644 --- a/adiscord/Cargo.toml +++ b/adiscord/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adiscord" -version = "0.0.7" +version = "0.0.8" authors = ["MoskalykA <100430077+MoskalykA@users.noreply.github.com>"] edition = "2021" description = "An API and Gateway Discord wrapper in Rust" @@ -10,16 +10,16 @@ repository = "https://github.com/MoskalykA/adiscord" license = "MIT" [dependencies] -reqwest = { version = "0.11.14", features = ["json"] } -serde = { version = "1.0.157", features = ["derive"] } -adiscord-types = "0.0.3" +reqwest = { version = "0.11.18", features = ["json"] } +serde = { version = "1.0.163", features = ["derive"] } +adiscord-types = "0.0.4" async-trait = { version = "0.1.68", optional = true } ezsockets = { version = "0.5.1", features = ["tls", "native-tls"], optional = true } url = { version = "2.3.1", optional = true } -serde_json = { version = "1.0.95", optional = true } -tokio = { version = "1.27.0", features = ["time", "process"], optional = true } -adiscord-intents = { version = "0.0.3", optional = true } +serde_json = { version = "1.0.96", optional = true } +tokio = { version = "1.28.2", features = ["time", "process"], optional = true } +adiscord-intents = { version = "0.0.4", optional = true } [features] gateway = ["async-trait", "ezsockets", "url", "serde_json", "tokio", "adiscord-intents", "adiscord-types/gateway"] diff --git a/adiscord/README.md b/adiscord/README.md index 622bfcd..7e86ebe 100644 --- a/adiscord/README.md +++ b/adiscord/README.md @@ -60,27 +60,7 @@ async fn main() { client.set_heartbeat_ack(true); // Send all the permissions you need from your bot to discord - client.add_intents(vec![ - Intent::Guilds, - Intent::GuildMembers, - Intent::GuildModeration, - Intent::GuildEmojisAndStickers, - Intent::GuildIntegrations, - Intent::GuildWebhooks, - Intent::GuildInvites, - Intent::GuildVoiceStates, - Intent::GuildPresences, - Intent::GuildMessages, - Intent::GuildMessageReactions, - Intent::GuildMessageTyping, - Intent::DirectMessages, - Intent::DirectMessageReactions, - Intent::DirectMessageTyping, - Intent::MessageContent, - Intent::GuildScheduledEvents, - Intent::AutoModerationConfiguration, - Intent::AutoModerationExecution, - ]); + client.all_intents(); // The ready event will be launched once your bot is connected client.on_ready(|ready| { diff --git a/adiscord/src/gateway/mod.rs b/adiscord/src/gateway/mod.rs index 29d3495..11222fb 100644 --- a/adiscord/src/gateway/mod.rs +++ b/adiscord/src/gateway/mod.rs @@ -38,7 +38,7 @@ enum Call { struct GatewayClient { token: String, handle: ezsockets::Client, - intents: u16, + intents: u32, callbacks: HashMap, heartbeat_ack: bool, heartbeat_count: u32, @@ -49,7 +49,7 @@ impl GatewayClient { fn new( token: String, handle: ezsockets::Client, - intents: u16, + intents: u32, callbacks: HashMap, heartbeat_ack: bool, heartbeat_count: u32,