Skip to content

Commit

Permalink
convert a couple more structures
Browse files Browse the repository at this point in the history
  • Loading branch information
TTtie committed Sep 26, 2023
1 parent 3987ef7 commit 9e07044
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 82 deletions.
92 changes: 74 additions & 18 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,22 @@ const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
/**
* Represents the main Dysnomia client
* @extends EventEmitter
* @prop {Object?} application Object containing the bot application's ID and its public flags
* @prop {Boolean} bot Whether the user belongs to an OAuth2 application
* @prop {Object} channelGuildMap Object mapping channel IDs to guild IDs
* @prop {String} gatewayURL The URL for the discord gateway
* @prop {Collection<Guild>} guilds Collection of guilds the bot is in
* @prop {Object} guildShardMap Object mapping guild IDs to shard IDs
* @prop {Object} options Dysnomia options
* @prop {Object} privateChannelMap Object mapping user IDs to private channel IDs
* @prop {Collection<PrivateChannel>} privateChannels Collection of private channels the bot is in
* @prop {RequestHandler} requestHandler The request handler the client will use
* @prop {Collection<Shard>} shards Collection of shards Dysnomia is using
* @prop {Number} startTime Timestamp of bot ready event
* @prop {Object} threadGuildMap Object mapping thread channel IDs to guild IDs
* @prop {Collection<UnavailableGuild>} unavailableGuilds Collection of unavailable guilds the bot is in
* @prop {Number} uptime How long in milliseconds the bot has been up for
* @prop {ExtendedUser} user The bot user
* @prop {Collection<User>} users Collection of users the bot sees
* @prop {Collection<VoiceConnection>} voiceConnections Extended collection of active VoiceConnections the bot has
*/
class Client extends EventEmitter {
/**
* Object mapping channel IDs to guild IDs
* @type {Object<string, string>}
*/
channelGuildMap = {};
/**
* Collection of guilds the bot is in
* @type {Collection<Guild>}
*/
guilds = new Collection(Guild);
/**
* Object mapping guild IDs to shard IDs
* @type {Object<string, number>}
*/
guildShardMap = {};
lastConnect = 0;
lastReconnectDelay = 0;
Expand All @@ -77,16 +71,54 @@ class Client extends EventEmitter {
since: null,
status: "offline"
};
/**
* Object mapping user IDs to private channel IDs
* @type {Object<string, string>}
*/
privateChannelMap = {};
/**
* Collection of private channels the bot is in
* @type {Collection<PrivateChannel>}
*/
privateChannels = new Collection(PrivateChannel);
ready = false;
reconnectAttempts = 0;
/**
* Timestamp of bot ready event
* @type {Number}
*/
startTime = 0;
/**
* Object mapping thread channel IDs to guild IDs
* @type {Object<string, string>}
*/
threadGuildMap = {};
/**
* Collection of unavailable guilds the bot is in
* @type {Collection<UnavailableGuild>}
*/
unavailableGuilds = new Collection(UnavailableGuild);
/**
* Collection of users the bot sees
* @type {Collection<User>}
*/
users = new Collection(User);
/**
* Extended collection of active VoiceConnections the bot has
* @type {Collection<VoiceConnection>}
*/
voiceConnections = new VoiceConnectionManager();

/**
* Object containing the bot application's ID and its public flags
* @member {Object?} Client#application
*/

/**
* The bot user
* @member {ExtendedUser} Client#user
*/

/**
* Create a Client
* @arg {String} token The auth token to use. Bot tokens should be prefixed with `Bot` (e.g. `Bot MTExIHlvdSAgdHJpZWQgMTEx.O5rKAA.dQw4w9WgXcQ_wpV-gGA4PSk_bm8`).
Expand Down Expand Up @@ -134,6 +166,10 @@ class Client extends EventEmitter {
constructor(token, options) {
super();

/**
* Dysnomia options
* @type {Object}
*/
this.options = Object.assign({
allowedMentions: {
users: true,
Expand Down Expand Up @@ -169,17 +205,33 @@ class Client extends EventEmitter {
value: token
});

/**
* The request handler the client will use
* @type {RequestHandler}
*/
this.requestHandler = new RequestHandler(this, this.options.rest);
delete this.options.rest;

/**
* Collection of shards Dysnomia is using
* @type {Collection<Shard>}
*/
this.shards = new ShardManager(this, this.options.gateway);
delete this.options.gateway;

/**
* Whether the user belongs to an OAuth2 application
* @type {Boolean}
*/
this.bot = this._token.startsWith("Bot ");

this.connect = this.connect.bind(this);
}

/**
* How long in milliseconds the bot has been up for
* @type {Number}
*/
get uptime() {
return this.startTime ? Date.now() - this.startTime : 0;
}
Expand Down Expand Up @@ -335,6 +387,10 @@ class Client extends EventEmitter {
if(!data.url.endsWith("/")) {
data.url += "/";
}
/**
* The URL for the discord gateway
* @type {String}
*/
this.gatewayURL = `${data.url}?v=${Constants.GATEWAY_VERSION}&encoding=${Erlpack ? "etf" : "json"}`;

if(this.shards.options.compress) {
Expand Down
Loading

0 comments on commit 9e07044

Please sign in to comment.