cloudstorm 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022 DasWolke
1
+ Copyright 2023 DasWolke
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -31,25 +31,24 @@ You may wonder how you you are able to get the id of a shard where an event orig
31
31
  So an event you receive may look like this:
32
32
  ```json
33
33
  {
34
- "op":0,
35
- "t":"PRESENCE_UPDATE",
36
- "s":1337,
37
- "shard_id":0,
34
+ "op": 0,
35
+ "t": "PRESENCE_UPDATE",
36
+ "s": 1337,
37
+ "shard_id": 0,
38
38
  "d": {
39
- "game": null,
40
- "guild_id": "id",
41
- "nick": null,
42
- "roles": [],
43
- "status": "offline",
44
39
  "user": {
45
40
  "id": "id"
46
- }
41
+ },
42
+ "guild_id": "id",
43
+ "status": "offline",
44
+ "activities": [],
45
+ "client_status": {}
47
46
  }
48
47
  }
49
48
  ```
50
49
 
51
50
  ## Sharding for VERY large bots
52
- CloudStorm supports max_concurrency, but does not automatically attempt to fetch new info related to max_concurrency. You are expected to re-fetch this data at your own discretion as Discord does not recommend caching the data for extended periods as it can change as your client leaves and joins guilds and possibly cause rate limit errors.
51
+ CloudStorm supports max_concurrency and gets this info on initial connect, but does not automatically attempt to fetch new info related to max_concurrency. You are expected to re-fetch this data at your own discretion as Discord does not recommend caching the data for extended periods as it can change as your client leaves and joins guilds and possibly cause rate limit errors.
53
52
 
54
53
  You should start your clusters 1 by 1 as rate limit info is only fetched on Client.connect or when you manually call Client.fetchConnectInfo when /gateway/bot is fetched
55
54
 
