diff options
| author | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:48:28 -0700 |
| commit | f9159ea2d994e14180fb02ab562f0119513e67cf (patch) | |
| tree | 09d14cdf05456567156738b681379d4bccd64e5c /node_modules/discord.js/src/util | |
| parent | 2020/04/03, 02:42, V1.2.1 (diff) | |
| download | s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.tar.xz s5nical-f9159ea2d994e14180fb02ab562f0119513e67cf.zip | |
2020/04/03, 02:47, V1.2.2
Diffstat (limited to 'node_modules/discord.js/src/util')
| -rw-r--r-- | node_modules/discord.js/src/util/BitField.js | 160 | ||||
| -rw-r--r-- | node_modules/discord.js/src/util/Collection.js | 532 | ||||
| -rw-r--r-- | node_modules/discord.js/src/util/Constants.js | 943 | ||||
| -rw-r--r-- | node_modules/discord.js/src/util/MessageFlags.js | 36 | ||||
| -rw-r--r-- | node_modules/discord.js/src/util/Permissions.js | 234 | ||||
| -rw-r--r-- | node_modules/discord.js/src/util/Snowflake.js | 82 | ||||
| -rw-r--r-- | node_modules/discord.js/src/util/SystemChannelFlags.js | 31 | ||||
| -rw-r--r-- | node_modules/discord.js/src/util/Util.js | 238 |
8 files changed, 0 insertions, 2256 deletions
diff --git a/node_modules/discord.js/src/util/BitField.js b/node_modules/discord.js/src/util/BitField.js deleted file mode 100644 index e0f86b1..0000000 --- a/node_modules/discord.js/src/util/BitField.js +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Data structure that makes it easy to interact with a bitfield. - */ -class BitField { - /** - * @param {BitFieldResolvable} [bits=0] Bits(s) to read from - */ - constructor(bits) { - /** - * Bitfield of the packed bits - * @type {number} - */ - this.bitfield = this.constructor.resolve(bits); - } - - /** - * Checks whether the bitfield has a bit, or any of multiple bits. - * @param {BitFieldResolvable} bit Bit(s) to check for - * @returns {boolean} - */ - any(bit) { - return (this.bitfield & this.constructor.resolve(bit)) !== 0; - } - - /** - * Checks if this bitfield equals another - * @param {BitFieldResolvable} bit Bit(s) to check for - * @returns {boolean} - */ - equals(bit) { - return this.bitfield === this.constructor.resolve(bit); - } - - /** - * Checks whether the bitfield has a bit, or multiple bits. - * @param {BitFieldResolvable} bit Bit(s) to check for - * @returns {boolean} - */ - has(bit) { - if (Array.isArray(bit)) return bit.every(p => this.has(p)); - bit = this.constructor.resolve(bit); - return (this.bitfield & bit) === bit; - } - - /** - * Gets all given bits that are missing from the bitfield. - * @param {BitFieldResolvable} bits Bits(s) to check for - * @param {...*} hasParams Additional parameters for the has method, if any - * @returns {string[]} - */ - missing(bits, ...hasParams) { - if (!Array.isArray(bits)) bits = new this.constructor(bits).toArray(false); - return bits.filter(p => !this.has(p, ...hasParams)); - } - - /** - * Freezes these bits, making them immutable. - * @returns {Readonly<BitField>} These bits - */ - freeze() { - return Object.freeze(this); - } - - /** - * Adds bits to these ones. - * @param {...BitFieldResolvable} [bits] Bits to add - * @returns {BitField} These bits or new BitField if the instance is frozen. - */ - add(...bits) { - let total = 0; - for (const bit of bits) { - total |= this.constructor.resolve(bit); - } - if (Object.isFrozen(this)) return new this.constructor(this.bitfield | total); - this.bitfield |= total; - return this; - } - - /** - * Removes bits from these. - * @param {...BitFieldResolvable} [bits] Bits to remove - * @returns {BitField} These bits or new BitField if the instance is frozen. - */ - remove(...bits) { - let total = 0; - for (const bit of bits) { - total |= this.constructor.resolve(bit); - } - if (Object.isFrozen(this)) return new this.constructor(this.bitfield & ~total); - this.bitfield &= ~total; - return this; - } - - /** - * Gets an object mapping field names to a {@link boolean} indicating whether the - * bit is available. - * @param {...*} hasParams Additional parameters for the has method, if any - * @returns {Object} - */ - serialize(...hasParams) { - const serialized = {}; - for (const flag of Object.keys(this.constructor.FLAGS)) { - serialized[flag] = this.has(this.constructor.FLAGS[flag], ...hasParams); - } - return serialized; - } - - /** - * Gets an {@link Array} of bitfield names based on the bits available. - * @param {...*} hasParams Additional parameters for the has method, if any - * @returns {string[]} - */ - toArray(...hasParams) { - return Object.keys(this.constructor.FLAGS).filter(bit => this.has(bit, ...hasParams)); - } - - toJSON() { - return this.bitfield; - } - - valueOf() { - return this.bitfield; - } - - *[Symbol.iterator]() { - yield* this.toArray(); - } - - /** - * Data that can be resolved to give a bitfield. This can be: - * * A string (see {@link BitField.FLAGS}) - * * A bit number - * * An instance of BitField - * * An Array of BitFieldResolvable - * @typedef {string|number|BitField|BitFieldResolvable[]} BitFieldResolvable - */ - - /** - * Resolves bitfields to their numeric form. - * @param {BitFieldResolvable} [bit=0] - bit(s) to resolve - * @returns {number} - */ - static resolve(bit = 0) { - if (typeof bit === 'number' && bit >= 0) return bit; - if (bit instanceof BitField) return bit.bitfield; - if (Array.isArray(bit)) return bit.map(p => this.resolve(p)).reduce((prev, p) => prev | p, 0); - if (typeof bit === 'string' && typeof this.FLAGS[bit] !== 'undefined') return this.FLAGS[bit]; - throw new RangeError('Invalid bitfield flag or number.'); - } -} - -/** - * Numeric bitfield flags. - * <info>Defined in extension classes</info> - * @type {Object} - * @abstract - */ -BitField.FLAGS = {}; - -module.exports = BitField; diff --git a/node_modules/discord.js/src/util/Collection.js b/node_modules/discord.js/src/util/Collection.js deleted file mode 100644 index 612b67c..0000000 --- a/node_modules/discord.js/src/util/Collection.js +++ /dev/null @@ -1,532 +0,0 @@ -const util = require('util'); - -/** - * 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 - * @name Collection#_array - * @type {?Array} - * @private - */ - Object.defineProperty(this, '_array', { value: null, writable: true, configurable: true }); - - /** - * Cached array for the `keyArray()` method - will be reset to `null` whenever `set()` or `delete()` are called - * @name Collection#_keyArray - * @type {?Array} - * @private - */ - Object.defineProperty(this, '_keyArray', { value: null, writable: true, configurable: true }); - } - - 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 behavior, use `[...collection.values()]` or - * `Array.from(collection.values())` instead. - * @returns {Array} - */ - array() { - if (!this._array || this._array.length !== this.size) this._array = [...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 behavior, use `[...collection.keys()]` or - * `Array.from(collection.keys())` instead. - * @returns {Array} - */ - keyArray() { - if (!this._keyArray || this._keyArray.length !== this.size) this._keyArray = [...this.keys()]; - return this._keyArray; - } - - /** - * Obtains the first value(s) in this collection. - * @param {number} [count] Number of values to obtain from the beginning - * @returns {*|Array<*>} The single value if `count` is undefined, or an array of values of `count` length - */ - first(count) { - if (count === undefined) return this.values().next().value; - if (typeof count !== 'number') throw new TypeError('The count must be a number.'); - if (!Number.isInteger(count) || count < 1) throw new RangeError('The count must be an integer greater than 0.'); - count = Math.min(this.size, count); - const arr = new Array(count); - const iter = this.values(); - for (let i = 0; i < count; i++) arr[i] = iter.next().value; - return arr; - } - - /** - * Obtains the first key(s) in this collection. - * @param {number} [count] Number of keys to obtain from the beginning - * @returns {*|Array<*>} The single key if `count` is undefined, or an array of keys of `count` length - */ - firstKey(count) { - if (count === undefined) return this.keys().next().value; - if (typeof count !== 'number') throw new TypeError('The count must be a number.'); - if (!Number.isInteger(count) || count < 1) throw new RangeError('The count must be an integer greater than 0.'); - count = Math.min(this.size, count); - const arr = new Array(count); - const iter = this.keys(); - for (let i = 0; i < count; i++) arr[i] = iter.next().value; - return arr; - } - - /** - * Obtains the last value(s) in this collection. This relies on {@link Collection#array}, and thus the caching - * mechanism applies here as well. - * @param {number} [count] Number of values to obtain from the end - * @returns {*|Array<*>} The single value if `count` is undefined, or an array of values of `count` length - */ - last(count) { - const arr = this.array(); - if (count === undefined) return arr[arr.length - 1]; - if (typeof count !== 'number') throw new TypeError('The count must be a number.'); - if (!Number.isInteger(count) || count < 1) throw new RangeError('The count must be an integer greater than 0.'); - return arr.slice(-count); - } - - /** - * Obtains the last key(s) in this collection. This relies on {@link Collection#keyArray}, and thus the caching - * mechanism applies here as well. - * @param {number} [count] Number of keys to obtain from the end - * @returns {*|Array<*>} The single key if `count` is undefined, or an array of keys of `count` length - */ - lastKey(count) { - const arr = this.keyArray(); - if (count === undefined) return arr[arr.length - 1]; - if (typeof count !== 'number') throw new TypeError('The count must be a number.'); - if (!Number.isInteger(count) || count < 1) throw new RangeError('The count must be an integer greater than 0.'); - return arr.slice(-count); - } - - /** - * Obtains random value(s) from this collection. This relies on {@link Collection#array}, and thus the caching - * mechanism applies here as well. - * @param {number} [count] Number of values to obtain randomly - * @returns {*|Array<*>} The single value if `count` is undefined, or an array of values of `count` length - */ - random(count) { - let arr = this.array(); - if (count === undefined) return arr[Math.floor(Math.random() * arr.length)]; - if (typeof count !== 'number') throw new TypeError('The count must be a number.'); - if (!Number.isInteger(count) || count < 1) throw new RangeError('The count must be an integer greater than 0.'); - if (arr.length === 0) return []; - const rand = new Array(count); - arr = arr.slice(); - for (let i = 0; i < count; i++) rand[i] = arr.splice(Math.floor(Math.random() * arr.length), 1)[0]; - return rand; - } - - /** - * Obtains random key(s) from this collection. This relies on {@link Collection#keyArray}, and thus the caching - * mechanism applies here as well. - * @param {number} [count] Number of keys to obtain randomly - * @returns {*|Array<*>} The single key if `count` is undefined, or an array of keys of `count` length - */ - randomKey(count) { - let arr = this.keyArray(); - if (count === undefined) return arr[Math.floor(Math.random() * arr.length)]; - if (typeof count !== 'number') throw new TypeError('The count must be a number.'); - if (!Number.isInteger(count) || count < 1) throw new RangeError('The count must be an integer greater than 0.'); - if (arr.length === 0) return []; - const rand = new Array(count); - arr = arr.slice(); - for (let i = 0; i < count; i++) rand[i] = arr.splice(Math.floor(Math.random() * arr.length), 1)[0]; - return rand; - } - - /** - * 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} - * @deprecated - * @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>All collections used in Discord.js are mapped using their `id` property, and if you want to find by id you - * should use the `get` method. 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.'); - 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'); - */ - findKey(propOrFn, value) { - /* eslint-enable max-len */ - 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} - * @deprecated - * @example - * if (collection.exists('username', 'Bob')) { - * console.log('user here!'); - * } - */ - exists(prop, value) { - return Boolean(this.find(prop, value)); - } - - /** - * Removes entries that satisfy the provided filter function. - * @param {Function} fn Function used to test (should return a boolean) - * @param {Object} [thisArg] Value to use as `this` when executing function - * @returns {number} The number of removed entries - */ - sweep(fn, thisArg) { - if (thisArg) fn = fn.bind(thisArg); - const previousSize = this.size; - for (const [key, val] of this) { - if (fn(val, key, this)) this.delete(key); - } - return previousSize - this.size; - } - - /** - * 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} - * @deprecated - */ - 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; - } - - /** - * Partitions the collection into two collections where the first collection - * contains the items that passed and the second contains the items that failed. - * @param {Function} fn Function used to test (should return a boolean) - * @param {*} [thisArg] Value to use as `this` when executing function - * @returns {Collection[]} - * @example const [big, small] = collection.partition(guild => guild.memberCount > 250); - */ - partition(fn, thisArg) { - if (typeof thisArg !== 'undefined') fn = fn.bind(thisArg); - const results = [new Collection(), new Collection()]; - for (const [key, val] of this) { - if (fn(val, key, this)) { - results[0].set(key, val); - } else { - results[1].set(key, 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; - } - - /** - * Identical to - * [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach), - * but returns the collection instead of undefined. - * @param {Function} fn Function to execute for each element - * @param {*} [thisArg] Value to use as `this` when executing function - * @returns {Collection} - * @example - * collection - * .tap(user => console.log(user.username)) - * .filter(user => user.bot) - * .tap(user => console.log(user.username)); - */ - tap(fn, thisArg) { - this.forEach(fn, thisArg); - return this; - } - - /** - * Creates an identical shallow copy of this collection. - * @returns {Collection} - * @example const newColl = someColl.clone(); - */ - clone() { - return new this.constructor(this); - } - - /** - * 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 = this.clone(); - 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)); - }); - } - - /** - * The sort() method sorts the elements of a collection in place and returns the collection. - * The sort is not necessarily stable. The default sort order is according to string Unicode code points. - * @param {Function} [compareFunction] Specifies a function that defines the sort order. - * if omitted, the collection is sorted according to each character's Unicode code point value, - * according to the string conversion of each element. - * @returns {Collection} - */ - sort(compareFunction = (x, y) => +(x > y) || +(x === y) - 1) { - return new Collection([...this.entries()].sort((a, b) => compareFunction(a[1], b[1], a[0], b[0]))); - } -} - -Collection.prototype.findAll = - util.deprecate(Collection.prototype.findAll, 'Collection#findAll: use Collection#filter instead'); - -Collection.prototype.filterArray = - util.deprecate(Collection.prototype.filterArray, 'Collection#filterArray: use Collection#filter instead'); - -Collection.prototype.exists = - util.deprecate(Collection.prototype.exists, 'Collection#exists: use Collection#some instead'); - -Collection.prototype.find = function find(propOrFn, value) { - if (typeof propOrFn === 'string') { - process.emitWarning('Collection#find: pass a function instead', 'DeprecationWarning'); - if (typeof value === 'undefined') throw new Error('Value must be specified.'); - 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.'); - } -}; - -Collection.prototype.findKey = function findKey(propOrFn, value) { - if (typeof propOrFn === 'string') { - process.emitWarning('Collection#findKey: pass a function instead', 'DeprecationWarning'); - 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.'); - } -}; - -module.exports = Collection; diff --git a/node_modules/discord.js/src/util/Constants.js b/node_modules/discord.js/src/util/Constants.js deleted file mode 100644 index 3a2392b..0000000 --- a/node_modules/discord.js/src/util/Constants.js +++ /dev/null @@ -1,943 +0,0 @@ -exports.Package = require('../../package.json'); - -/** - * Options for a client. - * @typedef {Object} ClientOptions - * @property {string} [apiRequestMethod='sequential'] One of `sequential` or `burst`. The sequential handler executes - * all requests in the order they are triggered, whereas the burst handler runs multiple in parallel, and doesn't - * provide the guarantee of any particular order. Burst mode is more likely to hit a 429 ratelimit error by its nature, - * and is therefore slightly riskier to use. - * @property {number} [shardId=0] ID of the shard to run - * @property {number} [shardCount=0] Total 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 a message should stay in the cache until it is considered - * sweepable (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 (should be avoided whenever possible) - * @property {boolean} [disableEveryone=false] Default value for {@link MessageOptions#disableEveryone} - * @property {boolean} [sync=false] Whether to periodically sync guilds (for user accounts) - * @property {number} [restWsBridgeTimeout=5000] Maximum time permitted between REST responses and their - * corresponding websocket events - * @property {number} [restTimeOffset=500] Extra time in millseconds to wait before continuing to make REST - * requests (higher values will reduce rate-limiting errors on bad connections) - * @property {number} [retryLimit=Infinity] How many times to retry on 5XX errors - * (Infinity for indefinite amount of retries) - * @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 - * @property {HTTPOptions} [http] HTTP options - */ -exports.DefaultOptions = { - apiRequestMethod: 'sequential', - shardId: 0, - shardCount: 0, - messageCacheMaxSize: 200, - messageCacheLifetime: 0, - messageSweepInterval: 0, - fetchAllMembers: false, - disableEveryone: false, - sync: false, - restWsBridgeTimeout: 5000, - retryLimit: Infinity, - 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: require('os').platform() !== 'browser', - properties: { - $os: process ? process.platform : 'discord.js', - $browser: 'discord.js', - $device: 'discord.js', - $referrer: '', - $referring_domain: '', - }, - version: 6, - }, - - /** - * HTTP options - * @typedef {Object} HTTPOptions - * @property {number} [version=7] API version to use - * @property {string} [api='https://discordapp.com/api'] Base url of the API - * @property {string} [cdn='https://cdn.discordapp.com'] Base url of the CDN - * @property {string} [invite='https://discord.gg'] Base url of invites - */ - http: { - version: 7, - host: 'https://discordapp.com', - cdn: 'https://cdn.discordapp.com', - }, -}; - -exports.WSCodes = { - 1000: 'Connection gracefully closed', - 4004: 'Tried to identify with an invalid token', - 4010: 'Sharding data provided was invalid', - 4011: 'Shard would be on too many guilds if connected', -}; - -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.', - SHARDING_REQUIRED: 'This session would have handled too many guilds - Sharding is required.', - INVALID_TOKEN: 'An invalid token was provided.', -}; - -const Endpoints = exports.Endpoints = { - User: userID => { - if (userID.id) userID = userID.id; - const base = `/users/${userID}`; - return { - toString: () => base, - channels: `${base}/channels`, - profile: `${base}/profile`, - relationships: `${base}/relationships`, - settings: `${base}/settings`, - Relationship: uID => `${base}/relationships/${uID}`, - Guild: guildID => ({ - toString: () => `${base}/guilds/${guildID}`, - settings: `${base}/guilds/${guildID}/settings`, - }), - Note: id => `${base}/notes/${id}`, - Mentions: (limit, roles, everyone, guildID) => - `${base}/mentions?limit=${limit}&roles=${roles}&everyone=${everyone}${guildID ? `&guild_id=${guildID}` : ''}`, - Avatar: (root, hash) => { - if (userID === '1') return hash; - return Endpoints.CDN(root).Avatar(userID, hash); - }, - }; - }, - guilds: '/guilds', - Guild: guildID => { - if (guildID.id) guildID = guildID.id; - const base = `/guilds/${guildID}`; - return { - toString: () => base, - prune: `${base}/prune`, - embed: `${base}/embed`, - bans: `${base}/bans`, - integrations: `${base}/integrations`, - members: `${base}/members`, - channels: `${base}/channels`, - invites: `${base}/invites`, - roles: `${base}/roles`, - emojis: `${base}/emojis`, - search: `${base}/messages/search`, - vanityURL: `${base}/vanity-url`, - voiceRegions: `${base}/regions`, - webhooks: `${base}/webhooks`, - ack: `${base}/ack`, - settings: `${base}/settings`, - auditLogs: `${base}/audit-logs`, - Emoji: emojiID => `${base}/emojis/${emojiID}`, - Icon: (root, hash) => Endpoints.CDN(root).Icon(guildID, hash), - Banner: (root, hash) => Endpoints.CDN(root).Banner(guildID, hash), - Splash: (root, hash) => Endpoints.CDN(root).Splash(guildID, hash), - Role: roleID => `${base}/roles/${roleID}`, - Member: memberID => { - if (memberID.id) memberID = memberID.id; - const mbase = `${base}/members/${memberID}`; - return { - toString: () => mbase, - Role: roleID => `${mbase}/roles/${roleID}`, - nickname: `${base}/members/@me/nick`, - }; - }, - Integration: id => `${base}/integrations/${id}`, - }; - }, - channels: '/channels', - Channel: channelID => { - if (channelID.id) channelID = channelID.id; - const base = `/channels/${channelID}`; - return { - toString: () => base, - messages: { - toString: () => `${base}/messages`, - bulkDelete: `${base}/messages/bulk-delete`, - }, - invites: `${base}/invites`, - typing: `${base}/typing`, - permissions: `${base}/permissions`, - webhooks: `${base}/webhooks`, - search: `${base}/messages/search`, - pins: `${base}/pins`, - Icon: (root, hash) => Endpoints.CDN(root).GDMIcon(channelID, hash), - Pin: messageID => `${base}/pins/${messageID}`, - Recipient: recipientID => `${base}/recipients/${recipientID}`, - Message: messageID => { - if (messageID.id) messageID = messageID.id; - const mbase = `${base}/messages/${messageID}`; - return { - toString: () => mbase, - reactions: `${mbase}/reactions`, - ack: `${mbase}/ack`, - Reaction: emoji => { - const rbase = `${mbase}/reactions/${emoji}`; - return { - toString: () => rbase, - User: userID => `${rbase}/${userID}`, - }; - }, - }; - }, - }; - }, - Message: m => exports.Endpoints.Channel(m.channel).Message(m), - Member: m => exports.Endpoints.Guild(m.guild).Member(m), - CDN(root) { - return { - Emoji: (emojiID, format = 'png') => `${root}/emojis/${emojiID}.${format}`, - Asset: name => `${root}/assets/${name}`, - Avatar: (userID, hash) => `${root}/avatars/${userID}/${hash}.${hash.startsWith('a_') ? 'gif' : 'png?size=2048'}`, - Icon: (guildID, hash) => `${root}/icons/${guildID}/${hash}.jpg`, - Banner: (guildID, hash) => `${root}/banners/${guildID}/${hash}.jpg`, - AppIcon: (clientID, hash) => `${root}/app-icons/${clientID}/${hash}.png`, - AppAsset: (clientID, hash) => `${root}/app-assets/${clientID}/${hash}.png`, - GDMIcon: (channelID, hash) => `${root}/channel-icons/${channelID}/${hash}.jpg?size=2048`, - Splash: (guildID, hash) => `${root}/splashes/${guildID}/${hash}.jpg`, - TeamIcon: (teamID, hash) => `${root}/team-icons/${teamID}/${hash}.jpg`, - }; - }, - OAUTH2: { - Application: appID => { - const base = `/oauth2/applications/${appID}`; - return { - toString: () => base, - resetSecret: `${base}/reset`, - resetToken: `${base}/bot/reset`, - }; - }, - App: appID => `/oauth2/authorize?client_id=${appID}`, - }, - login: '/auth/login', - logout: '/auth/logout', - voiceRegions: '/voice/regions', - gateway: { - toString: () => '/gateway', - bot: '/gateway/bot', - }, - Invite: inviteID => `/invite/${inviteID}?with_counts=true`, - inviteLink: id => `https://discord.gg/${id}`, - Webhook: (webhookID, token) => `/webhooks/${webhookID}${token ? `/${token}` : ''}`, -}; - - -/** - * The current status of the client. Here are the available statuses: - * * READY: 0 - * * CONNECTING: 1 - * * RECONNECTING: 2 - * * IDLE: 3 - * * NEARLY: 4 - * * DISCONNECTED: 5 - * @typedef {number} Status - */ -exports.Status = { - READY: 0, - CONNECTING: 1, - RECONNECTING: 2, - IDLE: 3, - NEARLY: 4, - DISCONNECTED: 5, -}; - -/** - * The current status of a voice connection. Here are the available statuses: - * * CONNECTED: 0 - * * CONNECTING: 1 - * * AUTHENTICATING: 2 - * * RECONNECTING: 3 - * * DISCONNECTED: 4 - * @typedef {number} VoiceStatus - */ -exports.VoiceStatus = { - CONNECTED: 0, - CONNECTING: 1, - AUTHENTICATING: 2, - RECONNECTING: 3, - DISCONNECTED: 4, -}; - -exports.ChannelTypes = { - TEXT: 0, - DM: 1, - VOICE: 2, - GROUP_DM: 3, - CATEGORY: 4, - NEWS: 5, - STORE: 6, -}; - -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 = { - RATE_LIMIT: 'rateLimit', - READY: 'ready', - RESUME: 'resume', - 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_INTEGRATIONS_UPDATE: 'guildIntegrationsUpdate', - 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', - INVITE_CREATE: 'inviteCreate', - INVITE_DELETE: 'inviteDelete', - 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_EMOJI: 'messageReactionRemoveEmoji', - MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll', - USER_UPDATE: 'userUpdate', - USER_NOTE_UPDATE: 'userNoteUpdate', - USER_SETTINGS_UPDATE: 'clientUserSettingsUpdate', - USER_GUILD_SETTINGS_UPDATE: 'clientUserGuildSettingsUpdate', - PRESENCE_UPDATE: 'presenceUpdate', - VOICE_STATE_UPDATE: 'voiceStateUpdate', - TYPING_START: 'typingStart', - TYPING_STOP: 'typingStop', - WEBHOOKS_UPDATE: 'webhookUpdate', - DISCONNECT: 'disconnect', - RECONNECTING: 'reconnecting', - ERROR: 'error', - WARN: 'warn', - DEBUG: 'debug', -}; - -/** - * <info>Bots cannot set a `CUSTOM_STATUS`, it is only for custom statuses received from users</info> - * The type of an activity of a users presence, e.g. `PLAYING`. Here are the available types: - * * PLAYING - * * STREAMING - * * LISTENING - * * WATCHING - * * CUSTOM_STATUS - * @typedef {string} ActivityType - */ -exports.ActivityTypes = [ - 'PLAYING', - 'STREAMING', - 'LISTENING', - 'WATCHING', - 'CUSTOM_STATUS', -]; - -/** - * Numeric activity flags. All available properties: - * * `INSTANCE` - * * `JOIN` - * * `SPECTATE` - * * `JOIN_REQUEST` - * * `SYNC` - * * `PLAY` - * @typedef {string} ActivityFlag - * @see {@link https://discordapp.com/developers/docs/topics/gateway#activity-object-activity-flags} - */ -exports.ActivityFlags = { - INSTANCE: 1 << 0, - JOIN: 1 << 1, - SPECTATE: 1 << 2, - JOIN_REQUEST: 1 << 3, - SYNC: 1 << 4, - PLAY: 1 << 5, -}; - -/** - * The type of a websocket message event, e.g. `MESSAGE_CREATE`. Here are the available events: - * * READY - * * RESUMED - * * GUILD_SYNC - * * GUILD_CREATE - * * GUILD_DELETE - * * GUILD_UPDATE - * * GUILD_MEMBER_ADD - * * GUILD_MEMBER_REMOVE - * * GUILD_MEMBER_UPDATE - * * GUILD_MEMBERS_CHUNK - * * GUILD_INTEGRATIONS_UPDATE - * * 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_EMOJI - * * MESSAGE_REACTION_REMOVE_ALL - * * USER_UPDATE - * * USER_NOTE_UPDATE - * * USER_SETTINGS_UPDATE - * * PRESENCE_UPDATE - * * VOICE_STATE_UPDATE - * * TYPING_START - * * VOICE_SERVER_UPDATE - * * RELATIONSHIP_ADD - * * RELATIONSHIP_REMOVE - * * WEBHOOKS_UPDATE - * @typedef {string} WSEventType - */ -exports.WSEvents = { - READY: 'READY', - RESUMED: 'RESUMED', - 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_INTEGRATIONS_UPDATE: 'GUILD_INTEGRATIONS_UPDATE', - 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', - INVITE_CREATE: 'INVITE_CREATE', - INVITE_DELETE: 'INVITE_DELETE', - 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_EMOJI: 'MESSAGE_REACTION_REMOVE_EMOJI', - MESSAGE_REACTION_REMOVE_ALL: 'MESSAGE_REACTION_REMOVE_ALL', - USER_UPDATE: 'USER_UPDATE', - USER_NOTE_UPDATE: 'USER_NOTE_UPDATE', - USER_SETTINGS_UPDATE: 'USER_SETTINGS_UPDATE', - USER_GUILD_SETTINGS_UPDATE: 'USER_GUILD_SETTINGS_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', - WEBHOOKS_UPDATE: 'WEBHOOKS_UPDATE', -}; - -/** - * The type of a message, e.g. `DEFAULT`. Here are the available types: - * * DEFAULT - * * RECIPIENT_ADD - * * RECIPIENT_REMOVE - * * CALL - * * CHANNEL_NAME_CHANGE - * * CHANNEL_ICON_CHANGE - * * PINS_ADD - * * GUILD_MEMBER_JOIN - * * USER_PREMIUM_GUILD_SUBSCRIPTION - * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 - * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 - * * USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3 - * * CHANNEL_FOLLOW_ADD - * * GUILD_DISCOVERY_DISQUALIFIED - * * GUILD_DISCOVERY_REQUALIFIED - * @typedef {string} MessageType - */ -exports.MessageTypes = [ - 'DEFAULT', - 'RECIPIENT_ADD', - 'RECIPIENT_REMOVE', - 'CALL', - 'CHANNEL_NAME_CHANGE', - 'CHANNEL_ICON_CHANGE', - 'PINS_ADD', - 'GUILD_MEMBER_JOIN', - 'USER_PREMIUM_GUILD_SUBSCRIPTION', - 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1', - 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2', - 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3', - 'CHANNEL_FOLLOW_ADD', - // 13 isn't yet documented - null, - 'GUILD_DISCOVERY_DISQUALIFIED', - 'GUILD_DISCOVERY_REQUALIFIED', -]; - -/** - * The type of a message notification setting. Here are the available types: - * * EVERYTHING - * * MENTIONS - * * NOTHING - * * INHERIT (only for GuildChannel) - * @typedef {string} MessageNotificationType - */ -exports.MessageNotificationTypes = [ - 'EVERYTHING', - 'MENTIONS', - 'NOTHING', - 'INHERIT', -]; - -exports.DefaultAvatars = { - BLURPLE: '6debd47ed13483642cf09e832ed0bc1b', - GREY: '322c936a8c8be1b803cd94861bdfa868', - GREEN: 'dd4dbc0016779df1378e7812eabaa04d', - ORANGE: '0e291f67c9274a1abdddeb3fd919cbaa', - RED: '1cbd08c76f8af6dddce02c5138971129', -}; - -exports.ExplicitContentFilterTypes = [ - 'DISABLED', - 'NON_FRIENDS', - 'FRIENDS_AND_NON_FRIENDS', -]; - -exports.UserSettingsMap = { - /** - * Automatically convert emoticons in your messages to emoji - * For example, when you type `:-)` Discord will convert it to 😃 - * @name ClientUserSettings#convertEmoticons - * @type {boolean} - */ - convert_emoticons: 'convertEmoticons', - - /** - * If new guilds should automatically disable DMs between you and its members - * @name ClientUserSettings#defaultGuildsRestricted - * @type {boolean} - */ - default_guilds_restricted: 'defaultGuildsRestricted', - - /** - * Automatically detect accounts from services like Steam and Blizzard when you open the Discord client - * @name ClientUserSettings#detectPlatformAccounts - * @type {boolean} - */ - detect_platform_accounts: 'detectPlatformAccounts', - - /** - * Developer Mode exposes context menu items helpful for people writing bots using the Discord API - * @name ClientUserSettings#developerMode - * @type {boolean} - */ - developer_mode: 'developerMode', - - /** - * Allow playback and usage of the `/tts` command - * @name ClientUserSettings#enableTTSCommand - * @type {boolean} - */ - enable_tts_command: 'enableTTSCommand', - - /** - * The theme of the client. Either `light` or `dark` - * @name ClientUserSettings#theme - * @type {string} - */ - theme: 'theme', - - /** - * Last status set in the client - * @name ClientUserSettings#status - * @type {PresenceStatus} - */ - status: 'status', - - /** - * Display currently running game as status message - * @name ClientUserSettings#showCurrentGame - * @type {boolean} - */ - show_current_game: 'showCurrentGame', - - /** - * Display images, videos, and lolcats when uploaded directly to Discord - * @name ClientUserSettings#inlineAttachmentMedia - * @type {boolean} - */ - inline_attachment_media: 'inlineAttachmentMedia', - - /** - * Display images, videos, and lolcats when uploaded posted as links in chat - * @name ClientUserSettings#inlineEmbedMedia - * @type {boolean} - */ - inline_embed_media: 'inlineEmbedMedia', - - /** - * Language the Discord client will use, as an RFC 3066 language identifier - * @name ClientUserSettings#locale - * @type {string} - */ - locale: 'locale', - - /** - * Display messages in compact mode - * @name ClientUserSettings#messageDisplayCompact - * @type {boolean} - */ - message_display_compact: 'messageDisplayCompact', - - /** - * Show emoji reactions on messages - * @name ClientUserSettings#renderReactions - * @type {boolean} - */ - render_reactions: 'renderReactions', - - /** - * Array of snowflake IDs for guilds, in the order they appear in the Discord client - * @name ClientUserSettings#guildPositions - * @type {Snowflake[]} - */ - guild_positions: 'guildPositions', - - /** - * Array of snowflake IDs for guilds which you will not recieve DMs from - * @name ClientUserSettings#restrictedGuilds - * @type {Snowflake[]} - */ - restricted_guilds: 'restrictedGuilds', - - explicit_content_filter: function explicitContentFilter(type) { // eslint-disable-line func-name-matching - /** - * Safe direct messaging; force people's messages with images to be scanned before they are sent to you. - * One of `DISABLED`, `NON_FRIENDS`, `FRIENDS_AND_NON_FRIENDS` - * @name ClientUserSettings#explicitContentFilter - * @type {string} - */ - return exports.ExplicitContentFilterTypes[type]; - }, - friend_source_flags: function friendSources(flags) { // eslint-disable-line func-name-matching - /** - * Who can add you as a friend - * @name ClientUserSettings#friendSources - * @type {Object} - * @property {boolean} all Mutual friends and mutual guilds - * @property {boolean} mutualGuilds Only mutual guilds - * @property {boolean} mutualFriends Only mutual friends - */ - return { - all: flags.all || false, - mutualGuilds: flags.all ? true : flags.mutual_guilds || false, - mutualFriends: flags.all ? true : flags.mutualFriends || false, - }; - }, -}; - -exports.UserGuildSettingsMap = { - message_notifications: function messageNotifications(type) { // eslint-disable-line func-name-matching - /** - * The type of message that should notify you - * @name ClientUserGuildSettings#messageNotifications - * @type {MessageNotificationType} - */ - return exports.MessageNotificationTypes[type]; - }, - /** - * Whether to receive mobile push notifications - * @name ClientUserGuildSettings#mobilePush - * @type {boolean} - */ - mobile_push: 'mobilePush', - /** - * Whether the guild is muted - * @name ClientUserGuildSettings#muted - * @type {boolean} - */ - muted: 'muted', - /** - * Whether to suppress everyone mention - * @name ClientUserGuildSettings#suppressEveryone - * @type {boolean} - */ - suppress_everyone: 'suppressEveryone', - /** - * A collection containing all the channel overrides - * @name ClientUserGuildSettings#channelOverrides - * @type {Collection<ClientUserChannelOverride>} - */ - channel_overrides: 'channelOverrides', -}; - -exports.UserChannelOverrideMap = { - message_notifications: function messageNotifications(type) { // eslint-disable-line func-name-matching - /** - * The type of message that should notify you - * @name ClientUserChannelOverride#messageNotifications - * @type {MessageNotificationType} - */ - return exports.MessageNotificationTypes[type]; - }, - /** - * Whether the channel is muted - * @name ClientUserChannelOverride#muted - * @type {boolean} - */ - muted: 'muted', -}; - -exports.Colors = { - DEFAULT: 0x000000, - WHITE: 0xFFFFFF, - AQUA: 0x1ABC9C, - GREEN: 0x2ECC71, - BLUE: 0x3498DB, - PURPLE: 0x9B59B6, - LUMINOUS_VIVID_PINK: 0xE91E63, - GOLD: 0xF1C40F, - ORANGE: 0xE67E22, - RED: 0xE74C3C, - GREY: 0x95A5A6, - NAVY: 0x34495E, - DARK_AQUA: 0x11806A, - DARK_GREEN: 0x1F8B4C, - DARK_BLUE: 0x206694, - DARK_PURPLE: 0x71368A, - DARK_VIVID_PINK: 0xAD1457, - DARK_GOLD: 0xC27C0E, - DARK_ORANGE: 0xA84300, - DARK_RED: 0x992D22, - DARK_GREY: 0x979C9F, - DARKER_GREY: 0x7F8C8D, - LIGHT_GREY: 0xBCC0C0, - DARK_NAVY: 0x2C3E50, - BLURPLE: 0x7289DA, - GREYPLE: 0x99AAB5, - DARK_BUT_NOT_BLACK: 0x2C2F33, - NOT_QUITE_BLACK: 0x23272A, -}; - -/** - * The value set for the verification levels for a guild: - * * None - * * Low - * * Medium - * * (╯°□°)╯︵ ┻━┻ - * * ┻━┻ ミヽ(ಠ益ಠ)ノ彡┻━┻ - * @typedef {string} VerificationLevel - */ -exports.VerificationLevels = [ - 'None', - 'Low', - 'Medium', - '(╯°□°)╯︵ ┻━┻', - '┻━┻ ミヽ(ಠ益ಠ)ノ彡┻━┻', -]; - -/** - * An error encountered while performing an API request. Here are the potential errors: - * * UNKNOWN_ACCOUNT - * * UNKNOWN_APPLICATION - * * UNKNOWN_CHANNEL - * * UNKNOWN_GUILD - * * UNKNOWN_INTEGRATION - * * UNKNOWN_INVITE - * * UNKNOWN_MEMBER - * * UNKNOWN_MESSAGE - * * UNKNOWN_OVERWRITE - * * UNKNOWN_PROVIDER - * * UNKNOWN_ROLE - * * UNKNOWN_TOKEN - * * UNKNOWN_USER - * * UNKNOWN_EMOJI - * * UNKNOWN_WEBHOOK - * * BOT_PROHIBITED_ENDPOINT - * * BOT_ONLY_ENDPOINT - * * MAXIMUM_GUILDS - * * MAXIMUM_FRIENDS - * * MAXIMUM_PINS - * * MAXIMUM_ROLES - * * MAXIMUM_REACTIONS - * * MAXIMUM_CHANNELS - * * MAXIMUM_INVITES - * * UNAUTHORIZED - * * USER_BANNED - * * MISSING_ACCESS - * * INVALID_ACCOUNT_TYPE - * * CANNOT_EXECUTE_ON_DM - * * EMBED_DISABLED - * * CANNOT_EDIT_MESSAGE_BY_OTHER - * * CANNOT_SEND_EMPTY_MESSAGE - * * CANNOT_MESSAGE_USER - * * CANNOT_SEND_MESSAGES_IN_VOICE_CHANNEL - * * CHANNEL_VERIFICATION_LEVEL_TOO_HIGH - * * OAUTH2_APPLICATION_BOT_ABSENT - * * MAXIMUM_OAUTH2_APPLICATIONS - * * INVALID_OAUTH_STATE - * * MISSING_PERMISSIONS - * * INVALID_AUTHENTICATION_TOKEN - * * NOTE_TOO_LONG - * * INVALID_BULK_DELETE_QUANTITY - * * CANNOT_PIN_MESSAGE_IN_OTHER_CHANNEL - * * INVALID_OR_TAKEN_INVITE_CODE - * * CANNOT_EXECUTE_ON_SYSTEM_MESSAGE - * * INVALID_OAUTH_TOKEN - * * BULK_DELETE_MESSAGE_TOO_OLD - * * INVALID_FORM_BODY - * * INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT - * * INVALID_API_VERSION - * * REACTION_BLOCKED - * * RESOURCE_OVERLOADED - * @typedef {string} APIError - */ -exports.APIErrors = { - UNKNOWN_ACCOUNT: 10001, - UNKNOWN_APPLICATION: 10002, - UNKNOWN_CHANNEL: 10003, - UNKNOWN_GUILD: 10004, - UNKNOWN_INTEGRATION: 10005, - UNKNOWN_INVITE: 10006, - UNKNOWN_MEMBER: 10007, - UNKNOWN_MESSAGE: 10008, - UNKNOWN_OVERWRITE: 10009, - UNKNOWN_PROVIDER: 10010, - UNKNOWN_ROLE: 10011, - UNKNOWN_TOKEN: 10012, - UNKNOWN_USER: 10013, - UNKNOWN_EMOJI: 10014, - UNKNOWN_WEBHOOK: 10015, - BOT_PROHIBITED_ENDPOINT: 20001, - BOT_ONLY_ENDPOINT: 20002, - MAXIMUM_GUILDS: 30001, - MAXIMUM_FRIENDS: 30002, - MAXIMUM_PINS: 30003, - MAXIMUM_ROLES: 30005, - MAXIMUM_REACTIONS: 30010, - MAXIMUM_CHANNELS: 30013, - MAXIMUM_INVITES: 30016, - UNAUTHORIZED: 40001, - USER_BANNED: 40007, - MISSING_ACCESS: 50001, - INVALID_ACCOUNT_TYPE: 50002, - CANNOT_EXECUTE_ON_DM: 50003, - EMBED_DISABLED: 50004, - CANNOT_EDIT_MESSAGE_BY_OTHER: 50005, - CANNOT_SEND_EMPTY_MESSAGE: 50006, - CANNOT_MESSAGE_USER: 50007, - CANNOT_SEND_MESSAGES_IN_VOICE_CHANNEL: 50008, - CHANNEL_VERIFICATION_LEVEL_TOO_HIGH: 50009, - OAUTH2_APPLICATION_BOT_ABSENT: 50010, - MAXIMUM_OAUTH2_APPLICATIONS: 50011, - INVALID_OAUTH_STATE: 50012, - MISSING_PERMISSIONS: 50013, - INVALID_AUTHENTICATION_TOKEN: 50014, - NOTE_TOO_LONG: 50015, - INVALID_BULK_DELETE_QUANTITY: 50016, - CANNOT_PIN_MESSAGE_IN_OTHER_CHANNEL: 50019, - INVALID_OR_TAKEN_INVITE_CODE: 50020, - CANNOT_EXECUTE_ON_SYSTEM_MESSAGE: 50021, - INVALID_OAUTH_TOKEN: 50025, - BULK_DELETE_MESSAGE_TOO_OLD: 50034, - INVALID_FORM_BODY: 50035, - INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT: 50036, - INVALID_API_VERSION: 50041, - REACTION_BLOCKED: 90001, - RESOURCE_OVERLOADED: 130000, -}; - -/** - * The value set for a guild's default message notifications, e.g. `ALL`. Here are the available types: - * * ALL - * * MENTIONS - * @typedef {string} DefaultMessageNotifications - */ -exports.DefaultMessageNotifications = [ - 'ALL', - 'MENTIONS', -]; - -/** - * The value set for a team members's membership state: - * * INVITED - * * ACCEPTED - * @typedef {string} MembershipStates - */ -exports.MembershipStates = [ - // They start at 1 - null, - 'INVITED', - 'ACCEPTED', -]; - -/** - * The value set for a webhook's type: - * * Incoming - * * Channel Follower - * @typedef {string} WebhookTypes - */ -exports.WebhookTypes = [ - // They start at 1 - null, - 'Incoming', - 'Channel Follower', -]; diff --git a/node_modules/discord.js/src/util/MessageFlags.js b/node_modules/discord.js/src/util/MessageFlags.js deleted file mode 100644 index 88c8014..0000000 --- a/node_modules/discord.js/src/util/MessageFlags.js +++ /dev/null @@ -1,36 +0,0 @@ -const BitField = require('./BitField'); - -/** - * Data structure that makes it easy to interact with an {@link Message#flags} bitfield. - * @extends {BitField} - */ -class MessageFlags extends BitField {} - -/** - * Data that can be resolved to give a permission number. This can be: - * * A string (see {@link MessageFlags.FLAGS}) - * * A message flag - * * An instance of MessageFlags - * * An array of MessageFlagsResolvable - * @typedef {string|number|MessageFlags|MessageFlagsResolvable[]} MessageFlagsResolvable - */ - -/** - * Numeric message flags. All available properties: - * * `CROSSPOSTED` - * * `IS_CROSSPOST` - * * `SUPPRESS_EMBEDS` - * * `SOURCE_MESSAGE_DELETED` - * * `URGENT` - * @type {Object} - * @see {@link https://discordapp.com/developers/docs/resources/channel#message-object-message-flags} - */ -MessageFlags.FLAGS = { - CROSSPOSTED: 1 << 0, - IS_CROSSPOST: 1 << 1, - SUPPRESS_EMBEDS: 1 << 2, - SOURCE_MESSAGE_DELETED: 1 << 3, - URGENT: 1 << 4, -}; - -module.exports = MessageFlags; diff --git a/node_modules/discord.js/src/util/Permissions.js b/node_modules/discord.js/src/util/Permissions.js deleted file mode 100644 index fa1d0e0..0000000 --- a/node_modules/discord.js/src/util/Permissions.js +++ /dev/null @@ -1,234 +0,0 @@ -const BitField = require('./BitField'); -const util = require('util'); - -/** - * Data structure that makes it easy to interact with a permission bitfield. All {@link GuildMember}s have a set of - * permissions in their guild, and each channel in the guild may also have {@link PermissionOverwrites} for the member - * that override their default permissions. - * @extends {BitField} - */ -class Permissions extends BitField { - /** - * @param {GuildMember} [member] Member the permissions are for **(deprecated)** - * @param {number|PermissionResolvable} permissions Permissions or bitfield to read from - */ - constructor(member, permissions) { - super(typeof member === 'object' && !(member instanceof Array) ? permissions : member); - - Object.defineProperty(this, '_member', { - writable: true, - value: typeof member === 'object' && !(member instanceof Array) ? member : null, - }); - } - - /** - * Member the permissions are for - * @type {GuildMember} - * @deprecated - */ - get member() { - return this._member; - } - - set member(value) { - this._member = value; - } - - /** - * Bitfield of the packed permissions - * @type {number} - * @see {@link Permissions#bitfield} - * @deprecated - * @readonly - */ - get raw() { - return this.bitfield; - } - - set raw(raw) { - this.bitfield = raw; - } - - /** - * Checks whether the bitfield has a permission, or any of multiple permissions. - * @param {PermissionResolvable} permission Permission(s) to check for - * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override - * @returns {boolean} - */ - any(permission, checkAdmin = true) { - return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.any(permission); - } - - /** - * Checks whether the bitfield has a permission, or multiple permissions. - * @param {PermissionResolvable} permission Permission(s) to check for - * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override - * @returns {boolean} - */ - has(permission, checkAdmin = true) { - return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission); - } - - /** - * Checks whether the user has a certain permission, e.g. `READ_MESSAGES`. - * @param {PermissionResolvable} permission The permission to check for - * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permission - * @returns {boolean} - * @see {@link Permissions#has} - * @deprecated - */ - hasPermission(permission, explicit = false) { - return this.has(permission, !explicit); - } - - /** - * Checks whether the user has all specified permissions. - * @param {PermissionResolvable} permissions The permissions to check for - * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permissions - * @returns {boolean} - * @see {@link Permissions#has} - * @deprecated - */ - hasPermissions(permissions, explicit = false) { - return this.has(permissions, !explicit); - } - - /** - * Checks whether the user has all specified permissions, and lists any missing permissions. - * @param {PermissionResolvable} permissions The permissions to check for - * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permissions - * @returns {PermissionResolvable} - * @see {@link Permissions#missing} - * @deprecated - */ - missingPermissions(permissions, explicit = false) { - return this.missing(permissions, !explicit); - } -} - -/** - * Data that can be resolved to give a permission number. This can be: - * * A string (see {@link Permissions.FLAGS}) - * * A permission number - * @typedef {string|number|Permissions|PermissionResolvable[]} PermissionResolvable - */ - -/** - * Numeric permission flags. All available properties: - * - `ADMINISTRATOR` (implicitly has *all* permissions, and bypasses all channel overwrites) - * - `CREATE_INSTANT_INVITE` (create invitations to the guild) - * - `KICK_MEMBERS` - * - `BAN_MEMBERS` - * - `MANAGE_CHANNELS` (edit and reorder channels) - * - `MANAGE_GUILD` (edit the guild information, region, etc.) - * - `ADD_REACTIONS` (add new reactions to messages) - * - `VIEW_AUDIT_LOG` - * - `PRIORITY_SPEAKER` - * - `STREAM` - * - `VIEW_CHANNEL` - * - `READ_MESSAGES` **(deprecated)** - * - `SEND_MESSAGES` - * - `SEND_TTS_MESSAGES` - * - `MANAGE_MESSAGES` (delete messages and reactions) - * - `EMBED_LINKS` (links posted will have a preview embedded) - * - `ATTACH_FILES` - * - `READ_MESSAGE_HISTORY` (view messages that were posted prior to opening Discord) - * - `MENTION_EVERYONE` - * - `USE_EXTERNAL_EMOJIS` (use emojis from different guilds) - * - `EXTERNAL_EMOJIS` **(deprecated)** - * - `CONNECT` (connect to a voice channel) - * - `SPEAK` (speak in a voice channel) - * - `MUTE_MEMBERS` (mute members across all voice channels) - * - `DEAFEN_MEMBERS` (deafen members across all voice channels) - * - `MOVE_MEMBERS` (move members between voice channels) - * - `USE_VAD` (use voice activity detection) - * - `CHANGE_NICKNAME` - * - `MANAGE_NICKNAMES` (change other members' nicknames) - * - `MANAGE_ROLES` - * - `MANAGE_ROLES_OR_PERMISSIONS` **(deprecated)** - * - `MANAGE_WEBHOOKS` - * - `MANAGE_EMOJIS` - * @type {Object} - * @see {@link https://discordapp.com/developers/docs/topics/permissions} - */ -Permissions.FLAGS = { - 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, - VIEW_AUDIT_LOG: 1 << 7, - PRIORITY_SPEAKER: 1 << 8, - STREAM: 1 << 9, - - VIEW_CHANNEL: 1 << 10, - 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, - USE_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: 1 << 28, - MANAGE_ROLES_OR_PERMISSIONS: 1 << 28, - MANAGE_WEBHOOKS: 1 << 29, - MANAGE_EMOJIS: 1 << 30, -}; - -/** - * Bitfield representing every permission combined - * @type {number} - */ -Permissions.ALL = Object.keys(Permissions.FLAGS).reduce((all, p) => all | Permissions.FLAGS[p], 0); - -/** - * Bitfield representing the default permissions for users - * @type {number} - */ -Permissions.DEFAULT = 104324673; - -/** - * @class EvaluatedPermissions - * @classdesc The final evaluated permissions for a member in a channel - * @see {@link Permissions} - * @deprecated - */ - -Permissions.prototype.hasPermission = util.deprecate(Permissions.prototype.hasPermission, - 'EvaluatedPermissions#hasPermission is deprecated, use Permissions#has instead'); -Permissions.prototype.hasPermissions = util.deprecate(Permissions.prototype.hasPermissions, - 'EvaluatedPermissions#hasPermissions is deprecated, use Permissions#has instead'); -Permissions.prototype.missingPermissions = util.deprecate(Permissions.prototype.missingPermissions, - 'EvaluatedPermissions#missingPermissions is deprecated, use Permissions#missing instead'); -Object.defineProperty(Permissions.prototype, 'raw', { - get: util - .deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'raw').get, - 'EvaluatedPermissions#raw is deprecated use Permissions#bitfield instead'), - set: util.deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'raw').set, - 'EvaluatedPermissions#raw is deprecated use Permissions#bitfield instead'), -}); -Object.defineProperty(Permissions.prototype, 'member', { - get: util - .deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'member').get, - 'EvaluatedPermissions#member is deprecated'), - set: util - .deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'member').set, - 'EvaluatedPermissions#member is deprecated'), -}); - -module.exports = Permissions; diff --git a/node_modules/discord.js/src/util/Snowflake.js b/node_modules/discord.js/src/util/Snowflake.js deleted file mode 100644 index 2775266..0000000 --- a/node_modules/discord.js/src/util/Snowflake.js +++ /dev/null @@ -1,82 +0,0 @@ -const Long = require('long'); - -// Discord epoch (2015-01-01T00:00:00.000Z) -const EPOCH = 1420070400000; -let INCREMENT = 0; - -/** - * A container for useful snowflake-related methods. - */ -class SnowflakeUtil { - constructor() { - throw new Error(`The ${this.constructor.name} class may not be instantiated.`); - } - - /** - * A Twitter snowflake, except the epoch is 2015-01-01T00:00:00.000Z - * ``` - * If we have a snowflake '266241948824764416' we can represent it as binary: - * - * 64 22 17 12 0 - * 000000111011000111100001101001000101000000 00001 00000 000000000000 - * number of ms since Discord epoch worker pid increment - * ``` - * @typedef {string} Snowflake - */ - - /** - * Generates a Discord snowflake. - * <info>This hardcodes the worker ID as 1 and the process ID as 0.</info> - * @param {number|Date} [timestamp=Date.now()] Timestamp or date of the snowflake to generate - * @returns {Snowflake} The generated snowflake - */ - static generate(timestamp = Date.now()) { - if (timestamp instanceof Date) timestamp = timestamp.getTime(); - if (typeof timestamp !== 'number' || isNaN(timestamp)) { - throw new TypeError( - `"timestamp" argument must be a number (received ${isNaN(timestamp) ? 'NaN' : typeof timestamp})` - ); - } - if (INCREMENT >= 4095) INCREMENT = 0; - const BINARY = `${pad((timestamp - EPOCH).toString(2), 42)}0000100000${pad((INCREMENT++).toString(2), 12)}`; - return Long.fromString(BINARY, 2).toString(); - } - - /** - * A deconstructed snowflake. - * @typedef {Object} DeconstructedSnowflake - * @property {number} timestamp Timestamp the snowflake was created - * @property {Date} date Date the snowflake was created - * @property {number} workerID Worker ID in the snowflake - * @property {number} processID Process ID in the snowflake - * @property {number} increment Increment in the snowflake - * @property {string} binary Binary representation of the snowflake - */ - - /** - * Deconstructs a Discord snowflake. - * @param {Snowflake} snowflake Snowflake to deconstruct - * @returns {DeconstructedSnowflake} Deconstructed snowflake - */ - static deconstruct(snowflake) { - const BINARY = pad(Long.fromString(snowflake).toString(2), 64); - const res = { - timestamp: parseInt(BINARY.substring(0, 42), 2) + EPOCH, - workerID: parseInt(BINARY.substring(42, 47), 2), - processID: parseInt(BINARY.substring(47, 52), 2), - increment: parseInt(BINARY.substring(52, 64), 2), - binary: BINARY, - }; - Object.defineProperty(res, 'date', { - get: function get() { return new Date(this.timestamp); }, - enumerable: true, - }); - return res; - } -} - -function pad(v, n, c = '0') { - return String(v).length >= n ? String(v) : (String(c).repeat(n) + v).slice(-n); -} - -module.exports = SnowflakeUtil; diff --git a/node_modules/discord.js/src/util/SystemChannelFlags.js b/node_modules/discord.js/src/util/SystemChannelFlags.js deleted file mode 100644 index 9f74984..0000000 --- a/node_modules/discord.js/src/util/SystemChannelFlags.js +++ /dev/null @@ -1,31 +0,0 @@ -const BitField = require('./BitField'); - -/** - * Data structure that makes it easy to interact with a {@link Guild#systemChannelFlags} bitfield. - * <info>Note that all event message types are enabled by default, - * and by setting their corresponding flags you are disabling them</info> - * @extends {BitField} - */ -class SystemChannelFlags extends BitField {} - -/** - * Data that can be resolved to give a sytem channel flag bitfield. This can be: - * * A string (see {@link SystemChannelFlags.FLAGS}) - * * A sytem channel flag - * * An instance of SystemChannelFlags - * * An Array of SystemChannelFlagsResolvable - * @typedef {string|number|SystemChannelFlags|SystemChannelFlagsResolvable[]} SystemChannelFlagsResolvable - */ - -/** - * Numeric system channel flags. All available properties: - * * `WELCOME_MESSAGE_DISABLED` - * * `BOOST_MESSAGE_DISABLED` - * @type {Object} - */ -SystemChannelFlags.FLAGS = { - WELCOME_MESSAGE_DISABLED: 1 << 0, - BOOST_MESSAGE_DISABLED: 1 << 1, -}; - -module.exports = SystemChannelFlags; diff --git a/node_modules/discord.js/src/util/Util.js b/node_modules/discord.js/src/util/Util.js deleted file mode 100644 index a286b07..0000000 --- a/node_modules/discord.js/src/util/Util.js +++ /dev/null @@ -1,238 +0,0 @@ -const snekfetch = require('snekfetch'); -const Constants = require('./Constants'); -const ConstantsHttp = Constants.DefaultOptions.http; - -/** - * Contains various general-purpose utility methods. These functions are also available on the base `Discord` object. - */ -class Util { - constructor() { - throw new Error(`The ${this.constructor.name} class may not be instantiated.`); - } - - /** - * Splits a string into multiple chunks at a designated character that do not exceed a specific length. - * @param {string} text Content to split - * @param {SplitOptions} [options] Options controlling the behaviour of the split - * @returns {string|string[]} - */ - static splitMessage(text, { maxLength = 1950, char = '\n', prepend = '', append = '' } = {}) { - if (text.length <= maxLength) return text; - const splitText = text.split(char); - if (splitText.some(chunk => chunk.length > maxLength)) { - 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; - } - - /** - * Data that can be resolved to give a string. This can be: - * * A string - * * An array (joined with a new line delimiter to give a string) - * * Any value - * @typedef {string|Array|*} StringResolvable - */ - - /** - * Resolves a StringResolvable to a string. - * @param {StringResolvable} data The string resolvable to resolve - * @returns {string} - */ - static resolveString(data) { - if (typeof data === 'string') return data; - if (Array.isArray(data)) return data.join('\n'); - return String(data); - } - - /** - * Escapes any Discord-flavour markdown in a string. - * @param {string} text Content to escape - * @param {boolean} [onlyCodeBlock=false] Whether to only escape codeblocks (takes priority) - * @param {boolean} [onlyInlineCode=false] Whether to only escape inline code - * @returns {string} - */ - static 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'); - } - - /** - * Gets the recommended shard count from Discord. - * @param {string} token Discord auth token - * @param {number} [guildsPerShard=1000] Number of guilds per shard - * @returns {Promise<number>} The recommended number of shards - */ - static fetchRecommendedShards(token, guildsPerShard = 1000) { - return new Promise((resolve, reject) => { - if (!token) throw new Error('A token must be provided.'); - snekfetch.get(`${ConstantsHttp.host}/api/v${ConstantsHttp.version}${Constants.Endpoints.gateway.bot}`) - .set('Authorization', `Bot ${token.replace(/^Bot\s*/i, '')}`) - .end((err, res) => { - if (err) reject(err); - resolve(res.body.shards * (1000 / guildsPerShard)); - }); - }); - } - - /** - * Parses emoji info out of a string. The string must be one of: - * * A UTF-8 emoji (no ID) - * * A URL-encoded UTF-8 emoji (no ID) - * * A Discord custom emoji (`<:name:id>` or `<a:name:id>`) - * @param {string} text Emoji string to parse - * @returns {?Object} Object with `animated`, `name`, and `id` properties - * @private - */ - static parseEmoji(text) { - if (text.includes('%')) text = decodeURIComponent(text); - if (!text.includes(':')) return { animated: false, name: text, id: null }; - const m = text.match(/<?(a:)?(\w{2,32}):(\d{17,19})>?/); - if (!m) return null; - return { animated: Boolean(m[1]), name: m[2], id: m[3] }; - } - - /** - * Checks whether two arrays are equal or have the same elements. - * @param {Array<*>} a The first array. - * @param {Array<*>} b The second array. - * @returns {boolean} Whether the arrays are equal. - * @private - */ - static arraysEqual(a, b) { - if (a === b) return true; - if (a.length !== b.length) return false; - - const setA = new Set(a); - const setB = new Set(b); - - return a.every(e => setB.has(e)) && b.every(e => setA.has(e)); - } - - /** - * Shallow-copies an object with its class/prototype intact. - * @param {Object} obj Object to clone - * @returns {Object} - * @private - */ - static cloneObject(obj) { - return Object.assign(Object.create(obj), obj); - } - - /** - * Sets default properties on an object that aren't already specified. - * @param {Object} def Default properties - * @param {Object} given Object to assign defaults to - * @returns {Object} - * @private - */ - static mergeDefault(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] = this.mergeDefault(def[key], given[key]); - } - } - - return given; - } - - /** - * Converts an ArrayBuffer or string to a Buffer. - * @param {ArrayBuffer|string} ab ArrayBuffer to convert - * @returns {Buffer} - * @private - */ - static convertToBuffer(ab) { - if (typeof ab === 'string') ab = this.str2ab(ab); - return Buffer.from(ab); - } - - /** - * Converts a string to an ArrayBuffer. - * @param {string} str String to convert - * @returns {ArrayBuffer} - * @private - */ - static 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; - } - - /** - * Makes an Error from a plain info object. - * @param {Object} obj Error info - * @param {string} obj.name Error type - * @param {string} obj.message Message for the error - * @param {string} obj.stack Stack for the error - * @returns {Error} - * @private - */ - static makeError(obj) { - const err = new Error(obj.message); - err.name = obj.name; - err.stack = obj.stack; - return err; - } - - /** - * Makes a plain error info object from an Error. - * @param {Error} err Error to get info from - * @returns {Object} - * @private - */ - static makePlainError(err) { - const obj = {}; - obj.name = err.name; - obj.message = err.message; - obj.stack = err.stack; - return obj; - } - - /** - * Moves an element in an array *in place*. - * @param {Array<*>} array Array to modify - * @param {*} element Element to move - * @param {number} newIndex Index or offset to move the element to - * @param {boolean} [offset=false] Move the element by an offset amount rather than to a set index - * @returns {number} - * @private - */ - static moveElementInArray(array, element, newIndex, offset = false) { - const index = array.indexOf(element); - newIndex = (offset ? index : 0) + newIndex; - if (newIndex > -1 && newIndex < array.length) { - const removedElement = array.splice(index, 1)[0]; - array.splice(newIndex, 0, removedElement); - } - return array.indexOf(element); - } - - /** - * Creates a Promise that resolves after a specified duration. - * @param {number} ms How long to wait before resolving (in milliseconds) - * @returns {Promise<void>} - * @private - */ - static delayFor(ms) { - return new Promise(resolve => { - setTimeout(resolve, ms); - }); - } -} - -module.exports = Util; |