Qore DiscordWebSocketClient Module Reference 1.0.1
Loading...
Searching...
No Matches
DiscordWebSocketClient.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* DiscordWebSocketClient.qm Copyright (C) 2020 - 2025 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without websocketriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum qore version
26
27// require type definitions everywhere
28
29// enable all warnings
30
31// don't use "$" for vars, members, and methods, assume local variable scope
32
33// do not ignore argument errors
34
35
36
37
74const DI_GUILDS = 1 << 0;
75
77const DI_MEMBERS = 1 << 1;
78
80const DI_MODERATION = 1 << 2;
81
84
86const DI_INTEGRATIONS = 1 << 4;
87
89const DI_WEBHOOKS = 1 << 5;
90
92const DI_INVITES = 1 << 6;
93
95const DI_VOICE_STATES = 1 << 7;
96
98const DI_PRESENCES = 1 << 8;
99
101const DI_GUILD_MESSAGES = 1 << 9;
102
104const DI_MESSAGE_REACTIONS = 1 << 10;
105
107const DI_MESSAGE_TYPING = 1 << 11;
108
110const DI_DIRECT_MESSAGES = 1 << 12;
111
114
117
119const DI_MESSAGE_CONTENT = 1 << 15;
120
123
126
130
135const DCC_UNKNOWN_ERROR = 4000;
136
139
141const DCC_DECODE_ERROR = 4002;
142
145
148
151
153const DCC_INVALID_SEQ = 4007;
154
156const DCC_RATE_LIMITED = 4008;
157
160
162const DCC_INVALID_SHARD = 4010;
163
166
168const DCC_INVALID_API = 4012;
169
172
174
178
181
182
184const CloseDescMap = ...;
185
186
188class DiscordWebSocketClient : public WebSocketClientWithSerialization {
189
190public:
192 const DefaultHeaders = ...;
193
194
196 const DefaultApi = 10;
197
199 const DefaultOptions = ...;
200
201
203 const DOP_DISPATCH = 0;
204
206 const DOP_HEARTBEAT = 1;
207
209 const DOP_IDENTIFY = 2;
210
212 const DOP_PRESENCE_UPDATE = 3;
213
215 const DOP_VOICE_STATE_UPDATE = 4;
216
218 const DOP_RESUME = 6;
219
221 const DOP_RECONNECT = 7;
222
224 const DOP_REQUEST_GUILD_MEMBERS = 8;
225
227 const DOP_INVALID_SESSION = 9;
228
230 const DOP_HELLO = 10;
231
233 const DOP_HEARTBEAT_ACK = 11;
234
236 const OpMap = ...;
237
238
239protected:
241 string token;
242
245
248
251
254
257
259 Counter heartbeat_cnt();
260
263
266
268 Condition heartbeat_cond();
269
272
274 int api = DefaultApi;
275
276public:
277
279
292 constructor(*hash<auto> opts) ;
293
294
297
298
300
313 hash<auto> getInfo();
314
315
317 static hash<auto> getOptions(*hash<auto> opts);
318
320protected:
322public:
323
324
326protected:
327 int handleMessage(hash<WsMsgInfo> h, reference<data> buf);
328public:
329
330
332protected:
333 int handleEventData(auto msgdata);
334public:
335
336
338protected:
339 handleReadyMessage(hash<auto> d);
340public:
341
342
344protected:
346public:
347
348
350protected:
352public:
353
354
356protected:
357 doReconnect(reference<hash<auto>> info);
358public:
359
360
362protected:
363 int handleMessage(hash<auto> msg);
364public:
365
366
368protected:
369 handleHello(hash<auto> d);
370public:
371
372
374protected:
376public:
377
378
380protected:
382public:
383
384
386
388protected:
390public:
391
392
393protected:
394 stopHeartbeatThread();
395public:
396
397
398protected:
399 heartbeatThread();
400public:
401
402
404protected:
405 constructorInit(hash<auto> opts);
406public:
407
408
410 *string setupUrl(*string url);
411
412
413 static auto convertData(auto v);
414
415 static auto convertData(string v);
416
417 static list<auto> convertData(list<auto> l);
418
419 static hash<auto> convertData(hash<auto> h);
420};
421
423
427class DiscordWebSocketConnection : public WebSocketClient::WebSocketConnectionObject {
428
429public:
431 const ConnectionScheme = ...;
432
433
435 const DefaultGatewayUrl = "wss://gateway.discord.gg/";
436
438 const GatewayDiscoveryUrl = "https://discord.com/api/gateway";
439
441
451 constructor(string name, string description, *string url, hash<auto> attributes = {}, hash<auto> options = {})
452 ;
453
454
456
473 constructor(hash<auto> config, *hash<auto> attr) ;
474
475
477 string getType();
478
479
481
486protected:
487 DiscordWebSocketClient getImpl(bool connect = True, *hash<auto> rtopts);
488public:
489
490
492
496protected:
497 setRealUrl(*string url);
498public:
499
500
502 static string discoverUrl();
503};
504};
505
int hb_tid
Heartbeat thread ID.
Definition DiscordWebSocketClient.qm.dox.h:262
int heartbeat_interval
The heartbeat interval in ms.
Definition DiscordWebSocketClient.qm.dox.h:247
hash< auto > getInfo()
Returns performance statistics for the socket.
int intents
Intents for the identify message.
Definition DiscordWebSocketClient.qm.dox.h:244
int last_sequence
The last received sequence number.
Definition DiscordWebSocketClient.qm.dox.h:250
int handleMessage(hash< WsMsgInfo > h, reference< data > buf)
Handles WebSocket protocol messages.
startHeartbeatThreadIntern()
Starts the heartbeat thread.
constructorInit(hash< auto > opts)
Common constructor code.
reconnectPreamble()
Executes before a reconnect.
string resume_gateway_url
Resume gateway URL.
Definition DiscordWebSocketClient.qm.dox.h:256
eventLoop()
Processes WebSocket events.
handleReadyMessage(hash< auto > d)
Handle a READY message.
Condition heartbeat_cond()
Heartbeat condition.
static hash< auto > getOptions(*hash< auto > opts)
Processes options for the DiscordWebSocketClient constructor.
bool hb_stop
Heartbeat thread stop flag.
Definition DiscordWebSocketClient.qm.dox.h:271
string token
Bot token.
Definition DiscordWebSocketClient.qm.dox.h:241
doReconnect(reference< hash< auto > > info)
Connects to the server when reconnecting.
constructor(*hash< auto > opts)
creates the object and optionally sets logging targets
int handleMessage(hash< auto > msg)
Handle a message by raising a data event.
string session_id
Current session ID.
Definition DiscordWebSocketClient.qm.dox.h:253
*string setupUrl(*string url)
setup URL
int handleEventData(auto msgdata)
Handles deserialized event data.
Counter heartbeat_cnt()
Heartbeat thread counter.
handleHello(hash< auto > d)
Handle a HELLO message.
class for Discord websocket connections; returns an object of class DiscordWebSocketClient
Definition DiscordWebSocketClient.qm.dox.h:427
const ConnectionScheme
Connection entry info.
Definition DiscordWebSocketClient.qm.dox.h:431
DiscordWebSocketClient getImpl(bool connect=True, *hash< auto > rtopts)
returns a DiscordWebSocketClient object
constructor(hash< auto > config, *hash< auto > attr)
creates the DiscordWebSocketConnection connection object
setRealUrl(*string url)
Called by the constructor to set the real URL.
const GatewayDiscoveryUrl
Discord gateway discovery URL.
Definition DiscordWebSocketClient.qm.dox.h:438
constructor(string name, string description, *string url, hash< auto > attributes={}, hash< auto > options={})
creates the DiscordWebSocketConnection connection object
const DefaultGatewayUrl
Default Discord gateway URL.
Definition DiscordWebSocketClient.qm.dox.h:435
static string discoverUrl()
Discover the Discord gateway URL.
const DCC_SHARDING_REQUIRED
The session would have handled too many guilds - you are required to shard yextern connection in orde...
Definition DiscordWebSocketClient.qm.dox.h:165
const DCC_INVALID_INTENT
You sent an invalid intent for a Gateway Intent. You may have incorrectly calculated the bitwise valu...
Definition DiscordWebSocketClient.qm.dox.h:171
const DCC_AUTHENTICATION_FAILED
The account token sent with yextern identify payload is incorrect.
Definition DiscordWebSocketClient.qm.dox.h:147
const DCC_INVALID_SEQ
The sequence sent when resuming the session was invalid. Reconnect and start a new session.
Definition DiscordWebSocketClient.qm.dox.h:153
const DCC_INVALID_SHARD
You sent us an invalid shard when identifying.
Definition DiscordWebSocketClient.qm.dox.h:162
const DCC_UNKNOWN_ERROR
Definition DiscordWebSocketClient.qm.dox.h:135
const DCC_SESSION_TIMED_OUT
Yextern session timed out. Reconnect and start a new one.
Definition DiscordWebSocketClient.qm.dox.h:159
const DCC_RATE_LIMITED
Woah nelly! You're sending payloads to us too quickly. Slow it down! You will be disconnected on rece...
Definition DiscordWebSocketClient.qm.dox.h:156
const DCC_INVALID_API
You sent an invalid version for the gateway.
Definition DiscordWebSocketClient.qm.dox.h:168
const DCC_UNKNOWN_OPCODE
You sent an invalid Gateway opcode or an invalid payload for an opcode. Don't do that!
Definition DiscordWebSocketClient.qm.dox.h:138
const DCC_ALREADY_AUTHENTICATED
You sent more than one identify payload. Don't do that!
Definition DiscordWebSocketClient.qm.dox.h:150
const DCC_DISALLOWED_INTENT
You sent a disallowed intent for a Gateway Intent.
Definition DiscordWebSocketClient.qm.dox.h:176
const DCC_NOT_AUTHENTICATED
You sent us a payload prior to identifying.
Definition DiscordWebSocketClient.qm.dox.h:144
const DCC_DECODE_ERROR
You sent an invalid payload to Discord. Don't do that!
Definition DiscordWebSocketClient.qm.dox.h:141
const DI_DIRECT_MESSAGES
Discord intent: DMs.
Definition DiscordWebSocketClient.qm.dox.h:110
const DI_GUILD_MESSAGES
Discord intent: guild (server) messages.
Definition DiscordWebSocketClient.qm.dox.h:101
const DI_MODERATION
Discord intent: moderation.
Definition DiscordWebSocketClient.qm.dox.h:80
const DI_AUTO_MODERATION_CONFIGURATION
Discord intent: message content.
Definition DiscordWebSocketClient.qm.dox.h:125
const DI_PRESENCES
Discord intent: presences.
Definition DiscordWebSocketClient.qm.dox.h:98
const DI_DIRECT_MESSAGE_REACTIONS
Discord intent: direct message reactions.
Definition DiscordWebSocketClient.qm.dox.h:113
const DI_GUILDS
Definition DiscordWebSocketClient.qm.dox.h:74
const DI_DIRECT_MESSAGE_TYPING
Discord intent: direct message typing.
Definition DiscordWebSocketClient.qm.dox.h:116
const DI_MESSAGE_REACTIONS
Discord intent: message reactions.
Definition DiscordWebSocketClient.qm.dox.h:104
const DI_INVITES
Discord intent: invites.
Definition DiscordWebSocketClient.qm.dox.h:92
const DI_MEMBERS
Discord intent: members.
Definition DiscordWebSocketClient.qm.dox.h:77
const DI_MESSAGE_TYPING
Discord intent: message typing.
Definition DiscordWebSocketClient.qm.dox.h:107
const DI_MESSAGE_CONTENT
Discord intent: message content.
Definition DiscordWebSocketClient.qm.dox.h:119
const DI_GUILD_SCHEDULED_EVENTS
Discord intent: message content.
Definition DiscordWebSocketClient.qm.dox.h:122
const DI_EMOJIS_AND_STICKERS
Discord intent: emojis and stickers.
Definition DiscordWebSocketClient.qm.dox.h:83
const DI_AUTO_MODERATION_EXECUTION
Discord intent:
Definition DiscordWebSocketClient.qm.dox.h:128
const DI_WEBHOOKS
Discord intent: webhooks.
Definition DiscordWebSocketClient.qm.dox.h:89
const DI_INTEGRATIONS
Discord intent: integrations.
Definition DiscordWebSocketClient.qm.dox.h:86
const DI_VOICE_STATES
Discord intent: voice states.
Definition DiscordWebSocketClient.qm.dox.h:95
the DiscordWebSocketClient namespace contains all the objects in the DiscordWebSocketClient module
Definition DiscordWebSocketClient.qm.dox.h:69
const CloseDescMap
Maps Discord close codes to a short description string.
Definition DiscordWebSocketClient.qm.dox.h:184
const CloseReconnectMap
Maps Discord close codes to a reconnect hint.
Definition DiscordWebSocketClient.qm.dox.h:180