aboutsummaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/util
diff options
context:
space:
mode:
authorAlee14 <alee14498@gmail.com>2017-03-26 15:18:10 -0400
committerAlee14 <alee14498@gmail.com>2017-03-26 15:18:10 -0400
commit29433e2f7dbd0e4a73d3c78ffe1005b922fb5982 (patch)
treeaa0ad3fe59468cbe452ee597e914839b68c01436 /node_modules/discord.js/src/util
parent878fefb4c4e1f12b804ae5c0def433fa873f4c8b (diff)
downloadAleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.gz
AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.tar.bz2
AleeBot-29433e2f7dbd0e4a73d3c78ffe1005b922fb5982.zip
Don't mind me i'm adding the discord.js files
Diffstat (limited to 'node_modules/discord.js/src/util')
-rw-r--r--node_modules/discord.js/src/util/ArraysEqual.js14
-rw-r--r--node_modules/discord.js/src/util/CloneObject.js5
-rw-r--r--node_modules/discord.js/src/util/Collection.js365
-rw-r--r--node_modules/discord.js/src/util/Constants.js371
-rw-r--r--node_modules/discord.js/src/util/ConvertArrayBuffer.js18
-rw-r--r--node_modules/discord.js/src/util/EscapeMarkdown.js5
-rw-r--r--node_modules/discord.js/src/util/FetchRecommendedShards.js19
-rw-r--r--node_modules/discord.js/src/util/MakeError.js6
-rw-r--r--node_modules/discord.js/src/util/MakePlainError.js7
-rw-r--r--node_modules/discord.js/src/util/MergeDefault.js12
-rw-r--r--node_modules/discord.js/src/util/ParseEmoji.js14
-rw-r--r--node_modules/discord.js/src/util/SplitMessage.js16
12 files changed, 852 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/util/ArraysEqual.js b/node_modules/discord.js/src/util/ArraysEqual.js
new file mode 100644
index 0000000..efd8275
--- /dev/null
+++ b/node_modules/discord.js/src/util/ArraysEqual.js
@@ -0,0 +1,14 @@
+module.exports = function arraysEqual(a, b) {
+ if (a === b) return true;
+ if (a.length !== b.length) return false;
+
+ for (const itemInd in a) {
+ const item = a[itemInd];
+ const ind = b.indexOf(item);
+ if (ind) {
+ b.splice(ind, 1);
+ }
+ }
+
+ return b.length === 0;
+};
diff --git a/node_modules/discord.js/src/util/CloneObject.js b/node_modules/discord.js/src/util/CloneObject.js
new file mode 100644
index 0000000..13366a7
--- /dev/null
+++ b/node_modules/discord.js/src/util/CloneObject.js
@@ -0,0 +1,5 @@
+module.exports = function cloneObject(obj) {
+ const cloned = Object.create(obj);
+ Object.assign(cloned, obj);
+ return cloned;
+};
diff --git a/node_modules/discord.js/src/util/Collection.js b/node_modules/discord.js/src/util/Collection.js
new file mode 100644
index 0000000..bafe710
--- /dev/null
+++ b/node_modules/discord.js/src/util/Collection.js
@@ -0,0 +1,365 @@
+/**
+ * A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
+ * an ID, for significantly improved performance and ease-of-use.
+ * @extends {Map}
+ */
+class Collection extends Map {
+ constructor(iterable) {
+ super(iterable);
+
+ /**
+ * Cached array for the `array()` method - will be reset to `null` whenever `set()` or `delete()` are called.
+ * @type {?Array}
+ * @private
+ */
+ this._array = null;
+
+ /**
+ * Cached array for the `keyArray()` method - will be reset to `null` whenever `set()` or `delete()` are called.
+ * @type {?Array}
+ * @private
+ */
+ this._keyArray = null;
+ }
+
+ set(key, val) {
+ this._array = null;
+ this._keyArray = null;
+ return super.set(key, val);
+ }
+
+ delete(key) {
+ this._array = null;
+ this._keyArray = null;
+ return super.delete(key);
+ }
+
+ /**
+ * Creates an ordered array of the values of this collection, and caches it internally. The array will only be
+ * reconstructed if an item is added to or removed from the collection, or if you change the length of the array
+ * itself. If you don't want this caching behaviour, use `Array.from(collection.values())` instead.
+ * @returns {Array}
+ */
+ array() {
+ if (!this._array || this._array.length !== this.size) this._array = Array.from(this.values());
+ return this._array;
+ }
+
+ /**
+ * Creates an ordered array of the keys of this collection, and caches it internally. The array will only be
+ * reconstructed if an item is added to or removed from the collection, or if you change the length of the array
+ * itself. If you don't want this caching behaviour, use `Array.from(collection.keys())` instead.
+ * @returns {Array}
+ */
+ keyArray() {
+ if (!this._keyArray || this._keyArray.length !== this.size) this._keyArray = Array.from(this.keys());
+ return this._keyArray;
+ }
+
+ /**
+ * Obtains the first item in this collection.
+ * @returns {*}
+ */
+ first() {
+ return this.values().next().value;
+ }
+
+ /**
+ * Obtains the first key in this collection.
+ * @returns {*}
+ */
+ firstKey() {
+ return this.keys().next().value;
+ }
+
+ /**
+ * Obtains the last item in this collection. This relies on the `array()` method, and thus the caching mechanism
+ * applies here as well.
+ * @returns {*}
+ */
+ last() {
+ const arr = this.array();
+ return arr[arr.length - 1];
+ }
+
+ /**
+ * Obtains the last key in this collection. This relies on the `keyArray()` method, and thus the caching mechanism
+ * applies here as well.
+ * @returns {*}
+ */
+ lastKey() {
+ const arr = this.keyArray();
+ return arr[arr.length - 1];
+ }
+
+ /**
+ * Obtains a random item from this collection. This relies on the `array()` method, and thus the caching mechanism
+ * applies here as well.
+ * @returns {*}
+ */
+ random() {
+ const arr = this.array();
+ return arr[Math.floor(Math.random() * arr.length)];
+ }
+
+ /**
+ * Obtains a random key from this collection. This relies on the `keyArray()` method, and thus the caching mechanism
+ * applies here as well.
+ * @returns {*}
+ */
+ randomKey() {
+ const arr = this.keyArray();
+ return arr[Math.floor(Math.random() * arr.length)];
+ }
+
+ /**
+ * Searches for all items where their specified property's value is identical to the given value
+ * (`item[prop] === value`).
+ * @param {string} prop The property to test against
+ * @param {*} value The expected value
+ * @returns {Array}
+ * @example
+ * collection.findAll('username', 'Bob');
+ */
+ findAll(prop, value) {
+ if (typeof prop !== 'string') throw new TypeError('Key must be a string.');
+ if (typeof value === 'undefined') throw new Error('Value must be specified.');
+ const results = [];
+ for (const item of this.values()) {
+ if (item[prop] === value) results.push(item);
+ }
+ return results;
+ }
+
+ /**
+ * Searches for a single item where its specified property's value is identical to the given value
+ * (`item[prop] === value`), or the given function returns a truthy value. In the latter case, this is identical to
+ * [Array.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
+ * <warn>Do not use this to obtain an item by its ID. Instead, use `collection.get(id)`. See
+ * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.</warn>
+ * @param {string|Function} propOrFn The property to test against, or the function to test with
+ * @param {*} [value] The expected value - only applicable and required if using a property for the first argument
+ * @returns {*}
+ * @example
+ * collection.find('username', 'Bob');
+ * @example
+ * collection.find(val => val.username === 'Bob');
+ */
+ find(propOrFn, value) {
+ if (typeof propOrFn === 'string') {
+ if (typeof value === 'undefined') throw new Error('Value must be specified.');
+ if (propOrFn === 'id') throw new RangeError('Don\'t use .find() with IDs. Instead, use .get(id).');
+ for (const item of this.values()) {
+ if (item[propOrFn] === value) return item;
+ }
+ return null;
+ } else if (typeof propOrFn === 'function') {
+ for (const [key, val] of this) {
+ if (propOrFn(val, key, this)) return val;
+ }
+ return null;
+ } else {
+ throw new Error('First argument must be a property string or a function.');
+ }
+ }
+
+ /* eslint-disable max-len */
+ /**
+ * Searches for the key of a single item where its specified property's value is identical to the given value
+ * (`item[prop] === value`), or the given function returns a truthy value. In the latter case, this is identical to
+ * [Array.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex).
+ * @param {string|Function} propOrFn The property to test against, or the function to test with
+ * @param {*} [value] The expected value - only applicable and required if using a property for the first argument
+ * @returns {*}
+ * @example
+ * collection.findKey('username', 'Bob');
+ * @example
+ * collection.findKey(val => val.username === 'Bob');
+ */
+ /* eslint-enable max-len */
+ findKey(propOrFn, value) {
+ if (typeof propOrFn === 'string') {
+ if (typeof value === 'undefined') throw new Error('Value must be specified.');
+ for (const [key, val] of this) {
+ if (val[propOrFn] === value) return key;
+ }
+ return null;
+ } else if (typeof propOrFn === 'function') {
+ for (const [key, val] of this) {
+ if (propOrFn(val, key, this)) return key;
+ }
+ return null;
+ } else {
+ throw new Error('First argument must be a property string or a function.');
+ }
+ }
+
+ /**
+ * Searches for the existence of a single item where its specified property's value is identical to the given value
+ * (`item[prop] === value`).
+ * <warn>Do not use this to check for an item by its ID. Instead, use `collection.has(id)`. See
+ * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has) for details.</warn>
+ * @param {string} prop The property to test against
+ * @param {*} value The expected value
+ * @returns {boolean}
+ * @example
+ * if (collection.exists('username', 'Bob')) {
+ * console.log('user here!');
+ * }
+ */
+ exists(prop, value) {
+ if (prop === 'id') throw new RangeError('Don\'t use .exists() with IDs. Instead, use .has(id).');
+ return Boolean(this.find(prop, value));
+ }
+
+ /**
+ * Identical to
+ * [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),
+ * but returns a Collection instead of an Array.
+ * @param {Function} fn Function used to test (should return a boolean)
+ * @param {Object} [thisArg] Value to use as `this` when executing function
+ * @returns {Collection}
+ */
+ filter(fn, thisArg) {
+ if (thisArg) fn = fn.bind(thisArg);
+ const results = new Collection();
+ for (const [key, val] of this) {
+ if (fn(val, key, this)) results.set(key, val);
+ }
+ return results;
+ }
+
+ /**
+ * Identical to
+ * [Array.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
+ * @param {Function} fn Function used to test (should return a boolean)
+ * @param {Object} [thisArg] Value to use as `this` when executing function
+ * @returns {Array}
+ */
+ filterArray(fn, thisArg) {
+ if (thisArg) fn = fn.bind(thisArg);
+ const results = [];
+ for (const [key, val] of this) {
+ if (fn(val, key, this)) results.push(val);
+ }
+ return results;
+ }
+
+ /**
+ * Identical to
+ * [Array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
+ * @param {Function} fn Function that produces an element of the new array, taking three arguments
+ * @param {*} [thisArg] Value to use as `this` when executing function
+ * @returns {Array}
+ */
+ map(fn, thisArg) {
+ if (thisArg) fn = fn.bind(thisArg);
+ const arr = new Array(this.size);
+ let i = 0;
+ for (const [key, val] of this) arr[i++] = fn(val, key, this);
+ return arr;
+ }
+
+ /**
+ * Identical to
+ * [Array.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).
+ * @param {Function} fn Function used to test (should return a boolean)
+ * @param {Object} [thisArg] Value to use as `this` when executing function
+ * @returns {boolean}
+ */
+ some(fn, thisArg) {
+ if (thisArg) fn = fn.bind(thisArg);
+ for (const [key, val] of this) {
+ if (fn(val, key, this)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Identical to
+ * [Array.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).
+ * @param {Function} fn Function used to test (should return a boolean)
+ * @param {Object} [thisArg] Value to use as `this` when executing function
+ * @returns {boolean}
+ */
+ every(fn, thisArg) {
+ if (thisArg) fn = fn.bind(thisArg);
+ for (const [key, val] of this) {
+ if (!fn(val, key, this)) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Identical to
+ * [Array.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
+ * @param {Function} fn Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
+ * and `collection`
+ * @param {*} [initialValue] Starting value for the accumulator
+ * @returns {*}
+ */
+ reduce(fn, initialValue) {
+ let accumulator;
+ if (typeof initialValue !== 'undefined') {
+ accumulator = initialValue;
+ for (const [key, val] of this) accumulator = fn(accumulator, val, key, this);
+ } else {
+ let first = true;
+ for (const [key, val] of this) {
+ if (first) {
+ accumulator = val;
+ first = false;
+ continue;
+ }
+ accumulator = fn(accumulator, val, key, this);
+ }
+ }
+ return accumulator;
+ }
+
+ /**
+ * Combines this collection with others into a new collection. None of the source collections are modified.
+ * @param {...Collection} collections Collections to merge
+ * @returns {Collection}
+ * @example const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
+ */
+ concat(...collections) {
+ const newColl = new this.constructor();
+ for (const [key, val] of this) newColl.set(key, val);
+ for (const coll of collections) {
+ for (const [key, val] of coll) newColl.set(key, val);
+ }
+ return newColl;
+ }
+
+ /**
+ * Calls the `delete()` method on all items that have it.
+ * @returns {Promise[]}
+ */
+ deleteAll() {
+ const returns = [];
+ for (const item of this.values()) {
+ if (item.delete) returns.push(item.delete());
+ }
+ return returns;
+ }
+
+ /**
+ * Checks if this collection shares identical key-value pairings with another.
+ * This is different to checking for equality using equal-signs, because
+ * the collections may be different objects, but contain the same data.
+ * @param {Collection} collection Collection to compare with
+ * @returns {boolean} Whether the collections have identical contents
+ */
+ equals(collection) {
+ if (!collection) return false;
+ if (this === collection) return true;
+ if (this.size !== collection.size) return false;
+ return !this.find((value, key) => {
+ const testVal = collection.get(key);
+ return testVal !== value || (testVal === undefined && !collection.has(key));
+ });
+ }
+}
+
+module.exports = Collection;
diff --git a/node_modules/discord.js/src/util/Constants.js b/node_modules/discord.js/src/util/Constants.js
new file mode 100644
index 0000000..cee2192
--- /dev/null
+++ b/node_modules/discord.js/src/util/Constants.js
@@ -0,0 +1,371 @@
+exports.Package = require('../../package.json');
+
+/**
+ * Options for a Client.
+ * @typedef {Object} ClientOptions
+ * @property {string} [apiRequestMethod='sequential'] 'sequential' or 'burst'. Sequential executes all requests in
+ * the order they are triggered, whereas burst runs multiple at a time, and doesn't guarantee a particular order.
+ * @property {number} [shardId=0] The ID of this shard
+ * @property {number} [shardCount=0] The number of shards
+ * @property {number} [messageCacheMaxSize=200] Maximum number of messages to cache per channel
+ * (-1 or Infinity for unlimited - don't do this without message sweeping, otherwise memory usage will climb
+ * indefinitely)
+ * @property {number} [messageCacheLifetime=0] How long until a message should be uncached by the message sweeping
+ * (in seconds, 0 for forever)
+ * @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than
+ * the message cache lifetime (in seconds, 0 for never)
+ * @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as
+ * upon joining a guild
+ * @property {boolean} [disableEveryone=false] Default value for MessageOptions.disableEveryone
+ * @property {boolean} [sync=false] Whether to periodically sync guilds (for userbots)
+ * @property {number} [restWsBridgeTimeout=5000] Maximum time permitted between REST responses and their
+ * corresponding websocket events
+ * @property {number} [restTimeOffset=500] The extra time in millseconds to wait before continuing to make REST
+ * requests (higher values will reduce rate-limiting errors on bad connections)
+ * @property {WSEventType[]} [disabledEvents] An array of disabled websocket events. Events in this array will not be
+ * processed, potentially resulting in performance improvements for larger bots. Only disable events you are
+ * 100% certain you don't need, as many are important, but not obviously so. The safest one to disable with the
+ * most impact is typically `TYPING_START`.
+ * @property {WebsocketOptions} [ws] Options for the websocket
+ */
+exports.DefaultOptions = {
+ apiRequestMethod: 'sequential',
+ shardId: 0,
+ shardCount: 0,
+ messageCacheMaxSize: 200,
+ messageCacheLifetime: 0,
+ messageSweepInterval: 0,
+ fetchAllMembers: false,
+ disableEveryone: false,
+ sync: false,
+ restWsBridgeTimeout: 5000,
+ disabledEvents: [],
+ restTimeOffset: 500,
+
+ /**
+ * Websocket options. These are left as snake_case to match the API.
+ * @typedef {Object} WebsocketOptions
+ * @property {number} [large_threshold=250] Number of members in a guild to be considered large
+ * @property {boolean} [compress=true] Whether to compress data sent on the connection.
+ * Defaults to `false` for browsers.
+ */
+ ws: {
+ large_threshold: 250,
+ compress: typeof window === 'undefined',
+ properties: {
+ $os: process ? process.platform : 'discord.js',
+ $browser: 'discord.js',
+ $device: 'discord.js',
+ $referrer: '',
+ $referring_domain: '',
+ },
+ },
+};
+
+exports.Errors = {
+ NO_TOKEN: 'Request to use token, but token was unavailable to the client.',
+ NO_BOT_ACCOUNT: 'Only bot accounts are able to make use of this feature.',
+ NO_USER_ACCOUNT: 'Only user accounts are able to make use of this feature.',
+ BAD_WS_MESSAGE: 'A bad message was received from the websocket; either bad compression, or not JSON.',
+ TOOK_TOO_LONG: 'Something took too long to do.',
+ NOT_A_PERMISSION: 'Invalid permission string or number.',
+ INVALID_RATE_LIMIT_METHOD: 'Unknown rate limiting method.',
+ BAD_LOGIN: 'Incorrect login details were provided.',
+ INVALID_SHARD: 'Invalid shard settings were provided.',
+ INVALID_TOKEN: 'An invalid token was provided.',
+};
+
+const PROTOCOL_VERSION = exports.PROTOCOL_VERSION = 6;
+const HOST = exports.HOST = `https://discordapp.com`;
+const API = exports.API = `${HOST}/api/v${PROTOCOL_VERSION}`;
+const Endpoints = exports.Endpoints = {
+ // general
+ login: `${API}/auth/login`,
+ logout: `${API}/auth/logout`,
+ gateway: `${API}/gateway`,
+ botGateway: `${API}/gateway/bot`,
+ invite: (id) => `${API}/invite/${id}`,
+ inviteLink: (id) => `https://discord.gg/${id}`,
+ assets: (asset) => `${HOST}/assets/${asset}`,
+ CDN: 'https://cdn.discordapp.com',
+
+ // users
+ user: (userID) => `${API}/users/${userID}`,
+ userChannels: (userID) => `${Endpoints.user(userID)}/channels`,
+ userProfile: (userID) => `${Endpoints.user(userID)}/profile`,
+ avatar: (userID, avatar) => {
+ if (userID === '1') return avatar;
+ return `${Endpoints.CDN}/avatars/${userID}/${avatar}.${avatar.startsWith('a_') ? 'gif' : 'jpg'}?size=1024`;
+ },
+ me: `${API}/users/@me`,
+ meGuild: (guildID) => `${Endpoints.me}/guilds/${guildID}`,
+ meMentions: (limit, roles, everyone, guildID) =>
+ `users/@me/mentions?limit=${limit}&roles=${roles}&everyone=${everyone}${guildID ? `&guild_id=${guildID}` : ''}`,
+ relationships: (userID) => `${Endpoints.user(userID)}/relationships`,
+ note: (userID) => `${Endpoints.me}/notes/${userID}`,
+
+ // guilds
+ guilds: `${API}/guilds`,
+ guild: (guildID) => `${Endpoints.guilds}/${guildID}`,
+ guildIcon: (guildID, hash) => `${Endpoints.CDN}/icons/${guildID}/${hash}.jpg`,
+ guildSplash: (guildID, hash) => `${Endpoints.CDN}/splashes/${guildID}/${hash}.jpg`,
+ guildPrune: (guildID) => `${Endpoints.guild(guildID)}/prune`,
+ guildEmbed: (guildID) => `${Endpoints.guild(guildID)}/embed`,
+ guildInvites: (guildID) => `${Endpoints.guild(guildID)}/invites`,
+ guildRoles: (guildID) => `${Endpoints.guild(guildID)}/roles`,
+ guildRole: (guildID, roleID) => `${Endpoints.guildRoles(guildID)}/${roleID}`,
+ guildBans: (guildID) => `${Endpoints.guild(guildID)}/bans`,
+ guildIntegrations: (guildID) => `${Endpoints.guild(guildID)}/integrations`,
+ guildMembers: (guildID) => `${Endpoints.guild(guildID)}/members`,
+ guildMember: (guildID, memberID) => `${Endpoints.guildMembers(guildID)}/${memberID}`,
+ guildMemberRole: (guildID, memberID, roleID) => `${Endpoints.guildMember(guildID, memberID)}/roles/${roleID}`,
+ guildMemberNickname: (guildID) => `${Endpoints.guildMember(guildID, '@me')}/nick`,
+ guildChannels: (guildID) => `${Endpoints.guild(guildID)}/channels`,
+ guildEmojis: (guildID) => `${Endpoints.guild(guildID)}/emojis`,
+
+ // channels
+ channels: `${API}/channels`,
+ channel: (channelID) => `${Endpoints.channels}/${channelID}`,
+ channelMessages: (channelID) => `${Endpoints.channel(channelID)}/messages`,
+ channelInvites: (channelID) => `${Endpoints.channel(channelID)}/invites`,
+ channelTyping: (channelID) => `${Endpoints.channel(channelID)}/typing`,
+ channelPermissions: (channelID) => `${Endpoints.channel(channelID)}/permissions`,
+ channelMessage: (channelID, messageID) => `${Endpoints.channelMessages(channelID)}/${messageID}`,
+ channelWebhooks: (channelID) => `${Endpoints.channel(channelID)}/webhooks`,
+
+ // message reactions
+ messageReactions: (channelID, messageID) => `${Endpoints.channelMessage(channelID, messageID)}/reactions`,
+ messageReaction:
+ (channel, msg, emoji, limit) =>
+ `${Endpoints.messageReactions(channel, msg)}/${emoji}` +
+ `${limit ? `?limit=${limit}` : ''}`,
+ selfMessageReaction: (channel, msg, emoji, limit) =>
+ `${Endpoints.messageReaction(channel, msg, emoji, limit)}/@me`,
+ userMessageReaction: (channel, msg, emoji, limit, id) =>
+ `${Endpoints.messageReaction(channel, msg, emoji, limit)}/${id}`,
+
+ // webhooks
+ webhook: (webhookID, token) => `${API}/webhooks/${webhookID}${token ? `/${token}` : ''}`,
+
+ // oauth
+ myApplication: `${API}/oauth2/applications/@me`,
+ getApp: (id) => `${API}/oauth2/authorize?client_id=${id}`,
+
+ // emoji
+ emoji: (emojiID) => `${Endpoints.CDN}/emojis/${emojiID}.png`,
+};
+
+exports.Status = {
+ READY: 0,
+ CONNECTING: 1,
+ RECONNECTING: 2,
+ IDLE: 3,
+ NEARLY: 4,
+ DISCONNECTED: 5,
+};
+
+exports.ChannelTypes = {
+ text: 0,
+ DM: 1,
+ voice: 2,
+ groupDM: 3,
+};
+
+exports.OPCodes = {
+ DISPATCH: 0,
+ HEARTBEAT: 1,
+ IDENTIFY: 2,
+ STATUS_UPDATE: 3,
+ VOICE_STATE_UPDATE: 4,
+ VOICE_GUILD_PING: 5,
+ RESUME: 6,
+ RECONNECT: 7,
+ REQUEST_GUILD_MEMBERS: 8,
+ INVALID_SESSION: 9,
+ HELLO: 10,
+ HEARTBEAT_ACK: 11,
+};
+
+exports.VoiceOPCodes = {
+ IDENTIFY: 0,
+ SELECT_PROTOCOL: 1,
+ READY: 2,
+ HEARTBEAT: 3,
+ SESSION_DESCRIPTION: 4,
+ SPEAKING: 5,
+};
+
+exports.Events = {
+ READY: 'ready',
+ GUILD_CREATE: 'guildCreate',
+ GUILD_DELETE: 'guildDelete',
+ GUILD_UPDATE: 'guildUpdate',
+ GUILD_UNAVAILABLE: 'guildUnavailable',
+ GUILD_AVAILABLE: 'guildAvailable',
+ GUILD_MEMBER_ADD: 'guildMemberAdd',
+ GUILD_MEMBER_REMOVE: 'guildMemberRemove',
+ GUILD_MEMBER_UPDATE: 'guildMemberUpdate',
+ GUILD_MEMBER_AVAILABLE: 'guildMemberAvailable',
+ GUILD_MEMBER_SPEAKING: 'guildMemberSpeaking',
+ GUILD_MEMBERS_CHUNK: 'guildMembersChunk',
+ GUILD_ROLE_CREATE: 'roleCreate',
+ GUILD_ROLE_DELETE: 'roleDelete',
+ GUILD_ROLE_UPDATE: 'roleUpdate',
+ GUILD_EMOJI_CREATE: 'emojiCreate',
+ GUILD_EMOJI_DELETE: 'emojiDelete',
+ GUILD_EMOJI_UPDATE: 'emojiUpdate',
+ GUILD_BAN_ADD: 'guildBanAdd',
+ GUILD_BAN_REMOVE: 'guildBanRemove',
+ CHANNEL_CREATE: 'channelCreate',
+ CHANNEL_DELETE: 'channelDelete',
+ CHANNEL_UPDATE: 'channelUpdate',
+ CHANNEL_PINS_UPDATE: 'channelPinsUpdate',
+ MESSAGE_CREATE: 'message',
+ MESSAGE_DELETE: 'messageDelete',
+ MESSAGE_UPDATE: 'messageUpdate',
+ MESSAGE_BULK_DELETE: 'messageDeleteBulk',
+ MESSAGE_REACTION_ADD: 'messageReactionAdd',
+ MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
+ MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll',
+ USER_UPDATE: 'userUpdate',
+ USER_NOTE_UPDATE: 'userNoteUpdate',
+ PRESENCE_UPDATE: 'presenceUpdate',
+ VOICE_STATE_UPDATE: 'voiceStateUpdate',
+ TYPING_START: 'typingStart',
+ TYPING_STOP: 'typingStop',
+ DISCONNECT: 'disconnect',
+ RECONNECTING: 'reconnecting',
+ ERROR: 'error',
+ WARN: 'warn',
+ DEBUG: 'debug',
+};
+
+/**
+ * The type of a websocket message event, e.g. `MESSAGE_CREATE`. Here are the available events:
+ * - READY
+ * - GUILD_SYNC
+ * - GUILD_CREATE
+ * - GUILD_DELETE
+ * - GUILD_UPDATE
+ * - GUILD_MEMBER_ADD
+ * - GUILD_MEMBER_REMOVE
+ * - GUILD_MEMBER_UPDATE
+ * - GUILD_MEMBERS_CHUNK
+ * - GUILD_ROLE_CREATE
+ * - GUILD_ROLE_DELETE
+ * - GUILD_ROLE_UPDATE
+ * - GUILD_BAN_ADD
+ * - GUILD_BAN_REMOVE
+ * - CHANNEL_CREATE
+ * - CHANNEL_DELETE
+ * - CHANNEL_UPDATE
+ * - CHANNEL_PINS_UPDATE
+ * - MESSAGE_CREATE
+ * - MESSAGE_DELETE
+ * - MESSAGE_UPDATE
+ * - MESSAGE_DELETE_BULK
+ * - MESSAGE_REACTION_ADD
+ * - MESSAGE_REACTION_REMOVE
+ * - MESSAGE_REACTION_REMOVE_ALL
+ * - USER_UPDATE
+ * - USER_NOTE_UPDATE
+ * - PRESENCE_UPDATE
+ * - VOICE_STATE_UPDATE
+ * - TYPING_START
+ * - VOICE_SERVER_UPDATE
+ * - RELATIONSHIP_ADD
+ * - RELATIONSHIP_REMOVE
+ * @typedef {string} WSEventType
+ */
+exports.WSEvents = {
+ READY: 'READY',
+ GUILD_SYNC: 'GUILD_SYNC',
+ GUILD_CREATE: 'GUILD_CREATE',
+ GUILD_DELETE: 'GUILD_DELETE',
+ GUILD_UPDATE: 'GUILD_UPDATE',
+ GUILD_MEMBER_ADD: 'GUILD_MEMBER_ADD',
+ GUILD_MEMBER_REMOVE: 'GUILD_MEMBER_REMOVE',
+ GUILD_MEMBER_UPDATE: 'GUILD_MEMBER_UPDATE',
+ GUILD_MEMBERS_CHUNK: 'GUILD_MEMBERS_CHUNK',
+ GUILD_ROLE_CREATE: 'GUILD_ROLE_CREATE',
+ GUILD_ROLE_DELETE: 'GUILD_ROLE_DELETE',
+ GUILD_ROLE_UPDATE: 'GUILD_ROLE_UPDATE',
+ GUILD_BAN_ADD: 'GUILD_BAN_ADD',
+ GUILD_BAN_REMOVE: 'GUILD_BAN_REMOVE',
+ GUILD_EMOJIS_UPDATE: 'GUILD_EMOJIS_UPDATE',
+ CHANNEL_CREATE: 'CHANNEL_CREATE',
+ CHANNEL_DELETE: 'CHANNEL_DELETE',
+ CHANNEL_UPDATE: 'CHANNEL_UPDATE',
+ CHANNEL_PINS_UPDATE: 'CHANNEL_PINS_UPDATE',
+ MESSAGE_CREATE: 'MESSAGE_CREATE',
+ MESSAGE_DELETE: 'MESSAGE_DELETE',
+ MESSAGE_UPDATE: 'MESSAGE_UPDATE',
+ MESSAGE_DELETE_BULK: 'MESSAGE_DELETE_BULK',
+ MESSAGE_REACTION_ADD: 'MESSAGE_REACTION_ADD',
+ MESSAGE_REACTION_REMOVE: 'MESSAGE_REACTION_REMOVE',
+ MESSAGE_REACTION_REMOVE_ALL: 'MESSAGE_REACTION_REMOVE_ALL',
+ USER_UPDATE: 'USER_UPDATE',
+ USER_NOTE_UPDATE: 'USER_NOTE_UPDATE',
+ PRESENCE_UPDATE: 'PRESENCE_UPDATE',
+ VOICE_STATE_UPDATE: 'VOICE_STATE_UPDATE',
+ TYPING_START: 'TYPING_START',
+ VOICE_SERVER_UPDATE: 'VOICE_SERVER_UPDATE',
+ RELATIONSHIP_ADD: 'RELATIONSHIP_ADD',
+ RELATIONSHIP_REMOVE: 'RELATIONSHIP_REMOVE',
+};
+
+exports.MessageTypes = {
+ 0: 'DEFAULT',
+ 1: 'RECIPIENT_ADD',
+ 2: 'RECIPIENT_REMOVE',
+ 3: 'CALL',
+ 4: 'CHANNEL_NAME_CHANGE',
+ 5: 'CHANNEL_ICON_CHANGE',
+ 6: 'PINS_ADD',
+};
+
+exports.DefaultAvatars = {
+ BLURPLE: '6debd47ed13483642cf09e832ed0bc1b',
+ GREY: '322c936a8c8be1b803cd94861bdfa868',
+ GREEN: 'dd4dbc0016779df1378e7812eabaa04d',
+ ORANGE: '0e291f67c9274a1abdddeb3fd919cbaa',
+ RED: '1cbd08c76f8af6dddce02c5138971129',
+};
+
+const PermissionFlags = exports.PermissionFlags = {
+ CREATE_INSTANT_INVITE: 1 << 0,
+ KICK_MEMBERS: 1 << 1,
+ BAN_MEMBERS: 1 << 2,
+ ADMINISTRATOR: 1 << 3,
+ MANAGE_CHANNELS: 1 << 4,
+ MANAGE_GUILD: 1 << 5,
+ ADD_REACTIONS: 1 << 6,
+
+ READ_MESSAGES: 1 << 10,
+ SEND_MESSAGES: 1 << 11,
+ SEND_TTS_MESSAGES: 1 << 12,
+ MANAGE_MESSAGES: 1 << 13,
+ EMBED_LINKS: 1 << 14,
+ ATTACH_FILES: 1 << 15,
+ READ_MESSAGE_HISTORY: 1 << 16,
+ MENTION_EVERYONE: 1 << 17,
+ EXTERNAL_EMOJIS: 1 << 18,
+
+ CONNECT: 1 << 20,
+ SPEAK: 1 << 21,
+ MUTE_MEMBERS: 1 << 22,
+ DEAFEN_MEMBERS: 1 << 23,
+ MOVE_MEMBERS: 1 << 24,
+ USE_VAD: 1 << 25,
+
+ CHANGE_NICKNAME: 1 << 26,
+ MANAGE_NICKNAMES: 1 << 27,
+ MANAGE_ROLES_OR_PERMISSIONS: 1 << 28,
+ MANAGE_WEBHOOKS: 1 << 29,
+ MANAGE_EMOJIS: 1 << 30,
+};
+
+let _ALL_PERMISSIONS = 0;
+for (const key in PermissionFlags) _ALL_PERMISSIONS |= PermissionFlags[key];
+exports.ALL_PERMISSIONS = _ALL_PERMISSIONS;
+exports.DEFAULT_PERMISSIONS = 104324097;
diff --git a/node_modules/discord.js/src/util/ConvertArrayBuffer.js b/node_modules/discord.js/src/util/ConvertArrayBuffer.js
new file mode 100644
index 0000000..26b1cc8
--- /dev/null
+++ b/node_modules/discord.js/src/util/ConvertArrayBuffer.js
@@ -0,0 +1,18 @@
+function arrayBufferToBuffer(ab) {
+ const buffer = new Buffer(ab.byteLength);
+ const view = new Uint8Array(ab);
+ for (var i = 0; i < buffer.length; ++i) buffer[i] = view[i];
+ return buffer;
+}
+
+function str2ab(str) {
+ const buffer = new ArrayBuffer(str.length * 2);
+ const view = new Uint16Array(buffer);
+ for (var i = 0, strLen = str.length; i < strLen; i++) view[i] = str.charCodeAt(i);
+ return buffer;
+}
+
+module.exports = function convertArrayBuffer(x) {
+ if (typeof x === 'string') x = str2ab(x);
+ return arrayBufferToBuffer(x);
+};
diff --git a/node_modules/discord.js/src/util/EscapeMarkdown.js b/node_modules/discord.js/src/util/EscapeMarkdown.js
new file mode 100644
index 0000000..9db8c13
--- /dev/null
+++ b/node_modules/discord.js/src/util/EscapeMarkdown.js
@@ -0,0 +1,5 @@
+module.exports = function escapeMarkdown(text, onlyCodeBlock = false, onlyInlineCode = false) {
+ if (onlyCodeBlock) return text.replace(/```/g, '`\u200b``');
+ if (onlyInlineCode) return text.replace(/\\(`|\\)/g, '$1').replace(/(`|\\)/g, '\\$1');
+ return text.replace(/\\(\*|_|`|~|\\)/g, '$1').replace(/(\*|_|`|~|\\)/g, '\\$1');
+};
diff --git a/node_modules/discord.js/src/util/FetchRecommendedShards.js b/node_modules/discord.js/src/util/FetchRecommendedShards.js
new file mode 100644
index 0000000..a60f510
--- /dev/null
+++ b/node_modules/discord.js/src/util/FetchRecommendedShards.js
@@ -0,0 +1,19 @@
+const superagent = require('superagent');
+const botGateway = require('./Constants').Endpoints.botGateway;
+
+/**
+ * Gets the recommended shard count from Discord
+ * @param {number} token Discord auth token
+ * @returns {Promise<number>} the recommended number of shards
+ */
+module.exports = function fetchRecommendedShards(token) {
+ return new Promise((resolve, reject) => {
+ if (!token) throw new Error('A token must be provided.');
+ superagent.get(botGateway)
+ .set('Authorization', `Bot ${token.replace(/^Bot\s*/i, '')}`)
+ .end((err, res) => {
+ if (err) reject(err);
+ resolve(res.body.shards);
+ });
+ });
+};
diff --git a/node_modules/discord.js/src/util/MakeError.js b/node_modules/discord.js/src/util/MakeError.js
new file mode 100644
index 0000000..bbc84db
--- /dev/null
+++ b/node_modules/discord.js/src/util/MakeError.js
@@ -0,0 +1,6 @@
+module.exports = function makeError(obj) {
+ const err = new Error(obj.message);
+ err.name = obj.name;
+ err.stack = obj.stack;
+ return err;
+};
diff --git a/node_modules/discord.js/src/util/MakePlainError.js b/node_modules/discord.js/src/util/MakePlainError.js
new file mode 100644
index 0000000..b409462
--- /dev/null
+++ b/node_modules/discord.js/src/util/MakePlainError.js
@@ -0,0 +1,7 @@
+module.exports = function makePlainError(err) {
+ const obj = {};
+ obj.name = err.name;
+ obj.message = err.message;
+ obj.stack = err.stack;
+ return obj;
+};
diff --git a/node_modules/discord.js/src/util/MergeDefault.js b/node_modules/discord.js/src/util/MergeDefault.js
new file mode 100644
index 0000000..b09f970
--- /dev/null
+++ b/node_modules/discord.js/src/util/MergeDefault.js
@@ -0,0 +1,12 @@
+module.exports = function merge(def, given) {
+ if (!given) return def;
+ for (const key in def) {
+ if (!{}.hasOwnProperty.call(given, key)) {
+ given[key] = def[key];
+ } else if (given[key] === Object(given[key])) {
+ given[key] = merge(def[key], given[key]);
+ }
+ }
+
+ return given;
+};
diff --git a/node_modules/discord.js/src/util/ParseEmoji.js b/node_modules/discord.js/src/util/ParseEmoji.js
new file mode 100644
index 0000000..d9f7b22
--- /dev/null
+++ b/node_modules/discord.js/src/util/ParseEmoji.js
@@ -0,0 +1,14 @@
+module.exports = function parseEmoji(text) {
+ if (text.includes('%')) {
+ text = decodeURIComponent(text);
+ }
+ if (text.includes(':')) {
+ const [name, id] = text.split(':');
+ return { name, id };
+ } else {
+ return {
+ name: text,
+ id: null,
+ };
+ }
+};
diff --git a/node_modules/discord.js/src/util/SplitMessage.js b/node_modules/discord.js/src/util/SplitMessage.js
new file mode 100644
index 0000000..3833f00
--- /dev/null
+++ b/node_modules/discord.js/src/util/SplitMessage.js
@@ -0,0 +1,16 @@
+module.exports = function splitMessage(text, { maxLength = 1950, char = '\n', prepend = '', append = '' } = {}) {
+ if (text.length <= maxLength) return text;
+ const splitText = text.split(char);
+ if (splitText.length === 1) throw new Error('Message exceeds the max length and contains no split characters.');
+ const messages = [''];
+ let msg = 0;
+ for (let i = 0; i < splitText.length; i++) {
+ if (messages[msg].length + splitText[i].length + 1 > maxLength) {
+ messages[msg] += append;
+ messages.push(prepend);
+ msg++;
+ }
+ messages[msg] += (messages[msg].length > 0 && messages[msg] !== prepend ? char : '') + splitText[i];
+ }
+ return messages;
+};