@@ -60,6 +59,6 @@ I've written a general whitepaper on the idea of microservice bots, which you ca
60
59
  You can find the docs at [https://daswolke.github.io/CloudStorm/](https://daswolke.github.io/CloudStorm/)
61
60
 
62
61
  ### Installation:
63
- To install CloudStorm, make sure that you have node 12 or higher and npm installed on your computer.
62
+ To install CloudStorm, make sure that you have node 12 or higher on your computer.
64
63
 
65
64
  Then run the following command in a terminal `npm install cloudstorm`
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import * as discord_typings from 'discord-typings';
2
1
  import * as snowtransfer from 'snowtransfer';
2
+ import APITypes from 'discord-api-types/v10';
3
3
  import * as events from 'events';
4
4
  import { EventEmitter } from 'events';
5
5
 
@@ -8,7 +8,7 @@ type IntentResolvable = number | Array<number> | keyof IntentFlags | Array<keyof
8
8
  declare const flags: {
9
9
  GUILDS: number;
10
10
  GUILD_MEMBERS: number;
11
- GUILD_BANS: number;
11
+ GUILD_MODERATION: number;
12
12
  GUILD_EMOJIS_AND_STICKERS: number;
13
13
  GUILD_INTEGRATIONS: number;
14
14
  GUILD_WEBHOOKS: number;
@@ -23,13 +23,15 @@ declare const flags: {
23
23
  DIRECT_MESSAGE_TYPING: number;
24
24
  MESSAGE_CONTENT: number;
25
25
  GUILD_SCHEDULED_EVENTS: number;
26
+ AUTO_MODERATION_CONFIGURATION: number;
27
+ AUTO_MODERATION_EXECUTION: number;
26
28
  };
27
29
  declare function resolve(bit?: IntentResolvable): number;
28
30
  declare const _default: {
29
31
  flags: {
30
32
  GUILDS: number;
31
33
  GUILD_MEMBERS: number;
32
- GUILD_BANS: number;
34
+ GUILD_MODERATION: number;
33
35
  GUILD_EMOJIS_AND_STICKERS: number;
34
36
  GUILD_INTEGRATIONS: number;
35
37
  GUILD_WEBHOOKS: number;
@@ -44,6 +46,8 @@ declare const _default: {
44
46
  DIRECT_MESSAGE_TYPING: number;
45
47
  MESSAGE_CONTENT: number;
46
48
  GUILD_SCHEDULED_EVENTS: number;
49
+ AUTO_MODERATION_CONFIGURATION: number;
50
+ AUTO_MODERATION_EXECUTION: number;
47
51
  };
48
52
  privileged: number;
49
53
  all: number;
@@ -51,15 +55,12 @@ declare const _default: {
51
55
  resolve: typeof resolve;
52
56
  };
53
57
 
54
- interface IWSMessage {
55
- op: discord_typings.GatewayOpcode;
56
- d?: any;
57
- s?: number;
58
- t?: discord_typings.GatewayEvent;
59
- }
60
- interface IGatewayMessage extends IWSMessage {
58
+ type IGatewayMessage = APITypes.GatewayReceivePayload & {
61
59
  shard_id: number;
62
- }
60
+ };
61
+ type IGatewayDispatch = APITypes.GatewayDispatchPayload & {
62
+ shard_id: number;
63
+ };
63
64
  interface IClientOptions {
64
65
  largeGuildThreshold?: number;
65
66
  /**
@@ -74,7 +75,7 @@ interface IClientOptions {
74
75
  */
75
76
  totalShards?: number;
76
77
  reconnect?: boolean;
77
- initialPresence?: discord_typings.GatewayPresenceUpdate;
78
+ initialPresence?: APITypes.GatewayPresenceUpdateData;
78
79
  intents?: IntentResolvable;
79
80
  snowtransferInstance?: snowtransfer.SnowTransfer;
80
81
  ws?: IClientWSOptions;
@@ -128,8 +129,8 @@ declare class RatelimitBucket {
128
129
  interface BWSEvents {
129
130
  ws_open: [];
130
131
  ws_close: [number, string];
131
- ws_message: [IGatewayMessage];
132
- debug_send: [IWSMessage];
132
+ ws_receive: [APITypes.GatewayReceivePayload];
133
+ ws_send: [APITypes.GatewaySendPayload];
133
134
  debug: [string];
134
135
  }
135
136
  interface BetterWs {
@@ -164,7 +165,7 @@ declare class BetterWs extends EventEmitter {
164
165
  get status(): 1 | 2 | 3 | 4;
165
166
  connect(): Promise<void>;
166
167
  close(code: number, reason?: string): Promise<void>;
167
- sendMessage(data: IWSMessage): Promise<void>;
168
+ sendMessage(data: APITypes.GatewaySendPayload): Promise<void>;
168
169
  private _write;
169
170
  private _onError;
170
171
  private _onClose;
@@ -174,7 +175,6 @@ declare class BetterWs extends EventEmitter {
174
175
 
175
176
  interface ConnectorEvents {
176
177
  queueIdentify: [number];
177
- event: [IWSMessage];
178
178
  ready: [boolean];
179
179
  disconnect: [number, string, boolean];
180
180
  stateChange: ["connecting" | "identifying" | "resuming" | "ready" | "disconnected"];
@@ -220,6 +220,7 @@ declare class DiscordConnector extends EventEmitter {
220
220
  private _closing;
221
221
  identifyAddress: string;
222
222
  resumeAddress: string | null;
223
+ reconnecting: boolean;
223
224
  static readonly default: typeof DiscordConnector;
224
225
  /**
225
226
  * Create a new Discord Connector.
@@ -266,7 +267,7 @@ declare class DiscordConnector extends EventEmitter {
266
267
  /**
267
268
  * Send an OP 6 RESUME to the gateway.
268
269
  */
269
- private resume;
270
+ resume(): Promise<void>;
270
271
  /**
271
272
  * Send an OP 1 HEARTBEAT to the gateway.
272
273
  */
@@ -286,12 +287,12 @@ declare class DiscordConnector extends EventEmitter {
286
287
  * Send an OP 3 PRESENCE_UPDATE to the gateway.
287
288
  * @param data Presence data to send.
288
289
  */
289
- presenceUpdate(data: discord_typings.GatewayPresenceUpdate): Promise<void>;
290
+ presenceUpdate(data: Partial<APITypes.GatewayPresenceUpdateData>): Promise<void>;
290
291
  /**
291
292
  * Send an OP 4 VOICE_STATE_UPDATE to the gateway.
292
293
  * @param data Voice state update data to send.
293
294
  */
294
- voiceStateUpdate(data: discord_typings.VoiceStateUpdatePayload & {
295
+ voiceStateUpdate(data: APITypes.GatewayVoiceStateUpdateData & {
295
296
  self_deaf?: boolean;
296
297
  self_mute?: boolean;
297
298
  }): Promise<void>;
@@ -299,7 +300,7 @@ declare class DiscordConnector extends EventEmitter {
299
300
  * Send an OP 8 REQUEST_GUILD_MEMBERS to the gateway.
300
301
  * @param data Data to send.
301
302
  */
302
- requestGuildMembers(data: discord_typings.GuildRequestMembersPayload & {
303
+ requestGuildMembers(data: APITypes.GatewayRequestGuildMembersData & {
303
304
  limit?: number;
304
305
  }): Promise<void>;
305
306
  /**
@@ -379,22 +380,17 @@ declare class Shard extends EventEmitter {
379
380
  * Send an OP 3 PRESENCE_UPDATE to Discord.
380
381
  * @param data Data to send.
381
382
  */
382
- presenceUpdate(data: discord_typings.GatewayPresenceUpdate): Promise<void>;
383
+ presenceUpdate(data: Parameters<Shard["connector"]["presenceUpdate"]>["0"]): Promise<void>;
383
384
  /**
384
385
  * Send an OP 4 VOICE_STATE_UPDATE to Discord.
385
386
  * @param data Data to send
386
387
  */
387
- voiceStateUpdate(data: discord_typings.VoiceStateUpdatePayload & {
388
- self_deaf?: boolean;
389
- self_mute?: boolean;
390
- }): Promise<void>;
388
+ voiceStateUpdate(data: Parameters<Shard["connector"]["voiceStateUpdate"]>["0"]): Promise<void>;
391
389
  /**
392
390
  * Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
393
391
  * @param data Data to send.
394
392
  */
395
- requestGuildMembers(data: discord_typings.GuildRequestMembersPayload & {
396
- limit?: number;
397
- }): Promise<void>;
393
+ requestGuildMembers(data: Parameters<Shard["connector"]["requestGuildMembers"]>["0"]): Promise<void>;
398
394
  }
399
395
 
400
396
  /**
@@ -444,44 +440,38 @@ declare class ShardManager {
444
440
  * Update the status of all currently connected shards which have been spawned by this manager.
445
441
  * @param data Data to send.
446
442
  */
447
- presenceUpdate(data: discord_typings.GatewayPresenceUpdate): Promise<void>;
443
+ presenceUpdate(data: Parameters<Shard["presenceUpdate"]>["0"]): Promise<void>;
448
444
  /**
449
445
  * Update the status of a single connected shard which has been spawned by this manager.
450
446
  * @param shardId id of the shard.
451
447
  * @param data Data to send.
452
448
  */
453
- shardPresenceUpdate(shardId: number, data: discord_typings.GatewayPresenceUpdate): Promise<void>;
449
+ shardPresenceUpdate(shardId: number, data: Parameters<Shard["presenceUpdate"]>["0"]): Promise<void>;
454
450
  /**
455
451
  * Send an OP 4 VOICE_STATE_UPDATE with a certain shard.
456
452
  * @param shardId id of the shard.
457
453
  * @param data Data to send.
458
454
  */
459
- voiceStateUpdate(shardId: number, data: discord_typings.VoiceStateUpdatePayload & {
460
- self_deaf?: boolean;
461
- self_mute?: boolean;
462
- }): Promise<void>;
455
+ voiceStateUpdate(shardId: number, data: Parameters<Shard["voiceStateUpdate"]>["0"]): Promise<void>;
463
456
  /**
464
457
  * Send an OP 8 REQUEST_GUILD_MEMBERS with a certain shard.
465
458
  * @param shardId id of the shard.
466
459
  * @param data Data to send.
467
460
  */
468
- requestGuildMembers(shardId: number, data: discord_typings.GuildRequestMembersPayload & {
469
- limit?: number;
470
- }): Promise<void>;
461
+ requestGuildMembers(shardId: number, data: Parameters<Shard["requestGuildMembers"]>["0"]): Promise<void>;
471
462
  }
472
463
 
473
464
  interface ClientEvents {
474
465
  debug: [string];
475
- rawSend: [IWSMessage];
476
- rawReceive: [IGatewayMessage];
466
+ rawSend: [APITypes.GatewaySendPayload];
467
+ rawReceive: [APITypes.GatewayReceivePayload];
468
+ error: [string];
477
469
  event: [IGatewayMessage];
478
- dispatch: [IGatewayMessage];
479
- voiceStateUpdate: [IGatewayMessage];
470
+ dispatch: [IGatewayDispatch];
480
471
  shardReady: [{
481
472
  id: number;
482
473
  ready: boolean;
483
474
  }];
484
- error: [string];
485
475
  ready: [];
486
476
  disconnected: [];
487
477
  }
@@ -538,11 +528,7 @@ declare class Client extends EventEmitter {
538
528
  * Get the GatewayData including recommended amount of shards and other helpful info.
539
529
  * @returns Object with url and shards to use to connect to discord.
540
530
  */
541
- getGatewayBot(): Promise<{
542
- url: string;
543
- shards: number;
544
- session_start_limit: discord_typings.SessionStartLimit;
545
- }>;
531
+ getGatewayBot(): Promise<APITypes.RESTGetAPIGatewayBotResult>;
546
532
  /**
547
533
  * Disconnect the bot gracefully,
548
534
  * you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections.
@@ -553,17 +539,17 @@ declare class Client extends EventEmitter {
553
539
  * @returns Promise that's resolved once all shards have sent the websocket payload.
554
540
  *
555
541
  * @example
556
- * // Connect to Discord and set status to do not disturb and game to "Memes are Dreams".
542
+ * // Connect to Discord and set status to do not disturb and activity to "Memes are Dreams".
557
543
  * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
558
544
  * const token = "token";
559
545
  * const client = new CloudStorm.Client(token);
560
546
  * client.connect();
561
547
  * client.once("ready", () => {
562
548
  * // Client is connected to Discord and is ready, so we can update the status.
563
- * client.presenceUpdate({ status: "dnd", game: { name: "Memes are Dreams" } });
549
+ * client.presenceUpdate({ status: "dnd", activities: [{ name: "Memes are Dreams", type: 0 }] });
564
550
  * });
565
551
  */
566
- presenceUpdate(data: discord_typings.GatewayPresenceUpdate): Promise<void>;
552
+ presenceUpdate(data: Parameters<Client["shardManager"]["presenceUpdate"]>["0"]): Promise<void>;
567
553
  /**
568
554
  * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
569
555
  * @param shardId id of the shard that should update it's status.
@@ -571,17 +557,17 @@ declare class Client extends EventEmitter {
571
557
  * @returns Promise that's resolved once the shard has sent the websocket payload.
572
558
  *
573
559
  * @example
574
- * // Connect to Discord and set status to do not disturb and game to "Im shard 0".
560
+ * // Connect to Discord and set status to do not disturb and activity to "Im shard 0".
575
561
  * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
576
562
  * const token = "token";
577
563
  * const client = new CloudStorm.Client(token);
578
564
  * client.connect();
579
565
  * client.once("ready", () => {
580
566
  * // Client is connected to Discord and is ready, so we can update the status of shard 0.
581
- * client.shardPresenceUpdate(0, { status: "dnd", game: { name: "Im shard 0" } });
567
+ * client.shardPresenceUpdate(0, { status: "dnd", activities: [{ name: "Im shard 0", type: 0 }] });
582
568
  * });
583
569
  */
584
- shardStatusUpdate(shardId: number, data: discord_typings.GatewayPresenceUpdate): Promise<void>;
570
+ shardStatusUpdate(shardId: number, data: Parameters<Client["shardManager"]["shardPresenceUpdate"]>["1"]): Promise<void>;
585
571
  /**
586
572
  * Send an OP 4 VOICE_STATE_UPDATE to Discord. this does **not** allow you to send audio with CloudStorm itself,
587
573
  * it just provides the necessary data for another application to send audio data to Discord.
@@ -601,10 +587,7 @@ declare class Client extends EventEmitter {
601
587
  * client.voiceStateUpdate(0, { guild_id: "id", channel_id: "id", self_mute: false, self_deaf: false });
602
588
  * });
603
589
  */
604
- voiceStateUpdate(shardId: number, data: discord_typings.VoiceStateUpdatePayload & {
605
- self_deaf?: boolean;
606
- self_mute?: boolean;
607
- }): Promise<void>;
590
+ voiceStateUpdate(shardId: number, data: Parameters<Client["shardManager"]["voiceStateUpdate"]>["1"]): Promise<void>;
608
591
  /**
609
592
  * Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
610
593
  * @param shardId id of the shard that should send the payload.
@@ -623,9 +606,7 @@ declare class Client extends EventEmitter {
623
606
  * client.requestGuildMembers(0, { guild_id: "id" });
624
607
  * });
625
608
  */
626
- requestGuildMembers(shardId: number, data: discord_typings.GuildRequestMembersPayload & {
627
- limit?: number;
628
- }): Promise<void>;
609
+ requestGuildMembers(shardId: number, data: Parameters<Client["shardManager"]["requestGuildMembers"]>["1"]): Promise<void>;
629
610
  /**
630
611
  * Update the endpoint shard websockets will connect to.
631
612
  * @param gatewayUrl Base gateway wss url to update the cached endpoint to.
@@ -683,4 +664,4 @@ declare const Constants: {
683
664
  GATEWAY_VERSION: 10;
684
665
  };
685
666
 
686
- export { Client, Constants, IClientOptions, IClientWSOptions, IGatewayMessage, IWSMessage, _default as Intents, Shard, ShardManager };
667
+ export { Client, Constants, IClientOptions, IClientWSOptions, IGatewayDispatch, IGatewayMessage, _default as Intents, Shard, ShardManager };