1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! A collection of constants used by the library.

/// The gateway version used by the library, URI is retrieved via the REST API.
pub const GATEWAY_VERSION: usize = 6;

/// The maximum length of textual size of an embed message.
pub const EMBED_MAX_LENGTH: usize = 6000;
/// The maximum length of a message in Unicode code points allowed by Discord.
pub const MESSAGE_MAX_LENGTH: usize = 2000;

/// The UserAgent header sent with every request.
pub const USER_AGENT: &str = concat!("DiscordBot (", pkg_repo!(), ", ", pkg_version!(), ")");

/// Gateway opcodes.
#[non_exhaustive]
#[int_enum::int_enum(u8)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum OpCode {
    /// Dispatches an event.
    Event = 0,
    /// Used for ping checking.
    Heartbeat = 1,
    /// Used for client handshake.
    Identify = 2,
    /// Used to update the client status.
    StatusUpdate = 3,
    /// Used to join/move/leave voice channels.
    VoiceStateUpdate = 4,
    /// Used for voice ping checking.
    VoiceServerPing = 5,
    /// Used to resume a closed connection.
    Resume = 6,
    /// Used to tell clients to reconnect to the gateway.
    Reconnect = 7,
    /// Used to request guild members.
    GetGuildMembers = 8,
    /// Used to notify clients that they have an invalid session Id.
    InvalidSession = 9,
    /// Sent immediately after connection, contains heartbeat + server info.
    Hello = 10,
    /// Sent immediately following a client heartbeat that was received.
    HeartbeatAck = 11,
}

/// Gateway close event codes.
pub mod close_codes {
    /// Unknown error. Try reconnecting?
    pub const UNKNOWN_ERROR: u16 = 4000;
    /// An invalid gateway opcode or an invalid payload for an opcode was sent.
    pub const UNKNOWN_OPCODE: u16 = 4001;
    /// An invalid payload was sent.
    pub const DECODE_ERROR: u16 = 4002;
    /// A payload was sent prior to identifying.
    pub const NOT_AUTHENTICATED: u16 = 4003;
    /// The account token sent with your identify payload is incorrect.
    pub const AUTHENTICATION_FAILED: u16 = 4004;
    /// More than one identify payload was sent.
    pub const ALREADY_AUTHENTICATED: u16 = 4005;
    /// The sequence sent when resuming the session was invalid.
    pub const INVALID_SEQUENCE: u16 = 4007;
    /// Payloads were sent too quickly.
    pub const RATE_LIMITED: u16 = 4008;
    /// Session timed out.
    pub const SESSION_TIMEOUT: u16 = 4009;
    /// An invalid shard was sent when identifying.
    pub const INVALID_SHARD: u16 = 4010;
    /// The session would have handled too many guilds.
    pub const SHARDING_REQUIRED: u16 = 4011;
}