serenity/constants.rs
1//! A set of constants used by the library.
2
3/// The maximum length of the textual size of an embed.
4pub const EMBED_MAX_LENGTH: usize = 6000;
5
6/// The maximum number of embeds in a message.
7pub const EMBED_MAX_COUNT: usize = 10;
8
9/// The maximum number of stickers in a message.
10pub const STICKER_MAX_COUNT: usize = 3;
11
12/// The gateway version used by the library. The gateway URL is retrieved via the REST API.
13pub const GATEWAY_VERSION: u8 = 10;
14
15/// The large threshold to send on identify.
16pub const LARGE_THRESHOLD: u8 = 250;
17
18/// The maximum unicode code points allowed within a message by Discord.
19pub const MESSAGE_CODE_LIMIT: usize = 2000;
20
21/// The maximum number of members the bot can fetch at once
22pub const MEMBER_FETCH_LIMIT: u64 = 1000;
23
24/// The [UserAgent] sent along with every request.
25///
26/// [UserAgent]: ::reqwest::header::USER_AGENT
27pub const USER_AGENT: &str = concat!(
28 "DiscordBot (https://github.com/serenity-rs/serenity, ",
29 env!("CARGO_PKG_VERSION"),
30 ")"
31);
32
33enum_number! {
34 /// An enum representing the [gateway opcodes].
35 ///
36 /// [Discord docs](https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes).
37 #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
38 #[serde(from = "u8", into = "u8")]
39 #[non_exhaustive]
40 pub enum Opcode {
41 /// Dispatches an event.
42 Dispatch = 0,
43 /// Used for ping checking.
44 Heartbeat = 1,
45 /// Used for client handshake.
46 Identify = 2,
47 /// Used to update the client status.
48 PresenceUpdate = 3,
49 /// Used to join/move/leave voice channels.
50 VoiceStateUpdate = 4,
51 /// Used for voice ping checking.
52 VoiceServerPing = 5,
53 /// Used to resume a closed connection.
54 Resume = 6,
55 /// Used to tell clients to reconnect to the gateway.
56 Reconnect = 7,
57 /// Used to request guild members.
58 RequestGuildMembers = 8,
59 /// Used to notify clients that they have an invalid session Id.
60 InvalidSession = 9,
61 /// Sent immediately after connection, contains heartbeat + server info.
62 Hello = 10,
63 /// Sent immediately following a client heartbeat that was received.
64 HeartbeatAck = 11,
65 _ => Unknown(u8),
66 }
67}
68
69pub mod close_codes {
70 /// Unknown error; try reconnecting?
71 ///
72 /// Can reconnect.
73 pub const UNKNOWN_ERROR: u16 = 4000;
74 /// Invalid Gateway OP Code.
75 ///
76 /// Can resume.
77 pub const UNKNOWN_OPCODE: u16 = 4001;
78 /// An invalid payload was sent.
79 ///
80 /// Can resume.
81 pub const DECODE_ERROR: u16 = 4002;
82 /// A payload was sent prior to identifying.
83 ///
84 /// Cannot reconnect.
85 pub const NOT_AUTHENTICATED: u16 = 4003;
86 /// The account token sent with the identify payload was incorrect.
87 ///
88 /// Cannot reconnect.
89 pub const AUTHENTICATION_FAILED: u16 = 4004;
90 /// More than one identify payload was sent.
91 ///
92 /// Can reconnect.
93 pub const ALREADY_AUTHENTICATED: u16 = 4005;
94 /// The sequence sent when resuming the session was invalid.
95 ///
96 /// Can reconnect.
97 pub const INVALID_SEQUENCE: u16 = 4007;
98 /// Payloads were being sent too quickly.
99 ///
100 /// Can resume.
101 pub const RATE_LIMITED: u16 = 4008;
102 /// A session timed out.
103 ///
104 /// Can reconnect.
105 pub const SESSION_TIMEOUT: u16 = 4009;
106 /// An invalid shard when identifying was sent.
107 ///
108 /// Cannot reconnect.
109 pub const INVALID_SHARD: u16 = 4010;
110 /// The session would have handled too many guilds.
111 ///
112 /// Cannot reconnect.
113 pub const SHARDING_REQUIRED: u16 = 4011;
114 /// Undocumented gateway intents have been provided.
115 pub const INVALID_GATEWAY_INTENTS: u16 = 4013;
116 /// Disallowed gateway intents have been provided.
117 pub const DISALLOWED_GATEWAY_INTENTS: u16 = 4014;
118}