diff --git a/discord.11.3.1.js b/discord.11.3.1.js new file mode 100644 index 00000000..3736c5f5 --- /dev/null +++ b/discord.11.3.1.js @@ -0,0 +1,21626 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 58); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(process) {exports.Package = __webpack_require__(36); + +/** + * 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 {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, + 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: __webpack_require__(69).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`, + 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), + 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`, + }; + }, + }; + }, + 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`, + GDMIcon: (channelID, hash) => `${root}/channel-icons/${channelID}/${hash}.jpg?size=2048`, + Splash: (guildID, hash) => `${root}/splashes/${guildID}/${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 + * * CONNECTING + * * RECONNECTING + * * IDLE + * * NEARLY + * * DISCONNECTED + * @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 + * * CONNECTING + * * AUTHENTICATING + * * RECONNECTING + * * DISCONNECTED + * @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, +}; + +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', + 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_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', + USER_SETTINGS_UPDATE: 'clientUserSettingsUpdate', + USER_GUILD_SETTINGS_UPDATE: 'clientUserGuildSettingsUpdate', + 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 an activity of a users presence, e.g. `PLAYING`. Here are the available types: + * * PLAYING + * * STREAMING + * * LISTENING + * * WATCHING + * @typedef {string} ActivityType + */ +exports.ActivityTypes = [ + 'PLAYING', + 'STREAMING', + 'LISTENING', + 'WATCHING', +]; + +/** + * 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_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 + * * USER_SETTINGS_UPDATE + * * PRESENCE_UPDATE + * * VOICE_STATE_UPDATE + * * TYPING_START + * * VOICE_SERVER_UPDATE + * * RELATIONSHIP_ADD + * * RELATIONSHIP_REMOVE + * @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_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', + 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', +}; + +/** + * 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 + * @typedef {string} MessageType + */ +exports.MessageTypes = [ + 'DEFAULT', + 'RECIPIENT_ADD', + 'RECIPIENT_REMOVE', + 'CALL', + 'CHANNEL_NAME_CHANGE', + 'CHANNEL_ICON_CHANGE', + 'PINS_ADD', + 'GUILD_MEMBER_JOIN', +]; + +/** + * 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} + */ + 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, + AQUA: 0x1ABC9C, + GREEN: 0x2ECC71, + BLUE: 0x3498DB, + PURPLE: 0x9B59B6, + GOLD: 0xF1C40F, + ORANGE: 0xE67E22, + RED: 0xE74C3C, + GREY: 0x95A5A6, + NAVY: 0x34495E, + DARK_AQUA: 0x11806A, + DARK_GREEN: 0x1F8B4C, + DARK_BLUE: 0x206694, + DARK_PURPLE: 0x71368A, + 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, +}; + +/** + * 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 + * * BOT_PROHIBITED_ENDPOINT + * * BOT_ONLY_ENDPOINT + * * MAXIMUM_GUILDS + * * MAXIMUM_FRIENDS + * * MAXIMUM_PINS + * * MAXIMUM_ROLES + * * MAXIMUM_REACTIONS + * * UNAUTHORIZED + * * 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 + * * CANNOT_EXECUTE_ON_SYSTEM_MESSAGE + * * BULK_DELETE_MESSAGE_TOO_OLD + * * INVITE_ACCEPTED_TO_GUILD_NOT_CONTANING_BOT + * * REACTION_BLOCKED + * @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, + BOT_PROHIBITED_ENDPOINT: 20001, + BOT_ONLY_ENDPOINT: 20002, + MAXIMUM_GUILDS: 30001, + MAXIMUM_FRIENDS: 30002, + MAXIMUM_PINS: 30003, + MAXIMUM_ROLES: 30005, + MAXIMUM_REACTIONS: 30010, + UNAUTHORIZED: 40001, + 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, + CANNOT_EXECUTE_ON_SYSTEM_MESSAGE: 50021, + BULK_DELETE_MESSAGE_TOO_OLD: 50034, + INVITE_ACCEPTED_TO_GUILD_NOT_CONTANING_BOT: 50036, + REACTION_BLOCKED: 90001, +}; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(13))) + +/***/ }), +/* 1 */ +/***/ (function(module, exports) { + +class AbstractHandler { + constructor(packetManager) { + this.packetManager = packetManager; + } + + handle(packet) { + return packet; + } +} + +module.exports = AbstractHandler; + + +/***/ }), +/* 2 */ +/***/ (function(module, exports) { + +/* + +ABOUT ACTIONS + +Actions are similar to WebSocket Packet Handlers, but since introducing +the REST API methods, in order to prevent rewriting code to handle data, +"actions" have been introduced. They're basically what Packet Handlers +used to be but they're strictly for manipulating data and making sure +that WebSocket events don't clash with REST methods. + +*/ + +class GenericAction { + constructor(client) { + this.client = client; + } + + handle(data) { + return data; + } +} + +module.exports = GenericAction; + + +/***/ }), +/* 3 */ +/***/ (function(module, exports) { + +/** + * 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 behaviour, 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 behaviour, 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} + * @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). + * 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. + * @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'); + */ + /* 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`). + * 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. + * @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) { + 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; + } + + /** + * 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]))); + } +} + +module.exports = Collection; + + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(Buffer) {const snekfetch = __webpack_require__(24); +const Constants = __webpack_require__(0); +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.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; + } + + /** + * 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} 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 ``) + * @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(/?/); + if (!m) return null; + return { animated: Boolean(m[1]), name: m[2], id: m[3] }; + } + + /** + * Checks whether the arrays are equal, also removes duplicated entries from b. + * @param {Array<*>} a Array which will not be modified. + * @param {Array<*>} b Array to remove duplicated entries from. + * @returns {boolean} Whether the arrays are equal. + * @private + */ + static arraysEqual(a, b) { + if (a === b) return true; + if (a.length !== b.length) return false; + + for (const item of a) { + const ind = b.indexOf(item); + if (ind !== -1) b.splice(ind, 1); + } + + return b.length === 0; + } + + /** + * 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); + } +} + +module.exports = Util; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12).Buffer)) + +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +const Long = __webpack_require__(25); + +// 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. + * This hardcodes the worker ID as 1 and the process ID as 0. + * @returns {Snowflake} The generated snowflake + */ + static generate() { + if (INCREMENT >= 4095) INCREMENT = 0; + const BINARY = `${pad((Date.now() - 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; + + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); +const util = __webpack_require__(7); + +/** + * 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. + */ +class Permissions { + /** + * @param {GuildMember} [member] Member the permissions are for **(deprecated)** + * @param {number|PermissionResolvable[]} permissions Permissions or bitfield to read from + */ + constructor(member, permissions) { + permissions = typeof member === 'object' && !(member instanceof Array) ? permissions : member; + + /** + * Member the permissions are for + * @type {GuildMember} + * @deprecated + */ + this._member = typeof member === 'object' ? member : null; + + /** + * Bitfield of the packed permissions + * @type {number} + */ + this.bitfield = typeof permissions === 'number' ? permissions : this.constructor.resolve(permissions); + } + + 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 multiple permissions. + * @param {PermissionResolvable|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) { + if (permission instanceof Array) return permission.every(p => this.has(p, checkAdmin)); + permission = this.constructor.resolve(permission); + if (checkAdmin && (this.bitfield & this.constructor.FLAGS.ADMINISTRATOR) > 0) return true; + return (this.bitfield & permission) === permission; + } + + /** + * Gets all given permissions that are missing from the bitfield. + * @param {PermissionResolvable[]} permissions Permissions to check for + * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override + * @returns {PermissionResolvable[]} + */ + missing(permissions, checkAdmin = true) { + return permissions.filter(p => !this.has(p, checkAdmin)); + } + + /** + * Adds permissions to this one, creating a new instance to represent the new bitfield. + * @param {...PermissionResolvable} permissions Permissions to add + * @returns {Permissions} + */ + add(...permissions) { + let total = 0; + for (let p = 0; p < permissions.length; p++) { + const perm = this.constructor.resolve(permissions[p]); + if ((this.bitfield & perm) !== perm) total |= perm; + } + return new this.constructor(this.member, this.bitfield | total); + } + + /** + * Removes permissions to this one, creating a new instance to represent the new bitfield. + * @param {...PermissionResolvable} permissions Permissions to remove + * @returns {Permissions} + */ + remove(...permissions) { + let total = 0; + for (let p = 0; p < permissions.length; p++) { + const perm = this.constructor.resolve(permissions[p]); + if ((this.bitfield & perm) === perm) total |= perm; + } + return new this.constructor(this.member, this.bitfield & ~total); + } + + /** + * Gets an object mapping permission name (like `VIEW_CHANNEL`) to a {@link boolean} indicating whether the + * permission is available. + * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override + * @returns {Object} + */ + serialize(checkAdmin = true) { + const serialized = {}; + for (const perm in this.constructor.FLAGS) serialized[perm] = this.has(perm, checkAdmin); + return serialized; + } + + /** + * 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} PermissionResolvable + */ + + /** + * Resolves permissions to their numeric form. + * @param {PermissionResolvable|PermissionResolvable[]} permission - Permission(s) to resolve + * @returns {number} + */ + static resolve(permission) { + if (permission instanceof Array) return permission.map(p => this.resolve(p)).reduce((prev, p) => prev | p, 0); + if (typeof permission === 'string') permission = this.FLAGS[permission]; + if (typeof permission !== 'number' || permission < 1) throw new RangeError(Constants.Errors.NOT_A_PERMISSION); + return permission; + } +} + +/** + * 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` + * - `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, + + 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 = 104324097; + +/** + * @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, 'member', { + get: util + .deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'member').get, + 'EvaluatedPermissions#member is deprecated'), +}); + +module.exports = Permissions; + + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(global, process) {// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; +}; + + +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } + + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +}; + + +var debugs = {}; +var debugEnviron; +exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = Object({"__DISCORD_WEBPACK__":"true"}).NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; + + +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} +exports.inspect = inspect; + + +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; + +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; + + +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; + + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } +} + + +function stylizeNoColor(str, styleType) { + return str; +} + + +function arrayToHash(array) { + var hash = {}; + + array.forEach(function(val, idx) { + hash[val] = true; + }); + + return hash; +} + + +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } + + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } + + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); + + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } + + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } + + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } + + var base = '', array = false, braces = ['{', '}']; + + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } + + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } + + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } + + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } + + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } + + ctx.seen.push(value); + + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } + + ctx.seen.pop(); + + return reduceToSingleString(output, base, braces); +} + + +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} + + +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} + + +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} + + +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } + + return name + ': ' + str; +} + + +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); + + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } + + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} + + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +exports.isBuffer = __webpack_require__(71); + +function objectToString(o) { + return Object.prototype.toString.call(o); +} + + +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} + + +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; + +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} + + +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; + + +/** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. + */ +exports.inherits = __webpack_require__(72); + +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; + + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; + +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(34), __webpack_require__(13))) + +/***/ }), +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { + +const Snowflake = __webpack_require__(5); +const Permissions = __webpack_require__(6); +const util = __webpack_require__(7); + +/** + * Represents a role on Discord. + */ +class Role { + constructor(guild, data) { + /** + * The client that instantiated the role + * @name Role#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: guild.client }); + + /** + * The guild that the role belongs to + * @type {Guild} + */ + this.guild = guild; + + if (data) this.setup(data); + } + + setup(data) { + /** + * The ID of the role (unique to the guild it is part of) + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The name of the role + * @type {string} + */ + this.name = data.name; + + /** + * The base 10 color of the role + * @type {number} + */ + this.color = data.color; + + /** + * If true, users that are part of this role will appear in a separate category in the users list + * @type {boolean} + */ + this.hoist = data.hoist; + + /** + * The position of the role from the API + * @type {number} + */ + this.position = data.position; + + /** + * The permissions bitfield of the role + * @type {number} + */ + this.permissions = data.permissions; + + /** + * Whether or not the role is managed by an external service + * @type {boolean} + */ + this.managed = data.managed; + + /** + * Whether or not the role can be mentioned by anyone + * @type {boolean} + */ + this.mentionable = data.mentionable; + } + + /** + * The timestamp the role was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return Snowflake.deconstruct(this.id).timestamp; + } + + /** + * The time the role was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * The hexadecimal version of the role color, with a leading hashtag + * @type {string} + * @readonly + */ + get hexColor() { + let col = this.color.toString(16); + while (col.length < 6) col = `0${col}`; + return `#${col}`; + } + + /** + * The cached guild members that have this role + * @type {Collection} + * @readonly + */ + get members() { + return this.guild.members.filter(m => m.roles.has(this.id)); + } + + /** + * Whether the role is editable by the client user + * @type {boolean} + * @readonly + */ + get editable() { + if (this.managed) return false; + const clientMember = this.guild.member(this.client.user); + if (!clientMember.permissions.has(Permissions.FLAGS.MANAGE_ROLES_OR_PERMISSIONS)) return false; + return clientMember.highestRole.comparePositionTo(this) > 0; + } + + /** + * The position of the role in the role manager + * @type {number} + * @readonly + */ + get calculatedPosition() { + const sorted = this.guild._sortedRoles; + return sorted.array().indexOf(sorted.get(this.id)); + } + + /** + * Get an object mapping permission names to whether or not the role enables that permission. + * @returns {Object} + * @example + * // Print the serialized role permissions + * console.log(role.serialize()); + */ + serialize() { + return new Permissions(this.permissions).serialize(); + } + + /** + * Checks if the role has a permission. + * @param {PermissionResolvable|PermissionResolvable[]} permission Permission(s) to check for + * @param {boolean} [explicit=false] Whether to require the role to explicitly have the exact permission + * **(deprecated)** + * @param {boolean} [checkAdmin] Whether to allow the administrator permission to override + * (takes priority over `explicit`) + * @returns {boolean} + * @example + * // See if a role can ban a member + * if (role.hasPermission('BAN_MEMBERS')) { + * console.log('This role can ban members'); + * } else { + * console.log('This role can\'t ban members'); + * } + */ + hasPermission(permission, explicit = false, checkAdmin) { + return new Permissions(this.permissions).has( + permission, typeof checkAdmin !== 'undefined' ? checkAdmin : !explicit + ); + } + + /** + * Checks if the role has all specified permissions. + * @param {PermissionResolvable[]} permissions The permissions to check for + * @param {boolean} [explicit=false] Whether to require the role to explicitly have the exact permissions + * @returns {boolean} + * @deprecated + */ + hasPermissions(permissions, explicit = false) { + return new Permissions(this.permissions).has(permissions, !explicit); + } + + /** + * Compares this role's position to another role's. + * @param {Role} role Role to compare to this one + * @returns {number} Negative number if the this role's position is lower (other role's is higher), + * positive number if the this one is higher (other's is lower), 0 if equal + */ + comparePositionTo(role) { + return this.constructor.comparePositions(this, role); + } + + /** + * The data for a role. + * @typedef {Object} RoleData + * @property {string} [name] The name of the role + * @property {ColorResolvable} [color] The color of the role, either a hex string or a base 10 number + * @property {boolean} [hoist] Whether or not the role should be hoisted + * @property {number} [position] The position of the role + * @property {PermissionResolvable[]|number} [permissions] The permissions of the role + * @property {boolean} [mentionable] Whether or not the role should be mentionable + */ + + /** + * Edits the role. + * @param {RoleData} data The new data for the role + * @param {string} [reason] The reason for editing this role + * @returns {Promise} + * @example + * // Edit name of a role + * role.edit({ name: 'New Name' }) + * .then(updated => console.log(`Edited role name from ${role.name} to ${updated.name}`)) + * .catch(console.error); + */ + edit(data, reason) { + return this.client.rest.methods.updateGuildRole(this, data, reason); + } + + /** + * Set a new name for the role. + * @param {string} name The new name of the role + * @param {string} [reason] Reason for changing the role's name + * @returns {Promise} + * @example + * // Set the name of the role + * role.setName('New Name') + * .then(updated => console.log(`Edited role name from ${role.name} to ${updated.name}`)) + * .catch(console.error); + */ + setName(name, reason) { + return this.edit({ name }, reason); + } + + /** + * Set a new color for the role. + * @param {ColorResolvable} color The color of the role + * @param {string} [reason] Reason for changing the role's color + * @returns {Promise} + * @example + * // Set the color of a role + * role.setColor('#FF0000') + * .then(updated => console.log(`Set color of role to ${role.color}`)) + * .catch(console.error); + */ + setColor(color, reason) { + return this.edit({ color }, reason); + } + + /** + * Set whether or not the role should be hoisted. + * @param {boolean} hoist Whether or not to hoist the role + * @param {string} [reason] Reason for setting whether or not the role should be hoisted + * @returns {Promise} + * @example + * // Set the hoist of the role + * role.setHoist(true) + * .then(updated => console.log(`Role hoisted: ${updated.hoist}`)) + * .catch(console.error); + */ + setHoist(hoist, reason) { + return this.edit({ hoist }, reason); + } + + /** + * Set the position of the role. + * @param {number} position The position of the role + * @param {boolean} [relative=false] Move the position relative to its current value + * @returns {Promise} + * @example + * // Set the position of the role + * role.setPosition(1) + * .then(updated => console.log(`Role position: ${updated.position}`)) + * .catch(console.error); + */ + setPosition(position, relative) { + return this.guild.setRolePosition(this, position, relative).then(() => this); + } + + /** + * Set the permissions of the role. + * @param {string[]} permissions The permissions of the role + * @param {string} [reason] Reason for changing the role's permissions + * @returns {Promise} + * @example + * // Set the permissions of the role + * role.setPermissions(['KICK_MEMBERS', 'BAN_MEMBERS']) + * .then(updated => console.log(`Updated permissions to ${updated.permissions.bitfield}`)) + * .catch(console.error); + */ + setPermissions(permissions, reason) { + return this.edit({ permissions }, reason); + } + + /** + * Set whether this role is mentionable. + * @param {boolean} mentionable Whether this role should be mentionable + * @param {string} [reason] Reason for setting whether or not this role should be mentionable + * @returns {Promise} + * @example + * // Make the role mentionable + * role.setMentionable(true, 'Role needs to be pinged') + * .then(updated => console.log(`Role mentionable: ${updated.mentionable}`)) + * .catch(console.error); + */ + setMentionable(mentionable, reason) { + return this.edit({ mentionable }, reason); + } + + /** + * Deletes the role. + * @param {string} [reason] Reason for deleting the role + * @returns {Promise} + * @example + * // Delete a role + * role.delete('The role needed to go') + * .then(deleted => console.log(`Deleted role ${deleted.name}`)) + * .catch(console.error); + */ + delete(reason) { + return this.client.rest.methods.deleteGuildRole(this, reason); + } + + /** + * Whether this role equals another role. It compares all properties, so for most operations + * it is advisable to just compare `role.id === role2.id` as it is much faster and is often + * what most users need. + * @param {Role} role Role to compare with + * @returns {boolean} + */ + equals(role) { + return role && + this.id === role.id && + this.name === role.name && + this.color === role.color && + this.hoist === role.hoist && + this.position === role.position && + this.permissions === role.permissions && + this.managed === role.managed; + } + + /** + * When concatenated with a string, this automatically concatenates the role mention rather than the Role object. + * @returns {string} + */ + toString() { + if (this.id === this.guild.id) return '@everyone'; + return `<@&${this.id}>`; + } + + /** + * Compares the positions of two roles. + * @param {Role} role1 First role to compare + * @param {Role} role2 Second role to compare + * @returns {number} Negative number if the first role's position is lower (second role's is higher), + * positive number if the first's is higher (second's is lower), 0 if equal + */ + static comparePositions(role1, role2) { + if (role1.position === role2.position) return role2.id - role1.id; + return role1.position - role2.position; + } +} + +Role.prototype.hasPermissions = util + .deprecate(Role.prototype.hasPermissions, + 'Role#hasPermissions is deprecated - use Role#hasPermission instead, it now takes an array'); + +module.exports = Role; + + +/***/ }), +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { + +const TextBasedChannel = __webpack_require__(14); +const Constants = __webpack_require__(0); +const Presence = __webpack_require__(10).Presence; +const Snowflake = __webpack_require__(5); + +/** + * Represents a user on Discord. + * @implements {TextBasedChannel} + */ +class User { + constructor(client, data) { + /** + * The client that created the instance of the user + * @name User#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + if (data) this.setup(data); + } + + setup(data) { + /** + * The ID of the user + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The username of the user + * @type {string} + */ + this.username = data.username; + + /** + * A discriminator based on username for the user + * @type {string} + */ + this.discriminator = data.discriminator; + + /** + * The ID of the user's avatar + * @type {string} + */ + this.avatar = data.avatar; + + /** + * Whether or not the user is a bot + * @type {boolean} + */ + this.bot = Boolean(data.bot); + + /** + * The ID of the last message sent by the user, if one was sent + * @type {?Snowflake} + */ + this.lastMessageID = null; + + /** + * The Message object of the last message sent by the user, if one was sent + * @type {?Message} + */ + this.lastMessage = null; + } + + patch(data) { + for (const prop of ['id', 'username', 'discriminator', 'avatar', 'bot']) { + if (typeof data[prop] !== 'undefined') this[prop] = data[prop]; + } + if (data.token) this.client.token = data.token; + } + + /** + * The timestamp the user was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return Snowflake.deconstruct(this.id).timestamp; + } + + /** + * The time the user was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * The presence of this user + * @type {Presence} + * @readonly + */ + get presence() { + if (this.client.presences.has(this.id)) return this.client.presences.get(this.id); + for (const guild of this.client.guilds.values()) { + if (guild.presences.has(this.id)) return guild.presences.get(this.id); + } + return new Presence(); + } + + /** + * A link to the user's avatar + * @type {?string} + * @readonly + */ + get avatarURL() { + if (!this.avatar) return null; + return Constants.Endpoints.User(this).Avatar(this.client.options.http.cdn, this.avatar); + } + + /** + * A link to the user's default avatar + * @type {string} + * @readonly + */ + get defaultAvatarURL() { + const avatars = Object.keys(Constants.DefaultAvatars); + const avatar = avatars[this.discriminator % avatars.length]; + return Constants.Endpoints.CDN(this.client.options.http.host).Asset(`${Constants.DefaultAvatars[avatar]}.png`); + } + + /** + * A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned + * @type {string} + * @readonly + */ + get displayAvatarURL() { + return this.avatarURL || this.defaultAvatarURL; + } + + /** + * The Discord "tag" for this user + * @type {string} + * @readonly + */ + get tag() { + return `${this.username}#${this.discriminator}`; + } + + /** + * The note that is set for the user + * This is only available when using a user account. + * @type {?string} + * @readonly + */ + get note() { + return this.client.user.notes.get(this.id) || null; + } + + /** + * Check whether the user is typing in a channel. + * @param {ChannelResolvable} channel The channel to check in + * @returns {boolean} + */ + typingIn(channel) { + channel = this.client.resolver.resolveChannel(channel); + return channel._typing.has(this.id); + } + + /** + * Get the time that the user started typing. + * @param {ChannelResolvable} channel The channel to get the time in + * @returns {?Date} + */ + typingSinceIn(channel) { + channel = this.client.resolver.resolveChannel(channel); + return channel._typing.has(this.id) ? new Date(channel._typing.get(this.id).since) : null; + } + + /** + * Get the amount of time the user has been typing in a channel for (in milliseconds), or -1 if they're not typing. + * @param {ChannelResolvable} channel The channel to get the time in + * @returns {number} + */ + typingDurationIn(channel) { + channel = this.client.resolver.resolveChannel(channel); + return channel._typing.has(this.id) ? channel._typing.get(this.id).elapsedTime : -1; + } + + /** + * The DM between the client's user and this user + * @type {?DMChannel} + * @readonly + */ + get dmChannel() { + return this.client.channels.filter(c => c.type === 'dm').find(c => c.recipient.id === this.id); + } + + /** + * Creates a DM channel between the client and the user. + * @returns {Promise} + */ + createDM() { + return this.client.rest.methods.createDM(this); + } + + /** + * Deletes a DM channel (if one exists) between the client and the user. Resolves with the channel if successful. + * @returns {Promise} + */ + deleteDM() { + return this.client.rest.methods.deleteChannel(this); + } + + /** + * Sends a friend request to the user. + * This is only available when using a user account. + * @returns {Promise} + */ + addFriend() { + return this.client.rest.methods.addFriend(this); + } + + /** + * Removes the user from your friends. + * This is only available when using a user account. + * @returns {Promise} + */ + removeFriend() { + return this.client.rest.methods.removeFriend(this); + } + + /** + * Blocks the user. + * This is only available when using a user account. + * @returns {Promise} + */ + block() { + return this.client.rest.methods.blockUser(this); + } + + /** + * Unblocks the user. + * This is only available when using a user account. + * @returns {Promise} + */ + unblock() { + return this.client.rest.methods.unblockUser(this); + } + + /** + * Get the profile of the user. + * This is only available when using a user account. + * @returns {Promise} + */ + fetchProfile() { + return this.client.rest.methods.fetchUserProfile(this); + } + + /** + * Sets a note for the user. + * This is only available when using a user account. + * @param {string} note The note to set for the user + * @returns {Promise} + */ + setNote(note) { + return this.client.rest.methods.setNote(this, note); + } + + /** + * Checks if the user is equal to another. It compares ID, username, discriminator, avatar, and bot flags. + * It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties. + * @param {User} user User to compare with + * @returns {boolean} + */ + equals(user) { + let equal = user && + this.id === user.id && + this.username === user.username && + this.discriminator === user.discriminator && + this.avatar === user.avatar && + this.bot === Boolean(user.bot); + + return equal; + } + + /** + * When concatenated with a string, this automatically concatenates the user's mention instead of the User object. + * @returns {string} + * @example + * // logs: Hello from <@123456789>! + * console.log(`Hello from ${user}!`); + */ + toString() { + return `<@${this.id}>`; + } + + // These are here only for documentation purposes - they are implemented by TextBasedChannel + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendCode() {} +} + +TextBasedChannel.applyToClass(User); + +module.exports = User; + + +/***/ }), +/* 10 */ +/***/ (function(module, exports) { + +/** + * Represents a user's presence. + */ +class Presence { + constructor(data = {}) { + /** + * The status of the presence: + * + * * **`online`** - user is online + * * **`offline`** - user is offline or invisible + * * **`idle`** - user is AFK + * * **`dnd`** - user is in Do not Disturb + * @type {string} + */ + this.status = data.status || 'offline'; + + /** + * The game that the user is playing + * @type {?Game} + */ + this.game = data.game ? new Game(data.game) : null; + } + + update(data) { + this.status = data.status || this.status; + this.game = data.game ? new Game(data.game) : null; + } + + /** + * Whether this presence is equal to another + * @param {Presence} presence The presence to compare with + * @returns {boolean} + */ + equals(presence) { + return this === presence || ( + presence && + this.status === presence.status && + this.game ? this.game.equals(presence.game) : !presence.game + ); + } +} + +/** + * Represents a game that is part of a user's presence. + */ +class Game { + constructor(data) { + /** + * The name of the game being played + * @type {string} + */ + this.name = data.name; + + /** + * The type of the game status + * @type {number} + */ + this.type = data.type; + + /** + * If the game is being streamed, a link to the stream + * @type {?string} + */ + this.url = data.url || null; + } + + /** + * Whether or not the game is being streamed + * @type {boolean} + * @readonly + */ + get streaming() { + return this.type === 1; + } + + /** + * Whether this game is equal to another game + * @param {Game} game The game to compare with + * @returns {boolean} + */ + equals(game) { + return this === game || ( + game && + this.name === game.name && + this.type === game.type && + this.url === game.url + ); + } +} + +exports.Presence = Presence; +exports.Game = Game; + + +/***/ }), +/* 11 */ +/***/ (function(module, exports, __webpack_require__) { + +const Snowflake = __webpack_require__(5); + +/** + * Represents any channel on Discord. + */ +class Channel { + constructor(client, data) { + /** + * The client that instantiated the Channel + * @name Channel#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + /** + * The type of the channel, either: + * * `dm` - a DM channel + * * `group` - a Group DM channel + * * `text` - a guild text channel + * * `voice` - a guild voice channel + * * `category` - a guild category channel + * @type {string} + */ + this.type = null; + + if (data) this.setup(data); + } + + setup(data) { + /** + * The unique ID of the channel + * @type {Snowflake} + */ + this.id = data.id; + } + + /** + * The timestamp the channel was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return Snowflake.deconstruct(this.id).timestamp; + } + + /** + * The time the channel was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * Deletes the channel. + * @returns {Promise} + * @example + * // Delete the channel + * channel.delete() + * .then(console.log) + * .catch(console.error); + */ + delete() { + return this.client.rest.methods.deleteChannel(this); + } +} + +module.exports = Channel; + + +/***/ }), +/* 12 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +/* WEBPACK VAR INJECTION */(function(global) {/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +/* eslint-disable no-proto */ + + + +var base64 = __webpack_require__(60) +var ieee754 = __webpack_require__(61) +var isArray = __webpack_require__(62) + +exports.Buffer = Buffer +exports.SlowBuffer = SlowBuffer +exports.INSPECT_MAX_BYTES = 50 + +/** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Use Object implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * + * Note: + * + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. + */ +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +/* + * Export kMaxLength after typed array support is determined. + */ +exports.kMaxLength = kMaxLength() + +function typedArraySupport () { + try { + var arr = new Uint8Array(1) + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} + return arr.foo() === 42 && // typed array instances can be augmented + typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + } catch (e) { + return false + } +} + +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} + +function createBuffer (that, length) { + if (kMaxLength() < length) { + throw new RangeError('Invalid typed array length') + } + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = new Uint8Array(length) + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + if (that === null) { + that = new Buffer(length) + } + that.length = length + } + + return that +} + +/** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ + +function Buffer (arg, encodingOrOffset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, encodingOrOffset, length) + } + + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new Error( + 'If encoding is specified then the first argument must be a string' + ) + } + return allocUnsafe(this, arg) + } + return from(this, arg, encodingOrOffset, length) +} + +Buffer.poolSize = 8192 // not used by this implementation + +// TODO: Legacy, not needed anymore. Remove in next major version. +Buffer._augment = function (arr) { + arr.__proto__ = Buffer.prototype + return arr +} + +function from (that, value, encodingOrOffset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') + } + + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + return fromArrayBuffer(that, value, encodingOrOffset, length) + } + + if (typeof value === 'string') { + return fromString(that, value, encodingOrOffset) + } + + return fromObject(that, value) +} + +/** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ +Buffer.from = function (value, encodingOrOffset, length) { + return from(null, value, encodingOrOffset, length) +} + +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array + if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true + }) + } +} + +function assertSize (size) { + if (typeof size !== 'number') { + throw new TypeError('"size" argument must be a number') + } else if (size < 0) { + throw new RangeError('"size" argument must not be negative') + } +} + +function alloc (that, size, fill, encoding) { + assertSize(size) + if (size <= 0) { + return createBuffer(that, size) + } + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpretted as a start offset. + return typeof encoding === 'string' + ? createBuffer(that, size).fill(fill, encoding) + : createBuffer(that, size).fill(fill) + } + return createBuffer(that, size) +} + +/** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ +Buffer.alloc = function (size, fill, encoding) { + return alloc(null, size, fill, encoding) +} + +function allocUnsafe (that, size) { + assertSize(size) + that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < size; ++i) { + that[i] = 0 + } + } + return that +} + +/** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ +Buffer.allocUnsafe = function (size) { + return allocUnsafe(null, size) +} +/** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ +Buffer.allocUnsafeSlow = function (size) { + return allocUnsafe(null, size) +} + +function fromString (that, string, encoding) { + if (typeof encoding !== 'string' || encoding === '') { + encoding = 'utf8' + } + + if (!Buffer.isEncoding(encoding)) { + throw new TypeError('"encoding" must be a valid string encoding') + } + + var length = byteLength(string, encoding) | 0 + that = createBuffer(that, length) + + var actual = that.write(string, encoding) + + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + that = that.slice(0, actual) + } + + return that +} + +function fromArrayLike (that, array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0 + that = createBuffer(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +function fromArrayBuffer (that, array, byteOffset, length) { + array.byteLength // this throws if `array` is not a valid ArrayBuffer + + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') + } + + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') + } + + if (byteOffset === undefined && length === undefined) { + array = new Uint8Array(array) + } else if (length === undefined) { + array = new Uint8Array(array, byteOffset) + } else { + array = new Uint8Array(array, byteOffset, length) + } + + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = array + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + that = fromArrayLike(that, array) + } + return that +} + +function fromObject (that, obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0 + that = createBuffer(that, len) + + if (that.length === 0) { + return that + } + + obj.copy(that, 0, 0, len) + return that + } + + if (obj) { + if ((typeof ArrayBuffer !== 'undefined' && + obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (typeof obj.length !== 'number' || isnan(obj.length)) { + return createBuffer(that, 0) + } + return fromArrayLike(that, obj) + } + + if (obj.type === 'Buffer' && isArray(obj.data)) { + return fromArrayLike(that, obj.data) + } + } + + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') +} + +function checked (length) { + // Note: cannot use `length < kMaxLength()` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= kMaxLength()) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + kMaxLength().toString(16) + ' bytes') + } + return length | 0 +} + +function SlowBuffer (length) { + if (+length != length) { // eslint-disable-line eqeqeq + length = 0 + } + return Buffer.alloc(+length) +} + +Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) +} + +Buffer.compare = function compare (a, b) { + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError('Arguments must be Buffers') + } + + if (a === b) return 0 + + var x = a.length + var y = b.length + + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i] + y = b[i] + break + } + } + + if (x < y) return -1 + if (y < x) return 1 + return 0 +} + +Buffer.isEncoding = function isEncoding (encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'latin1': + case 'binary': + case 'base64': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } +} + +Buffer.concat = function concat (list, length) { + if (!isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + + if (list.length === 0) { + return Buffer.alloc(0) + } + + var i + if (length === undefined) { + length = 0 + for (i = 0; i < list.length; ++i) { + length += list[i].length + } + } + + var buffer = Buffer.allocUnsafe(length) + var pos = 0 + for (i = 0; i < list.length; ++i) { + var buf = list[i] + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos) + pos += buf.length + } + return buffer +} + +function byteLength (string, encoding) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && + (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string + } + + var len = string.length + if (len === 0) return 0 + + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'latin1': + case 'binary': + return len + case 'utf8': + case 'utf-8': + case undefined: + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) return utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} +Buffer.byteLength = byteLength + +function slowToString (encoding, start, end) { + var loweredCase = false + + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. + + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0 + } + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return '' + } + + if (end === undefined || end > this.length) { + end = this.length + } + + if (end <= 0) { + return '' + } + + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0 + start >>>= 0 + + if (end <= start) { + return '' + } + + if (!encoding) encoding = 'utf8' + + while (true) { + switch (encoding) { + case 'hex': + return hexSlice(this, start, end) + + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end) + + case 'ascii': + return asciiSlice(this, start, end) + + case 'latin1': + case 'binary': + return latin1Slice(this, start, end) + + case 'base64': + return base64Slice(this, start, end) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = (encoding + '').toLowerCase() + loweredCase = true + } + } +} + +// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect +// Buffer instances. +Buffer.prototype._isBuffer = true + +function swap (b, n, m) { + var i = b[n] + b[n] = b[m] + b[m] = i +} + +Buffer.prototype.swap16 = function swap16 () { + var len = this.length + if (len % 2 !== 0) { + throw new RangeError('Buffer size must be a multiple of 16-bits') + } + for (var i = 0; i < len; i += 2) { + swap(this, i, i + 1) + } + return this +} + +Buffer.prototype.swap32 = function swap32 () { + var len = this.length + if (len % 4 !== 0) { + throw new RangeError('Buffer size must be a multiple of 32-bits') + } + for (var i = 0; i < len; i += 4) { + swap(this, i, i + 3) + swap(this, i + 1, i + 2) + } + return this +} + +Buffer.prototype.swap64 = function swap64 () { + var len = this.length + if (len % 8 !== 0) { + throw new RangeError('Buffer size must be a multiple of 64-bits') + } + for (var i = 0; i < len; i += 8) { + swap(this, i, i + 7) + swap(this, i + 1, i + 6) + swap(this, i + 2, i + 5) + swap(this, i + 3, i + 4) + } + return this +} + +Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) +} + +Buffer.prototype.equals = function equals (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return true + return Buffer.compare(this, b) === 0 +} + +Buffer.prototype.inspect = function inspect () { + var str = '' + var max = exports.INSPECT_MAX_BYTES + if (this.length > 0) { + str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') + if (this.length > max) str += ' ... ' + } + return '' +} + +Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (!Buffer.isBuffer(target)) { + throw new TypeError('Argument must be a Buffer') + } + + if (start === undefined) { + start = 0 + } + if (end === undefined) { + end = target ? target.length : 0 + } + if (thisStart === undefined) { + thisStart = 0 + } + if (thisEnd === undefined) { + thisEnd = this.length + } + + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError('out of range index') + } + + if (thisStart >= thisEnd && start >= end) { + return 0 + } + if (thisStart >= thisEnd) { + return -1 + } + if (start >= end) { + return 1 + } + + start >>>= 0 + end >>>= 0 + thisStart >>>= 0 + thisEnd >>>= 0 + + if (this === target) return 0 + + var x = thisEnd - thisStart + var y = end - start + var len = Math.min(x, y) + + var thisCopy = this.slice(thisStart, thisEnd) + var targetCopy = target.slice(start, end) + + for (var i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i] + y = targetCopy[i] + break + } + } + + if (x < y) return -1 + if (y < x) return 1 + return 0 +} + +// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, +// OR the last index of `val` in `buffer` at offset <= `byteOffset`. +// +// Arguments: +// - buffer - a Buffer to search +// - val - a string, Buffer, or number +// - byteOffset - an index into `buffer`; will be clamped to an int32 +// - encoding - an optional encoding, relevant is val is a string +// - dir - true for indexOf, false for lastIndexOf +function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1 + + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset + byteOffset = 0 + } else if (byteOffset > 0x7fffffff) { + byteOffset = 0x7fffffff + } else if (byteOffset < -0x80000000) { + byteOffset = -0x80000000 + } + byteOffset = +byteOffset // Coerce to Number. + if (isNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : (buffer.length - 1) + } + + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset + if (byteOffset >= buffer.length) { + if (dir) return -1 + else byteOffset = buffer.length - 1 + } else if (byteOffset < 0) { + if (dir) byteOffset = 0 + else return -1 + } + + // Normalize val + if (typeof val === 'string') { + val = Buffer.from(val, encoding) + } + + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1 + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir) + } else if (typeof val === 'number') { + val = val & 0xFF // Search for a byte value [0-255] + if (Buffer.TYPED_ARRAY_SUPPORT && + typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) + } + } + return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) + } + + throw new TypeError('val must be string, number or Buffer') +} + +function arrayIndexOf (arr, val, byteOffset, encoding, dir) { + var indexSize = 1 + var arrLength = arr.length + var valLength = val.length + + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase() + if (encoding === 'ucs2' || encoding === 'ucs-2' || + encoding === 'utf16le' || encoding === 'utf-16le') { + if (arr.length < 2 || val.length < 2) { + return -1 + } + indexSize = 2 + arrLength /= 2 + valLength /= 2 + byteOffset /= 2 + } + } + + function read (buf, i) { + if (indexSize === 1) { + return buf[i] + } else { + return buf.readUInt16BE(i * indexSize) + } + } + + var i + if (dir) { + var foundIndex = -1 + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize + } else { + if (foundIndex !== -1) i -= i - foundIndex + foundIndex = -1 + } + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength + for (i = byteOffset; i >= 0; i--) { + var found = true + for (var j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false + break + } + } + if (found) return i + } + } + + return -1 +} + +Buffer.prototype.includes = function includes (val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1 +} + +Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true) +} + +Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false) +} + +function hexWrite (buf, string, offset, length) { + offset = Number(offset) || 0 + var remaining = buf.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } + } + + // must be an even number of digits + var strLen = string.length + if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') + + if (length > strLen / 2) { + length = strLen / 2 + } + for (var i = 0; i < length; ++i) { + var parsed = parseInt(string.substr(i * 2, 2), 16) + if (isNaN(parsed)) return i + buf[offset + i] = parsed + } + return i +} + +function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) +} + +function asciiWrite (buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length) +} + +function latin1Write (buf, string, offset, length) { + return asciiWrite(buf, string, offset, length) +} + +function base64Write (buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length) +} + +function ucs2Write (buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) +} + +Buffer.prototype.write = function write (string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8' + length = this.length + offset = 0 + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset + length = this.length + offset = 0 + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset | 0 + if (isFinite(length)) { + length = length | 0 + if (encoding === undefined) encoding = 'utf8' + } else { + encoding = length + length = undefined + } + // legacy write(string, encoding, offset, length) - remove in v0.13 + } else { + throw new Error( + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' + ) + } + + var remaining = this.length - offset + if (length === undefined || length > remaining) length = remaining + + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') + } + + if (!encoding) encoding = 'utf8' + + var loweredCase = false + for (;;) { + switch (encoding) { + case 'hex': + return hexWrite(this, string, offset, length) + + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length) + + case 'ascii': + return asciiWrite(this, string, offset, length) + + case 'latin1': + case 'binary': + return latin1Write(this, string, offset, length) + + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} + +Buffer.prototype.toJSON = function toJSON () { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + } +} + +function base64Slice (buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf) + } else { + return base64.fromByteArray(buf.slice(start, end)) + } +} + +function utf8Slice (buf, start, end) { + end = Math.min(buf.length, end) + var res = [] + + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } + } + } + + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF + } + + res.push(codePoint) + i += bytesPerSequence + } + + return decodeCodePointsArray(res) +} + +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res +} + +function asciiSlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 0x7F) + } + return ret +} + +function latin1Slice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]) + } + return ret +} + +function hexSlice (buf, start, end) { + var len = buf.length + + if (!start || start < 0) start = 0 + if (!end || end < 0 || end > len) end = len + + var out = '' + for (var i = start; i < end; ++i) { + out += toHex(buf[i]) + } + return out +} + +function utf16leSlice (buf, start, end) { + var bytes = buf.slice(start, end) + var res = '' + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) + } + return res +} + +Buffer.prototype.slice = function slice (start, end) { + var len = this.length + start = ~~start + end = end === undefined ? len : ~~end + + if (start < 0) { + start += len + if (start < 0) start = 0 + } else if (start > len) { + start = len + } + + if (end < 0) { + end += len + if (end < 0) end = 0 + } else if (end > len) { + end = len + } + + if (end < start) end = start + + var newBuf + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = this.subarray(start, end) + newBuf.__proto__ = Buffer.prototype + } else { + var sliceLen = end - start + newBuf = new Buffer(sliceLen, undefined) + for (var i = 0; i < sliceLen; ++i) { + newBuf[i] = this[i + start] + } + } + + return newBuf +} + +/* + * Need to make sure that buffer isn't trying to write out of bounds. + */ +function checkOffset (offset, ext, length) { + if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') +} + +Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } + + return val +} + +Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + checkOffset(offset, byteLength, this.length) + } + + var val = this[offset + --byteLength] + var mul = 1 + while (byteLength > 0 && (mul *= 0x100)) { + val += this[offset + --byteLength] * mul + } + + return val +} + +Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + return this[offset] +} + +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return this[offset] | (this[offset + 1] << 8) +} + +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return (this[offset] << 8) | this[offset + 1] +} + +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return ((this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16)) + + (this[offset + 3] * 0x1000000) +} + +Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset] * 0x1000000) + + ((this[offset + 1] << 16) | + (this[offset + 2] << 8) | + this[offset + 3]) +} + +Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } + mul *= 0x80 + + if (val >= mul) val -= Math.pow(2, 8 * byteLength) + + return val +} + +Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var i = byteLength + var mul = 1 + var val = this[offset + --i] + while (i > 0 && (mul *= 0x100)) { + val += this[offset + --i] * mul + } + mul *= 0x80 + + if (val >= mul) val -= Math.pow(2, 8 * byteLength) + + return val +} + +Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + if (!(this[offset] & 0x80)) return (this[offset]) + return ((0xff - this[offset] + 1) * -1) +} + +Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset] | (this[offset + 1] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} + +Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset + 1] | (this[offset] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} + +Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16) | + (this[offset + 3] << 24) +} + +Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset] << 24) | + (this[offset + 1] << 16) | + (this[offset + 2] << 8) | + (this[offset + 3]) +} + +Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, true, 23, 4) +} + +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, false, 23, 4) +} + +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, true, 52, 8) +} + +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, false, 52, 8) +} + +function checkInt (buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') + if (offset + ext > buf.length) throw new RangeError('Index out of range') +} + +Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } + + var mul = 1 + var i = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } + + var i = byteLength - 1 + var mul = 1 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + this[offset] = (value & 0xff) + return offset + 1 +} + +function objectWriteUInt16 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { + buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> + (littleEndian ? i : 1 - i) * 8 + } +} + +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + return offset + 2 +} + +Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 +} + +function objectWriteUInt32 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffffffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { + buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + } +} + +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 +} + +Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 +} + +Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } + + var i = 0 + var mul = 1 + var sub = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } + + var i = byteLength - 1 + var mul = 1 + var sub = 0 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + if (value < 0) value = 0xff + value + 1 + this[offset] = (value & 0xff) + return offset + 1 +} + +Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + return offset + 2 +} + +Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 +} + +Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 +} + +Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (value < 0) value = 0xffffffff + value + 1 + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 +} + +function checkIEEE754 (buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError('Index out of range') + if (offset < 0) throw new RangeError('Index out of range') +} + +function writeFloat (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) + } + ieee754.write(buf, value, offset, littleEndian, 23, 4) + return offset + 4 +} + +Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert) +} + +Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert) +} + +function writeDouble (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + } + ieee754.write(buf, value, offset, littleEndian, 52, 8) + return offset + 8 +} + +Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert) +} + +Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert) +} + +// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) +Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0 + if (!end && end !== 0) end = this.length + if (targetStart >= target.length) targetStart = target.length + if (!targetStart) targetStart = 0 + if (end > 0 && end < start) end = start + + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') + } + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') + + // Are we oob? + if (end > this.length) end = this.length + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start + } + + var len = end - start + var i + + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; ++i) { + target[i + targetStart] = this[i + start] + } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, start + len), + targetStart + ) + } + + return len +} + +// Usage: +// buffer.fill(number[, offset[, end]]) +// buffer.fill(buffer[, offset[, end]]) +// buffer.fill(string[, offset[, end]][, encoding]) +Buffer.prototype.fill = function fill (val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start + start = 0 + end = this.length + } else if (typeof end === 'string') { + encoding = end + end = this.length + } + if (val.length === 1) { + var code = val.charCodeAt(0) + if (code < 256) { + val = code + } + } + if (encoding !== undefined && typeof encoding !== 'string') { + throw new TypeError('encoding must be a string') + } + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding) + } + } else if (typeof val === 'number') { + val = val & 255 + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') + } + + if (end <= start) { + return this + } + + start = start >>> 0 + end = end === undefined ? this.length : end >>> 0 + + if (!val) val = 0 + + var i + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val + } + } else { + var bytes = Buffer.isBuffer(val) + ? val + : utf8ToBytes(new Buffer(val, encoding).toString()) + var len = bytes.length + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len] + } + } + + return this +} + +// HELPER FUNCTIONS +// ================ + +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g + +function base64clean (str) { + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = stringtrim(str).replace(INVALID_BASE64_RE, '') + // Node converts strings with length < 2 to '' + if (str.length < 2) return '' + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + '=' + } + return str +} + +function stringtrim (str) { + if (str.trim) return str.trim() + return str.replace(/^\s+|\s+$/g, '') +} + +function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) +} + +function utf8ToBytes (string, units) { + units = units || Infinity + var codePoint + var length = string.length + var leadSurrogate = null + var bytes = [] + + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i) + + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } + + // valid lead + leadSurrogate = codePoint + + continue + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + } + + leadSurrogate = null + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint) + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else { + throw new Error('Invalid code point') + } + } + + return bytes +} + +function asciiToBytes (str) { + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xFF) + } + return byteArray +} + +function utf16leToBytes (str, units) { + var c, hi, lo + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + if ((units -= 2) < 0) break + + c = str.charCodeAt(i) + hi = c >> 8 + lo = c % 256 + byteArray.push(lo) + byteArray.push(hi) + } + + return byteArray +} + +function base64ToBytes (str) { + return base64.toByteArray(base64clean(str)) +} + +function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i] + } + return i +} + +function isnan (val) { + return val !== val // eslint-disable-line no-self-compare +} + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(34))) + +/***/ }), +/* 13 */ +/***/ (function(module, exports) { + +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + + +/***/ }), +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(Buffer) {const path = __webpack_require__(26); +const Message = __webpack_require__(15); +const MessageCollector = __webpack_require__(44); +const Collection = __webpack_require__(3); +const Attachment = __webpack_require__(21); +const RichEmbed = __webpack_require__(20); +const Snowflake = __webpack_require__(5); +const util = __webpack_require__(7); + +/** + * Interface for classes that have text-channel-like features. + * @interface + */ +class TextBasedChannel { + constructor() { + /** + * A collection containing the messages sent to this channel + * @type {Collection} + */ + this.messages = new Collection(); + + /** + * The ID of the last message in the channel, if one was sent + * @type {?Snowflake} + */ + this.lastMessageID = null; + + /** + * The Message object of the last message in the channel, if one was sent + * @type {?Message} + */ + this.lastMessage = null; + } + + /** + * Options provided when sending or editing a message. + * @typedef {Object} MessageOptions + * @property {boolean} [tts=false] Whether or not the message should be spoken aloud + * @property {string} [nonce=''] The nonce for the message + * @property {RichEmbed|Object} [embed] An embed for the message + * (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details) + * @property {boolean} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here + * should be replaced with plain-text + * @property {FileOptions|BufferResolvable|Attachment} [file] A file to send with the message **(deprecated)** + * @property {FileOptions[]|BufferResolvable[]|Attachment[]} [files] Files to send with the message + * @property {string|boolean} [code] Language for optional codeblock formatting to apply + * @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if + * it exceeds the character limit. If an object is provided, these are the options for splitting the message + * @property {UserResolvable} [reply] User to reply to (prefixes the message with a mention, except in DMs) + */ + + /** + * @typedef {Object} FileOptions + * @property {BufferResolvable} attachment File to attach + * @property {string} [name='file.jpg'] Filename of the attachment + */ + + /** + * Options for splitting a message. + * @typedef {Object} SplitOptions + * @property {number} [maxLength=1950] Maximum character length per message piece + * @property {string} [char='\n'] Character to split the message with + * @property {string} [prepend=''] Text to prepend to every piece except the first + * @property {string} [append=''] Text to append to every piece except the last + */ + + /** + * Send a message to this channel. + * @param {StringResolvable} [content] Text for the message + * @param {MessageOptions|Attachment|RichEmbed} [options] Options for the message, + * can also be just a RichEmbed or Attachment + * @returns {Promise} + * @example + * // Send a basic message + * channel.send('hello!') + * .then(message => console.log(`Sent message: ${message.content}`)) + * .catch(console.error); + * @example + * // Send a remote file + * channel.send({ + * files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048'] + * }) + * .then(console.log) + * .catch(console.error); + * @example + * // Send a local file + * channel.send({ + * files: [{ + * attachment: 'entire/path/to/file.jpg', + * name: 'file.jpg' + * }] + * }) + * .then(console.log) + * .catch(console.error); + * @example + * // Send an embed with a local image inside + * channel.send('This is an embed', { + * embed: { + * thumbnail: { + * url: 'attachment://file.jpg' + * } + * }, + * files: [{ + * attachment: 'entire/path/to/file.jpg', + * name: 'file.jpg' + * }] + * }) + * .then(console.log) + * .catch(console.error); + */ + // eslint-disable-next-line complexity + send(content, options) { + if (!options && typeof content === 'object' && !(content instanceof Array)) { + options = content; + content = ''; + } else if (!options) { + options = {}; + } + + if (options instanceof Attachment) options = { files: [options.file] }; + if (options instanceof RichEmbed) options = { embed: options }; + + if (options.embed && options.embed.file) { + if (options.files) options.files.push(options.embed.file); + else options.files = [options.embed.file]; + } + + if (options.file) { + if (options.files) options.files.push(options.file); + else options.files = [options.file]; + } + + if (options.files) { + for (let i = 0; i < options.files.length; i++) { + let file = options.files[i]; + if (typeof file === 'string' || Buffer.isBuffer(file)) file = { attachment: file }; + if (!file.name) { + if (typeof file.attachment === 'string') { + file.name = path.basename(file.attachment); + } else if (file.attachment && file.attachment.path) { + file.name = path.basename(file.attachment.path); + } else if (file instanceof Attachment) { + file = { attachment: file.file, name: path.basename(file.file) || 'file.jpg' }; + } else { + file.name = 'file.jpg'; + } + } else if (file instanceof Attachment) { + file = file.file; + } + options.files[i] = file; + } + + return Promise.all(options.files.map(file => + this.client.resolver.resolveFile(file.attachment).then(resource => { + file.file = resource; + return file; + }) + )).then(files => this.client.rest.methods.sendMessage(this, content, options, files)); + } + + return this.client.rest.methods.sendMessage(this, content, options); + } + + /** + * Gets a single message from this channel, regardless of it being cached or not. Since the single message fetching + * endpoint is reserved for bot accounts, this abstracts the `fetchMessages` method to obtain the single message when + * using a user account. + * @param {Snowflake} messageID ID of the message to get + * @returns {Promise} + * @example + * // Get message + * channel.fetchMessage('99539446449315840') + * .then(message => console.log(message.content)) + * .catch(console.error); + */ + fetchMessage(messageID) { + if (!this.client.user.bot) { + return this.fetchMessages({ limit: 1, around: messageID }).then(messages => { + const msg = messages.get(messageID); + if (!msg) throw new Error('Message not found.'); + return msg; + }); + } + return this.client.rest.methods.getChannelMessage(this, messageID).then(data => { + const msg = data instanceof Message ? data : new Message(this, data, this.client); + this._cacheMessage(msg); + return msg; + }); + } + + /** + * The parameters to pass in when requesting previous messages from a channel. `around`, `before` and + * `after` are mutually exclusive. All the parameters are optional. + * @typedef {Object} ChannelLogsQueryOptions + * @property {number} [limit=50] Number of messages to acquire + * @property {Snowflake} [before] ID of a message to get the messages that were posted before it + * @property {Snowflake} [after] ID of a message to get the messages that were posted after it + * @property {Snowflake} [around] ID of a message to get the messages that were posted around it + */ + + /** + * Gets the past messages sent in this channel. Resolves with a collection mapping message ID's to Message objects. + * @param {ChannelLogsQueryOptions} [options={}] Query parameters to pass in + * @returns {Promise>} + * @example + * // Get messages + * channel.fetchMessages({ limit: 10 }) + * .then(messages => console.log(`Received ${messages.size} messages`)) + * .catch(console.error); + */ + fetchMessages(options = {}) { + return this.client.rest.methods.getChannelMessages(this, options).then(data => { + const messages = new Collection(); + for (const message of data) { + const msg = new Message(this, message, this.client); + messages.set(message.id, msg); + this._cacheMessage(msg); + } + return messages; + }); + } + + /** + * Fetches the pinned messages of this channel and returns a collection of them. + * @returns {Promise>} + */ + fetchPinnedMessages() { + return this.client.rest.methods.getChannelPinnedMessages(this).then(data => { + const messages = new Collection(); + for (const message of data) { + const msg = new Message(this, message, this.client); + messages.set(message.id, msg); + this._cacheMessage(msg); + } + return messages; + }); + } + + /** + * @typedef {Object} MessageSearchOptions + * @property {string} [content] Message content + * @property {Snowflake} [maxID] Maximum ID for the filter + * @property {Snowflake} [minID] Minimum ID for the filter + * @property {string} [has] One of `link`, `embed`, `file`, `video`, `image`, or `sound`, + * or add `-` to negate (e.g. `-file`) + * @property {ChannelResolvable} [channel] Channel to limit search to (only for guild search endpoint) + * @property {UserResolvable} [author] Author to limit search + * @property {string} [authorType] One of `user`, `bot`, `webhook`, or add `-` to negate (e.g. `-webhook`) + * @property {string} [sortBy='recent'] `recent` or `relevant` + * @property {string} [sortOrder='desc'] `asc` or `desc` + * @property {number} [contextSize=2] How many messages to get around the matched message (0 to 2) + * @property {number} [limit=25] Maximum number of results to get (1 to 25) + * @property {number} [offset=0] Offset the "pages" of results (since you can only see 25 at a time) + * @property {UserResolvable} [mentions] Mentioned user filter + * @property {boolean} [mentionsEveryone] If everyone is mentioned + * @property {string} [linkHostname] Filter links by hostname + * @property {string} [embedProvider] The name of an embed provider + * @property {string} [embedType] one of `image`, `video`, `url`, `rich` + * @property {string} [attachmentFilename] The name of an attachment + * @property {string} [attachmentExtension] The extension of an attachment + * @property {Date} [before] Date to find messages before + * @property {Date} [after] Date to find messages before + * @property {Date} [during] Date to find messages during (range of date to date + 24 hours) + * @property {boolean} [nsfw=false] Include results from NSFW channels + */ + + /** + * @typedef {Object} MessageSearchResult + * @property {number} totalResults Total result count + * @property {Message[][]} messages Array of message results + * The message which has triggered the result will have the `hit` property set to `true` + */ + + /** + * Performs a search within the channel. + * This is only available when using a user account. + * @param {MessageSearchOptions} [options={}] Options to pass to the search + * @returns {Promise} + * @example + * channel.search({ + * content: 'discord.js', + * before: '2016-11-17' + * }).then(res => { + * const hit = res.messages[0].find(m => m.hit).content; + * console.log(`I found: **${hit}**, total results: ${res.totalResults}`); + * }).catch(console.error); + */ + search(options = {}) { + return this.client.rest.methods.search(this, options); + } + + /** + * Starts a typing indicator in the channel. + * @param {number} [count] The number of times startTyping should be considered to have been called + * @example + * // Start typing in a channel + * channel.startTyping(); + */ + startTyping(count) { + if (typeof count !== 'undefined' && count < 1) throw new RangeError('Count must be at least 1.'); + if (this.client.user._typing.has(this.id)) { + const entry = this.client.user._typing.get(this.id); + entry.count = count || entry.count + 1; + return; + } + + const entry = { + count: count || 1, + interval: this.client.setInterval(() => { + this.client.rest.methods.sendTyping(this.id).catch(() => { + this.client.clearInterval(entry.interval); + this.client.user._typing.delete(this.id); + }); + }, 9000), + }; + this.client.rest.methods.sendTyping(this.id).catch(() => { + this.client.clearInterval(entry.interval); + this.client.user._typing.delete(this.id); + }); + this.client.user._typing.set(this.id, entry); + } + + /** + * Stops the typing indicator in the channel. + * The indicator will only stop if this is called as many times as startTyping(). + * It can take a few seconds for the client user to stop typing. + * @param {boolean} [force=false] Whether or not to reset the call count and force the indicator to stop + * @example + * // Reduce the typing count by one and stop typing if it reached 0 + * channel.stopTyping(); + * @example + * // Force typing to fully stop in a channel + * channel.stopTyping(true); + */ + stopTyping(force = false) { + if (this.client.user._typing.has(this.id)) { + const entry = this.client.user._typing.get(this.id); + entry.count--; + if (entry.count <= 0 || force) { + this.client.clearInterval(entry.interval); + this.client.user._typing.delete(this.id); + } + } + } + + /** + * Whether or not the typing indicator is being shown in the channel + * @type {boolean} + * @readonly + */ + get typing() { + return this.client.user._typing.has(this.id); + } + + /** + * Number of times `startTyping` has been called + * @type {number} + * @readonly + */ + get typingCount() { + if (this.client.user._typing.has(this.id)) return this.client.user._typing.get(this.id).count; + return 0; + } + + /** + * Creates a Message Collector + * @param {CollectorFilter} filter The filter to create the collector with + * @param {MessageCollectorOptions} [options={}] The options to pass to the collector + * @returns {MessageCollector} + * @deprecated + */ + createCollector(filter, options) { + return this.createMessageCollector(filter, options); + } + + /** + * Creates a Message Collector. + * @param {CollectorFilter} filter The filter to create the collector with + * @param {MessageCollectorOptions} [options={}] The options to pass to the collector + * @returns {MessageCollector} + * @example + * // Create a message collector + * const filter = m => m.content.includes('discord'); + * const collector = channel.createMessageCollector(filter, { time: 15000 }); + * collector.on('collect', m => console.log(`Collected ${m.content}`)); + * collector.on('end', collected => console.log(`Collected ${collected.size} items`)); + */ + createMessageCollector(filter, options = {}) { + return new MessageCollector(this, filter, options); + } + + /** + * An object containing the same properties as CollectorOptions, but a few more: + * @typedef {MessageCollectorOptions} AwaitMessagesOptions + * @property {string[]} [errors] Stop/end reasons that cause the promise to reject + */ + + /** + * Similar to createCollector but in promise form. Resolves with a collection of messages that pass the specified + * filter. + * @param {CollectorFilter} filter The filter function to use + * @param {AwaitMessagesOptions} [options={}] Optional options to pass to the internal collector + * @returns {Promise>} + * @example + * // Await !vote messages + * const filter = m => m.content.startsWith('!vote'); + * // Errors: ['time'] treats ending because of the time limit as an error + * channel.awaitMessages(filter, { max: 4, time: 60000, errors: ['time'] }) + * .then(collected => console.log(collected.size)) + * .catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`)); + */ + awaitMessages(filter, options = {}) { + return new Promise((resolve, reject) => { + const collector = this.createCollector(filter, options); + collector.once('end', (collection, reason) => { + if (options.errors && options.errors.includes(reason)) { + reject(collection); + } else { + resolve(collection); + } + }); + }); + } + + /** + * Bulk delete given messages that are newer than two weeks. + * This is only available when using a bot account. + * @param {Collection|Message[]|number} messages Messages or number of messages to delete + * @param {boolean} [filterOld=false] Filter messages to remove those which are older than two weeks automatically + * @returns {Promise>} Deleted messages + * @example + * // Bulk delete messages + * channel.bulkDelete(5) + * .then(messages => console.log(`Bulk deleted ${messages.size} messages`)) + * .catch(console.error); + */ + bulkDelete(messages, filterOld = false) { + if (messages instanceof Collection) messages = [...messages.values()]; + if (messages instanceof Array) { + if (filterOld) { + messages = messages.filter(m => Date.now() - Snowflake.deconstruct(m.id).date.getTime() < 1209600000); + } + if (messages.length === 0) return new Collection(); + if (messages.length === 1) { + return messages[0].delete().then(() => new Collection([[messages[0].id, messages[0]]])); + } + return this.client.rest.methods.bulkDeleteMessages(this, messages); + } + if (!isNaN(messages)) return this.fetchMessages({ limit: messages }).then(msgs => this.bulkDelete(msgs, filterOld)); + throw new TypeError('The messages must be an Array, Collection, or number.'); + } + + /** + * Marks all messages in this channel as read. + * This is only available when using a user account. + * @returns {Promise} + */ + acknowledge() { + if (!this.lastMessageID) return Promise.resolve(this); + return this.client.rest.methods.ackTextChannel(this); + } + + _cacheMessage(message) { + const maxSize = this.client.options.messageCacheMaxSize; + if (maxSize === 0) return null; + if (this.messages.size >= maxSize && maxSize > 0) this.messages.delete(this.messages.firstKey()); + this.messages.set(message.id, message); + return message; + } +} + +/** @lends TextBasedChannel.prototype */ +const Deprecated = { + /** + * Send a message to this channel. + * @param {StringResolvable} [content] Text for the message + * @param {MessageOptions} [options={}] Options for the message + * @returns {Promise} + * @deprecated + * @example + * // Send a message + * channel.sendMessage('hello!') + * .then(message => console.log(`Sent message: ${message.content}`)) + * .catch(console.error); + */ + sendMessage(content, options) { + return this.send(content, options); + }, + + /** + * Send an embed to this channel. + * @param {RichEmbed|Object} embed Embed for the message + * @param {string} [content] Text for the message + * @param {MessageOptions} [options] Options for the message + * @returns {Promise} + * @deprecated + */ + sendEmbed(embed, content, options) { + if (!options && typeof content === 'object' && !(content instanceof Array)) { + options = content; + content = ''; + } else if (!options) { + options = {}; + } + return this.send(content, Object.assign(options, { embed })); + }, + + /** + * Send files to this channel. + * @param {FileOptions[]|string[]} files Files to send with the message + * @param {StringResolvable} [content] Text for the message + * @param {MessageOptions} [options] Options for the message + * @returns {Promise} + * @deprecated + */ + sendFiles(files, content, options = {}) { + return this.send(content, Object.assign(options, { files })); + }, + + /** + * Send a file to this channel. + * @param {BufferResolvable} attachment File to send + * @param {string} [name='file.jpg'] Name and extension of the file + * @param {StringResolvable} [content] Text for the message + * @param {MessageOptions} [options] Options for the message + * @returns {Promise} + * @deprecated + */ + sendFile(attachment, name, content, options = {}) { + return this.send({ files: [{ attachment, name }], content, options }); + }, + + /** + * Send a code block to this channel. + * @param {string} lang Language for the code block + * @param {StringResolvable} content Content of the code block + * @param {MessageOptions} [options] Options for the message + * @returns {Promise} + * @deprecated + */ + sendCode(lang, content, options = {}) { + return this.send(content, Object.assign(options, { code: lang })); + }, +}; + +for (const key of Object.keys(Deprecated)) { + TextBasedChannel.prototype[key] = util.deprecate(Deprecated[key], `TextChannel#${key}: use TextChannel#send instead`); +} + +exports.applyToClass = (structure, full = false, ignore = []) => { + const props = ['send', 'sendMessage', 'sendEmbed', 'sendFile', 'sendFiles', 'sendCode']; + if (full) { + props.push( + '_cacheMessage', + 'acknowledge', + 'fetchMessages', + 'fetchMessage', + 'search', + 'bulkDelete', + 'startTyping', + 'stopTyping', + 'typing', + 'typingCount', + 'fetchPinnedMessages', + 'createCollector', + 'createMessageCollector', + 'awaitMessages' + ); + } + for (const prop of props) { + if (ignore.includes(prop)) continue; + Object.defineProperty(structure.prototype, prop, Object.getOwnPropertyDescriptor(TextBasedChannel.prototype, prop)); + } +}; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12).Buffer)) + +/***/ }), +/* 15 */ +/***/ (function(module, exports, __webpack_require__) { + +const Mentions = __webpack_require__(38); +const Attachment = __webpack_require__(39); +const Embed = __webpack_require__(40); +const RichEmbed = __webpack_require__(20); +const MessageReaction = __webpack_require__(42); +const ReactionCollector = __webpack_require__(43); +const Util = __webpack_require__(4); +const Collection = __webpack_require__(3); +const Constants = __webpack_require__(0); +const Permissions = __webpack_require__(6); +let GuildMember; + +/** + * Represents a message on Discord. + */ +class Message { + constructor(channel, data, client) { + /** + * The client that instantiated the Message + * @name Message#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + /** + * The channel that the message was sent in + * @type {TextChannel|DMChannel|GroupDMChannel} + */ + this.channel = channel; + + if (data) this.setup(data); + } + + setup(data) { // eslint-disable-line complexity + /** + * The ID of the message + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The type of the message + * @type {MessageType} + */ + this.type = Constants.MessageTypes[data.type]; + + /** + * The content of the message + * @type {string} + */ + this.content = data.content; + + /** + * The author of the message + * @type {User} + */ + this.author = this.client.dataManager.newUser(data.author); + + /** + * Represents the author of the message as a guild member + * Only available if the message comes from a guild where the author is still a member + * @type {?GuildMember} + */ + this.member = this.guild ? this.guild.member(this.author) || null : null; + + /** + * Whether or not this message is pinned + * @type {boolean} + */ + this.pinned = data.pinned; + + /** + * Whether or not the message was Text-To-Speech + * @type {boolean} + */ + this.tts = data.tts; + + /** + * A random number or string used for checking message delivery + * @type {string} + */ + this.nonce = data.nonce; + + /** + * Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications) + * @type {boolean} + */ + this.system = data.type === 6; + + /** + * A list of embeds in the message - e.g. YouTube Player + * @type {MessageEmbed[]} + */ + this.embeds = data.embeds.map(e => new Embed(this, e)); + + /** + * A collection of attachments in the message - e.g. Pictures - mapped by their ID + * @type {Collection} + */ + this.attachments = new Collection(); + for (const attachment of data.attachments) this.attachments.set(attachment.id, new Attachment(this, attachment)); + + /** + * The timestamp the message was sent at + * @type {number} + */ + this.createdTimestamp = new Date(data.timestamp).getTime(); + + /** + * The timestamp the message was last edited at (if applicable) + * @type {?number} + */ + this.editedTimestamp = data.edited_timestamp ? new Date(data.edited_timestamp).getTime() : null; + + /** + * A collection of reactions to this message, mapped by the reaction ID + * @type {Collection} + */ + this.reactions = new Collection(); + if (data.reactions && data.reactions.length > 0) { + for (const reaction of data.reactions) { + const id = reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name; + this.reactions.set(id, new MessageReaction(this, reaction.emoji, reaction.count, reaction.me)); + } + } + + /** + * All valid mentions that the message contains + * @type {MessageMentions} + */ + this.mentions = new Mentions(this, data.mentions, data.mention_roles, data.mention_everyone); + + /** + * ID of the webhook that sent the message, if applicable + * @type {?Snowflake} + */ + this.webhookID = data.webhook_id || null; + + /** + * Whether this message is a hit in a search + * @type {?boolean} + */ + this.hit = typeof data.hit === 'boolean' ? data.hit : null; + + /** + * The previous versions of the message, sorted with the most recent first + * @type {Message[]} + * @private + */ + this._edits = []; + } + + /** + * Updates the message. + * @param {Object} data Raw Discord message update data + * @private + */ + patch(data) { + const clone = Util.cloneObject(this); + this._edits.unshift(clone); + + this.editedTimestamp = new Date(data.edited_timestamp).getTime(); + if ('content' in data) this.content = data.content; + if ('pinned' in data) this.pinned = data.pinned; + if ('tts' in data) this.tts = data.tts; + if ('embeds' in data) this.embeds = data.embeds.map(e => new Embed(this, e)); + else this.embeds = this.embeds.slice(); + + if ('attachments' in data) { + this.attachments = new Collection(); + for (const attachment of data.attachments) this.attachments.set(attachment.id, new Attachment(this, attachment)); + } else { + this.attachments = new Collection(this.attachments); + } + + this.mentions = new Mentions( + this, + 'mentions' in data ? data.mentions : this.mentions.users, + 'mentions_roles' in data ? data.mentions_roles : this.mentions.roles, + 'mention_everyone' in data ? data.mention_everyone : this.mentions.everyone + ); + } + + /** + * The time the message was sent + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * The time the message was last edited at (if applicable) + * @type {?Date} + * @readonly + */ + get editedAt() { + return this.editedTimestamp ? new Date(this.editedTimestamp) : null; + } + + /** + * The guild the message was sent in (if in a guild channel) + * @type {?Guild} + * @readonly + */ + get guild() { + return this.channel.guild || null; + } + + /** + * The message contents with all mentions replaced by the equivalent text. + * If mentions cannot be resolved to a name, the relevant mention in the message content will not be converted. + * @type {string} + * @readonly + */ + get cleanContent() { + return this.content + .replace(/@(everyone|here)/g, '@\u200b$1') + .replace(/<@!?[0-9]+>/g, input => { + const id = input.replace(/<|!|>|@/g, ''); + if (this.channel.type === 'dm' || this.channel.type === 'group') { + return this.client.users.has(id) ? `@${this.client.users.get(id).username}` : input; + } + + const member = this.channel.guild.members.get(id); + if (member) { + if (member.nickname) return `@${member.nickname}`; + return `@${member.user.username}`; + } else { + const user = this.client.users.get(id); + if (user) return `@${user.username}`; + return input; + } + }) + .replace(/<#[0-9]+>/g, input => { + const channel = this.client.channels.get(input.replace(/<|#|>/g, '')); + if (channel) return `#${channel.name}`; + return input; + }) + .replace(/<@&[0-9]+>/g, input => { + if (this.channel.type === 'dm' || this.channel.type === 'group') return input; + const role = this.guild.roles.get(input.replace(/<|@|>|&/g, '')); + if (role) return `@${role.name}`; + return input; + }); + } + + /** + * Creates a reaction collector. + * @param {CollectorFilter} filter The filter to apply + * @param {ReactionCollectorOptions} [options={}] Options to send to the collector + * @returns {ReactionCollector} + * @example + * // Create a reaction collector + * const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID' + * const collector = message.createReactionCollector(filter, { time: 15000 }); + * collector.on('collect', r => console.log(`Collected ${r.emoji.name}`)); + * collector.on('end', collected => console.log(`Collected ${collected.size} items`)); + */ + createReactionCollector(filter, options = {}) { + return new ReactionCollector(this, filter, options); + } + + /** + * An object containing the same properties as CollectorOptions, but a few more: + * @typedef {ReactionCollectorOptions} AwaitReactionsOptions + * @property {string[]} [errors] Stop/end reasons that cause the promise to reject + */ + + /** + * Similar to createMessageCollector but in promise form. + * Resolves with a collection of reactions that pass the specified filter. + * @param {CollectorFilter} filter The filter function to use + * @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector + * @returns {Promise>} + * @example + * // Create a reaction collector + * const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID' + * message.awaitReactions(filter, { time: 15000 }) + * .then(collected => console.log(`Collected ${collected.size} reactions`)) + * .catch(console.error); + */ + awaitReactions(filter, options = {}) { + return new Promise((resolve, reject) => { + const collector = this.createReactionCollector(filter, options); + collector.once('end', (reactions, reason) => { + if (options.errors && options.errors.includes(reason)) reject(reactions); + else resolve(reactions); + }); + }); + } + + /** + * An array of cached versions of the message, including the current version + * Sorted from latest (first) to oldest (last) + * @type {Message[]} + * @readonly + */ + get edits() { + const copy = this._edits.slice(); + copy.unshift(this); + return copy; + } + + /** + * Whether the message is editable by the client user + * @type {boolean} + * @readonly + */ + get editable() { + return this.author.id === this.client.user.id; + } + + /** + * Whether the message is deletable by the client user + * @type {boolean} + * @readonly + */ + get deletable() { + return this.author.id === this.client.user.id || (this.guild && + this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES) + ); + } + + /** + * Whether the message is pinnable by the client user + * @type {boolean} + * @readonly + */ + get pinnable() { + return !this.guild || + this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES); + } + + /** + * Whether or not a user, channel or role is mentioned in this message. + * @param {GuildChannel|User|Role|string} data Either a guild channel, user or a role object, or a string representing + * the ID of any of these + * @returns {boolean} + */ + isMentioned(data) { + data = data && data.id ? data.id : data; + return this.mentions.users.has(data) || this.mentions.channels.has(data) || this.mentions.roles.has(data); + } + + /** + * Whether or not a guild member is mentioned in this message. Takes into account + * user mentions, role mentions, and @everyone/@here mentions. + * @param {GuildMember|User} member The member/user to check for a mention of + * @returns {boolean} + */ + isMemberMentioned(member) { + // Lazy-loading is used here to get around a circular dependency that breaks things + if (!GuildMember) GuildMember = __webpack_require__(17); + if (this.mentions.everyone) return true; + if (this.mentions.users.has(member.id)) return true; + if (member instanceof GuildMember && member.roles.some(r => this.mentions.roles.has(r.id))) return true; + return false; + } + + /** + * Options that can be passed into editMessage. + * @typedef {Object} MessageEditOptions + * @property {Object} [embed] An embed to be added/edited + * @property {string|boolean} [code] Language for optional codeblock formatting to apply + */ + + /** + * Edit the content of the message. + * @param {StringResolvable} [content] The new content for the message + * @param {MessageEditOptions|RichEmbed} [options] The options to provide + * @returns {Promise} + * @example + * // Update the content of a message + * message.edit('This is my new content!') + * .then(msg => console.log(`New message content: ${msg}`)) + * .catch(console.error); + */ + edit(content, options) { + if (!options && typeof content === 'object' && !(content instanceof Array)) { + options = content; + content = ''; + } else if (!options) { + options = {}; + } + if (options instanceof RichEmbed) options = { embed: options }; + return this.client.rest.methods.updateMessage(this, content, options); + } + + /** + * Edit the content of the message, with a code block. + * @param {string} lang The language for the code block + * @param {StringResolvable} content The new content for the message + * @returns {Promise} + * @deprecated + */ + editCode(lang, content) { + content = Util.escapeMarkdown(this.client.resolver.resolveString(content), true); + return this.edit(`\`\`\`${lang || ''}\n${content}\n\`\`\``); + } + + /** + * Pins this message to the channel's pinned messages. + * @returns {Promise} + */ + pin() { + return this.client.rest.methods.pinMessage(this); + } + + /** + * Unpins this message from the channel's pinned messages. + * @returns {Promise} + */ + unpin() { + return this.client.rest.methods.unpinMessage(this); + } + + /** + * Add a reaction to the message. + * @param {string|Emoji|ReactionEmoji} emoji The emoji to react with + * @returns {Promise} + * @example + * // React to a message with a unicode emoji + * message.react('🤔') + * .then(console.log) + * .catch(console.error); + * @example + * // React to a message with a custom emoji + * message.react(message.guild.emojis.get('123456789012345678')) + * .then(console.log) + * .catch(console.error); + */ + react(emoji) { + emoji = this.client.resolver.resolveEmojiIdentifier(emoji); + if (!emoji) throw new TypeError('Emoji must be a string or Emoji/ReactionEmoji'); + + return this.client.rest.methods.addMessageReaction(this, emoji); + } + + /** + * Remove all reactions from a message. + * @returns {Promise} + */ + clearReactions() { + return this.client.rest.methods.removeMessageReactions(this); + } + + /** + * Deletes the message. + * @param {number} [timeout=0] How long to wait to delete the message in milliseconds + * @returns {Promise} + * @example + * // Delete a message + * message.delete() + * .then(msg => console.log(`Deleted message from ${msg.author.username}`)) + * .catch(console.error); + */ + delete(timeout = 0) { + if (timeout <= 0) { + return this.client.rest.methods.deleteMessage(this); + } else { + return new Promise(resolve => { + this.client.setTimeout(() => { + resolve(this.delete()); + }, timeout); + }); + } + } + + /** + * Reply to the message. + * @param {StringResolvable} [content] The content for the message + * @param {MessageOptions} [options] The options to provide + * @returns {Promise} + * @example + * // Reply to a message + * message.reply('Hey, I\'m a reply!') + * .then(sent => console.log(`Sent a reply to ${sent.author.username}`)) + * .catch(console.error); + */ + reply(content, options) { + if (!options && typeof content === 'object' && !(content instanceof Array)) { + options = content; + content = ''; + } else if (!options) { + options = {}; + } + return this.channel.send(content, Object.assign(options, { reply: this.member || this.author })); + } + + /** + * Marks the message as read. + * This is only available when using a user account. + * @returns {Promise} + */ + acknowledge() { + return this.client.rest.methods.ackMessage(this); + } + + /** + * Fetches the webhook used to create this message. + * @returns {Promise} + */ + fetchWebhook() { + if (!this.webhookID) return Promise.reject(new Error('The message was not sent by a webhook.')); + return this.client.fetchWebhook(this.webhookID); + } + + /** + * Used mainly internally. Whether two messages are identical in properties. If you want to compare messages + * without checking all the properties, use `message.id === message2.id`, which is much more efficient. This + * method allows you to see if there are differences in content, embeds, attachments, nonce and tts properties. + * @param {Message} message The message to compare it to + * @param {Object} rawData Raw data passed through the WebSocket about this message + * @returns {boolean} + */ + equals(message, rawData) { + if (!message) return false; + const embedUpdate = !message.author && !message.attachments; + if (embedUpdate) return this.id === message.id && this.embeds.length === message.embeds.length; + + let equal = this.id === message.id && + this.author.id === message.author.id && + this.content === message.content && + this.tts === message.tts && + this.nonce === message.nonce && + this.embeds.length === message.embeds.length && + this.attachments.length === message.attachments.length; + + if (equal && rawData) { + equal = this.mentions.everyone === message.mentions.everyone && + this.createdTimestamp === new Date(rawData.timestamp).getTime() && + this.editedTimestamp === new Date(rawData.edited_timestamp).getTime(); + } + + return equal; + } + + /** + * When concatenated with a string, this automatically concatenates the message's content instead of the object. + * @returns {string} + * @example + * // Logs: Message: This is a message! + * console.log(`Message: ${message}`); + */ + toString() { + return this.content; + } + + _addReaction(emoji, user) { + const emojiID = emoji.id ? `${emoji.name}:${emoji.id}` : emoji.name; + let reaction; + if (this.reactions.has(emojiID)) { + reaction = this.reactions.get(emojiID); + if (!reaction.me) reaction.me = user.id === this.client.user.id; + } else { + reaction = new MessageReaction(this, emoji, 0, user.id === this.client.user.id); + this.reactions.set(emojiID, reaction); + } + if (!reaction.users.has(user.id)) { + reaction.users.set(user.id, user); + reaction.count++; + } + return reaction; + } + + _removeReaction(emoji, user) { + const emojiID = emoji.id ? `${emoji.name}:${emoji.id}` : emoji.name; + if (this.reactions.has(emojiID)) { + const reaction = this.reactions.get(emojiID); + if (reaction.users.has(user.id)) { + reaction.users.delete(user.id); + reaction.count--; + if (user.id === this.client.user.id) reaction.me = false; + if (reaction.count <= 0) this.reactions.delete(emojiID); + return reaction; + } + } + return null; + } + + _clearReactions() { + this.reactions.clear(); + } +} + +module.exports = Message; + + +/***/ }), +/* 16 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); +const Collection = __webpack_require__(3); +const Snowflake = __webpack_require__(5); + +/** + * Represents a custom emoji. + */ +class Emoji { + constructor(guild, data) { + /** + * The client that instantiated this object + * @name Emoji#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: guild.client }); + + /** + * The guild this emoji is part of + * @type {Guild} + */ + this.guild = guild; + + this.setup(data); + } + + setup(data) { + /** + * The ID of the emoji + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The name of the emoji + * @type {string} + */ + this.name = data.name; + + /** + * Whether or not this emoji requires colons surrounding it + * @type {boolean} + */ + this.requiresColons = data.require_colons; + + /** + * Whether this emoji is managed by an external service + * @type {boolean} + */ + this.managed = data.managed; + + /** + * Whether this emoji is animated + * @type {boolean} + */ + this.animated = data.animated; + + this._roles = data.roles; + } + + /** + * The timestamp the emoji was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return Snowflake.deconstruct(this.id).timestamp; + } + + /** + * The time the emoji was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * A collection of roles this emoji is active for (empty if all), mapped by role ID + * @type {Collection} + * @readonly + */ + get roles() { + const roles = new Collection(); + for (const role of this._roles) { + if (this.guild.roles.has(role)) roles.set(role, this.guild.roles.get(role)); + } + return roles; + } + + /** + * The URL to the emoji file + * @type {string} + * @readonly + */ + get url() { + return Constants.Endpoints.CDN(this.client.options.http.cdn).Emoji(this.id, this.animated ? 'gif' : 'png'); + } + + /** + * The identifier of this emoji, used for message reactions + * @type {string} + * @readonly + */ + get identifier() { + if (this.id) return `${this.name}:${this.id}`; + return encodeURIComponent(this.name); + } + + /** + * Data for editing an emoji. + * @typedef {Object} EmojiEditData + * @property {string} [name] The name of the emoji + * @property {Collection|Array} [roles] Roles to restrict emoji to + */ + + /** + * Edits the emoji. + * @param {EmojiEditData} data The new data for the emoji + * @param {string} [reason] Reason for editing this emoji + * @returns {Promise} + * @example + * // Edit an emoji + * emoji.edit({name: 'newemoji'}) + * .then(e => console.log(`Edited emoji ${e}`)) + * .catch(console.error); + */ + edit(data, reason) { + return this.client.rest.methods.updateEmoji(this, data, reason); + } + + /** + * Set the name of the emoji. + * @param {string} name The new name for the emoji + * @param {string} [reason] The reason for changing the emoji's name + * @returns {Promise} + */ + setName(name, reason) { + return this.edit({ name }, reason); + } + + /** + * Add a role to the list of roles that can use this emoji. + * @param {Role} role The role to add + * @returns {Promise} + */ + addRestrictedRole(role) { + return this.addRestrictedRoles([role]); + } + + /** + * Add multiple roles to the list of roles that can use this emoji. + * @param {Role[]} roles Roles to add + * @returns {Promise} + */ + addRestrictedRoles(roles) { + const newRoles = new Collection(this.roles); + for (const role of roles) { + if (this.guild.roles.has(role.id)) newRoles.set(role.id, role); + } + return this.edit({ roles: newRoles }); + } + + /** + * Remove a role from the list of roles that can use this emoji. + * @param {Role} role The role to remove + * @returns {Promise} + */ + removeRestrictedRole(role) { + return this.removeRestrictedRoles([role]); + } + + /** + * Remove multiple roles from the list of roles that can use this emoji. + * @param {Role[]} roles Roles to remove + * @returns {Promise} + */ + removeRestrictedRoles(roles) { + const newRoles = new Collection(this.roles); + for (const role of roles) { + if (newRoles.has(role.id)) newRoles.delete(role.id); + } + return this.edit({ roles: newRoles }); + } + + /** + * When concatenated with a string, this automatically returns the emoji mention rather than the object. + * @returns {string} + * @example + * // Send an emoji: + * const emoji = guild.emojis.first(); + * msg.reply(`Hello! ${emoji}`); + */ + toString() { + if (!this.id || !this.requiresColons) { + return this.name; + } + + return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`; + } + + /** + * Whether this emoji is the same as another one. + * @param {Emoji|Object} other The emoji to compare it to + * @returns {boolean} Whether the emoji is equal to the given emoji or not + */ + equals(other) { + if (other instanceof Emoji) { + return ( + other.id === this.id && + other.name === this.name && + other.managed === this.managed && + other.requiresColons === this.requiresColons + ); + } else { + return ( + other.id === this.id && + other.name === this.name + ); + } + } +} + +module.exports = Emoji; + + +/***/ }), +/* 17 */ +/***/ (function(module, exports, __webpack_require__) { + +const TextBasedChannel = __webpack_require__(14); +const Role = __webpack_require__(8); +const Permissions = __webpack_require__(6); +const Collection = __webpack_require__(3); +const Presence = __webpack_require__(10).Presence; +const util = __webpack_require__(7); + +/** + * Represents a member of a guild on Discord. + * @implements {TextBasedChannel} + */ +class GuildMember { + constructor(guild, data) { + /** + * The client that instantiated this GuildMember + * @name GuildMember#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: guild.client }); + + /** + * The guild that this member is part of + * @type {Guild} + */ + this.guild = guild; + + /** + * The user that this guild member instance Represents + * @type {User} + */ + this.user = {}; + + this._roles = []; + if (data) this.setup(data); + + /** + * The ID of the last message sent by the member in their guild, if one was sent + * @type {?Snowflake} + */ + this.lastMessageID = null; + + /** + * The Message object of the last message sent by the member in their guild, if one was sent + * @type {?Message} + */ + this.lastMessage = null; + } + + setup(data) { + /** + * Whether this member is deafened server-wide + * @type {boolean} + */ + this.serverDeaf = data.deaf; + + /** + * Whether this member is muted server-wide + * @type {boolean} + */ + this.serverMute = data.mute; + + /** + * Whether this member is self-muted + * @type {boolean} + */ + this.selfMute = data.self_mute; + + /** + * Whether this member is self-deafened + * @type {boolean} + */ + this.selfDeaf = data.self_deaf; + + /** + * The voice session ID of this member, if any + * @type {?Snowflake} + */ + this.voiceSessionID = data.session_id; + + /** + * The voice channel ID of this member, if any + * @type {?Snowflake} + */ + this.voiceChannelID = data.channel_id; + + /** + * Whether this member is speaking + * @type {boolean} + */ + this.speaking = false; + + /** + * The nickname of this guild member, if they have one + * @type {?string} + */ + this.nickname = data.nick || null; + + /** + * The timestamp the member joined the guild at + * @type {number} + */ + this.joinedTimestamp = new Date(data.joined_at).getTime(); + + this.user = data.user; + this._roles = data.roles; + } + + /** + * The time the member joined the guild + * @type {Date} + * @readonly + */ + get joinedAt() { + return new Date(this.joinedTimestamp); + } + + /** + * The presence of this guild member + * @type {Presence} + * @readonly + */ + get presence() { + return this.frozenPresence || this.guild.presences.get(this.id) || new Presence(); + } + + /** + * A list of roles that are applied to this GuildMember, mapped by the role ID + * @type {Collection} + * @readonly + */ + get roles() { + const list = new Collection(); + const everyoneRole = this.guild.roles.get(this.guild.id); + + if (everyoneRole) list.set(everyoneRole.id, everyoneRole); + + for (const roleID of this._roles) { + const role = this.guild.roles.get(roleID); + if (role) list.set(role.id, role); + } + + return list; + } + + /** + * The role of the member with the highest position + * @type {Role} + * @readonly + */ + get highestRole() { + return this.roles.reduce((prev, role) => !prev || role.comparePositionTo(prev) > 0 ? role : prev); + } + + /** + * The role of the member used to set their color + * @type {?Role} + * @readonly + */ + get colorRole() { + const coloredRoles = this.roles.filter(role => role.color); + if (!coloredRoles.size) return null; + return coloredRoles.reduce((prev, role) => !prev || role.comparePositionTo(prev) > 0 ? role : prev); + } + + /** + * The displayed color of the member in base 10 + * @type {number} + * @readonly + */ + get displayColor() { + const role = this.colorRole; + return (role && role.color) || 0; + } + + /** + * The displayed color of the member in hexadecimal + * @type {string} + * @readonly + */ + get displayHexColor() { + const role = this.colorRole; + return (role && role.hexColor) || '#000000'; + } + + /** + * The role of the member used to hoist them in a separate category in the users list + * @type {?Role} + * @readonly + */ + get hoistRole() { + const hoistedRoles = this.roles.filter(role => role.hoist); + if (!hoistedRoles.size) return null; + return hoistedRoles.reduce((prev, role) => !prev || role.comparePositionTo(prev) > 0 ? role : prev); + } + + /** + * Whether this member is muted in any way + * @type {boolean} + * @readonly + */ + get mute() { + return this.selfMute || this.serverMute; + } + + /** + * Whether this member is deafened in any way + * @type {boolean} + * @readonly + */ + get deaf() { + return this.selfDeaf || this.serverDeaf; + } + + /** + * The voice channel this member is in, if any + * @type {?VoiceChannel} + * @readonly + */ + get voiceChannel() { + return this.guild.channels.get(this.voiceChannelID); + } + + /** + * The ID of this user + * @type {Snowflake} + * @readonly + */ + get id() { + return this.user.id; + } + + /** + * The nickname of the member, or their username if they don't have one + * @type {string} + * @readonly + */ + get displayName() { + return this.nickname || this.user.username; + } + + /** + * The overall set of permissions for the guild member, taking only roles into account + * @type {Permissions} + * @readonly + */ + get permissions() { + if (this.user.id === this.guild.ownerID) return new Permissions(this, Permissions.ALL); + + let permissions = 0; + const roles = this.roles; + for (const role of roles.values()) permissions |= role.permissions; + + return new Permissions(this, permissions); + } + + /** + * Whether the member is kickable by the client user + * @type {boolean} + * @readonly + */ + get kickable() { + if (this.user.id === this.guild.ownerID) return false; + if (this.user.id === this.client.user.id) return false; + const clientMember = this.guild.member(this.client.user); + if (!clientMember.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) return false; + return clientMember.highestRole.comparePositionTo(this.highestRole) > 0; + } + + /** + * Whether the member is bannable by the client user + * @type {boolean} + * @readonly + */ + get bannable() { + if (this.user.id === this.guild.ownerID) return false; + if (this.user.id === this.client.user.id) return false; + const clientMember = this.guild.member(this.client.user); + if (!clientMember.permissions.has(Permissions.FLAGS.BAN_MEMBERS)) return false; + return clientMember.highestRole.comparePositionTo(this.highestRole) > 0; + } + + /** + * Returns `channel.permissionsFor(guildMember)`. Returns permissions for a member in a guild channel, + * taking into account roles and permission overwrites. + * @param {ChannelResolvable} channel The guild channel to use as context + * @returns {?Permissions} + */ + permissionsIn(channel) { + channel = this.client.resolver.resolveChannel(channel); + if (!channel || !channel.guild) throw new Error('Could not resolve channel to a guild channel.'); + return channel.permissionsFor(this); + } + + /** + * Checks if any of the member's roles have a permission. + * @param {PermissionResolvable|PermissionResolvable[]} permission Permission(s) to check for + * @param {boolean} [explicit=false] Whether to require the role to explicitly have the exact permission + * **(deprecated)** + * @param {boolean} [checkAdmin] Whether to allow the administrator permission to override + * (takes priority over `explicit`) + * @param {boolean} [checkOwner] Whether to allow being the guild's owner to override + * (takes priority over `explicit`) + * @returns {boolean} + */ + hasPermission(permission, explicit = false, checkAdmin, checkOwner) { + if (typeof checkAdmin === 'undefined') checkAdmin = !explicit; + if (typeof checkOwner === 'undefined') checkOwner = !explicit; + if (checkOwner && this.user.id === this.guild.ownerID) return true; + return this.roles.some(r => r.hasPermission(permission, undefined, checkAdmin)); + } + + /** + * Checks whether the roles of the member allows them to perform specific actions. + * @param {PermissionResolvable[]} permissions The permissions to check for + * @param {boolean} [explicit=false] Whether to require the member to explicitly have the exact permissions + * @returns {boolean} + * @deprecated + */ + hasPermissions(permissions, explicit = false) { + if (!explicit && this.user.id === this.guild.ownerID) return true; + return this.hasPermission(permissions, explicit); + } + + /** + * Checks whether the roles of the member allows them to perform specific actions, and lists any missing permissions. + * @param {PermissionResolvable[]} permissions The permissions to check for + * @param {boolean} [explicit=false] Whether to require the member to explicitly have the exact permissions + * @returns {PermissionResolvable[]} + */ + missingPermissions(permissions, explicit = false) { + return this.permissions.missing(permissions, explicit); + } + + /** + * The data for editing a guild member. + * @typedef {Object} GuildMemberEditData + * @property {string} [nick] The nickname to set for the member + * @property {Collection|RoleResolvable[]} [roles] The roles or role IDs to apply + * @property {boolean} [mute] Whether or not the member should be muted + * @property {boolean} [deaf] Whether or not the member should be deafened + * @property {ChannelResolvable} [channel] Channel to move member to (if they are connected to voice) + */ + + /** + * Edit a guild member. + * @param {GuildMemberEditData} data The data to edit the member with + * @param {string} [reason] Reason for editing this user + * @returns {Promise} + * @example + * // Set a member's nickname and clear their roles + * message.member.edit({ + * nick: 'Cool Name', + * roles: [] + * }) + * .then(console.log) + * .catch(console.error); + */ + edit(data, reason) { + return this.client.rest.methods.updateGuildMember(this, data, reason); + } + + /** + * Mute/unmute a user. + * @param {boolean} mute Whether or not the member should be muted + * @param {string} [reason] Reason for muting or unmuting + * @returns {Promise} + * @example + * // Mute a member with a reason + * message.member.setMute(true, 'It needed to be done') + * .then(() => console.log(`Muted ${message.member.displayName}`))) + * .catch(console.error); + */ + setMute(mute, reason) { + return this.edit({ mute }, reason); + } + + /** + * Deafen/undeafen a user. + * @param {boolean} deaf Whether or not the member should be deafened + * @param {string} [reason] Reason for deafening or undeafening + * @returns {Promise} + * @example + * // Deafen a member + * message.member.setDeaf(true) + * .then(() => console.log(`Deafened ${message.member.displayName}`)) + * .catch(console.error); + */ + setDeaf(deaf, reason) { + return this.edit({ deaf }, reason); + } + + /** + * Moves the guild member to the given channel. + * @param {ChannelResolvable} channel The channel to move the member to + * @returns {Promise} + * @example + * // Moves a member to a voice channel + * member.setVoiceChannel('174674066072928256') + * .then(() => console.log(`Moved ${member.displayName}`)) + * .catch(console.error); + */ + setVoiceChannel(channel) { + return this.edit({ channel }); + } + + /** + * Sets the roles applied to the member. + * @param {Collection|RoleResolvable[]} roles The roles or role IDs to apply + * @param {string} [reason] Reason for applying the roles + * @returns {Promise} + * @example + * // Set the member's roles to a single role + * guildMember.setRoles(['391156570408615936']) + * .then(console.log) + * .catch(console.error); + * @example + * // Remove all of the member's roles + * guildMember.setRoles([]) + * .then(member => console.log(`${member.displayName} now has ${member.roles.size} roles`)) + * .catch(console.error); + */ + setRoles(roles, reason) { + return this.edit({ roles }, reason); + } + + /** + * Adds a single role to the member. + * @param {RoleResolvable} role The role or ID of the role to add + * @param {string} [reason] Reason for adding the role + * @returns {Promise} + * @example + * // Give a role to a member + * message.member.addRole('193654001089118208') + * .then(console.log) + * .catch(console.error); + */ + addRole(role, reason) { + if (!(role instanceof Role)) role = this.guild.roles.get(role); + if (!role) return Promise.reject(new TypeError('Supplied parameter was neither a Role nor a Snowflake.')); + return this.client.rest.methods.addMemberRole(this, role, reason); + } + + /** + * Adds multiple roles to the member. + * @param {Collection|RoleResolvable[]} roles The roles or role IDs to add + * @param {string} [reason] Reason for adding the roles + * @returns {Promise} + * @example + * // Gives a member a few roles + * message.member.addRoles(['193654001089118208', '369308579892690945']) + * .then(console.log) + * .catch(console.error); + */ + addRoles(roles, reason) { + let allRoles; + if (roles instanceof Collection) { + allRoles = this._roles.slice(); + for (const role of roles.values()) allRoles.push(role.id); + } else { + allRoles = this._roles.concat(roles); + } + return this.edit({ roles: allRoles }, reason); + } + + /** + * Removes a single role from the member. + * @param {RoleResolvable} role The role or ID of the role to remove + * @param {string} [reason] Reason for removing the role + * @returns {Promise} + * @example + * // Remove a role from a member + * message.member.removeRole('193654001089118208') + * .then(console.log) + * .catch(console.error); + */ + removeRole(role, reason) { + if (!(role instanceof Role)) role = this.guild.roles.get(role); + if (!role) return Promise.reject(new TypeError('Supplied parameter was neither a Role nor a Snowflake.')); + return this.client.rest.methods.removeMemberRole(this, role, reason); + } + + /** + * Removes multiple roles from the member. + * @param {Collection|RoleResolvable[]} roles The roles or role IDs to remove + * @param {string} [reason] Reason for removing the roles + * @returns {Promise} + * @example + * // Removes a few roles from the member + * message.member.removeRoles(['193654001089118208', '369308579892690945']) + * .then(console.log) + * .catch(console.error); + */ + removeRoles(roles, reason) { + const allRoles = this._roles.slice(); + if (roles instanceof Collection) { + for (const role of roles.values()) { + const index = allRoles.indexOf(role.id); + if (index >= 0) allRoles.splice(index, 1); + } + } else { + for (const role of roles) { + const index = allRoles.indexOf(role instanceof Role ? role.id : role); + if (index >= 0) allRoles.splice(index, 1); + } + } + return this.edit({ roles: allRoles }, reason); + } + + /** + * Set the nickname for the guild member. + * @param {string} nick The nickname for the guild member + * @param {string} [reason] Reason for setting the nickname + * @returns {Promise} + * @example + * // Update the member's nickname + * message.member.setNickname('Cool Name') + * .then(console.log) + * .catch(console.error); + */ + setNickname(nick, reason) { + return this.edit({ nick }, reason); + } + + /** + * Creates a DM channel between the client and the member. + * @returns {Promise} + */ + createDM() { + return this.user.createDM(); + } + + /** + * Deletes any DMs with this guild member. + * @returns {Promise} + */ + deleteDM() { + return this.user.deleteDM(); + } + + /** + * Kick this member from the guild. + * @param {string} [reason] Reason for kicking user + * @returns {Promise} + * @example + * // Kick a member + * member.kick() + * .then(() => console.log(`Kicked ${member.displayName}`)) + * .catch(console.error); + */ + kick(reason) { + return this.client.rest.methods.kickGuildMember(this.guild, this, reason); + } + + /** + * Ban this guild member. + * @param {Object|number|string} [options] Ban options. If a number, the number of days to delete messages for, if a + * string, the ban reason. Supplying an object allows you to do both. + * @param {number} [options.days=0] Number of days of messages to delete + * @param {string} [options.reason] Reason for banning + * @returns {Promise} + * @example + * // Ban a guild member + * member.ban(7) + * .then(() => console.log(`Banned ${member.displayName}`)) + * .catch(console.error); + */ + ban(options) { + return this.guild.ban(this, options); + } + + /** + * When concatenated with a string, this automatically concatenates the user's mention instead of the Member object. + * @returns {string} + * @example + * // Logs: Hello from <@123456789>! + * console.log(`Hello from ${member}!`); + */ + toString() { + return `<@${this.nickname ? '!' : ''}${this.user.id}>`; + } + + // These are here only for documentation purposes - they are implemented by TextBasedChannel + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendCode() {} +} + +TextBasedChannel.applyToClass(GuildMember); + +GuildMember.prototype.hasPermissions = util.deprecate(GuildMember.prototype.hasPermissions, + 'GuildMember#hasPermissions is deprecated - use GuildMember#hasPermission, it now takes an array'); + +module.exports = GuildMember; + + +/***/ }), +/* 18 */ +/***/ (function(module, exports, __webpack_require__) { + +const Channel = __webpack_require__(11); +const Role = __webpack_require__(8); +const PermissionOverwrites = __webpack_require__(50); +const Permissions = __webpack_require__(6); +const Collection = __webpack_require__(3); +const Constants = __webpack_require__(0); + +/** + * Represents a guild channel (i.e. text channels and voice channels). + * @extends {Channel} + */ +class GuildChannel extends Channel { + constructor(guild, data) { + super(guild.client, data); + + /** + * The guild the channel is in + * @type {Guild} + */ + this.guild = guild; + } + + setup(data) { + super.setup(data); + + /** + * The name of the guild channel + * @type {string} + */ + this.name = data.name; + + /** + * The position of the channel in the list + * @type {number} + */ + this.position = data.position; + + /** + * The ID of the category parent of this channel + * @type {?Snowflake} + */ + this.parentID = data.parent_id; + + /** + * A map of permission overwrites in this channel for roles and users + * @type {Collection} + */ + this.permissionOverwrites = new Collection(); + if (data.permission_overwrites) { + for (const overwrite of data.permission_overwrites) { + this.permissionOverwrites.set(overwrite.id, new PermissionOverwrites(this, overwrite)); + } + } + } + + /** + * The position of the channel + * @type {number} + * @readonly + */ + get calculatedPosition() { + const sorted = this.guild._sortedChannels(this.type); + return sorted.array().indexOf(sorted.get(this.id)); + } + + /** + * The category parent of this channel + * @type {?CategoryChannel} + * @readonly + */ + get parent() { + return this.guild.channels.get(this.parentID) || null; + } + + /** + * Gets the overall set of permissions for a user in this channel, taking into account roles and permission + * overwrites. + * @param {GuildMemberResolvable} member The user that you want to obtain the overall permissions for + * @returns {?Permissions} + */ + permissionsFor(member) { + member = this.client.resolver.resolveGuildMember(this.guild, member); + if (!member) return null; + if (member.id === this.guild.ownerID) return new Permissions(member, Permissions.ALL); + + let permissions = 0; + + const roles = member.roles; + for (const role of roles.values()) permissions |= role.permissions; + + const admin = Boolean(permissions & Permissions.FLAGS.ADMINISTRATOR); + if (admin) return new Permissions(Permissions.ALL); + + const overwrites = this.overwritesFor(member, true, roles); + + if (overwrites.everyone) { + permissions &= ~overwrites.everyone.deny; + permissions |= overwrites.everyone.allow; + } + + let allow = 0; + for (const overwrite of overwrites.roles) { + permissions &= ~overwrite.deny; + allow |= overwrite.allow; + } + permissions |= allow; + + if (overwrites.member) { + permissions &= ~overwrites.member.deny; + permissions |= overwrites.member.allow; + } + + return new Permissions(member, permissions); + } + + overwritesFor(member, verified = false, roles = null) { + if (!verified) member = this.client.resolver.resolveGuildMember(this.guild, member); + if (!member) return []; + + roles = roles || member.roles; + const roleOverwrites = []; + let memberOverwrites; + let everyoneOverwrites; + + for (const overwrite of this.permissionOverwrites.values()) { + if (overwrite.id === this.guild.id) { + everyoneOverwrites = overwrite; + } else if (roles.has(overwrite.id)) { + roleOverwrites.push(overwrite); + } else if (overwrite.id === member.id) { + memberOverwrites = overwrite; + } + } + + return { + everyone: everyoneOverwrites, + roles: roleOverwrites, + member: memberOverwrites, + }; + } + + /** + * An object mapping permission flags to `true` (enabled) or `false` (disabled). + * ```js + * { + * 'SEND_MESSAGES': true, + * 'ATTACH_FILES': false, + * } + * ``` + * @typedef {Object} PermissionOverwriteOptions + */ + + /** + * Overwrites the permissions for a user or role in this channel. + * @param {Role|Snowflake|UserResolvable} userOrRole The user or role to update + * @param {PermissionOverwriteOptions} options The configuration for the update + * @param {string} [reason] Reason for creating/editing this overwrite + * @returns {Promise} + * @example + * // Overwrite permissions for a message author + * message.channel.overwritePermissions(message.author, { + * SEND_MESSAGES: false + * }) + * .then(updated => console.log(updated.permissionOverwrites.get(message.author.id))) + * .catch(console.error); + */ + overwritePermissions(userOrRole, options, reason) { + const payload = { + allow: 0, + deny: 0, + }; + + if (userOrRole instanceof Role) { + payload.type = 'role'; + } else if (this.guild.roles.has(userOrRole)) { + userOrRole = this.guild.roles.get(userOrRole); + payload.type = 'role'; + } else { + userOrRole = this.client.resolver.resolveUser(userOrRole); + payload.type = 'member'; + if (!userOrRole) return Promise.reject(new TypeError('Supplied parameter was neither a User nor a Role.')); + } + + payload.id = userOrRole.id; + + const prevOverwrite = this.permissionOverwrites.get(userOrRole.id); + + if (prevOverwrite) { + payload.allow = prevOverwrite.allow; + payload.deny = prevOverwrite.deny; + } + + for (const perm in options) { + if (options[perm] === true) { + payload.allow |= Permissions.FLAGS[perm] || 0; + payload.deny &= ~(Permissions.FLAGS[perm] || 0); + } else if (options[perm] === false) { + payload.allow &= ~(Permissions.FLAGS[perm] || 0); + payload.deny |= Permissions.FLAGS[perm] || 0; + } else if (options[perm] === null) { + payload.allow &= ~(Permissions.FLAGS[perm] || 0); + payload.deny &= ~(Permissions.FLAGS[perm] || 0); + } + } + + return this.client.rest.methods.setChannelOverwrite(this, payload, reason).then(() => this); + } + + /** + * The data for a guild channel. + * @typedef {Object} ChannelData + * @property {string} [name] The name of the channel + * @property {number} [position] The position of the channel + * @property {string} [topic] The topic of the text channel + * @property {number} [bitrate] The bitrate of the voice channel + * @property {number} [userLimit] The user limit of the channel + */ + + /** + * Edits the channel. + * @param {ChannelData} data The new data for the channel + * @param {string} [reason] Reason for editing this channel + * @returns {Promise} + * @example + * // Edit a channel + * channel.edit({ name: 'new-channel' }) + * .then(console.log) + * .catch(console.error); + */ + edit(data, reason) { + return this.client.rest.methods.updateChannel(this, data, reason).then(() => this); + } + + /** + * Set a new name for the guild channel. + * @param {string} name The new name for the guild channel + * @param {string} [reason] Reason for changing the guild channel's name + * @returns {Promise} + * @example + * // Set a new channel name + * channel.setName('not_general') + * .then(newChannel => console.log(`Channel's new name is ${newChannel.name}`)) + * .catch(console.error); + */ + setName(name, reason) { + return this.edit({ name }, reason); + } + + /** + * Set a new position for the guild channel. + * @param {number} position The new position for the guild channel + * @param {boolean} [relative=false] Move the position relative to its current value + * @returns {Promise} + * @example + * // Set a new channel position + * channel.setPosition(2) + * .then(newChannel => console.log(`Channel's new position is ${newChannel.position}`)) + * .catch(console.error); + */ + setPosition(position, relative) { + return this.guild.setChannelPosition(this, position, relative); + } + + /** + * Set a new parent for the guild channel. + * @param {CategoryChannel|SnowFlake} parent The new parent for the guild channel + * @param {string} [reason] Reason for changing the guild channel's parent + * @returns {Promise} + * @example + * // Sets the parent of a channel + * channel.setParent('174674066072928256') + * .then(updated => console.log(`Set the category of ${updated.name} to ${updated.parent.name}`)) + * .catch(console.error); + */ + setParent(parent, reason) { + parent = this.client.resolver.resolveChannelID(parent); + return this.edit({ parent }, reason); + } + + /** + * Set a new topic for the guild channel. + * @param {string} topic The new topic for the guild channel + * @param {string} [reason] Reason for changing the guild channel's topic + * @returns {Promise} + * @example + * // Set a new channel topic + * channel.setTopic('Needs more rate limiting') + * .then(updated => console.log(`Channel's new topic is ${updated.topic}`)) + * .catch(console.error); + */ + setTopic(topic, reason) { + return this.edit({ topic }, reason); + } + + /** + * Create an invite to this guild channel. + * This is only available when using a bot account. + * @param {Object} [options={}] Options for the invite + * @param {boolean} [options.temporary=false] Whether members that joined via the invite should be automatically + * kicked after 24 hours if they have not yet received a role + * @param {number} [options.maxAge=86400] How long the invite should last (in seconds, 0 for forever) + * @param {number} [options.maxUses=0] Maximum number of uses + * @param {boolean} [options.unique=false] Create a unique invite, or use an existing one with similar settings + * @param {string} [reason] Reason for creating the invite + * @returns {Promise} + * @example + * // Create an invite to a channel + * channel.createInvite() + * .then(invite => console.log(`Created an invite with a code of ${invite.code}`)) + * .catch(console.error); + */ + createInvite(options = {}, reason) { + return this.client.rest.methods.createChannelInvite(this, options, reason); + } + + /** + * Clone this channel. + * @param {string} [name=this.name] Optional name for the new channel, otherwise it has the name of this channel + * @param {boolean} [withPermissions=true] Whether to clone the channel with this channel's permission overwrites + * @param {boolean} [withTopic=true] Whether to clone the channel with this channel's topic + * @param {string} [reason] Reason for cloning this channel + * @returns {Promise} + * @example + * // Clone a channel + * channel.clone(undefined, true, false, 'Needed a clone') + * .then(clone => console.log(`Cloned ${channel.name} to make a channel called ${clone.name}`)) + * .catch(console.error); + */ + clone(name = this.name, withPermissions = true, withTopic = true, reason) { + return this.guild.createChannel(name, this.type, withPermissions ? this.permissionOverwrites : [], reason) + .then(channel => withTopic ? channel.setTopic(this.topic) : channel); + } + + /** + * Deletes this channel. + * @param {string} [reason] Reason for deleting this channel + * @returns {Promise} + * @example + * // Delete the channel + * channel.delete('Making room for new channels') + * .then(deleted => console.log(`Deleted ${deleted.name} to make room for new channels`)) + * .catch(console.error); + */ + delete(reason) { + return this.client.rest.methods.deleteChannel(this, reason); + } + + /** + * Checks if this channel has the same type, topic, position, name, overwrites and ID as another channel. + * In most cases, a simple `channel.id === channel2.id` will do, and is much faster too. + * @param {GuildChannel} channel Channel to compare with + * @returns {boolean} + */ + equals(channel) { + let equal = channel && + this.id === channel.id && + this.type === channel.type && + this.topic === channel.topic && + this.position === channel.position && + this.name === channel.name; + + if (equal) { + if (this.permissionOverwrites && channel.permissionOverwrites) { + equal = this.permissionOverwrites.equals(channel.permissionOverwrites); + } else { + equal = !this.permissionOverwrites && !channel.permissionOverwrites; + } + } + + return equal; + } + + /** + * Whether the channel is deletable by the client user + * @type {boolean} + * @readonly + */ + get deletable() { + return this.id !== this.guild.id && + this.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS); + } + + /** + * Whether the channel is muted + * This is only available when using a user account. + * @type {?boolean} + * @readonly + */ + get muted() { + if (this.client.user.bot) return null; + try { + return this.client.user.guildSettings.get(this.guild.id).channelOverrides.get(this.id).muted; + } catch (err) { + return false; + } + } + + /** + * The type of message that should notify you + * This is only available when using a user account. + * @type {?MessageNotificationType} + * @readonly + */ + get messageNotifications() { + if (this.client.user.bot) return null; + try { + return this.client.user.guildSettings.get(this.guild.id).channelOverrides.get(this.id).messageNotifications; + } catch (err) { + return Constants.MessageNotificationTypes[3]; + } + } + + /** + * When concatenated with a string, this automatically returns the channel's mention instead of the Channel object. + * @returns {string} + * @example + * // Logs: Hello from <#123456789012345678> + * console.log(`Hello from ${channel}`); + * @example + * // Logs: Hello from <#123456789012345678> + * console.log('Hello from ' + channel); + */ + toString() { + return `<#${this.id}>`; + } +} + +module.exports = GuildChannel; + + +/***/ }), +/* 19 */ +/***/ (function(module, exports) { + +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +function EventEmitter() { + this._events = this._events || {}; + this._maxListeners = this._maxListeners || undefined; +} +module.exports = EventEmitter; + +// Backwards-compat with node 0.10.x +EventEmitter.EventEmitter = EventEmitter; + +EventEmitter.prototype._events = undefined; +EventEmitter.prototype._maxListeners = undefined; + +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +EventEmitter.defaultMaxListeners = 10; + +// Obviously not all Emitters should be limited to 10. This function allows +// that to be increased. Set to zero for unlimited. +EventEmitter.prototype.setMaxListeners = function(n) { + if (!isNumber(n) || n < 0 || isNaN(n)) + throw TypeError('n must be a positive number'); + this._maxListeners = n; + return this; +}; + +EventEmitter.prototype.emit = function(type) { + var er, handler, len, args, i, listeners; + + if (!this._events) + this._events = {}; + + // If there is no 'error' event listener then throw. + if (type === 'error') { + if (!this._events.error || + (isObject(this._events.error) && !this._events.error.length)) { + er = arguments[1]; + if (er instanceof Error) { + throw er; // Unhandled 'error' event + } else { + // At least give some kind of context to the user + var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); + err.context = er; + throw err; + } + } + } + + handler = this._events[type]; + + if (isUndefined(handler)) + return false; + + if (isFunction(handler)) { + switch (arguments.length) { + // fast cases + case 1: + handler.call(this); + break; + case 2: + handler.call(this, arguments[1]); + break; + case 3: + handler.call(this, arguments[1], arguments[2]); + break; + // slower + default: + args = Array.prototype.slice.call(arguments, 1); + handler.apply(this, args); + } + } else if (isObject(handler)) { + args = Array.prototype.slice.call(arguments, 1); + listeners = handler.slice(); + len = listeners.length; + for (i = 0; i < len; i++) + listeners[i].apply(this, args); + } + + return true; +}; + +EventEmitter.prototype.addListener = function(type, listener) { + var m; + + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + if (!this._events) + this._events = {}; + + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (this._events.newListener) + this.emit('newListener', type, + isFunction(listener.listener) ? + listener.listener : listener); + + if (!this._events[type]) + // Optimize the case of one listener. Don't need the extra array object. + this._events[type] = listener; + else if (isObject(this._events[type])) + // If we've already got an array, just append. + this._events[type].push(listener); + else + // Adding the second element, need to change to array. + this._events[type] = [this._events[type], listener]; + + // Check for listener leak + if (isObject(this._events[type]) && !this._events[type].warned) { + if (!isUndefined(this._maxListeners)) { + m = this._maxListeners; + } else { + m = EventEmitter.defaultMaxListeners; + } + + if (m && m > 0 && this._events[type].length > m) { + this._events[type].warned = true; + console.error('(node) warning: possible EventEmitter memory ' + + 'leak detected. %d listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit.', + this._events[type].length); + if (typeof console.trace === 'function') { + // not supported in IE 10 + console.trace(); + } + } + } + + return this; +}; + +EventEmitter.prototype.on = EventEmitter.prototype.addListener; + +EventEmitter.prototype.once = function(type, listener) { + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + var fired = false; + + function g() { + this.removeListener(type, g); + + if (!fired) { + fired = true; + listener.apply(this, arguments); + } + } + + g.listener = listener; + this.on(type, g); + + return this; +}; + +// emits a 'removeListener' event iff the listener was removed +EventEmitter.prototype.removeListener = function(type, listener) { + var list, position, length, i; + + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + if (!this._events || !this._events[type]) + return this; + + list = this._events[type]; + length = list.length; + position = -1; + + if (list === listener || + (isFunction(list.listener) && list.listener === listener)) { + delete this._events[type]; + if (this._events.removeListener) + this.emit('removeListener', type, listener); + + } else if (isObject(list)) { + for (i = length; i-- > 0;) { + if (list[i] === listener || + (list[i].listener && list[i].listener === listener)) { + position = i; + break; + } + } + + if (position < 0) + return this; + + if (list.length === 1) { + list.length = 0; + delete this._events[type]; + } else { + list.splice(position, 1); + } + + if (this._events.removeListener) + this.emit('removeListener', type, listener); + } + + return this; +}; + +EventEmitter.prototype.removeAllListeners = function(type) { + var key, listeners; + + if (!this._events) + return this; + + // not listening for removeListener, no need to emit + if (!this._events.removeListener) { + if (arguments.length === 0) + this._events = {}; + else if (this._events[type]) + delete this._events[type]; + return this; + } + + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + for (key in this._events) { + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = {}; + return this; + } + + listeners = this._events[type]; + + if (isFunction(listeners)) { + this.removeListener(type, listeners); + } else if (listeners) { + // LIFO order + while (listeners.length) + this.removeListener(type, listeners[listeners.length - 1]); + } + delete this._events[type]; + + return this; +}; + +EventEmitter.prototype.listeners = function(type) { + var ret; + if (!this._events || !this._events[type]) + ret = []; + else if (isFunction(this._events[type])) + ret = [this._events[type]]; + else + ret = this._events[type].slice(); + return ret; +}; + +EventEmitter.prototype.listenerCount = function(type) { + if (this._events) { + var evlistener = this._events[type]; + + if (isFunction(evlistener)) + return 1; + else if (evlistener) + return evlistener.length; + } + return 0; +}; + +EventEmitter.listenerCount = function(emitter, type) { + return emitter.listenerCount(type); +}; + +function isFunction(arg) { + return typeof arg === 'function'; +} + +function isNumber(arg) { + return typeof arg === 'number'; +} + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} + +function isUndefined(arg) { + return arg === void 0; +} + + +/***/ }), +/* 20 */ +/***/ (function(module, exports, __webpack_require__) { + +const Attachment = __webpack_require__(21); +let ClientDataResolver; + +/** + * A rich embed to be sent with a message with a fluent interface for creation. + * @param {Object} [data] Data to set in the rich embed + */ +class RichEmbed { + constructor(data = {}) { + /** + * Title for this Embed + * @type {string} + */ + this.title = data.title; + + /** + * Description for this Embed + * @type {string} + */ + this.description = data.description; + + /** + * URL for this Embed + * @type {string} + */ + this.url = data.url; + + /** + * Color for this Embed + * @type {number} + */ + this.color = data.color; + + /** + * Author for this Embed + * @type {Object} + */ + this.author = data.author; + + /** + * Timestamp for this Embed + * @type {Date} + */ + this.timestamp = data.timestamp; + + /** + * Fields for this Embed + * @type {Object[]} + */ + this.fields = data.fields || []; + + /** + * Thumbnail for this Embed + * @type {Object} + */ + this.thumbnail = data.thumbnail; + + /** + * Image for this Embed + * @type {Object} + */ + this.image = data.image; + + /** + * Footer for this Embed + * @type {Object} + */ + this.footer = data.footer; + + /** + * File to upload alongside this Embed + * @type {FileOptions|string|Attachment} + */ + this.file = data.file; + } + + /** + * Sets the title of this embed. + * @param {StringResolvable} title The title + * @returns {RichEmbed} This embed + */ + setTitle(title) { + title = resolveString(title); + if (title.length > 256) throw new RangeError('RichEmbed titles may not exceed 256 characters.'); + this.title = title; + return this; + } + + /** + * Sets the description of this embed. + * @param {StringResolvable} description The description + * @returns {RichEmbed} This embed + */ + setDescription(description) { + description = resolveString(description); + if (description.length > 2048) throw new RangeError('RichEmbed descriptions may not exceed 2048 characters.'); + this.description = description; + return this; + } + + /** + * Sets the URL of this embed. + * @param {string} url The URL + * @returns {RichEmbed} This embed + */ + setURL(url) { + this.url = url; + return this; + } + + /** + * Sets the color of this embed. + * @param {ColorResolvable} color The color of the embed + * @returns {RichEmbed} This embed + */ + setColor(color) { + if (!ClientDataResolver) ClientDataResolver = __webpack_require__(27); + this.color = ClientDataResolver.resolveColor(color); + return this; + } + + /** + * Sets the author of this embed. + * @param {StringResolvable} name The name of the author + * @param {string} [icon] The icon URL of the author + * @param {string} [url] The URL of the author + * @returns {RichEmbed} This embed + */ + setAuthor(name, icon, url) { + this.author = { name: resolveString(name), icon_url: icon, url }; + return this; + } + + /** + * Sets the timestamp of this embed. + * @param {Date} [timestamp=current date] The timestamp + * @returns {RichEmbed} This embed + */ + setTimestamp(timestamp = new Date()) { + this.timestamp = timestamp; + return this; + } + + /** + * Adds a field to the embed (max 25). + * @param {StringResolvable} name The name of the field + * @param {StringResolvable} value The value of the field + * @param {boolean} [inline=false] Set the field to display inline + * @returns {RichEmbed} This embed + */ + addField(name, value, inline = false) { + if (this.fields.length >= 25) throw new RangeError('RichEmbeds may not exceed 25 fields.'); + name = resolveString(name); + if (name.length > 256) throw new RangeError('RichEmbed field names may not exceed 256 characters.'); + if (!/\S/.test(name)) throw new RangeError('RichEmbed field names may not be empty.'); + value = resolveString(value); + if (value.length > 1024) throw new RangeError('RichEmbed field values may not exceed 1024 characters.'); + if (!/\S/.test(value)) throw new RangeError('RichEmbed field values may not be empty.'); + this.fields.push({ name, value, inline }); + return this; + } + + /** + * Convenience function for `.addField('\u200B', '\u200B', inline)`. + * @param {boolean} [inline=false] Set the field to display inline + * @returns {RichEmbed} This embed + */ + addBlankField(inline = false) { + return this.addField('\u200B', '\u200B', inline); + } + + /** + * Set the thumbnail of this embed. + * @param {string} url The URL of the thumbnail + * @returns {RichEmbed} This embed + */ + setThumbnail(url) { + this.thumbnail = { url }; + return this; + } + + /** + * Set the image of this embed. + * @param {string} url The URL of the image + * @returns {RichEmbed} This embed + */ + setImage(url) { + this.image = { url }; + return this; + } + + /** + * Sets the footer of this embed. + * @param {StringResolvable} text The text of the footer + * @param {string} [icon] The icon URL of the footer + * @returns {RichEmbed} This embed + */ + setFooter(text, icon) { + text = resolveString(text); + if (text.length > 2048) throw new RangeError('RichEmbed footer text may not exceed 2048 characters.'); + this.footer = { text, icon_url: icon }; + return this; + } + + /** + * Sets the file to upload alongside the embed. This file can be accessed via `attachment://fileName.extension` when + * setting an embed image or author/footer icons. Only one file may be attached. + * @param {FileOptions|string|Attachment} file Local path or URL to the file to attach, + * or valid FileOptions for a file to attach + * @returns {RichEmbed} This embed + */ + attachFile(file) { + if (this.file) throw new RangeError('You may not upload more than one file at once.'); + if (file instanceof Attachment) file = file.file; + this.file = file; + return this; + } +} + +module.exports = RichEmbed; + +function resolveString(data) { + if (typeof data === 'string') return data; + if (data instanceof Array) return data.join('\n'); + return String(data); +} + + +/***/ }), +/* 21 */ +/***/ (function(module, exports) { + +/** + * Represents an attachment in a message. + * @param {BufferResolvable|Stream} file The file + * @param {string} [name] The name of the file, if any + */ +class Attachment { + constructor(file, name) { + this.file = null; + if (name) this.setAttachment(file, name); + else this._attach(file); + } + + /** + * The name of the file + * @type {?string} + * @readonly + */ + get name() { + return this.file.name; + } + + /** + * The file + * @type {?BufferResolvable|Stream} + * @readonly + */ + get attachment() { + return this.file.attachment; + } + + /** + * Set the file of this attachment. + * @param {BufferResolvable|Stream} file The file + * @param {string} name The name of the file + * @returns {Attachment} This attachment + */ + setAttachment(file, name) { + this.file = { attachment: file, name }; + return this; + } + + /** + * Set the file of this attachment. + * @param {BufferResolvable|Stream} attachment The file + * @returns {Attachment} This attachment + */ + setFile(attachment) { + this.file = { attachment }; + return this; + } + + /** + * Set the name of this attachment. + * @param {string} name The name of the image + * @returns {Attachment} This attachment + */ + setName(name) { + this.file.name = name; + return this; + } + + /** + * Set the file of this attachment. + * @param {BufferResolvable|Stream} file The file + * @param {string} name The name of the file + * @returns {void} + * @private + */ + _attach(file, name) { + if (typeof file === 'string') this.file = file; + else this.setAttachment(file, name); + } +} + +module.exports = Attachment; + + +/***/ }), +/* 22 */ +/***/ (function(module, exports, __webpack_require__) { + +const util = __webpack_require__(7); +const Long = __webpack_require__(25); +const User = __webpack_require__(9); +const Role = __webpack_require__(8); +const Emoji = __webpack_require__(16); +const Presence = __webpack_require__(10).Presence; +const GuildMember = __webpack_require__(17); +const Constants = __webpack_require__(0); +const Collection = __webpack_require__(3); +const Util = __webpack_require__(4); +const Snowflake = __webpack_require__(5); + +/** + * Represents a guild (or a server) on Discord. + * It's recommended to see if a guild is available before performing operations or reading data from it. You can + * check this with `guild.available`. + */ +class Guild { + constructor(client, data) { + /** + * The client that created the instance of the guild + * @name Guild#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + /** + * A collection of members that are in this guild. The key is the member's ID, the value is the member + * @type {Collection} + */ + this.members = new Collection(); + + /** + * A collection of channels that are in this guild. The key is the channel's ID, the value is the channel + * @type {Collection} + */ + this.channels = new Collection(); + + /** + * A collection of roles that are in this guild. The key is the role's ID, the value is the role + * @type {Collection} + */ + this.roles = new Collection(); + + /** + * A collection of presences in this guild + * @type {Collection} + */ + this.presences = new Collection(); + + if (!data) return; + if (data.unavailable) { + /** + * Whether the guild is available to access. If it is not available, it indicates a server outage + * @type {boolean} + */ + this.available = false; + + /** + * The Unique ID of the guild, useful for comparisons + * @type {Snowflake} + */ + this.id = data.id; + } else { + this.setup(data); + if (!data.channels) this.available = false; + } + } + + /** + * Sets up the guild. + * @param {*} data The raw data of the guild + * @private + */ + setup(data) { + /** + * The name of the guild + * @type {string} + */ + this.name = data.name; + + /** + * The hash of the guild icon + * @type {?string} + */ + this.icon = data.icon; + + /** + * The hash of the guild splash image (VIP only) + * @type {?string} + */ + this.splash = data.splash; + + /** + * The region the guild is located in + * @type {string} + */ + this.region = data.region; + + /** + * The full amount of members in this guild as of `READY` + * @type {number} + */ + this.memberCount = data.member_count || this.memberCount; + + /** + * Whether the guild is "large" (has more than 250 members) + * @type {boolean} + */ + this.large = Boolean('large' in data ? data.large : this.large); + + /** + * An array of guild features + * @type {Object[]} + */ + this.features = data.features; + + /** + * The ID of the application that created this guild (if applicable) + * @type {?Snowflake} + */ + this.applicationID = data.application_id; + + /** + * The time in seconds before a user is counted as "away from keyboard" + * @type {?number} + */ + this.afkTimeout = data.afk_timeout; + + /** + * The ID of the voice channel where AFK members are moved + * @type {?string} + */ + this.afkChannelID = data.afk_channel_id; + + /** + * The ID of the system channel + * @type {?Snowflake} + */ + this.systemChannelID = data.system_channel_id; + + /** + * Whether embedded images are enabled on this guild + * @type {boolean} + */ + this.embedEnabled = data.embed_enabled; + + /** + * The verification level of the guild + * @type {number} + */ + this.verificationLevel = data.verification_level; + + /** + * The explicit content filter level of the guild + * @type {number} + */ + this.explicitContentFilter = data.explicit_content_filter; + + /** + * The timestamp the client user joined the guild at + * @type {number} + */ + this.joinedTimestamp = data.joined_at ? new Date(data.joined_at).getTime() : this.joinedTimestamp; + + this.id = data.id; + this.available = !data.unavailable; + this.features = data.features || this.features || []; + + if (data.members) { + this.members.clear(); + for (const guildUser of data.members) this._addMember(guildUser, false); + } + + if (data.owner_id) { + /** + * The user ID of this guild's owner + * @type {Snowflake} + */ + this.ownerID = data.owner_id; + } + + if (data.channels) { + this.channels.clear(); + for (const channel of data.channels) this.client.dataManager.newChannel(channel, this); + } + + if (data.roles) { + this.roles.clear(); + for (const role of data.roles) { + const newRole = new Role(this, role); + this.roles.set(newRole.id, newRole); + } + } + + if (data.presences) { + for (const presence of data.presences) { + this._setPresence(presence.user.id, presence); + } + } + + this._rawVoiceStates = new Collection(); + if (data.voice_states) { + for (const voiceState of data.voice_states) { + this._rawVoiceStates.set(voiceState.user_id, voiceState); + const member = this.members.get(voiceState.user_id); + if (member) { + member.serverMute = voiceState.mute; + member.serverDeaf = voiceState.deaf; + member.selfMute = voiceState.self_mute; + member.selfDeaf = voiceState.self_deaf; + member.voiceSessionID = voiceState.session_id; + member.voiceChannelID = voiceState.channel_id; + this.channels.get(voiceState.channel_id).members.set(member.user.id, member); + } + } + } + + if (!this.emojis) { + /** + * A collection of emojis that are in this guild + * The key is the emoji's ID, the value is the emoji + * @type {Collection} + */ + this.emojis = new Collection(); + for (const emoji of data.emojis) this.emojis.set(emoji.id, new Emoji(this, emoji)); + } else { + this.client.actions.GuildEmojisUpdate.handle({ + guild_id: this.id, + emojis: data.emojis, + }); + } + } + + /** + * The timestamp the guild was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return Snowflake.deconstruct(this.id).timestamp; + } + + /** + * The time the guild was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * The time the client user joined the guild + * @type {Date} + * @readonly + */ + get joinedAt() { + return new Date(this.joinedTimestamp); + } + + /** + * The URL to this guild's icon + * @type {?string} + * @readonly + */ + get iconURL() { + if (!this.icon) return null; + return Constants.Endpoints.Guild(this).Icon(this.client.options.http.cdn, this.icon); + } + + /** + * The acronym that shows up in place of a guild icon. + * @type {string} + * @readonly + */ + get nameAcronym() { + return this.name.replace(/\w+/g, name => name[0]).replace(/\s/g, ''); + } + + /** + * The URL to this guild's splash + * @type {?string} + * @readonly + */ + get splashURL() { + if (!this.splash) return null; + return Constants.Endpoints.Guild(this).Splash(this.client.options.http.cdn, this.splash); + } + + /** + * The owner of the guild + * @type {GuildMember} + * @readonly + */ + get owner() { + return this.members.get(this.ownerID); + } + + /** + * AFK voice channel for this guild + * @type {?VoiceChannel} + * @readonly + */ + get afkChannel() { + return this.client.channels.get(this.afkChannelID) || null; + } + + /** + * System channel for this guild + * @type {?GuildChannel} + * @readonly + */ + get systemChannel() { + return this.client.channels.get(this.systemChannelID) || null; + } + + /** + * If the client is connected to any voice channel in this guild, this will be the relevant VoiceConnection + * @type {?VoiceConnection} + * @readonly + */ + get voiceConnection() { + if (this.client.browser) return null; + return this.client.voice.connections.get(this.id) || null; + } + + /** + * The position of this guild + * This is only available when using a user account. + * @type {?number} + * @readonly + */ + get position() { + if (this.client.user.bot) return null; + if (!this.client.user.settings.guildPositions) return null; + return this.client.user.settings.guildPositions.indexOf(this.id); + } + + /** + * Whether the guild is muted + * This is only available when using a user account. + * @type {?boolean} + * @readonly + */ + get muted() { + if (this.client.user.bot) return null; + try { + return this.client.user.guildSettings.get(this.id).muted; + } catch (err) { + return false; + } + } + + /** + * The type of message that should notify you + * This is only available when using a user account. + * @type {?MessageNotificationType} + * @readonly + */ + get messageNotifications() { + if (this.client.user.bot) return null; + try { + return this.client.user.guildSettings.get(this.id).messageNotifications; + } catch (err) { + return null; + } + } + + /** + * Whether to receive mobile push notifications + * This is only available when using a user account. + * @type {?boolean} + * @readonly + */ + get mobilePush() { + if (this.client.user.bot) return null; + try { + return this.client.user.guildSettings.get(this.id).mobilePush; + } catch (err) { + return false; + } + } + + /** + * Whether to suppress everyone messages + * This is only available when using a user account. + * @type {?boolean} + * @readonly + */ + get suppressEveryone() { + if (this.client.user.bot) return null; + try { + return this.client.user.guildSettings.get(this.id).suppressEveryone; + } catch (err) { + return null; + } + } + + /** + * The `@everyone` role of the guild + * @type {Role} + * @readonly + */ + get defaultRole() { + return this.roles.get(this.id); + } + + /** + * The client user as a GuildMember of this guild + * @type {?GuildMember} + * @readonly + */ + get me() { + return this.members.get(this.client.user.id); + } + + /** + * Fetches a collection of roles in the current guild sorted by position + * @type {Collection} + * @readonly + * @private + */ + get _sortedRoles() { + return this._sortPositionWithID(this.roles); + } + + /** + * Returns the GuildMember form of a User object, if the user is present in the guild. + * @param {UserResolvable} user The user that you want to obtain the GuildMember of + * @returns {?GuildMember} + * @example + * // Get the guild member of a user + * const member = guild.member(message.author); + */ + member(user) { + return this.client.resolver.resolveGuildMember(this, user); + } + + /** + * Fetch a collection of banned users in this guild. + * @returns {Promise>} + * @example + * // Fetch bans in guild + * guild.fetchBans() + * .then(bans => console.log(`This guild has ${bans.size} bans`)) + * .catch(console.error); + */ + fetchBans() { + return this.client.rest.methods.getGuildBans(this) + .then(bans => { + const users = new Collection(); + for (const ban of bans.values()) users.set(ban.user.id, ban.user); + return users; + }); + } + + /** + * Fetch a collection of invites to this guild. + * Resolves with a collection mapping invites by their codes. + * @returns {Promise>} + * @example + * // Fetch invites + * guild.fetchInvites() + * .then(invites => console.log(`Fetched ${invites.size} invites`)) + * .catch(console.error); + * @example + * // Fetch invite creator by their id + * guild.fetchInvites() + * .then(invites => console.log(invites.find(invite => invite.inviter.id === '84484653687267328'))) + * .then(console.error); + */ + fetchInvites() { + return this.client.rest.methods.getGuildInvites(this); + } + + /** + * Fetch all webhooks for the guild. + * @returns {Promise>} + * @example + * // Fetch webhooks + * guild.fetchWebhooks() + * .then(webhooks => console.log(`Fetched ${webhooks.size} webhooks`)) + * .catch(console.error); + */ + fetchWebhooks() { + return this.client.rest.methods.getGuildWebhooks(this); + } + + /** + * Fetch available voice regions. + * @returns {Promise>} + * @example + * // Fetch voice regions + * guild.fetchVoiceRegions() + * .then(console.log) + * .catch(console.error); + */ + fetchVoiceRegions() { + return this.client.rest.methods.fetchVoiceRegions(this.id); + } + + /** + * Fetch audit logs for this guild. + * @param {Object} [options={}] Options for fetching audit logs + * @param {Snowflake|GuildAuditLogsEntry} [options.before] Limit to entries from before specified entry + * @param {Snowflake|GuildAuditLogsEntry} [options.after] Limit to entries from after specified entry + * @param {number} [options.limit] Limit number of entries + * @param {UserResolvable} [options.user] Only show entries involving this user + * @param {string|number} [options.type] Only show entries involving this action type + * @returns {Promise} + * @example + * // Output audit log entries + * guild.fetchAuditLogs() + * .then(audit => console.log(audit.entries.first())) + * .catch(console.error); + */ + fetchAuditLogs(options) { + return this.client.rest.methods.getGuildAuditLogs(this, options); + } + + /** + * Adds a user to the guild using OAuth2. Requires the `CREATE_INSTANT_INVITE` permission. + * @param {UserResolvable} user User to add to the guild + * @param {Object} options Options for the addition + * @param {string} options.accessToken An OAuth2 access token for the user with the `guilds.join` scope granted to the + * bot's application + * @param {string} [options.nick] Nickname to give the member (requires `MANAGE_NICKNAMES`) + * @param {Collection|Role[]|Snowflake[]} [options.roles] Roles to add to the member + * (requires `MANAGE_ROLES`) + * @param {boolean} [options.mute] Whether the member should be muted (requires `MUTE_MEMBERS`) + * @param {boolean} [options.deaf] Whether the member should be deafened (requires `DEAFEN_MEMBERS`) + * @returns {Promise} + */ + addMember(user, options) { + if (this.members.has(user.id)) return Promise.resolve(this.members.get(user.id)); + return this.client.rest.methods.putGuildMember(this, user, options); + } + + /** + * Fetch a single guild member from a user. + * @param {UserResolvable} user The user to fetch the member for + * @param {boolean} [cache=true] Insert the member into the members cache + * @returns {Promise} + * @example + * // Fetch a guild member + * guild.fetchMember(message.author) + * .then(console.log) + * .catch(console.error); + */ + fetchMember(user, cache = true) { + user = this.client.resolver.resolveUser(user); + if (!user) return Promise.reject(new Error('Invalid or uncached id provided.')); + if (this.members.has(user.id)) return Promise.resolve(this.members.get(user.id)); + return this.client.rest.methods.getGuildMember(this, user, cache); + } + + /** + * Fetches all the members in the guild, even if they are offline. If the guild has less than 250 members, + * this should not be necessary. + * @param {string} [query=''] Limit fetch to members with similar usernames + * @param {number} [limit=0] Maximum number of members to request + * @returns {Promise} + * @example + * // Fetch guild members + * guild.fetchMembers() + * .then(console.log) + * .catch(console.error); + * @example + * // Fetches a maximum of 1 member with the given query + * guild.fetchMembers('hydrabolt', 1) + * .then(console.log) + * .catch(console.error); + */ + fetchMembers(query = '', limit = 0) { + return new Promise((resolve, reject) => { + if (this.memberCount === this.members.size) { + resolve(this); + return; + } + this.client.ws.send({ + op: Constants.OPCodes.REQUEST_GUILD_MEMBERS, + d: { + guild_id: this.id, + query, + limit, + }, + }); + const handler = (members, guild) => { + if (guild.id !== this.id) return; + if (this.memberCount === this.members.size || members.length < 1000) { + this.client.removeListener(Constants.Events.GUILD_MEMBERS_CHUNK, handler); + resolve(this); + } + }; + this.client.on(Constants.Events.GUILD_MEMBERS_CHUNK, handler); + this.client.setTimeout(() => reject(new Error('Members didn\'t arrive in time.')), 120 * 1000); + }); + } + + /** + * Performs a search within the entire guild. + * This is only available when using a user account. + * @param {MessageSearchOptions} [options={}] Options to pass to the search + * @returns {Promise} + * @example + * guild.search({ + * content: 'discord.js', + * before: '2016-11-17' + * }) + * .then(res => { + * const hit = res.messages[0].find(m => m.hit).content; + * console.log(`I found: **${hit}**, total results: ${res.totalResults}`); + * }) + * .catch(console.error); + */ + search(options = {}) { + return this.client.rest.methods.search(this, options); + } + + /** + * The data for editing a guild. + * @typedef {Object} GuildEditData + * @property {string} [name] The name of the guild + * @property {string} [region] The region of the guild + * @property {number} [verificationLevel] The verification level of the guild + * @property {number} [explicitContentFilter] The level of the explicit content filter + * @property {ChannelResolvable} [afkChannel] The AFK channel of the guild + * @property {ChannelResolvable} [systemChannel] The system channel of the guild + * @property {number} [afkTimeout] The AFK timeout of the guild + * @property {Base64Resolvable} [icon] The icon of the guild + * @property {GuildMemberResolvable} [owner] The owner of the guild + * @property {Base64Resolvable} [splash] The splash screen of the guild + */ + + /** + * Updates the guild with new information - e.g. a new name. + * @param {GuildEditData} data The data to update the guild with + * @param {string} [reason] Reason for editing the guild + * @returns {Promise} + * @example + * // Set the guild name and region + * guild.edit({ + * name: 'Discord Guild', + * region: 'london', + * }) + * .then(g => console.log(`Changed guild name to ${g} and region to ${g.region}`)) + * .catch(console.error); + */ + edit(data, reason) { + const _data = {}; + if (data.name) _data.name = data.name; + if (data.region) _data.region = data.region; + if (typeof data.verificationLevel !== 'undefined') _data.verification_level = Number(data.verificationLevel); + if (typeof data.afkChannel !== 'undefined') { + _data.afk_channel_id = this.client.resolver.resolveChannelID(data.afkChannel); + } + if (typeof data.systemChannel !== 'undefined') { + _data.system_channel_id = this.client.resolver.resolveChannelID(data.systemChannel); + } + if (data.afkTimeout) _data.afk_timeout = Number(data.afkTimeout); + if (typeof data.icon !== 'undefined') _data.icon = data.icon; + if (data.owner) _data.owner_id = this.client.resolver.resolveUser(data.owner).id; + if (typeof data.splash !== 'undefined') _data.splash = data.splash; + if (typeof data.explicitContentFilter !== 'undefined') { + _data.explicit_content_filter = Number(data.explicitContentFilter); + } + return this.client.rest.methods.updateGuild(this, _data, reason); + } + + /** + * Edit the level of the explicit content filter. + * @param {number} explicitContentFilter The new level of the explicit content filter + * @param {string} [reason] Reason for changing the level of the guild's explicit content filter + * @returns {Promise} + */ + setExplicitContentFilter(explicitContentFilter, reason) { + return this.edit({ explicitContentFilter }, reason); + } + + /** + * Edit the name of the guild. + * @param {string} name The new name of the guild + * @param {string} [reason] Reason for changing the guild's name + * @returns {Promise} + * @example + * // Edit the guild name + * guild.setName('Discord Guild') + * .then(g => console.log(`Updated guild name to ${g}`)) + * .catch(console.error); + */ + setName(name, reason) { + return this.edit({ name }, reason); + } + + /** + * Edit the region of the guild. + * @param {string} region The new region of the guild + * @param {string} [reason] Reason for changing the guild's region + * @returns {Promise} + * @example + * // Edit the guild region + * guild.setRegion('london') + * .then(g => console.log(`Updated guild region to ${g.region}`)) + * .catch(console.error); + */ + setRegion(region, reason) { + return this.edit({ region }, reason); + } + + /** + * Edit the verification level of the guild. + * @param {number} verificationLevel The new verification level of the guild + * @param {string} [reason] Reason for changing the guild's verification level + * @returns {Promise} + * @example + * // Edit the guild verification level + * guild.setVerificationLevel(1) + * .then(g => console.log(`Updated guild verification level to ${g.verificationLevel}`)) + * .catch(console.error); + */ + setVerificationLevel(verificationLevel, reason) { + return this.edit({ verificationLevel }, reason); + } + + /** + * Edit the AFK channel of the guild. + * @param {ChannelResolvable} afkChannel The new AFK channel + * @param {string} [reason] Reason for changing the guild's AFK channel + * @returns {Promise} + * @example + * // Edit the guild AFK channel + * guild.setAFKChannel(channel) + * .then(g => console.log(`Updated guild AFK channel to ${g.afkChannel.name}`)) + * .catch(console.error); + */ + setAFKChannel(afkChannel, reason) { + return this.edit({ afkChannel }, reason); + } + + /** + * Edit the system channel of the guild. + * @param {ChannelResolvable} systemChannel The new system channel + * @param {string} [reason] Reason for changing the guild's system channel + * @returns {Promise} + */ + setSystemChannel(systemChannel, reason) { + return this.edit({ systemChannel }, reason); + } + + /** + * Edit the AFK timeout of the guild. + * @param {number} afkTimeout The time in seconds that a user must be idle to be considered AFK + * @param {string} [reason] Reason for changing the guild's AFK timeout + * @returns {Promise} + * @example + * // Edit the guild AFK channel + * guild.setAFKTimeout(60) + * .then(g => console.log(`Updated guild AFK timeout to ${g.afkTimeout}`)) + * .catch(console.error); + */ + setAFKTimeout(afkTimeout, reason) { + return this.edit({ afkTimeout }, reason); + } + + /** + * Set a new guild icon. + * @param {Base64Resolvable|BufferResolvable} icon The new icon of the guild + * @param {string} [reason] Reason for changing the guild's icon + * @returns {Promise} + * @example + * // Edit the guild icon + * guild.setIcon('./icon.png') + * .then(console.log) + * .catch(console.error); + */ + setIcon(icon, reason) { + return this.client.resolver.resolveImage(icon).then(data => this.edit({ icon: data, reason })); + } + + /** + * Sets a new owner of the guild. + * @param {GuildMemberResolvable} owner The new owner of the guild + * @param {string} [reason] Reason for setting the new owner + * @returns {Promise} + * @example + * // Edit the guild owner + * guild.setOwner(guild.members.first()) + * .then(g => console.log(`Updated the guild owner to ${g.owner.displayName}`)) + * .catch(console.error); + */ + setOwner(owner, reason) { + return this.edit({ owner }, reason); + } + + /** + * Set a new guild splash screen. + * @param {BufferResolvable|Base64Resolvable} splash The new splash screen of the guild + * @param {string} [reason] Reason for changing the guild's splash screen + * @returns {Promise} + * @example + * // Edit the guild splash + * guild.setSplash('./splash.png') + * .then(console.log) + * .catch(console.error); + */ + setSplash(splash) { + return this.client.resolver.resolveImage(splash).then(data => this.edit({ splash: data })); + } + + /** + * Sets the position of the guild in the guild listing. + * This is only available when using a user account. + * @param {number} position Absolute or relative position + * @param {boolean} [relative=false] Whether to position relatively or absolutely + * @returns {Promise} + */ + setPosition(position, relative) { + if (this.client.user.bot) { + return Promise.reject(new Error('Setting guild position is only available for user accounts')); + } + return this.client.user.settings.setGuildPosition(this, position, relative); + } + + /** + * Marks all messages in this guild as read. + * This is only available when using a user account. + * @returns {Promise} + */ + acknowledge() { + return this.client.rest.methods.ackGuild(this); + } + + /** + * Allow direct messages from guild members. + * This is only available when using a user account. + * @param {boolean} allow Whether to allow direct messages + * @returns {Promise} + */ + allowDMs(allow) { + const settings = this.client.user.settings; + if (allow) return settings.removeRestrictedGuild(this); + else return settings.addRestrictedGuild(this); + } + + /** + * Bans a user from the guild. + * @param {UserResolvable} user The user to ban + * @param {Object|number|string} [options] Ban options. If a number, the number of days to delete messages for, if a + * string, the ban reason. Supplying an object allows you to do both. + * @param {number} [options.days=0] Number of days of messages to delete + * @param {string} [options.reason] Reason for banning + * @returns {Promise} Result object will be resolved as specifically as possible. + * If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot + * be resolved, the user ID will be the result. + * @example + * // Ban a user by ID + * guild.ban('some user ID') + * .then(user => console.log(`Banned ${user.username || user.id || user} from ${guild}`)) + * .catch(console.error); + * @example + * // Ban a user by object with reason and days + * guild.ban(user, { days: 7, reason: 'He needed to go' }) + * .then(console.log) + * .catch(console.error); + */ + ban(user, options = {}) { + if (typeof options === 'number') { + options = { reason: null, 'delete-message-days': options }; + } else if (typeof options === 'string') { + options = { reason: options, 'delete-message-days': 0 }; + } + if (options.days) options['delete-message-days'] = options.days; + return this.client.rest.methods.banGuildMember(this, user, options); + } + + /** + * Unbans a user from the guild. + * @param {UserResolvable} user The user to unban + * @param {string} [reason] Reason for unbanning the user + * @returns {Promise} + * @example + * // Unban a user by ID (or with a user/guild member object) + * guild.unban('some user ID') + * .then(user => console.log(`Unbanned ${user.username} from ${guild}`)) + * .catch(console.error); + */ + unban(user, reason) { + return this.client.rest.methods.unbanGuildMember(this, user, reason); + } + + /** + * Prunes members from the guild based on how long they have been inactive. + * @param {number} days Number of days of inactivity required to kick + * @param {boolean} [dry=false] If true, will return number of users that will be kicked, without actually doing it + * @param {string} [reason] Reason for this prune + * @returns {Promise} The number of members that were/will be kicked + * @example + * // See how many members will be pruned + * guild.pruneMembers(12, true) + * .then(pruned => console.log(`This will prune ${pruned} people!`)) + * .catch(console.error); + * @example + * // Actually prune the members + * guild.pruneMembers(12) + * .then(pruned => console.log(`I just pruned ${pruned} people!`)) + * .catch(console.error); + */ + pruneMembers(days, dry = false, reason) { + if (typeof days !== 'number') throw new TypeError('Days must be a number.'); + return this.client.rest.methods.pruneGuildMembers(this, days, dry, reason); + } + + /** + * Syncs this guild (already done automatically every 30 seconds). + * This is only available when using a user account. + */ + sync() { + if (!this.client.user.bot) this.client.syncGuilds([this]); + } + + /** + * Can be used to overwrite permissions when creating a channel. + * @typedef {Object} ChannelCreationOverwrites + * @property {PermissionResolvable[]|number} [allow] The permissions to allow + * @property {PermissionResolvable[]|number} [deny] The permissions to deny + * @property {RoleResolvable|UserResolvable} id ID of the role or member this overwrite is for + */ + + /** + * Creates a new channel in the guild. + * @param {string} name The name of the new channel + * @param {string} [type='text'] The type of the new channel, either `text` or `voice` or `category` + * @param {Array} [overwrites] Permission overwrites + * @param {string} [reason] Reason for creating this channel + * @returns {Promise} + * @example + * // Create a new text channel + * guild.createChannel('new-general', 'text') + * .then(console.log) + * .catch(console.error); + * @example + * // Create a new category channel with permission overwrites + * guild.createChannel('new-category', 'category', [{ + * id: guild.id, + * deny: ['MANAGE_MESSAGES'], + * allow: ['SEND_MESSAGES'] + * }]) + * .then(console.log) + * .catch(console.error); + */ + createChannel(name, type, overwrites, reason) { + return this.client.rest.methods.createChannel(this, name, type, overwrites, reason); + } + + /** + * The data needed for updating a channel's position. + * @typedef {Object} ChannelPosition + * @property {ChannelResolvable} channel Channel to update + * @property {number} position New position for the channel + */ + + /** + * Batch-updates the guild's channels' positions. + * @param {ChannelPosition[]} channelPositions Channel positions to update + * @returns {Promise} + * @example + * guild.updateChannels([{ channel: channelID, position: newChannelIndex }]) + * .then(g => console.log(`Updated channel positions for ${g}`)) + * .catch(console.error); + */ + setChannelPositions(channelPositions) { + return this.client.rest.methods.updateChannelPositions(this.id, channelPositions); + } + + /** + * Creates a new role in the guild with given information. + * @param {RoleData} [data] The data to update the role with + * @param {string} [reason] Reason for creating this role + * @returns {Promise} + * @example + * // Create a new role + * guild.createRole() + * .then(role => console.log(`Created new role with name ${role.name}`)) + * .catch(console.error); + * @example + * // Create a new role with data + * guild.createRole({ + * name: 'Super Cool People', + * color: 'BLUE', + * }) + * .then(role => console.log(`Created new role with name ${role.name} and color ${role.color}`)) + * .catch(console.error) + */ + createRole(data = {}, reason) { + return this.client.rest.methods.createGuildRole(this, data, reason); + } + + /** + * Creates a new custom emoji in the guild. + * @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji + * @param {string} name The name for the emoji + * @param {Collection|Role[]} [roles] Roles to limit the emoji to + * @param {string} [reason] Reason for creating the emoji + * @returns {Promise} The created emoji + * @example + * // Create a new emoji from a url + * guild.createEmoji('https://i.imgur.com/w3duR07.png', 'rip') + * .then(emoji => console.log(`Created new emoji with name ${emoji.name}`)) + * .catch(console.error); + * @example + * // Create a new emoji from a file on your computer + * guild.createEmoji('./memes/banana.png', 'banana') + * .then(emoji => console.log(`Created new emoji with name ${emoji.name}`)) + * .catch(console.error); + */ + createEmoji(attachment, name, roles, reason) { + if (typeof attachment === 'string' && attachment.startsWith('data:')) { + return this.client.rest.methods.createEmoji(this, attachment, name, roles, reason); + } else { + return this.client.resolver.resolveImage(attachment).then(data => + this.client.rest.methods.createEmoji(this, data, name, roles, reason) + ); + } + } + + /** + * Delete an emoji. + * @param {Emoji|string} emoji The emoji to delete + * @param {string} [reason] Reason for deleting the emoji + * @returns {Promise} + */ + deleteEmoji(emoji, reason) { + if (!(emoji instanceof Emoji)) emoji = this.emojis.get(emoji); + return this.client.rest.methods.deleteEmoji(emoji, reason); + } + + /** + * Causes the client to leave the guild. + * @returns {Promise} + * @example + * // Leave a guild + * guild.leave() + * .then(g => console.log(`Left the guild ${g}`)) + * .catch(console.error); + */ + leave() { + return this.client.rest.methods.leaveGuild(this); + } + + /** + * Causes the client to delete the guild. + * @returns {Promise} + * @example + * // Delete a guild + * guild.delete() + * .then(g => console.log(`Deleted the guild ${g}`)) + * .catch(console.error); + */ + delete() { + return this.client.rest.methods.deleteGuild(this); + } + + /** + * Whether this guild equals another guild. It compares all properties, so for most operations + * it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often + * what most users need. + * @param {Guild} guild The guild to compare with + * @returns {boolean} + */ + equals(guild) { + let equal = + guild && + this.id === guild.id && + this.available === !guild.unavailable && + this.splash === guild.splash && + this.region === guild.region && + this.name === guild.name && + this.memberCount === guild.member_count && + this.large === guild.large && + this.icon === guild.icon && + Util.arraysEqual(this.features, guild.features) && + this.ownerID === guild.owner_id && + this.verificationLevel === guild.verification_level && + this.embedEnabled === guild.embed_enabled; + + if (equal) { + if (this.embedChannel) { + if (this.embedChannel.id !== guild.embed_channel_id) equal = false; + } else if (guild.embed_channel_id) { + equal = false; + } + } + + return equal; + } + + /** + * When concatenated with a string, this automatically concatenates the guild's name instead of the guild object. + * @returns {string} + * @example + * // Logs: Hello from My Guild! + * console.log(`Hello from ${guild}!`); + * @example + * // Logs: Hello from My Guild! + * console.log('Hello from ' + guild + '!'); + */ + toString() { + return this.name; + } + + _addMember(guildUser, emitEvent = true) { + const existing = this.members.has(guildUser.user.id); + if (!(guildUser.user instanceof User)) guildUser.user = this.client.dataManager.newUser(guildUser.user); + + guildUser.joined_at = guildUser.joined_at || 0; + const member = new GuildMember(this, guildUser); + this.members.set(member.id, member); + + if (this._rawVoiceStates && this._rawVoiceStates.has(member.user.id)) { + const voiceState = this._rawVoiceStates.get(member.user.id); + member.serverMute = voiceState.mute; + member.serverDeaf = voiceState.deaf; + member.selfMute = voiceState.self_mute; + member.selfDeaf = voiceState.self_deaf; + member.voiceSessionID = voiceState.session_id; + member.voiceChannelID = voiceState.channel_id; + if (this.client.channels.has(voiceState.channel_id)) { + this.client.channels.get(voiceState.channel_id).members.set(member.user.id, member); + } else { + this.client.emit('warn', `Member ${member.id} added in guild ${this.id} with an uncached voice channel`); + } + } + + /** + * Emitted whenever a user joins a guild. + * @event Client#guildMemberAdd + * @param {GuildMember} member The member that has joined a guild + */ + if (this.client.ws.connection.status === Constants.Status.READY && emitEvent && !existing) { + this.client.emit(Constants.Events.GUILD_MEMBER_ADD, member); + } + + return member; + } + + _updateMember(member, data) { + const oldMember = Util.cloneObject(member); + + if (data.roles) member._roles = data.roles; + if (typeof data.nick !== 'undefined') member.nickname = data.nick; + + const notSame = member.nickname !== oldMember.nickname || !Util.arraysEqual(member._roles, oldMember._roles); + + if (this.client.ws.connection.status === Constants.Status.READY && notSame) { + /** + * Emitted whenever a guild member changes - i.e. new role, removed role, nickname. + * @event Client#guildMemberUpdate + * @param {GuildMember} oldMember The member before the update + * @param {GuildMember} newMember The member after the update + */ + this.client.emit(Constants.Events.GUILD_MEMBER_UPDATE, oldMember, member); + } + + return { + old: oldMember, + mem: member, + }; + } + + _removeMember(guildMember) { + this.members.delete(guildMember.id); + } + + _memberSpeakUpdate(user, speaking) { + const member = this.members.get(user); + if (member && member.speaking !== speaking) { + member.speaking = speaking; + /** + * Emitted once a guild member starts/stops speaking. + * @event Client#guildMemberSpeaking + * @param {GuildMember} member The member that started/stopped speaking + * @param {boolean} speaking Whether or not the member is speaking + */ + this.client.emit(Constants.Events.GUILD_MEMBER_SPEAKING, member, speaking); + } + } + + _setPresence(id, presence) { + if (this.presences.get(id)) { + this.presences.get(id).update(presence); + return; + } + this.presences.set(id, new Presence(presence)); + } + + /** + * Set the position of a role in this guild. + * @param {string|Role} role The role to edit, can be a role object or a role ID + * @param {number} position The new position of the role + * @param {boolean} [relative=false] Position Moves the role relative to its current position + * @returns {Promise} + */ + setRolePosition(role, position, relative = false) { + if (typeof role === 'string') { + role = this.roles.get(role); + if (!role) return Promise.reject(new Error('Supplied role is not a role or snowflake.')); + } + + position = Number(position); + if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.')); + + let updatedRoles = this._sortedRoles.array(); + + Util.moveElementInArray(updatedRoles, role, position, relative); + + updatedRoles = updatedRoles.map((r, i) => ({ id: r.id, position: i })); + return this.client.rest.methods.setRolePositions(this.id, updatedRoles); + } + + /** + * Set the position of a channel in this guild. + * @param {string|GuildChannel} channel The channel to edit, can be a channel object or a channel ID + * @param {number} position The new position of the channel + * @param {boolean} [relative=false] Position Moves the channel relative to its current position + * @returns {Promise} + */ + setChannelPosition(channel, position, relative = false) { + if (typeof channel === 'string') { + channel = this.channels.get(channel); + if (!channel) return Promise.reject(new Error('Supplied channel is not a channel or snowflake.')); + } + + position = Number(position); + if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.')); + + let updatedChannels = this._sortedChannels(channel.type).array(); + + Util.moveElementInArray(updatedChannels, channel, position, relative); + + updatedChannels = updatedChannels.map((r, i) => ({ id: r.id, position: i })); + return this.client.rest.methods.setChannelPositions(this.id, updatedChannels); + } + + /** + * Fetches a collection of channels in the current guild sorted by position. + * @param {string} type The channel type + * @returns {Collection} + * @private + */ + _sortedChannels(type) { + return this._sortPositionWithID(this.channels.filter(c => { + if (type === 'voice' && c.type === 'voice') return true; + else if (type !== 'voice' && c.type !== 'voice') return true; + else return type === c.type; + })); + } + + /** + * Sorts a collection by object position or ID if the positions are equivalent. + * Intended to be identical to Discord's sorting method. + * @param {Collection} collection The collection to sort + * @returns {Collection} + * @private + */ + _sortPositionWithID(collection) { + return collection.sort((a, b) => + a.position !== b.position ? + a.position - b.position : + Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber() + ); + } +} + +/** + * The `#general` TextChannel of the guild + * @name Guild#defaultChannel + * @type {TextChannel} + * @readonly + * @deprecated + */ +Object.defineProperty(Guild.prototype, 'defaultChannel', { + get: util.deprecate(function defaultChannel() { + return this.channels.get(this.id); + }, 'Guild#defaultChannel: This property is obsolete, will be removed in v12.0.0, and may not function as expected.'), +}); + +module.exports = Guild; + + +/***/ }), +/* 23 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(Buffer) {const path = __webpack_require__(26); +const Util = __webpack_require__(4); +const Attachment = __webpack_require__(21); +const RichEmbed = __webpack_require__(20); + +/** + * Represents a webhook. + */ +class Webhook { + constructor(client, dataOrID, token) { + if (client) { + /** + * The client that instantiated the webhook + * @name Webhook#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + if (dataOrID) this.setup(dataOrID); + } else { + this.id = dataOrID; + this.token = token; + Object.defineProperty(this, 'client', { value: this }); + } + } + + setup(data) { + /** + * The name of the webhook + * @type {string} + */ + this.name = data.name; + + /** + * The token for the webhook + * @type {string} + */ + this.token = data.token; + + /** + * The avatar for the webhook + * @type {?string} + */ + this.avatar = data.avatar; + + /** + * The ID of the webhook + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The guild the webhook belongs to + * @type {Snowflake} + */ + this.guildID = data.guild_id; + + /** + * The channel the webhook belongs to + * @type {Snowflake} + */ + this.channelID = data.channel_id; + + if (data.user) { + /** + * The owner of the webhook + * @type {?User|Object} + */ + this.owner = this.client.users ? this.client.users.get(data.user.id) : data.user; + } else { + this.owner = null; + } + } + + /** + * Options that can be passed into send, sendMessage, sendFile, sendEmbed, and sendCode. + * @typedef {Object} WebhookMessageOptions + * @property {string} [username=this.name] Username override for the message + * @property {string} [avatarURL] Avatar URL override for the message + * @property {boolean} [tts=false] Whether or not the message should be spoken aloud + * @property {string} [nonce=''] The nonce for the message + * @property {Array} [embeds] An array of embeds for the message + * (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details) + * @property {boolean} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here + * should be replaced with plain-text + * @property {FileOptions|BufferResolvable|Attachment} [file] A file to send with the message **(deprecated)** + * @property {FileOptions[]|BufferResolvable[]|Attachment[]} [files] Files to send with the message + * @property {string|boolean} [code] Language for optional codeblock formatting to apply + * @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if + * it exceeds the character limit. If an object is provided, these are the options for splitting the message. + */ + + /** + * Send a message with this webhook. + * @param {StringResolvable} content The content to send + * @param {WebhookMessageOptions|Attachment|RichEmbed} [options] The options to provide, + * can also be just a RichEmbed or Attachment + * @returns {Promise} + * @example + * // Send a basic message + * webhook.send('hello!') + * .then(message => console.log(`Sent message: ${message.content}`)) + * .catch(console.error); + * @example + * // Send a remote file + * webhook.send({ + * files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048'] + * }) + * .then(console.log) + * .catch(console.error); + * @example + * // Send a local file + * webhook.send({ + * files: [{ + * attachment: 'entire/path/to/file.jpg', + * name: 'file.jpg' + * }] + * }) + * .then(console.log) + * .catch(console.error); + * @example + * // Send an embed with a local image inside + * webhook.send('This is an embed', { + * embeds: [{ + * thumbnail: { + * url: 'attachment://file.jpg' + * } + * }], + * files: [{ + * attachment: 'entire/path/to/file.jpg', + * name: 'file.jpg' + * }] + * }) + * .then(console.log) + * .catch(console.error); + */ + send(content, options) { // eslint-disable-line complexity + if (!options && typeof content === 'object' && !(content instanceof Array)) { + options = content; + content = ''; + } else if (!options) { + options = {}; + } + + if (options instanceof Attachment) options = { files: [options] }; + if (options instanceof RichEmbed) options = { embeds: [options] }; + + if (content) { + content = this.client.resolver.resolveString(content); + let { split, code, disableEveryone } = options; + if (split && typeof split !== 'object') split = {}; + if (typeof code !== 'undefined' && (typeof code !== 'boolean' || code === true)) { + content = Util.escapeMarkdown(content, true); + content = `\`\`\`${typeof code !== 'boolean' ? code || '' : ''}\n${content}\n\`\`\``; + if (split) { + split.prepend = `\`\`\`${typeof code !== 'boolean' ? code || '' : ''}\n`; + split.append = '\n```'; + } + } + if (disableEveryone || (typeof disableEveryone === 'undefined' && this.client.options.disableEveryone)) { + content = content.replace(/@(everyone|here)/g, '@\u200b$1'); + } + + if (split) content = Util.splitMessage(content, split); + } + + if (options.file) { + if (options.files) options.files.push(options.file); + else options.files = [options.file]; + } + + if (options.embeds) { + const files = []; + for (const embed of options.embeds) { + if (embed.file) files.push(embed.file); + } + if (options.files) options.files.push(...files); + else options.files = files; + } + + if (options.files) { + for (let i = 0; i < options.files.length; i++) { + let file = options.files[i]; + if (typeof file === 'string' || Buffer.isBuffer(file)) file = { attachment: file }; + if (!file.name) { + if (typeof file.attachment === 'string') { + file.name = path.basename(file.attachment); + } else if (file.attachment && file.attachment.path) { + file.name = path.basename(file.attachment.path); + } else if (file instanceof Attachment) { + file = { attachment: file.file, name: path.basename(file.file) || 'file.jpg' }; + } else { + file.name = 'file.jpg'; + } + } else if (file instanceof Attachment) { + file = file.file; + } + options.files[i] = file; + } + + return Promise.all(options.files.map(file => + this.client.resolver.resolveFile(file.attachment).then(resource => { + file.file = resource; + return file; + }) + )).then(files => this.client.rest.methods.sendWebhookMessage(this, content, options, files)); + } + + return this.client.rest.methods.sendWebhookMessage(this, content, options); + } + + /** + * Send a message with this webhook + * @param {StringResolvable} content The content to send + * @param {WebhookMessageOptions} [options={}] The options to provide + * @returns {Promise} + * @deprecated + * @example + * // Send a message + * webhook.sendMessage('hello!') + * .then(message => console.log(`Sent message: ${message.content}`)) + * .catch(console.error); + */ + sendMessage(content, options = {}) { + return this.send(content, options); + } + + /** + * Send a file with this webhook. + * @param {BufferResolvable} attachment The file to send + * @param {string} [name='file.jpg'] The name and extension of the file + * @param {StringResolvable} [content] Text message to send with the attachment + * @param {WebhookMessageOptions} [options] The options to provide + * @returns {Promise} + * @deprecated + */ + sendFile(attachment, name, content, options = {}) { + return this.send(content, Object.assign(options, { file: { attachment, name } })); + } + + /** + * Send a code block with this webhook. + * @param {string} lang Language for the code block + * @param {StringResolvable} content Content of the code block + * @param {WebhookMessageOptions} options The options to provide + * @returns {Promise} + * @deprecated + */ + sendCode(lang, content, options = {}) { + return this.send(content, Object.assign(options, { code: lang })); + } + + /** + * Send a raw slack message with this webhook. + * @param {Object} body The raw body to send + * @returns {Promise} + * @example + * // Send a slack message + * webhook.sendSlackMessage({ + * 'username': 'Wumpus', + * 'attachments': [{ + * 'pretext': 'this looks pretty cool', + * 'color': '#F0F', + * 'footer_icon': 'http://snek.s3.amazonaws.com/topSnek.png', + * 'footer': 'Powered by sneks', + * 'ts': Date.now() / 1000 + * }] + * }).catch(console.error); + */ + sendSlackMessage(body) { + return this.client.rest.methods.sendSlackWebhookMessage(this, body); + } + + /** + * Edit the webhook. + * @param {string} name The new name for the webhook + * @param {BufferResolvable} [avatar] The new avatar for the webhook + * @returns {Promise} + */ + edit(name = this.name, avatar) { + if (avatar) { + return this.client.resolver.resolveImage(avatar).then(data => + this.client.rest.methods.editWebhook(this, name, data) + ); + } + return this.client.rest.methods.editWebhook(this, name); + } + + /** + * Delete the webhook. + * @param {string} [reason] Reason for deleting the webhook + * @returns {Promise} + */ + delete(reason) { + return this.client.rest.methods.deleteWebhook(this, reason); + } +} + +module.exports = Webhook; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12).Buffer)) + +/***/ }), +/* 24 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "delete", function() { return _delete; }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__index_js__ = __webpack_require__(63); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__index_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__index_js__); + + +/* harmony default export */ __webpack_exports__["default"] = (__WEBPACK_IMPORTED_MODULE_0__index_js___default.a); + +const version = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.version; +/* harmony export (immutable) */ __webpack_exports__["version"] = version; + +const METHODS = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.METHODS; +/* harmony export (immutable) */ __webpack_exports__["METHODS"] = METHODS; + + +const acl = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.acl; +/* harmony export (immutable) */ __webpack_exports__["acl"] = acl; + +const bind = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.bind; +/* harmony export (immutable) */ __webpack_exports__["bind"] = bind; + +const checkout = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.checkout; +/* harmony export (immutable) */ __webpack_exports__["checkout"] = checkout; + +const connect = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.connect; +/* harmony export (immutable) */ __webpack_exports__["connect"] = connect; + +const copy = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.copy; +/* harmony export (immutable) */ __webpack_exports__["copy"] = copy; + +const _delete = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.delete; + +const get = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.get; +/* harmony export (immutable) */ __webpack_exports__["get"] = get; + +const head = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.head; +/* harmony export (immutable) */ __webpack_exports__["head"] = head; + +const link = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.link; +/* harmony export (immutable) */ __webpack_exports__["link"] = link; + +const lock = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.lock; +/* harmony export (immutable) */ __webpack_exports__["lock"] = lock; + +const merge = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.merge; +/* harmony export (immutable) */ __webpack_exports__["merge"] = merge; + +const mkactivity = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.mkactivity; +/* harmony export (immutable) */ __webpack_exports__["mkactivity"] = mkactivity; + +const mkcalendar = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.mkcalendar; +/* harmony export (immutable) */ __webpack_exports__["mkcalendar"] = mkcalendar; + +const mkcol = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.mkcol; +/* harmony export (immutable) */ __webpack_exports__["mkcol"] = mkcol; + +const move = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.move; +/* harmony export (immutable) */ __webpack_exports__["move"] = move; + +const notify = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.notify; +/* harmony export (immutable) */ __webpack_exports__["notify"] = notify; + +const options = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.options; +/* harmony export (immutable) */ __webpack_exports__["options"] = options; + +const patch = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.patch; +/* harmony export (immutable) */ __webpack_exports__["patch"] = patch; + +const post = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.post; +/* harmony export (immutable) */ __webpack_exports__["post"] = post; + +const propfind = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.propfind; +/* harmony export (immutable) */ __webpack_exports__["propfind"] = propfind; + +const proppatch = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.proppatch; +/* harmony export (immutable) */ __webpack_exports__["proppatch"] = proppatch; + +const purge = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.purge; +/* harmony export (immutable) */ __webpack_exports__["purge"] = purge; + +const put = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.put; +/* harmony export (immutable) */ __webpack_exports__["put"] = put; + +const rebind = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.rebind; +/* harmony export (immutable) */ __webpack_exports__["rebind"] = rebind; + +const report = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.report; +/* harmony export (immutable) */ __webpack_exports__["report"] = report; + +const search = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.search; +/* harmony export (immutable) */ __webpack_exports__["search"] = search; + +const subscribe = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.subscribe; +/* harmony export (immutable) */ __webpack_exports__["subscribe"] = subscribe; + +const trace = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.trace; +/* harmony export (immutable) */ __webpack_exports__["trace"] = trace; + +const unbind = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.unbind; +/* harmony export (immutable) */ __webpack_exports__["unbind"] = unbind; + +const unlink = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.unlink; +/* harmony export (immutable) */ __webpack_exports__["unlink"] = unlink; + +const unlock = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.unlock; +/* harmony export (immutable) */ __webpack_exports__["unlock"] = unlock; + +const unsubscribe = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.unsubscribe; +/* harmony export (immutable) */ __webpack_exports__["unsubscribe"] = unsubscribe; + +const brew = __WEBPACK_IMPORTED_MODULE_0__index_js___default.a.brew; +/* harmony export (immutable) */ __webpack_exports__["brew"] = brew; + + + +/***/ }), +/* 25 */ +/***/ (function(module, exports) { + +module.exports = Long; + +/** + * wasm optimizations, to do native i64 multiplication and divide + */ +var wasm = null; + +try { + wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 + ])), {}).exports; +} catch (e) { + // no wasm support :( +} + +/** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. + * See the from* functions below for more convenient ways of constructing Longs. + * @exports Long + * @class A Long class for representing a 64 bit two's-complement integer value. + * @param {number} low The low (signed) 32 bits of the long + * @param {number} high The high (signed) 32 bits of the long + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @constructor + */ +function Long(low, high, unsigned) { + + /** + * The low 32 bits as a signed value. + * @type {number} + */ + this.low = low | 0; + + /** + * The high 32 bits as a signed value. + * @type {number} + */ + this.high = high | 0; + + /** + * Whether unsigned or not. + * @type {boolean} + */ + this.unsigned = !!unsigned; +} + +// The internal representation of a long is the two given signed, 32-bit values. +// We use 32-bit pieces because these are the size of integers on which +// Javascript performs bit-operations. For operations like addition and +// multiplication, we split each number into 16 bit pieces, which can easily be +// multiplied within Javascript's floating-point representation without overflow +// or change in sign. +// +// In the algorithms below, we frequently reduce the negative case to the +// positive case by negating the input(s) and then post-processing the result. +// Note that we must ALWAYS check specially whether those values are MIN_VALUE +// (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as +// a positive number, it overflows back into a negative). Not handling this +// case would often result in infinite recursion. +// +// Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* +// methods on which they depend. + +/** + * An indicator used to reliably determine if an object is a Long or not. + * @type {boolean} + * @const + * @private + */ +Long.prototype.__isLong__; + +Object.defineProperty(Long.prototype, "__isLong__", { value: true }); + +/** + * @function + * @param {*} obj Object + * @returns {boolean} + * @inner + */ +function isLong(obj) { + return (obj && obj["__isLong__"]) === true; +} + +/** + * Tests if the specified object is a Long. + * @function + * @param {*} obj Object + * @returns {boolean} + */ +Long.isLong = isLong; + +/** + * A cache of the Long representations of small integer values. + * @type {!Object} + * @inner + */ +var INT_CACHE = {}; + +/** + * A cache of the Long representations of small unsigned integer values. + * @type {!Object} + * @inner + */ +var UINT_CACHE = {}; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromInt(value, unsigned) { + var obj, cachedObj, cache; + if (unsigned) { + value >>>= 0; + if (cache = (0 <= value && value < 256)) { + cachedObj = UINT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true); + if (cache) + UINT_CACHE[value] = obj; + return obj; + } else { + value |= 0; + if (cache = (-128 <= value && value < 128)) { + cachedObj = INT_CACHE[value]; + if (cachedObj) + return cachedObj; + } + obj = fromBits(value, value < 0 ? -1 : 0, false); + if (cache) + INT_CACHE[value] = obj; + return obj; + } +} + +/** + * Returns a Long representing the given 32 bit integer value. + * @function + * @param {number} value The 32 bit integer in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromInt = fromInt; + +/** + * @param {number} value + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromNumber(value, unsigned) { + if (isNaN(value)) + return unsigned ? UZERO : ZERO; + if (unsigned) { + if (value < 0) + return UZERO; + if (value >= TWO_PWR_64_DBL) + return MAX_UNSIGNED_VALUE; + } else { + if (value <= -TWO_PWR_63_DBL) + return MIN_VALUE; + if (value + 1 >= TWO_PWR_63_DBL) + return MAX_VALUE; + } + if (value < 0) + return fromNumber(-value, unsigned).neg(); + return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); +} + +/** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + * @function + * @param {number} value The number in question + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromNumber = fromNumber; + +/** + * @param {number} lowBits + * @param {number} highBits + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromBits(lowBits, highBits, unsigned) { + return new Long(lowBits, highBits, unsigned); +} + +/** + * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is + * assumed to use 32 bits. + * @function + * @param {number} lowBits The low 32 bits + * @param {number} highBits The high 32 bits + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} The corresponding Long value + */ +Long.fromBits = fromBits; + +/** + * @function + * @param {number} base + * @param {number} exponent + * @returns {number} + * @inner + */ +var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) + +/** + * @param {string} str + * @param {(boolean|number)=} unsigned + * @param {number=} radix + * @returns {!Long} + * @inner + */ +function fromString(str, unsigned, radix) { + if (str.length === 0) + throw Error('empty string'); + if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") + return ZERO; + if (typeof unsigned === 'number') { + // For goog.math.long compatibility + radix = unsigned, + unsigned = false; + } else { + unsigned = !! unsigned; + } + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + + var p; + if ((p = str.indexOf('-')) > 0) + throw Error('interior hyphen'); + else if (p === 0) { + return fromString(str.substring(1), unsigned, radix).neg(); + } + + // Do several (8) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 8)); + + var result = ZERO; + for (var i = 0; i < str.length; i += 8) { + var size = Math.min(8, str.length - i), + value = parseInt(str.substring(i, i + size), radix); + if (size < 8) { + var power = fromNumber(pow_dbl(radix, size)); + result = result.mul(power).add(fromNumber(value)); + } else { + result = result.mul(radixToPower); + result = result.add(fromNumber(value)); + } + } + result.unsigned = unsigned; + return result; +} + +/** + * Returns a Long representation of the given string, written using the specified radix. + * @function + * @param {string} str The textual representation of the Long + * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed + * @param {number=} radix The radix in which the text is written (2-36), defaults to 10 + * @returns {!Long} The corresponding Long value + */ +Long.fromString = fromString; + +/** + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val + * @param {boolean=} unsigned + * @returns {!Long} + * @inner + */ +function fromValue(val, unsigned) { + if (typeof val === 'number') + return fromNumber(val, unsigned); + if (typeof val === 'string') + return fromString(val, unsigned); + // Throws for non-objects, converts non-instanceof Long: + return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); +} + +/** + * Converts the specified value to a Long using the appropriate from* function for its type. + * @function + * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {!Long} + */ +Long.fromValue = fromValue; + +// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be +// no runtime penalty for these. + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_16_DBL = 1 << 16; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_24_DBL = 1 << 24; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; + +/** + * @type {number} + * @const + * @inner + */ +var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; + +/** + * @type {!Long} + * @const + * @inner + */ +var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); + +/** + * @type {!Long} + * @inner + */ +var ZERO = fromInt(0); + +/** + * Signed zero. + * @type {!Long} + */ +Long.ZERO = ZERO; + +/** + * @type {!Long} + * @inner + */ +var UZERO = fromInt(0, true); + +/** + * Unsigned zero. + * @type {!Long} + */ +Long.UZERO = UZERO; + +/** + * @type {!Long} + * @inner + */ +var ONE = fromInt(1); + +/** + * Signed one. + * @type {!Long} + */ +Long.ONE = ONE; + +/** + * @type {!Long} + * @inner + */ +var UONE = fromInt(1, true); + +/** + * Unsigned one. + * @type {!Long} + */ +Long.UONE = UONE; + +/** + * @type {!Long} + * @inner + */ +var NEG_ONE = fromInt(-1); + +/** + * Signed negative one. + * @type {!Long} + */ +Long.NEG_ONE = NEG_ONE; + +/** + * @type {!Long} + * @inner + */ +var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false); + +/** + * Maximum signed value. + * @type {!Long} + */ +Long.MAX_VALUE = MAX_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true); + +/** + * Maximum unsigned value. + * @type {!Long} + */ +Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; + +/** + * @type {!Long} + * @inner + */ +var MIN_VALUE = fromBits(0, 0x80000000|0, false); + +/** + * Minimum signed value. + * @type {!Long} + */ +Long.MIN_VALUE = MIN_VALUE; + +/** + * @alias Long.prototype + * @inner + */ +var LongPrototype = Long.prototype; + +/** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + * @returns {number} + */ +LongPrototype.toInt = function toInt() { + return this.unsigned ? this.low >>> 0 : this.low; +}; + +/** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + * @returns {number} + */ +LongPrototype.toNumber = function toNumber() { + if (this.unsigned) + return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); + return this.high * TWO_PWR_32_DBL + (this.low >>> 0); +}; + +/** + * Converts the Long to a string written in the specified radix. + * @param {number=} radix Radix (2-36), defaults to 10 + * @returns {string} + * @override + * @throws {RangeError} If `radix` is out of range + */ +LongPrototype.toString = function toString(radix) { + radix = radix || 10; + if (radix < 2 || 36 < radix) + throw RangeError('radix'); + if (this.isZero()) + return '0'; + if (this.isNegative()) { // Unsigned Longs are never negative + if (this.eq(MIN_VALUE)) { + // We need to change the Long value before it can be negated, so we remove + // the bottom-most digit in this base and then recurse to do the rest. + var radixLong = fromNumber(radix), + div = this.div(radixLong), + rem1 = div.mul(radixLong).sub(this); + return div.toString(radix) + rem1.toInt().toString(radix); + } else + return '-' + this.neg().toString(radix); + } + + // Do several (6) digits each time through the loop, so as to + // minimize the calls to the very expensive emulated div. + var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), + rem = this; + var result = ''; + while (true) { + var remDiv = rem.div(radixToPower), + intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, + digits = intval.toString(radix); + rem = remDiv; + if (rem.isZero()) + return digits + result; + else { + while (digits.length < 6) + digits = '0' + digits; + result = '' + digits + result; + } + } +}; + +/** + * Gets the high 32 bits as a signed integer. + * @returns {number} Signed high bits + */ +LongPrototype.getHighBits = function getHighBits() { + return this.high; +}; + +/** + * Gets the high 32 bits as an unsigned integer. + * @returns {number} Unsigned high bits + */ +LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { + return this.high >>> 0; +}; + +/** + * Gets the low 32 bits as a signed integer. + * @returns {number} Signed low bits + */ +LongPrototype.getLowBits = function getLowBits() { + return this.low; +}; + +/** + * Gets the low 32 bits as an unsigned integer. + * @returns {number} Unsigned low bits + */ +LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { + return this.low >>> 0; +}; + +/** + * Gets the number of bits needed to represent the absolute value of this Long. + * @returns {number} + */ +LongPrototype.getNumBitsAbs = function getNumBitsAbs() { + if (this.isNegative()) // Unsigned Longs are never negative + return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs(); + var val = this.high != 0 ? this.high : this.low; + for (var bit = 31; bit > 0; bit--) + if ((val & (1 << bit)) != 0) + break; + return this.high != 0 ? bit + 33 : bit + 1; +}; + +/** + * Tests if this Long's value equals zero. + * @returns {boolean} + */ +LongPrototype.isZero = function isZero() { + return this.high === 0 && this.low === 0; +}; + +/** + * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}. + * @returns {boolean} + */ +LongPrototype.eqz = LongPrototype.isZero; + +/** + * Tests if this Long's value is negative. + * @returns {boolean} + */ +LongPrototype.isNegative = function isNegative() { + return !this.unsigned && this.high < 0; +}; + +/** + * Tests if this Long's value is positive. + * @returns {boolean} + */ +LongPrototype.isPositive = function isPositive() { + return this.unsigned || this.high >= 0; +}; + +/** + * Tests if this Long's value is odd. + * @returns {boolean} + */ +LongPrototype.isOdd = function isOdd() { + return (this.low & 1) === 1; +}; + +/** + * Tests if this Long's value is even. + * @returns {boolean} + */ +LongPrototype.isEven = function isEven() { + return (this.low & 1) === 0; +}; + +/** + * Tests if this Long's value equals the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.equals = function equals(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) + return false; + return this.high === other.high && this.low === other.low; +}; + +/** + * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.eq = LongPrototype.equals; + +/** + * Tests if this Long's value differs from the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.notEquals = function notEquals(other) { + return !this.eq(/* validates */ other); +}; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.neq = LongPrototype.notEquals; + +/** + * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ne = LongPrototype.notEquals; + +/** + * Tests if this Long's value is less than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThan = function lessThan(other) { + return this.comp(/* validates */ other) < 0; +}; + +/** + * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lt = LongPrototype.lessThan; + +/** + * Tests if this Long's value is less than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { + return this.comp(/* validates */ other) <= 0; +}; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.lte = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.le = LongPrototype.lessThanOrEqual; + +/** + * Tests if this Long's value is greater than the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThan = function greaterThan(other) { + return this.comp(/* validates */ other) > 0; +}; + +/** + * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gt = LongPrototype.greaterThan; + +/** + * Tests if this Long's value is greater than or equal the specified's. + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { + return this.comp(/* validates */ other) >= 0; +}; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.gte = LongPrototype.greaterThanOrEqual; + +/** + * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. + * @function + * @param {!Long|number|string} other Other value + * @returns {boolean} + */ +LongPrototype.ge = LongPrototype.greaterThanOrEqual; + +/** + * Compares this Long's value with the specified's. + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.compare = function compare(other) { + if (!isLong(other)) + other = fromValue(other); + if (this.eq(other)) + return 0; + var thisNeg = this.isNegative(), + otherNeg = other.isNegative(); + if (thisNeg && !otherNeg) + return -1; + if (!thisNeg && otherNeg) + return 1; + // At this point the sign bits are the same + if (!this.unsigned) + return this.sub(other).isNegative() ? -1 : 1; + // Both are positive if at least one is unsigned + return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; +}; + +/** + * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. + * @function + * @param {!Long|number|string} other Other value + * @returns {number} 0 if they are the same, 1 if the this is greater and -1 + * if the given one is greater + */ +LongPrototype.comp = LongPrototype.compare; + +/** + * Negates this Long's value. + * @returns {!Long} Negated Long + */ +LongPrototype.negate = function negate() { + if (!this.unsigned && this.eq(MIN_VALUE)) + return MIN_VALUE; + return this.not().add(ONE); +}; + +/** + * Negates this Long's value. This is an alias of {@link Long#negate}. + * @function + * @returns {!Long} Negated Long + */ +LongPrototype.neg = LongPrototype.negate; + +/** + * Returns the sum of this and the specified Long. + * @param {!Long|number|string} addend Addend + * @returns {!Long} Sum + */ +LongPrototype.add = function add(addend) { + if (!isLong(addend)) + addend = fromValue(addend); + + // Divide each number into 4 chunks of 16 bits, and then sum the chunks. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = addend.high >>> 16; + var b32 = addend.high & 0xFFFF; + var b16 = addend.low >>> 16; + var b00 = addend.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 + b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 + b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 + b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 + b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the difference of this and the specified Long. + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.subtract = function subtract(subtrahend) { + if (!isLong(subtrahend)) + subtrahend = fromValue(subtrahend); + return this.add(subtrahend.neg()); +}; + +/** + * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. + * @function + * @param {!Long|number|string} subtrahend Subtrahend + * @returns {!Long} Difference + */ +LongPrototype.sub = LongPrototype.subtract; + +/** + * Returns the product of this and the specified Long. + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.multiply = function multiply(multiplier) { + if (this.isZero()) + return ZERO; + if (!isLong(multiplier)) + multiplier = fromValue(multiplier); + + // use wasm support if present + if (wasm) { + var low = wasm.mul(this.low, + this.high, + multiplier.low, + multiplier.high); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + if (multiplier.isZero()) + return ZERO; + if (this.eq(MIN_VALUE)) + return multiplier.isOdd() ? MIN_VALUE : ZERO; + if (multiplier.eq(MIN_VALUE)) + return this.isOdd() ? MIN_VALUE : ZERO; + + if (this.isNegative()) { + if (multiplier.isNegative()) + return this.neg().mul(multiplier.neg()); + else + return this.neg().mul(multiplier).neg(); + } else if (multiplier.isNegative()) + return this.mul(multiplier.neg()).neg(); + + // If both longs are small, use float multiplication + if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) + return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); + + // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. + // We can skip products that would overflow. + + var a48 = this.high >>> 16; + var a32 = this.high & 0xFFFF; + var a16 = this.low >>> 16; + var a00 = this.low & 0xFFFF; + + var b48 = multiplier.high >>> 16; + var b32 = multiplier.high & 0xFFFF; + var b16 = multiplier.low >>> 16; + var b00 = multiplier.low & 0xFFFF; + + var c48 = 0, c32 = 0, c16 = 0, c00 = 0; + c00 += a00 * b00; + c16 += c00 >>> 16; + c00 &= 0xFFFF; + c16 += a16 * b00; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c16 += a00 * b16; + c32 += c16 >>> 16; + c16 &= 0xFFFF; + c32 += a32 * b00; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a16 * b16; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c32 += a00 * b32; + c48 += c32 >>> 16; + c32 &= 0xFFFF; + c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; + c48 &= 0xFFFF; + return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); +}; + +/** + * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. + * @function + * @param {!Long|number|string} multiplier Multiplier + * @returns {!Long} Product + */ +LongPrototype.mul = LongPrototype.multiply; + +/** + * Returns this Long divided by the specified. The result is signed if this Long is signed or + * unsigned if this Long is unsigned. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.divide = function divide(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + if (divisor.isZero()) + throw Error('division by zero'); + + // use wasm support if present + if (wasm) { + // guard against signed division overflow: the largest + // negative number / -1 would be 1 larger than the largest + // positive number, due to two's complement. + if (!this.unsigned && + this.high === -0x80000000 && + divisor.low === -1 && divisor.high === -1) { + // be consistent with non-wasm code path + return this; + } + var low = (this.unsigned ? wasm.div_u : wasm.div_s)( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + if (this.isZero()) + return this.unsigned ? UZERO : ZERO; + var approx, rem, res; + if (!this.unsigned) { + // This section is only relevant for signed longs and is derived from the + // closure library as a whole. + if (this.eq(MIN_VALUE)) { + if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) + return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE + else if (divisor.eq(MIN_VALUE)) + return ONE; + else { + // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. + var halfThis = this.shr(1); + approx = halfThis.div(divisor).shl(1); + if (approx.eq(ZERO)) { + return divisor.isNegative() ? ONE : NEG_ONE; + } else { + rem = this.sub(divisor.mul(approx)); + res = approx.add(rem.div(divisor)); + return res; + } + } + } else if (divisor.eq(MIN_VALUE)) + return this.unsigned ? UZERO : ZERO; + if (this.isNegative()) { + if (divisor.isNegative()) + return this.neg().div(divisor.neg()); + return this.neg().div(divisor).neg(); + } else if (divisor.isNegative()) + return this.div(divisor.neg()).neg(); + res = ZERO; + } else { + // The algorithm below has not been made for unsigned longs. It's therefore + // required to take special care of the MSB prior to running it. + if (!divisor.unsigned) + divisor = divisor.toUnsigned(); + if (divisor.gt(this)) + return UZERO; + if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true + return UONE; + res = UZERO; + } + + // Repeat the following until the remainder is less than other: find a + // floating-point that approximates remainder / other *from below*, add this + // into the result, and subtract it from the remainder. It is critical that + // the approximate value is less than or equal to the real value so that the + // remainder never becomes negative. + rem = this; + while (rem.gte(divisor)) { + // Approximate the result of division. This may be a little greater or + // smaller than the actual value. + approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); + + // We will tweak the approximate result by changing it in the 48-th digit or + // the smallest non-fractional digit, whichever is larger. + var log2 = Math.ceil(Math.log(approx) / Math.LN2), + delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), + + // Decrease the approximation until it is smaller than the remainder. Note + // that if it is too large, the product overflows and is negative. + approxRes = fromNumber(approx), + approxRem = approxRes.mul(divisor); + while (approxRem.isNegative() || approxRem.gt(rem)) { + approx -= delta; + approxRes = fromNumber(approx, this.unsigned); + approxRem = approxRes.mul(divisor); + } + + // We know the answer can't be zero... and actually, zero would cause + // infinite recursion since we would make no progress. + if (approxRes.isZero()) + approxRes = ONE; + + res = res.add(approxRes); + rem = rem.sub(approxRem); + } + return res; +}; + +/** + * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Quotient + */ +LongPrototype.div = LongPrototype.divide; + +/** + * Returns this Long modulo the specified. + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.modulo = function modulo(divisor) { + if (!isLong(divisor)) + divisor = fromValue(divisor); + + // use wasm support if present + if (wasm) { + var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)( + this.low, + this.high, + divisor.low, + divisor.high + ); + return fromBits(low, wasm.get_high(), this.unsigned); + } + + return this.sub(this.div(divisor).mul(divisor)); +}; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.mod = LongPrototype.modulo; + +/** + * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. + * @function + * @param {!Long|number|string} divisor Divisor + * @returns {!Long} Remainder + */ +LongPrototype.rem = LongPrototype.modulo; + +/** + * Returns the bitwise NOT of this Long. + * @returns {!Long} + */ +LongPrototype.not = function not() { + return fromBits(~this.low, ~this.high, this.unsigned); +}; + +/** + * Returns the bitwise AND of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.and = function and(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low & other.low, this.high & other.high, this.unsigned); +}; + +/** + * Returns the bitwise OR of this Long and the specified. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.or = function or(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low | other.low, this.high | other.high, this.unsigned); +}; + +/** + * Returns the bitwise XOR of this Long and the given one. + * @param {!Long|number|string} other Other Long + * @returns {!Long} + */ +LongPrototype.xor = function xor(other) { + if (!isLong(other)) + other = fromValue(other); + return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftLeft = function shiftLeft(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); + else + return fromBits(0, this.low << (numBits - 32), this.unsigned); +}; + +/** + * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shl = LongPrototype.shiftLeft; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRight = function shiftRight(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + if ((numBits &= 63) === 0) + return this; + else if (numBits < 32) + return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned); + else + return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); +}; + +/** + * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr = LongPrototype.shiftRight; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { + if (isLong(numBits)) + numBits = numBits.toInt(); + numBits &= 63; + if (numBits === 0) + return this; + else { + var high = this.high; + if (numBits < 32) { + var low = this.low; + return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); + } else if (numBits === 32) + return fromBits(high, 0, this.unsigned); + else + return fromBits(high >>> (numBits - 32), 0, this.unsigned); + } +}; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shru = LongPrototype.shiftRightUnsigned; + +/** + * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. + * @function + * @param {number|!Long} numBits Number of bits + * @returns {!Long} Shifted Long + */ +LongPrototype.shr_u = LongPrototype.shiftRightUnsigned; + +/** + * Converts this Long to signed. + * @returns {!Long} Signed long + */ +LongPrototype.toSigned = function toSigned() { + if (!this.unsigned) + return this; + return fromBits(this.low, this.high, false); +}; + +/** + * Converts this Long to unsigned. + * @returns {!Long} Unsigned long + */ +LongPrototype.toUnsigned = function toUnsigned() { + if (this.unsigned) + return this; + return fromBits(this.low, this.high, true); +}; + +/** + * Converts this Long to its byte representation. + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {!Array.} Byte representation + */ +LongPrototype.toBytes = function toBytes(le) { + return le ? this.toBytesLE() : this.toBytesBE(); +}; + +/** + * Converts this Long to its little endian byte representation. + * @returns {!Array.} Little endian byte representation + */ +LongPrototype.toBytesLE = function toBytesLE() { + var hi = this.high, + lo = this.low; + return [ + lo & 0xff, + lo >>> 8 & 0xff, + lo >>> 16 & 0xff, + lo >>> 24 , + hi & 0xff, + hi >>> 8 & 0xff, + hi >>> 16 & 0xff, + hi >>> 24 + ]; +}; + +/** + * Converts this Long to its big endian byte representation. + * @returns {!Array.} Big endian byte representation + */ +LongPrototype.toBytesBE = function toBytesBE() { + var hi = this.high, + lo = this.low; + return [ + hi >>> 24 , + hi >>> 16 & 0xff, + hi >>> 8 & 0xff, + hi & 0xff, + lo >>> 24 , + lo >>> 16 & 0xff, + lo >>> 8 & 0xff, + lo & 0xff + ]; +}; + +/** + * Creates a Long from its byte representation. + * @param {!Array.} bytes Byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @param {boolean=} le Whether little or big endian, defaults to big endian + * @returns {Long} The corresponding Long value + */ +Long.fromBytes = function fromBytes(bytes, unsigned, le) { + return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned); +}; + +/** + * Creates a Long from its little endian byte representation. + * @param {!Array.} bytes Little endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesLE = function fromBytesLE(bytes, unsigned) { + return new Long( + bytes[0] | + bytes[1] << 8 | + bytes[2] << 16 | + bytes[3] << 24, + bytes[4] | + bytes[5] << 8 | + bytes[6] << 16 | + bytes[7] << 24, + unsigned + ); +}; + +/** + * Creates a Long from its big endian byte representation. + * @param {!Array.} bytes Big endian byte representation + * @param {boolean=} unsigned Whether unsigned or not, defaults to signed + * @returns {Long} The corresponding Long value + */ +Long.fromBytesBE = function fromBytesBE(bytes, unsigned) { + return new Long( + bytes[4] << 24 | + bytes[5] << 16 | + bytes[6] << 8 | + bytes[7], + bytes[0] << 24 | + bytes[1] << 16 | + bytes[2] << 8 | + bytes[3], + unsigned + ); +}; + + +/***/ }), +/* 26 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// resolves . and .. elements in a path array with directory names there +// must be no slashes, empty elements, or device names (c:\) in the array +// (so also no leading and trailing slashes - it does not distinguish +// relative and absolute paths) +function normalizeArray(parts, allowAboveRoot) { + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = parts.length - 1; i >= 0; i--) { + var last = parts[i]; + if (last === '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; + } + } + + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); + } + } + + return parts; +} + +// Split a filename into [root, dir, basename, ext], unix version +// 'root' is just a slash, or nothing. +var splitPathRe = + /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; +var splitPath = function(filename) { + return splitPathRe.exec(filename).slice(1); +}; + +// path.resolve([from ...], to) +// posix version +exports.resolve = function() { + var resolvedPath = '', + resolvedAbsolute = false; + + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path = (i >= 0) ? arguments[i] : process.cwd(); + + // Skip empty and invalid entries + if (typeof path !== 'string') { + throw new TypeError('Arguments to path.resolve must be strings'); + } else if (!path) { + continue; + } + + resolvedPath = path + '/' + resolvedPath; + resolvedAbsolute = path.charAt(0) === '/'; + } + + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) + + // Normalize the path + resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { + return !!p; + }), !resolvedAbsolute).join('/'); + + return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; +}; + +// path.normalize(path) +// posix version +exports.normalize = function(path) { + var isAbsolute = exports.isAbsolute(path), + trailingSlash = substr(path, -1) === '/'; + + // Normalize the path + path = normalizeArray(filter(path.split('/'), function(p) { + return !!p; + }), !isAbsolute).join('/'); + + if (!path && !isAbsolute) { + path = '.'; + } + if (path && trailingSlash) { + path += '/'; + } + + return (isAbsolute ? '/' : '') + path; +}; + +// posix version +exports.isAbsolute = function(path) { + return path.charAt(0) === '/'; +}; + +// posix version +exports.join = function() { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(filter(paths, function(p, index) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to path.join must be strings'); + } + return p; + }).join('/')); +}; + + +// path.relative(from, to) +// posix version +exports.relative = function(from, to) { + from = exports.resolve(from).substr(1); + to = exports.resolve(to).substr(1); + + function trim(arr) { + var start = 0; + for (; start < arr.length; start++) { + if (arr[start] !== '') break; + } + + var end = arr.length - 1; + for (; end >= 0; end--) { + if (arr[end] !== '') break; + } + + if (start > end) return []; + return arr.slice(start, end - start + 1); + } + + var fromParts = trim(from.split('/')); + var toParts = trim(to.split('/')); + + var length = Math.min(fromParts.length, toParts.length); + var samePartsLength = length; + for (var i = 0; i < length; i++) { + if (fromParts[i] !== toParts[i]) { + samePartsLength = i; + break; + } + } + + var outputParts = []; + for (var i = samePartsLength; i < fromParts.length; i++) { + outputParts.push('..'); + } + + outputParts = outputParts.concat(toParts.slice(samePartsLength)); + + return outputParts.join('/'); +}; + +exports.sep = '/'; +exports.delimiter = ':'; + +exports.dirname = function(path) { + var result = splitPath(path), + root = result[0], + dir = result[1]; + + if (!root && !dir) { + // No dirname whatsoever + return '.'; + } + + if (dir) { + // It has a dirname, strip trailing slash + dir = dir.substr(0, dir.length - 1); + } + + return root + dir; +}; + + +exports.basename = function(path, ext) { + var f = splitPath(path)[2]; + // TODO: make this comparison case-insensitive on windows? + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; +}; + + +exports.extname = function(path) { + return splitPath(path)[3]; +}; + +function filter (xs, f) { + if (xs.filter) return xs.filter(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + if (f(xs[i], i, xs)) res.push(xs[i]); + } + return res; +} + +// String.prototype.substr - negative index don't work in IE8 +var substr = 'ab'.substr(-1) === 'b' + ? function (str, start, len) { return str.substr(start, len) } + : function (str, start, len) { + if (start < 0) start = str.length + start; + return str.substr(start, len); + } +; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(13))) + +/***/ }), +/* 27 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(Buffer) {const path = __webpack_require__(26); +const fs = __webpack_require__(41); +const snekfetch = __webpack_require__(24); + +const Constants = __webpack_require__(0); +const convertToBuffer = __webpack_require__(4).convertToBuffer; +const User = __webpack_require__(9); +const Message = __webpack_require__(15); +const Guild = __webpack_require__(22); +const Channel = __webpack_require__(11); +const GuildMember = __webpack_require__(17); +const Emoji = __webpack_require__(16); +const ReactionEmoji = __webpack_require__(28); +const Role = __webpack_require__(8); + +/** + * The DataResolver identifies different objects and tries to resolve a specific piece of information from them, e.g. + * extracting a User from a Message object. + * @private + */ +class ClientDataResolver { + /** + * @param {Client} client The client the resolver is for + */ + constructor(client) { + this.client = client; + } + + /** + * Data that resolves to give a User object. This can be: + * * A User object + * * A Snowflake + * * A Message object (resolves to the message author) + * * A Guild object (owner of the guild) + * * A GuildMember object + * @typedef {User|Snowflake|Message|Guild|GuildMember} UserResolvable + */ + + /** + * Resolves a UserResolvable to a User object. + * @param {UserResolvable} user The UserResolvable to identify + * @returns {?User} + */ + resolveUser(user) { + if (user instanceof User) return user; + if (typeof user === 'string') return this.client.users.get(user) || null; + if (user instanceof GuildMember) return user.user; + if (user instanceof Message) return user.author; + if (user instanceof Guild) return user.owner; + return null; + } + + /** + * Resolves a UserResolvable to a user ID string. + * @param {UserResolvable} user The UserResolvable to identify + * @returns {?Snowflake} + */ + resolveUserID(user) { + if (user instanceof User || user instanceof GuildMember) return user.id; + if (typeof user === 'string') return user || null; + if (user instanceof Message) return user.author.id; + if (user instanceof Guild) return user.ownerID; + return null; + } + + /** + * Data that resolves to give a Guild object. This can be: + * * A Guild object + * * A Snowflake + * @typedef {Guild|Snowflake} GuildResolvable + */ + + /** + * Resolves a GuildResolvable to a Guild object. + * @param {GuildResolvable} guild The GuildResolvable to identify + * @returns {?Guild} + */ + resolveGuild(guild) { + if (guild instanceof Guild) return guild; + if (typeof guild === 'string') return this.client.guilds.get(guild) || null; + return null; + } + + /** + * Data that resolves to give a GuildMember object. This can be: + * * A GuildMember object + * * A User object + * @typedef {GuildMember|User} GuildMemberResolvable + */ + + /** + * Resolves a GuildMemberResolvable to a GuildMember object. + * @param {GuildResolvable} guild The guild that the member is part of + * @param {UserResolvable} user The user that is part of the guild + * @returns {?GuildMember} + */ + resolveGuildMember(guild, user) { + if (user instanceof GuildMember) return user; + guild = this.resolveGuild(guild); + user = this.resolveUser(user); + if (!guild || !user) return null; + return guild.members.get(user.id) || null; + } + + /** + * Data that can be resolved to a Role object. This can be: + * * A Role + * * A Snowflake + * @typedef {Role|Snowflake} RoleResolvable + */ + + /** + * Resolves a RoleResolvable to a Role object. + * @param {GuildResolvable} guild The guild that this role is part of + * @param {RoleResolvable} role The role resolvable to resolve + * @returns {?Role} + */ + resolveRole(guild, role) { + if (role instanceof Role) return role; + guild = this.resolveGuild(guild); + if (!guild) return null; + if (typeof role === 'string') return guild.roles.get(role); + return null; + } + + /** + * Data that can be resolved to give a Channel object. This can be: + * * A Channel object + * * A Message object (the channel the message was sent in) + * * A Guild object (the #general channel) + * * A Snowflake + * @typedef {Channel|Guild|Message|Snowflake} ChannelResolvable + */ + + /** + * Resolves a ChannelResolvable to a Channel object. + * @param {ChannelResolvable} channel The channel resolvable to resolve + * @returns {?Channel} + */ + resolveChannel(channel) { + if (channel instanceof Channel) return channel; + if (typeof channel === 'string') return this.client.channels.get(channel) || null; + if (channel instanceof Message) return channel.channel; + if (channel instanceof Guild) return channel.channels.get(channel.id) || null; + return null; + } + + /** + * Resolves a ChannelResolvable to a channel ID. + * @param {ChannelResolvable} channel The channel resolvable to resolve + * @returns {?Snowflake} + */ + resolveChannelID(channel) { + if (channel instanceof Channel) return channel.id; + if (typeof channel === 'string') return channel; + if (channel instanceof Message) return channel.channel.id; + if (channel instanceof Guild) return channel.defaultChannel.id; + return null; + } + + /** + * Data that can be resolved to give an invite code. This can be: + * * An invite code + * * An invite URL + * @typedef {string} InviteResolvable + */ + + /** + * Resolves InviteResolvable to an invite code. + * @param {InviteResolvable} data The invite resolvable to resolve + * @returns {string} + */ + resolveInviteCode(data) { + const inviteRegex = /discord(?:app\.com\/invite|\.gg)\/([\w-]{2,255})/i; + const match = inviteRegex.exec(data); + if (match && match[1]) return match[1]; + return data; + } + + /** + * 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} + */ + resolveString(data) { + if (typeof data === 'string') return data; + if (data instanceof Array) return data.join('\n'); + return String(data); + } + + + /** + * Resolves a Base64Resolvable, a string, or a BufferResolvable to a Base 64 image. + * @param {BufferResolvable|Base64Resolvable} image The image to be resolved + * @returns {Promise} + */ + resolveImage(image) { + if (!image) return Promise.resolve(null); + if (typeof image === 'string' && image.startsWith('data:')) { + return Promise.resolve(image); + } + return this.resolveFile(image).then(this.resolveBase64); + } + + /** + * Data that resolves to give a Base64 string, typically for image uploading. This can be: + * * A Buffer + * * A base64 string + * @typedef {Buffer|string} Base64Resolvable + */ + + /** + * Resolves a Base64Resolvable to a Base 64 image. + * @param {Base64Resolvable} data The base 64 resolvable you want to resolve + * @returns {?string} + */ + resolveBase64(data) { + if (data instanceof Buffer) return `data:image/jpg;base64,${data.toString('base64')}`; + return data; + } + + /** + * Data that can be resolved to give a Buffer. This can be: + * * A Buffer + * * The path to a local file + * * A URL + * * A Stream + * @typedef {string|Buffer} BufferResolvable + */ + + /** + * @external Stream + * @see {@link https://nodejs.org/api/stream.html} + */ + + /** + * Resolves a BufferResolvable to a Buffer. + * @param {BufferResolvable|Stream} resource The buffer or stream resolvable to resolve + * @returns {Promise} + */ + resolveFile(resource) { + if (resource instanceof Buffer) return Promise.resolve(resource); + if (this.client.browser && resource instanceof ArrayBuffer) return Promise.resolve(convertToBuffer(resource)); + + if (typeof resource === 'string') { + return new Promise((resolve, reject) => { + if (/^https?:\/\//.test(resource)) { + snekfetch.get(resource) + .end((err, res) => { + if (err) return reject(err); + if (!(res.body instanceof Buffer)) return reject(new TypeError('The response body isn\'t a Buffer.')); + return resolve(res.body); + }); + } else { + const file = path.resolve(resource); + fs.stat(file, (err, stats) => { + if (err) return reject(err); + if (!stats || !stats.isFile()) return reject(new Error(`The file could not be found: ${file}`)); + fs.readFile(file, (err2, data) => { + if (err2) reject(err2); else resolve(data); + }); + return null; + }); + } + }); + } else if (resource.pipe && typeof resource.pipe === 'function') { + return new Promise((resolve, reject) => { + const buffers = []; + resource.once('error', reject); + resource.on('data', data => buffers.push(data)); + resource.once('end', () => resolve(Buffer.concat(buffers))); + }); + } + + return Promise.reject(new TypeError('The resource must be a string or Buffer.')); + } + + /** + * Data that can be resolved to give an emoji identifier. This can be: + * * The unicode representation of an emoji + * * A custom emoji ID + * * An Emoji object + * * A ReactionEmoji object + * @typedef {string|Emoji|ReactionEmoji} EmojiIdentifierResolvable + */ + + /** + * Resolves an EmojiResolvable to an emoji identifier. + * @param {EmojiIdentifierResolvable} emoji The emoji resolvable to resolve + * @returns {?string} + */ + resolveEmojiIdentifier(emoji) { + if (emoji instanceof Emoji || emoji instanceof ReactionEmoji) return emoji.identifier; + if (typeof emoji === 'string') { + if (this.client.emojis.has(emoji)) return this.client.emojis.get(emoji).identifier; + else if (!emoji.includes('%')) return encodeURIComponent(emoji); + else return emoji; + } + return null; + } + + /** + * Can be a Hex Literal, Hex String, Number, RGB Array, or one of the following + * ``` + * [ + * 'DEFAULT', + * 'AQUA', + * 'GREEN', + * 'BLUE', + * 'PURPLE', + * 'GOLD', + * 'ORANGE', + * 'RED', + * 'GREY', + * 'DARKER_GREY', + * 'NAVY', + * 'DARK_AQUA', + * 'DARK_GREEN', + * 'DARK_BLUE', + * 'DARK_PURPLE', + * 'DARK_GOLD', + * 'DARK_ORANGE', + * 'DARK_RED', + * 'DARK_GREY', + * 'LIGHT_GREY', + * 'DARK_NAVY', + * 'RANDOM', + * ] + * ``` + * or something like + * ``` + * [255, 0, 255] + * ``` + * for purple + * @typedef {string|number|Array} ColorResolvable + */ + + /** + * Resolves a ColorResolvable into a color number. + * @param {ColorResolvable} color Color to resolve + * @returns {number} A color + */ + static resolveColor(color) { + if (typeof color === 'string') { + if (color === 'RANDOM') return Math.floor(Math.random() * (0xFFFFFF + 1)); + if (color === 'DEFAULT') return 0; + color = Constants.Colors[color] || parseInt(color.replace('#', ''), 16); + } else if (color instanceof Array) { + color = (color[0] << 16) + (color[1] << 8) + color[2]; + } + + if (color < 0 || color > 0xFFFFFF) { + throw new RangeError('Color must be within the range 0 - 16777215 (0xFFFFFF).'); + } else if (color && isNaN(color)) { + throw new TypeError('Unable to convert color to a number.'); + } + + return color; + } + + /** + * @param {ColorResolvable} color Color to resolve + * @returns {number} A color + */ + resolveColor(color) { + return this.constructor.resolveColor(color); + } +} + +module.exports = ClientDataResolver; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12).Buffer)) + +/***/ }), +/* 28 */ +/***/ (function(module, exports) { + +/** + * Represents a limited emoji set used for both custom and unicode emojis. Custom emojis + * will use this class opposed to the Emoji class when the client doesn't know enough + * information about them. + */ +class ReactionEmoji { + constructor(reaction, name, id) { + /** + * The message reaction this emoji refers to + * @type {MessageReaction} + */ + this.reaction = reaction; + + /** + * The name of this reaction emoji + * @type {string} + */ + this.name = name; + + /** + * The ID of this reaction emoji + * @type {?Snowflake} + */ + this.id = id; + } + + /** + * The identifier of this emoji, used for message reactions + * @type {string} + * @readonly + */ + get identifier() { + if (this.id) return `${this.name}:${this.id}`; + return encodeURIComponent(this.name); + } + + /** + * Creates the text required to form a graphical emoji on Discord. + * @example + * // Send the emoji used in a reaction to the channel the reaction is part of + * reaction.message.channel.send(`The emoji used is ${reaction.emoji}`); + * @returns {string} + */ + toString() { + return this.id ? `<:${this.name}:${this.id}>` : this.name; + } +} + +module.exports = ReactionEmoji; + + +/***/ }), +/* 29 */ +/***/ (function(module, exports, __webpack_require__) { + +const Collection = __webpack_require__(3); +const EventEmitter = __webpack_require__(19).EventEmitter; + +/** + * Filter to be applied to the collector. + * @typedef {Function} CollectorFilter + * @param {...*} args Any arguments received by the listener + * @param {Collection} collection The items collected by this collector + * @returns {boolean} + */ + +/** + * Options to be applied to the collector. + * @typedef {Object} CollectorOptions + * @property {number} [time] How long to run the collector for + */ + +/** + * Abstract class for defining a new Collector. + * @abstract + */ +class Collector extends EventEmitter { + constructor(client, filter, options = {}) { + super(); + + /** + * The client + * @name Collector#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + /** + * The filter applied to this collector + * @type {CollectorFilter} + */ + this.filter = filter; + + /** + * The options of this collector + * @type {CollectorOptions} + */ + this.options = options; + + /** + * The items collected by this collector + * @type {Collection} + */ + this.collected = new Collection(); + + /** + * Whether this collector has finished collecting + * @type {boolean} + */ + this.ended = false; + + /** + * Timeout for cleanup + * @type {?Timeout} + * @private + */ + this._timeout = null; + + /** + * Call this to handle an event as a collectable element + * Accepts any event data as parameters + * @type {Function} + * @private + */ + this.listener = this._handle.bind(this); + if (options.time) this._timeout = this.client.setTimeout(() => this.stop('time'), options.time); + } + + /** + * @param {...*} args The arguments emitted by the listener + * @emits Collector#collect + * @private + */ + _handle(...args) { + const collect = this.handle(...args); + if (!collect || !this.filter(...args, this.collected)) return; + + this.collected.set(collect.key, collect.value); + + /** + * Emitted whenever an element is collected. + * @event Collector#collect + * @param {*} element The element that got collected + * @param {Collector} collector The collector + */ + this.emit('collect', collect.value, this); + + const post = this.postCheck(...args); + if (post) this.stop(post); + } + + /** + * Return a promise that resolves with the next collected element; + * rejects with collected elements if the collector finishes without receving a next element + * @type {Promise} + * @readonly + */ + get next() { + return new Promise((resolve, reject) => { + if (this.ended) { + reject(this.collected); + return; + } + + const cleanup = () => { + this.removeListener('collect', onCollect); + this.removeListener('end', onEnd); + }; + + const onCollect = item => { + cleanup(); + resolve(item); + }; + + const onEnd = () => { + cleanup(); + reject(this.collected); // eslint-disable-line prefer-promise-reject-errors + }; + + this.on('collect', onCollect); + this.on('end', onEnd); + }); + } + + /** + * Stop this collector and emit the `end` event. + * @param {string} [reason='user'] The reason this collector is ending + * @emits Collector#end + */ + stop(reason = 'user') { + if (this.ended) return; + + if (this._timeout) this.client.clearTimeout(this._timeout); + this.ended = true; + this.cleanup(); + + /** + * Emitted when the collector is finished collecting. + * @event Collector#end + * @param {Collection} collected The elements collected by the collector + * @param {string} reason The reason the collector ended + */ + this.emit('end', this.collected, reason); + } + + /* eslint-disable no-empty-function, valid-jsdoc */ + /** + * Handles incoming events from the `listener` function. Returns null if the event should not be collected, + * or returns an object describing the data that should be stored. + * @see Collector#listener + * @param {...*} args Any args the event listener emits + * @returns {?{key: string, value}} Data to insert into collection, if any + * @abstract + */ + handle() {} + + /** + * This method runs after collection to see if the collector should finish. + * @param {...*} args Any args the event listener emits + * @returns {?string} Reason to end the collector, if any + * @abstract + */ + postCheck() {} + + /** + * Called when the collector is ending. + * @abstract + */ + cleanup() {} + /* eslint-enable no-empty-function, valid-jsdoc */ +} + +module.exports = Collector; + + +/***/ }), +/* 30 */ +/***/ (function(module, exports, __webpack_require__) { + +const PartialGuild = __webpack_require__(45); +const PartialGuildChannel = __webpack_require__(46); +const Constants = __webpack_require__(0); + +/** + * Represents an invitation to a guild channel. + * The only guaranteed properties are `code`, `guild` and `channel`. Other properties can be missing. + */ +class Invite { + constructor(client, data) { + /** + * The client that instantiated the invite + * @name Invite#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + this.setup(data); + } + + setup(data) { + /** + * The guild the invite is for. If this guild is already known, this will be a guild object. If the guild is + * unknown, this will be a PartialGuild object + * @type {Guild|PartialGuild} + */ + this.guild = this.client.guilds.get(data.guild.id) || new PartialGuild(this.client, data.guild); + + /** + * The code for this invite + * @type {string} + */ + this.code = data.code; + + /** + * The approximate number of online members of the guild this invite is for + * @type {number} + */ + this.presenceCount = data.approximate_presence_count; + + /** + * The approximate total number of members of the guild this invite is for + * @type {number} + */ + this.memberCount = data.approximate_member_count; + + /** + * The number of text channels the guild this invite goes to has + * @type {number} + */ + this.textChannelCount = data.guild.text_channel_count; + + /** + * The number of voice channels the guild this invite goes to has + * @type {number} + */ + this.voiceChannelCount = data.guild.voice_channel_count; + + /** + * Whether or not this invite is temporary + * @type {boolean} + */ + this.temporary = data.temporary; + + /** + * The maximum age of the invite, in seconds + * @type {?number} + */ + this.maxAge = data.max_age; + + /** + * How many times this invite has been used + * @type {number} + */ + this.uses = data.uses; + + /** + * The maximum uses of this invite + * @type {number} + */ + this.maxUses = data.max_uses; + + if (data.inviter) { + /** + * The user who created this invite + * @type {User} + */ + this.inviter = this.client.dataManager.newUser(data.inviter); + } + + /** + * The channel the invite is for. If this channel is already known, this will be a GuildChannel object. + * If the channel is unknown, this will be a PartialGuildChannel object. + * @type {GuildChannel|PartialGuildChannel} + */ + this.channel = this.client.channels.get(data.channel.id) || new PartialGuildChannel(this.client, data.channel); + + /** + * The timestamp the invite was created at + * @type {number} + */ + this.createdTimestamp = new Date(data.created_at).getTime(); + } + + /** + * The time the invite was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * The timestamp the invite will expire at + * @type {number} + * @readonly + */ + get expiresTimestamp() { + return this.createdTimestamp + (this.maxAge * 1000); + } + + /** + * The time the invite will expire + * @type {Date} + * @readonly + */ + get expiresAt() { + return new Date(this.expiresTimestamp); + } + + /** + * The URL to the invite + * @type {string} + * @readonly + */ + get url() { + return Constants.Endpoints.inviteLink(this.code); + } + + /** + * Deletes this invite. + * @param {string} [reason] Reason for deleting this invite + * @returns {Promise} + */ + delete(reason) { + return this.client.rest.methods.deleteInvite(this, reason); + } + + /** + * When concatenated with a string, this automatically concatenates the invite's URL instead of the object. + * @returns {string} + * @example + * // Logs: Invite: https://discord.gg/A1b2C3 + * console.log(`Invite: ${invite}`); + */ + toString() { + return this.url; + } +} + +module.exports = Invite; + + +/***/ }), +/* 31 */ +/***/ (function(module, exports, __webpack_require__) { + +const Snowflake = __webpack_require__(5); + +/** + * Represents an OAuth2 Application. + */ +class OAuth2Application { + constructor(client, data) { + /** + * The client that instantiated the application + * @name OAuth2Application#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + this.setup(data); + } + + setup(data) { + /** + * The ID of the app + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The name of the app + * @type {string} + */ + this.name = data.name; + + /** + * The app's description + * @type {string} + */ + this.description = data.description; + + /** + * The app's icon hash + * @type {?string} + */ + this.icon = data.icon; + + /** + * The app's icon URL + * @type {string} + */ + this.iconURL = `https://cdn.discordapp.com/app-icons/${this.id}/${this.icon}.jpg`; + + /** + * The app's RPC origins + * @type {?string[]} + */ + this.rpcOrigins = data.rpc_origins; + + /** + * The app's redirect URIs + * @type {string[]} + */ + this.redirectURIs = data.redirect_uris; + + /** + * If this app's bot requires a code grant when using the OAuth2 flow + * @type {boolean} + */ + this.botRequireCodeGrant = data.bot_require_code_grant; + + /** + * If this app's bot is public + * @type {boolean} + */ + this.botPublic = data.bot_public; + + /** + * If this app can use rpc + * @type {boolean} + */ + this.rpcApplicationState = data.rpc_application_state; + + /** + * Object containing basic info about this app's bot + * @type {Object} + */ + this.bot = data.bot; + + /** + * The flags for the app + * @type {number} + */ + this.flags = data.flags; + + /** + * OAuth2 secret for the application + * @type {boolean} + */ + this.secret = data.secret; + + if (data.owner) { + /** + * The owner of this OAuth application + * @type {?User} + */ + this.owner = this.client.dataManager.newUser(data.owner); + } + } + + /** + * The timestamp the app was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return Snowflake.deconstruct(this.id).timestamp; + } + + /** + * The time the app was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * Reset the app's secret and bot token. + * This is only available when using a user account. + * @returns {OAuth2Application} + */ + reset() { + return this.client.rest.methods.resetApplication(this.id); + } + + /** + * When concatenated with a string, this automatically concatenates the app name rather than the app object. + * @returns {string} + */ + toString() { + return this.name; + } +} + +module.exports = OAuth2Application; + + +/***/ }), +/* 32 */ +/***/ (function(module, exports, __webpack_require__) { + +const Channel = __webpack_require__(11); +const TextBasedChannel = __webpack_require__(14); +const Collection = __webpack_require__(3); +const Constants = __webpack_require__(0); + +/* +{ type: 3, + recipients: + [ { username: 'Charlie', + id: '123', + discriminator: '6631', + avatar: '123' }, + { username: 'Ben', + id: '123', + discriminator: '2055', + avatar: '123' }, + { username: 'Adam', + id: '123', + discriminator: '2406', + avatar: '123' } ], + owner_id: '123', + name: null, + last_message_id: '123', + id: '123', + icon: null } +*/ + +/** + * Represents a Group DM on Discord. + * @extends {Channel} + * @implements {TextBasedChannel} + */ +class GroupDMChannel extends Channel { + constructor(client, data) { + super(client, data); + this.type = 'group'; + this.messages = new Collection(); + this._typing = new Map(); + } + + setup(data) { + super.setup(data); + + /** + * The name of this Group DM, can be null if one isn't set + * @type {string} + */ + this.name = data.name; + + /** + * A hash of this Group DM icon + * @type {?string} + */ + this.icon = data.icon; + + /** + * The user ID of this Group DM's owner + * @type {string} + */ + this.ownerID = data.owner_id; + + /** + * If the DM is managed by an application + * @type {boolean} + */ + this.managed = data.managed; + + /** + * Application ID of the application that made this Group DM, if applicable + * @type {?string} + */ + this.applicationID = data.application_id; + + if (data.nicks) { + /** + * Nicknames for group members + * @type {?Collection} + */ + this.nicks = new Collection(data.nicks.map(n => [n.id, n.nick])); + } + + if (!this.recipients) { + /** + * A collection of the recipients of this DM, mapped by their ID + * @type {Collection} + */ + this.recipients = new Collection(); + } + + if (data.recipients) { + for (const recipient of data.recipients) { + const user = this.client.dataManager.newUser(recipient); + this.recipients.set(user.id, user); + } + } + + this.lastMessageID = data.last_message_id; + } + + /** + * The owner of this Group DM + * @type {User} + * @readonly + */ + get owner() { + return this.client.users.get(this.ownerID); + } + + /** + * The URL to this guild's icon + * @type {?string} + * @readonly + */ + get iconURL() { + if (!this.icon) return null; + return Constants.Endpoints.Channel(this).Icon(this.client.options.http.cdn, this.icon); + } + + edit(data) { + const _data = {}; + if (data.name) _data.name = data.name; + if (typeof data.icon !== 'undefined') _data.icon = data.icon; + return this.client.rest.methods.updateGroupDMChannel(this, _data); + } + + /** + * Whether this channel equals another channel. It compares all properties, so for most operations + * it is advisable to just compare `channel.id === channel2.id` as it is much faster and is often + * what most users need. + * @param {GroupDMChannel} channel Channel to compare with + * @returns {boolean} + */ + equals(channel) { + const equal = channel && + this.id === channel.id && + this.name === channel.name && + this.icon === channel.icon && + this.ownerID === channel.ownerID; + + if (equal) { + return this.recipients.equals(channel.recipients); + } + + return equal; + } + + /** + * Add a user to the DM + * @param {UserResolvable|string} accessTokenOrID Access token or user resolvable + * @param {string} [nick] Permanent nickname to give the user (only available if a bot is creating the DM) + * @returns {Promise} + */ + + addUser(accessTokenOrID, nick) { + return this.client.rest.methods.addUserToGroupDM(this, { + nick, + id: this.client.resolver.resolveUserID(accessTokenOrID), + accessToken: accessTokenOrID, + }); + } + + /** + * Set a new GroupDMChannel icon. + * @param {Base64Resolvable|BufferResolvable} icon The new icon of the group dm + * @returns {Promise} + * @example + * // Edit the group dm icon + * channel.setIcon('./icon.png') + * .then(updated => console.log('Updated the channel icon')) + * .catch(console.error); + */ + setIcon(icon) { + return this.client.resolver.resolveImage(icon).then(data => this.edit({ icon: data })); + } + + /** + * Sets a new name for this Group DM. + * @param {string} name New name for this Group DM + * @returns {Promise} + */ + setName(name) { + return this.edit({ name }); + } + + /** + * Removes an user from this Group DM. + * @param {UserResolvable} user User to remove + * @returns {Promise} + */ + removeUser(user) { + const id = this.client.resolver.resolveUserID(user); + return this.client.rest.methods.removeUserFromGroupDM(this, id); + } + + /** + * When concatenated with a string, this automatically concatenates the channel's name instead of the Channel object. + * @returns {string} + * @example + * // Logs: Hello from My Group DM! + * console.log(`Hello from ${channel}!`); + * @example + * // Logs: Hello from My Group DM! + * console.log(`Hello from ' + channel + '!'); + */ + toString() { + return this.name; + } + + // These are here only for documentation purposes - they are implemented by TextBasedChannel + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendFiles() {} + sendCode() {} + fetchMessage() {} + fetchMessages() {} + fetchPinnedMessages() {} + search() {} + startTyping() {} + stopTyping() {} + get typing() {} + get typingCount() {} + createCollector() {} + createMessageCollector() {} + awaitMessages() {} + // Doesn't work on Group DMs; bulkDelete() {} + acknowledge() {} + _cacheMessage() {} +} + +TextBasedChannel.applyToClass(GroupDMChannel, true, ['bulkDelete']); + +module.exports = GroupDMChannel; + + +/***/ }), +/* 33 */ +/***/ (function(module, exports) { + +/** + * Represents an error from the Discord API. + * @extends Error + */ +class DiscordAPIError extends Error { + constructor(path, error) { + super(); + const flattened = this.constructor.flattenErrors(error.errors || error).join('\n'); + this.name = 'DiscordAPIError'; + this.message = error.message && flattened ? `${error.message}\n${flattened}` : error.message || flattened; + + /** + * The path of the request relative to the HTTP endpoint + * @type {string} + */ + this.path = path; + + /** + * HTTP error code returned by Discord + * @type {number} + */ + this.code = error.code; + } + + /** + * Flattens an errors object returned from the API into an array. + * @param {Object} obj Discord errors object + * @param {string} [key] Used internally to determine key names of nested fields + * @returns {string[]} + * @private + */ + static flattenErrors(obj, key = '') { + let messages = []; + + for (const k of Object.keys(obj)) { + if (k === 'message') continue; + const newKey = key ? isNaN(k) ? `${key}.${k}` : `${key}[${k}]` : k; + + if (obj[k]._errors) { + messages.push(`${newKey}: ${obj[k]._errors.map(e => e.message).join(' ')}`); + } else if (obj[k].code || obj[k].message) { + messages.push(`${obj[k].code ? `${obj[k].code}: ` : ''}: ${obj[k].message}`.trim()); + } else if (typeof obj[k] === 'string') { + messages.push(obj[k]); + } else { + messages = messages.concat(this.flattenErrors(obj[k], newKey)); + } + } + + return messages; + } +} + +module.exports = DiscordAPIError; + + +/***/ }), +/* 34 */ +/***/ (function(module, exports) { + +var g; + +// This works in non-strict mode +g = (function() { + return this; +})(); + +try { + // This works if eval is allowed (see CSP) + g = g || Function("return this")() || (1,eval)("this"); +} catch(e) { + // This works if the window reference is available + if(typeof window === "object") + g = window; +} + +// g can still be undefined, but nothing to do about it... +// We return undefined, instead of nothing here, so it's +// easier to handle this case. if(!global) { ...} + +module.exports = g; + + +/***/ }), +/* 35 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +exports.decode = exports.parse = __webpack_require__(65); +exports.encode = exports.stringify = __webpack_require__(66); + + +/***/ }), +/* 36 */ +/***/ (function(module, exports) { + +module.exports = {"name":"discord.js","version":"11.3.1","description":"A powerful library for interacting with the Discord API","main":"./src/index","types":"./typings/index.d.ts","scripts":{"test":"npm run lint && npm run docs:test","docs":"docgen --source src --custom docs/index.yml --output docs/docs.json","docs:test":"docgen --source src --custom docs/index.yml","lint":"eslint src","lint:fix":"eslint --fix src","webpack":"parallel-webpack"},"repository":{"type":"git","url":"git+https://github.com/discordjs/discord.js.git"},"keywords":["discord","api","bot","client","node","discordapp"],"author":"Amish Shah ","license":"Apache-2.0","bugs":{"url":"https://github.com/discordjs/discord.js/issues"},"homepage":"https://github.com/discordjs/discord.js#readme","runkitExampleFilename":"./docs/examples/ping.js","dependencies":{"long":"^4.0.0","prism-media":"^0.0.2","snekfetch":"^3.6.4","tweetnacl":"^1.0.0","ws":"^4.0.0"},"peerDependencies":{"bufferutil":"^3.0.3","erlpack":"discordapp/erlpack","node-opus":"^0.2.7","opusscript":"^0.0.6","sodium":"^2.0.3","libsodium-wrappers":"^0.7.3","uws":"^9.14.0"},"devDependencies":{"@types/node":"^9.4.6","discord.js-docgen":"discordjs/docgen","eslint":"^4.18.0","parallel-webpack":"^2.2.0","uglifyjs-webpack-plugin":"^1.2.0","webpack":"^3.11.0"},"engines":{"node":">=6.0.0"},"browser":{"ws":false,"uws":false,"erlpack":false,"prism-media":false,"opusscript":false,"node-opus":false,"tweetnacl":false,"sodium":false,"src/sharding/Shard.js":false,"src/sharding/ShardClientUtil.js":false,"src/sharding/ShardingManager.js":false,"src/client/voice/dispatcher/StreamDispatcher.js":false,"src/client/voice/opus/BaseOpusEngine.js":false,"src/client/voice/opus/NodeOpusEngine.js":false,"src/client/voice/opus/OpusEngineList.js":false,"src/client/voice/opus/OpusScriptEngine.js":false,"src/client/voice/pcm/ConverterEngine.js":false,"src/client/voice/pcm/ConverterEngineList.js":false,"src/client/voice/pcm/FfmpegConverterEngine.js":false,"src/client/voice/player/AudioPlayer.js":false,"src/client/voice/receiver/VoiceReadable.js":false,"src/client/voice/receiver/VoiceReceiver.js":false,"src/client/voice/util/Secretbox.js":false,"src/client/voice/util/SecretKey.js":false,"src/client/voice/util/VolumeInterface.js":false,"src/client/voice/ClientVoiceManager.js":false,"src/client/voice/VoiceBroadcast.js":false,"src/client/voice/VoiceConnection.js":false,"src/client/voice/VoiceUDPClient.js":false,"src/client/voice/VoiceWebSocket.js":false}} + +/***/ }), +/* 37 */ +/***/ (function(module, exports, __webpack_require__) { + +const UserAgentManager = __webpack_require__(73); +const RESTMethods = __webpack_require__(74); +const SequentialRequestHandler = __webpack_require__(78); +const BurstRequestHandler = __webpack_require__(79); +const APIRequest = __webpack_require__(80); +const Constants = __webpack_require__(0); + +class RESTManager { + constructor(client) { + this.client = client; + this.handlers = {}; + this.userAgentManager = new UserAgentManager(this); + this.methods = new RESTMethods(this); + this.rateLimitedEndpoints = {}; + this.globallyRateLimited = false; + } + + destroy() { + for (const handler of Object.values(this.handlers)) { + if (handler.destroy) handler.destroy(); + } + } + + push(handler, apiRequest) { + return new Promise((resolve, reject) => { + handler.push({ + request: apiRequest, + resolve, + reject, + }); + }); + } + + getRequestHandler() { + switch (this.client.options.apiRequestMethod) { + case 'sequential': + return SequentialRequestHandler; + case 'burst': + return BurstRequestHandler; + default: + throw new Error(Constants.Errors.INVALID_RATE_LIMIT_METHOD); + } + } + + makeRequest(method, url, auth, data, file, reason) { + const apiRequest = new APIRequest(this, method, url, auth, data, file, reason); + if (!this.handlers[apiRequest.route]) { + const RequestHandlerType = this.getRequestHandler(); + this.handlers[apiRequest.route] = new RequestHandlerType(this, apiRequest.route); + } + + return this.push(this.handlers[apiRequest.route], apiRequest); + } +} + +module.exports = RESTManager; + + +/***/ }), +/* 38 */ +/***/ (function(module, exports, __webpack_require__) { + +const Collection = __webpack_require__(3); + +/** + * Keeps track of mentions in a {@link Message}. + */ +class MessageMentions { + constructor(message, users, roles, everyone) { + /** + * Whether `@everyone` or `@here` were mentioned + * @type {boolean} + */ + this.everyone = Boolean(everyone); + + if (users) { + if (users instanceof Collection) { + /** + * Any users that were mentioned + * @type {Collection} + */ + this.users = new Collection(users); + } else { + this.users = new Collection(); + for (const mention of users) { + let user = message.client.users.get(mention.id); + if (!user) user = message.client.dataManager.newUser(mention); + this.users.set(user.id, user); + } + } + } else { + this.users = new Collection(); + } + + if (roles) { + if (roles instanceof Collection) { + /** + * Any roles that were mentioned + * @type {Collection} + */ + this.roles = new Collection(roles); + } else { + this.roles = new Collection(); + for (const mention of roles) { + const role = message.channel.guild.roles.get(mention); + if (role) this.roles.set(role.id, role); + } + } + } else { + this.roles = new Collection(); + } + + /** + * Content of the message + * @type {Message} + * @private + */ + this._content = message.content; + + /** + * The client the message is from + * @type {Client} + * @private + */ + this._client = message.client; + + /** + * The guild the message is in + * @type {?Guild} + * @private + */ + this._guild = message.channel.guild; + + /** + * Cached members for {@MessageMention#members} + * @type {?Collection} + * @private + */ + this._members = null; + + /** + * Cached channels for {@MessageMention#channels} + * @type {?Collection} + * @private + */ + this._channels = null; + } + + /** + * Any members that were mentioned (only in {@link TextChannel}s) + * @type {?Collection} + * @readonly + */ + get members() { + if (this._members) return this._members; + if (!this._guild) return null; + this._members = new Collection(); + this.users.forEach(user => { + const member = this._guild.member(user); + if (member) this._members.set(member.user.id, member); + }); + return this._members; + } + + /** + * Any channels that were mentioned + * @type {Collection} + * @readonly + */ + get channels() { + if (this._channels) return this._channels; + this._channels = new Collection(); + let matches; + while ((matches = this.constructor.CHANNELS_PATTERN.exec(this._content)) !== null) { + const chan = this._client.channels.get(matches[1]); + if (chan) this._channels.set(chan.id, chan); + } + return this._channels; + } +} + +/** + * Regular expression that globally matches `@everyone` and `@here` + * @type {RegExp} + */ +MessageMentions.EVERYONE_PATTERN = /@(everyone|here)/g; + +/** + * Regular expression that globally matches user mentions like `<@81440962496172032>` + * @type {RegExp} + */ +MessageMentions.USERS_PATTERN = /<@!?[0-9]+>/g; + +/** + * Regular expression that globally matches role mentions like `<@&297577916114403338>` + * @type {RegExp} + */ +MessageMentions.ROLES_PATTERN = /<@&[0-9]+>/g; + +/** + * Regular expression that globally matches channel mentions like `<#222079895583457280>` + * @type {RegExp} + */ +MessageMentions.CHANNELS_PATTERN = /<#([0-9]+)>/g; + +module.exports = MessageMentions; + + +/***/ }), +/* 39 */ +/***/ (function(module, exports) { + +/** + * Represents an attachment in a message. + */ +class MessageAttachment { + constructor(message, data) { + /** + * The client that instantiated this MessageAttachment + * @name MessageAttachment#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: message.client }); + + /** + * The message this attachment is part of + * @type {Message} + */ + this.message = message; + + this.setup(data); + } + + setup(data) { + /** + * The ID of this attachment + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The file name of this attachment + * @type {string} + */ + this.filename = data.filename; + + /** + * The size of this attachment in bytes + * @type {number} + */ + this.filesize = data.size; + + /** + * The URL to this attachment + * @type {string} + */ + this.url = data.url; + + /** + * The Proxy URL to this attachment + * @type {string} + */ + this.proxyURL = data.proxy_url; + + /** + * The height of this attachment (if an image) + * @type {?number} + */ + this.height = data.height; + + /** + * The width of this attachment (if an image) + * @type {?number} + */ + this.width = data.width; + } +} + +module.exports = MessageAttachment; + + +/***/ }), +/* 40 */ +/***/ (function(module, exports) { + +/** + * Represents an embed in a message (image/video preview, rich embed, etc.) + * This class is only used for *recieved* embeds. If you wish to send one, use the {@link RichEmbed} class. + */ +class MessageEmbed { + constructor(message, data) { + /** + * The client that instantiated this embed + * @name MessageEmbed#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: message.client }); + + /** + * The message this embed is part of + * @type {Message} + */ + this.message = message; + + this.setup(data); + } + + setup(data) { + /** + * The type of this embed + * @type {string} + */ + this.type = data.type; + + /** + * The title of this embed + * @type {?string} + */ + this.title = data.title; + + /** + * The description of this embed + * @type {?string} + */ + this.description = data.description; + + /** + * The URL of this embed + * @type {string} + */ + this.url = data.url; + + /** + * The color of the embed + * @type {number} + */ + this.color = data.color; + + /** + * The fields of this embed + * @type {MessageEmbedField[]} + */ + this.fields = []; + if (data.fields) for (const field of data.fields) this.fields.push(new MessageEmbedField(this, field)); + + /** + * The timestamp of this embed + * @type {number} + */ + this.timestamp = data.timestamp; + + /** + * The thumbnail of this embed + * @type {?MessageEmbedThumbnail} + */ + this.thumbnail = data.thumbnail ? new MessageEmbedThumbnail(this, data.thumbnail) : null; + + /** + * The image of this embed + * @type {?MessageEmbedImage} + */ + this.image = data.image ? new MessageEmbedImage(this, data.image) : null; + + /** + * The video of this embed + * @type {?MessageEmbedVideo} + */ + this.video = data.video ? new MessageEmbedVideo(this, data.video) : null; + + /** + * The author of this embed + * @type {?MessageEmbedAuthor} + */ + this.author = data.author ? new MessageEmbedAuthor(this, data.author) : null; + + /** + * The provider of this embed + * @type {?MessageEmbedProvider} + */ + this.provider = data.provider ? new MessageEmbedProvider(this, data.provider) : null; + + /** + * The footer of this embed + * @type {?MessageEmbedFooter} + */ + this.footer = data.footer ? new MessageEmbedFooter(this, data.footer) : null; + } + + /** + * The date this embed was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + + /** + * The hexadecimal version of the embed color, with a leading hash + * @type {string} + * @readonly + */ + get hexColor() { + let col = this.color.toString(16); + while (col.length < 6) col = `0${col}`; + return `#${col}`; + } +} + +/** + * Represents a thumbnail for a message embed. + */ +class MessageEmbedThumbnail { + constructor(embed, data) { + /** + * The embed this thumbnail is part of + * @type {MessageEmbed} + */ + this.embed = embed; + + this.setup(data); + } + + setup(data) { + /** + * The URL for this thumbnail + * @type {string} + */ + this.url = data.url; + + /** + * The Proxy URL for this thumbnail + * @type {string} + */ + this.proxyURL = data.proxy_url; + + /** + * The height of the thumbnail + * @type {number} + */ + this.height = data.height; + + /** + * The width of the thumbnail + * @type {number} + */ + this.width = data.width; + } +} + +/** + * Represents an image for a message embed. + */ +class MessageEmbedImage { + constructor(embed, data) { + /** + * The embed this image is part of + * @type {MessageEmbed} + */ + this.embed = embed; + + this.setup(data); + } + + setup(data) { + /** + * The URL for this image + * @type {string} + */ + this.url = data.url; + + /** + * The Proxy URL for this image + * @type {string} + */ + this.proxyURL = data.proxy_url; + + /** + * The height of the image + * @type {number} + */ + this.height = data.height; + + /** + * The width of the image + * @type {number} + */ + this.width = data.width; + } +} + +/** + * Represents a video for a message embed. + */ +class MessageEmbedVideo { + constructor(embed, data) { + /** + * The embed this video is part of + * @type {MessageEmbed} + */ + this.embed = embed; + + this.setup(data); + } + + setup(data) { + /** + * The source URL for this video + * @type {string} + */ + this.url = data.url; + + /** + * The height of the video + * @type {number} + */ + this.height = data.height; + + /** + * The width of the video + * @type {number} + */ + this.width = data.width; + } +} + +/** + * Represents a provider for a message embed. + */ +class MessageEmbedProvider { + constructor(embed, data) { + /** + * The embed this provider is part of + * @type {MessageEmbed} + */ + this.embed = embed; + + this.setup(data); + } + + setup(data) { + /** + * The name of this provider + * @type {string} + */ + this.name = data.name; + + /** + * The URL of this provider + * @type {string} + */ + this.url = data.url; + } +} + +/** + * Represents an author for a message embed. + */ +class MessageEmbedAuthor { + constructor(embed, data) { + /** + * The embed this author is part of + * @type {MessageEmbed} + */ + this.embed = embed; + + this.setup(data); + } + + setup(data) { + /** + * The name of this author + * @type {string} + */ + this.name = data.name; + + /** + * The URL of this author + * @type {string} + */ + this.url = data.url; + + /** + * The icon URL of this author + * @type {string} + */ + this.iconURL = data.icon_url; + } +} + +/** + * Represents a field for a message embed. + */ +class MessageEmbedField { + constructor(embed, data) { + /** + * The embed this footer is part of + * @type {MessageEmbed} + */ + this.embed = embed; + + this.setup(data); + } + + setup(data) { + /** + * The name of this field + * @type {string} + */ + this.name = data.name; + + /** + * The value of this field + * @type {string} + */ + this.value = data.value; + + /** + * If this field is displayed inline + * @type {boolean} + */ + this.inline = data.inline; + } +} + +/** + * Represents the footer of a message embed. + */ +class MessageEmbedFooter { + constructor(embed, data) { + /** + * The embed this footer is part of + * @type {MessageEmbed} + */ + this.embed = embed; + + this.setup(data); + } + + setup(data) { + /** + * The text in this footer + * @type {string} + */ + this.text = data.text; + + /** + * The icon URL of this footer + * @type {string} + */ + this.iconURL = data.icon_url; + + /** + * The proxy icon URL of this footer + * @type {string} + */ + this.proxyIconUrl = data.proxy_icon_url; + } +} + +MessageEmbed.Thumbnail = MessageEmbedThumbnail; +MessageEmbed.Image = MessageEmbedImage; +MessageEmbed.Video = MessageEmbedVideo; +MessageEmbed.Provider = MessageEmbedProvider; +MessageEmbed.Author = MessageEmbedAuthor; +MessageEmbed.Field = MessageEmbedField; +MessageEmbed.Footer = MessageEmbedFooter; + +module.exports = MessageEmbed; + + +/***/ }), +/* 41 */ +/***/ (function(module, exports) { + + + +/***/ }), +/* 42 */ +/***/ (function(module, exports, __webpack_require__) { + +const Collection = __webpack_require__(3); +const Emoji = __webpack_require__(16); +const ReactionEmoji = __webpack_require__(28); + +/** + * Represents a reaction to a message. + */ +class MessageReaction { + constructor(message, emoji, count, me) { + /** + * The message that this reaction refers to + * @type {Message} + */ + this.message = message; + + /** + * Whether the client has given this reaction + * @type {boolean} + */ + this.me = me; + + /** + * The number of people that have given the same reaction + * @type {number} + */ + this.count = count || 0; + + /** + * The users that have given this reaction, mapped by their ID + * @type {Collection} + */ + this.users = new Collection(); + + this._emoji = new ReactionEmoji(this, emoji.name, emoji.id); + } + + /** + * The emoji of this reaction, either an Emoji object for known custom emojis, or a ReactionEmoji + * object which has fewer properties. Whatever the prototype of the emoji, it will still have + * `name`, `id`, `identifier` and `toString()` + * @type {Emoji|ReactionEmoji} + * @readonly + */ + get emoji() { + if (this._emoji instanceof Emoji) return this._emoji; + // Check to see if the emoji has become known to the client + if (this._emoji.id) { + const emojis = this.message.client.emojis; + if (emojis.has(this._emoji.id)) { + const emoji = emojis.get(this._emoji.id); + this._emoji = emoji; + return emoji; + } + } + return this._emoji; + } + + /** + * Removes a user from this reaction. + * @param {UserResolvable} [user=this.message.client.user] The user to remove the reaction of + * @returns {Promise} + */ + remove(user = this.message.client.user) { + const message = this.message; + const userID = this.message.client.resolver.resolveUserID(user); + if (!userID) return Promise.reject(new Error('Couldn\'t resolve the user ID to remove from the reaction.')); + return message.client.rest.methods.removeMessageReaction( + message, this.emoji.identifier, userID + ); + } + + /** + * Fetch all the users that gave this reaction. Resolves with a collection of users, mapped by their IDs. + * @param {number} [limit=100] The maximum amount of users to fetch, defaults to 100 + * @param {Object} [options] Options to fetch users + * @param {Snowflake} [options.before] Limit fetching users to those with an id lower than the supplied id + * @param {Snowflake} [options.after] Limit fetching users to those with an id greater than the supplied id + * @returns {Promise>} + */ + fetchUsers(limit = 100, { after, before } = {}) { + const message = this.message; + return message.client.rest.methods.getMessageReactionUsers( + message, this.emoji.identifier, { after, before, limit } + ).then(users => { + for (const rawUser of users) { + const user = this.message.client.dataManager.newUser(rawUser); + this.users.set(user.id, user); + } + return this.users; + }); + } +} + +module.exports = MessageReaction; + + +/***/ }), +/* 43 */ +/***/ (function(module, exports, __webpack_require__) { + +const Collector = __webpack_require__(29); +const Collection = __webpack_require__(3); + +/** + * @typedef {CollectorOptions} ReactionCollectorOptions + * @property {number} max The maximum total amount of reactions to collect + * @property {number} maxEmojis The maximum number of emojis to collect + * @property {number} maxUsers The maximum number of users to react + */ + +/** + * Collects reactions on messages. + * @extends {Collector} + */ +class ReactionCollector extends Collector { + /** + * @param {Message} message The message upon which to collect reactions + * @param {CollectorFilter} filter The filter to apply to this collector + * @param {ReactionCollectorOptions} [options={}] The options to apply to this collector + */ + constructor(message, filter, options = {}) { + super(message.client, filter, options); + + /** + * The message + * @type {Message} + */ + this.message = message; + + /** + * The users which have reacted + * @type {Collection} + */ + this.users = new Collection(); + + /** + * The total number of reactions collected + * @type {number} + */ + this.total = 0; + + this.client.on('messageReactionAdd', this.listener); + } + + /** + * Handle an incoming reaction for possible collection. + * @param {MessageReaction} reaction The reaction to possibly collect + * @returns {?{key: Snowflake, value: MessageReaction}} + * @private + */ + handle(reaction) { + if (reaction.message.id !== this.message.id) return null; + return { + key: reaction.emoji.id || reaction.emoji.name, + value: reaction, + }; + } + + /** + * Check after collection to see if the collector is done. + * @param {MessageReaction} reaction The reaction that was collected + * @param {User} user The user that reacted + * @returns {?string} Reason to end the collector, if any + * @private + */ + postCheck(reaction, user) { + this.users.set(user.id, user); + if (this.options.max && ++this.total >= this.options.max) return 'limit'; + if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit'; + if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit'; + return null; + } + + /** + * Remove event listeners. + * @private + */ + cleanup() { + this.client.removeListener('messageReactionAdd', this.listener); + } +} + +module.exports = ReactionCollector; + + +/***/ }), +/* 44 */ +/***/ (function(module, exports, __webpack_require__) { + +const Collector = __webpack_require__(29); +const util = __webpack_require__(7); + +/** + * @typedef {CollectorOptions} MessageCollectorOptions + * @property {number} max The maximum amount of messages to process + * @property {number} maxMatches The maximum amount of messages to collect + */ + +/** + * Collects messages on a channel. + * @extends {Collector} + */ +class MessageCollector extends Collector { + /** + * @param {TextChannel|DMChannel|GroupDMChannel} channel The channel + * @param {CollectorFilter} filter The filter to be applied to this collector + * @param {MessageCollectorOptions} options The options to be applied to this collector + * @emits MessageCollector#message + */ + constructor(channel, filter, options = {}) { + super(channel.client, filter, options); + + /** + * The channel + * @type {TextBasedChannel} + */ + this.channel = channel; + + /** + * Total number of messages that were received in the channel during message collection + * @type {number} + */ + this.received = 0; + + this.client.on('message', this.listener); + + // For backwards compatibility (remove in v12) + if (this.options.max) this.options.maxProcessed = this.options.max; + if (this.options.maxMatches) this.options.max = this.options.maxMatches; + this._reEmitter = message => { + /** + * Emitted when the collector receives a message. + * @event MessageCollector#message + * @param {Message} message The message + * @deprecated + */ + this.emit('message', message); + }; + this.on('collect', this._reEmitter); + } + + // Remove in v12 + on(eventName, listener) { + if (eventName === 'message') { + listener = util.deprecate(listener, 'MessageCollector will soon no longer emit "message", use "collect" instead'); + } + super.on(eventName, listener); + } + + /** + * Handle an incoming message for possible collection. + * @param {Message} message The message that could be collected + * @returns {?{key: Snowflake, value: Message}} + * @private + */ + handle(message) { + if (message.channel.id !== this.channel.id) return null; + this.received++; + return { + key: message.id, + value: message, + }; + } + + /** + * Check after collection to see if the collector is done. + * @returns {?string} Reason to end the collector, if any + * @private + */ + postCheck() { + // Consider changing the end reasons for v12 + if (this.options.maxMatches && this.collected.size >= this.options.max) return 'matchesLimit'; + if (this.options.max && this.received >= this.options.maxProcessed) return 'limit'; + return null; + } + + /** + * Removes event listeners. + * @private + */ + cleanup() { + this.removeListener('collect', this._reEmitter); + this.client.removeListener('message', this.listener); + } +} + +module.exports = MessageCollector; + + +/***/ }), +/* 45 */ +/***/ (function(module, exports) { + +/* +{ splash: null, + id: '123123123', + icon: '123123123', + name: 'name' } +*/ + +/** + * Represents a guild that the client only has limited information for - e.g. from invites. + */ +class PartialGuild { + constructor(client, data) { + /** + * The client that instantiated this PartialGuild + * @name PartialGuild#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + this.setup(data); + } + + setup(data) { + /** + * The ID of this guild + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The name of this guild + * @type {string} + */ + this.name = data.name; + + /** + * The hash of this guild's icon + * @type {?string} + */ + this.icon = data.icon; + + /** + * The hash of the guild splash image (VIP only) + * @type {?string} + */ + this.splash = data.splash; + } +} + +module.exports = PartialGuild; + + +/***/ }), +/* 46 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); + +/* +{ type: 0, id: '123123', name: 'heavy-testing' } } +*/ + +/** + * Represents a guild channel that the client only has limited information for - e.g. from invites. + */ +class PartialGuildChannel { + constructor(client, data) { + /** + * The client that instantiated this PartialGuildChannel + * @name PartialGuildChannel#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + + this.setup(data); + } + + setup(data) { + /** + * The ID of this guild channel + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The name of this guild channel + * @type {string} + */ + this.name = data.name; + + /** + * The type of this guild channel - `text` or `voice` + * @type {string} + */ + this.type = Constants.ChannelTypes.TEXT === data.type ? 'text' : 'voice'; + } +} + +module.exports = PartialGuildChannel; + + +/***/ }), +/* 47 */ +/***/ (function(module, exports, __webpack_require__) { + +const Collection = __webpack_require__(3); +const Snowflake = __webpack_require__(5); +const Webhook = __webpack_require__(23); +const Invite = __webpack_require__(30); + +/** + * The target type of an entry, e.g. `GUILD`. Here are the available types: + * * GUILD + * * CHANNEL + * * USER + * * ROLE + * * INVITE + * * WEBHOOK + * * EMOJI + * * MESSAGE + * @typedef {string} AuditLogTargetType + */ + +/** + * Key mirror of all available audit log targets. + * @name GuildAuditLogs.Targets + * @type {AuditLogTargetType} + */ +const Targets = { + ALL: 'ALL', + GUILD: 'GUILD', + CHANNEL: 'CHANNEL', + USER: 'USER', + ROLE: 'ROLE', + INVITE: 'INVITE', + WEBHOOK: 'WEBHOOK', + EMOJI: 'EMOJI', + MESSAGE: 'MESSAGE', +}; + +/** + * The action of an entry. Here are the available actions: + * * ALL: null + * * GUILD_UPDATE: 1 + * * CHANNEL_CREATE: 10 + * * CHANNEL_UPDATE: 11 + * * CHANNEL_DELETE: 12 + * * CHANNEL_OVERWRITE_CREATE: 13 + * * CHANNEL_OVERWRITE_UPDATE: 14 + * * CHANNEL_OVERWRITE_DELETE: 15 + * * MEMBER_KICK: 20 + * * MEMBER_PRUNE: 21 + * * MEMBER_BAN_ADD: 22 + * * MEMBER_BAN_REMOVE: 23 + * * MEMBER_UPDATE: 24 + * * MEMBER_ROLE_UPDATE: 25 + * * ROLE_CREATE: 30 + * * ROLE_UPDATE: 31 + * * ROLE_DELETE: 32 + * * INVITE_CREATE: 40 + * * INVITE_UPDATE: 41 + * * INVITE_DELETE: 42 + * * WEBHOOK_CREATE: 50 + * * WEBHOOK_UPDATE: 51 + * * WEBHOOK_DELETE: 50 + * * EMOJI_CREATE: 60 + * * EMOJI_UPDATE: 61 + * * EMOJI_DELETE: 62 + * * MESSAGE_DELETE: 72 + * @typedef {?number|string} AuditLogAction + */ + +/** + * All available actions keyed under their names to their numeric values. + * @name GuildAuditLogs.Actions + * @type {AuditLogAction} + */ +const Actions = { + ALL: null, + GUILD_UPDATE: 1, + CHANNEL_CREATE: 10, + CHANNEL_UPDATE: 11, + CHANNEL_DELETE: 12, + CHANNEL_OVERWRITE_CREATE: 13, + CHANNEL_OVERWRITE_UPDATE: 14, + CHANNEL_OVERWRITE_DELETE: 15, + MEMBER_KICK: 20, + MEMBER_PRUNE: 21, + MEMBER_BAN_ADD: 22, + MEMBER_BAN_REMOVE: 23, + MEMBER_UPDATE: 24, + MEMBER_ROLE_UPDATE: 25, + ROLE_CREATE: 30, + ROLE_UPDATE: 31, + ROLE_DELETE: 32, + INVITE_CREATE: 40, + INVITE_UPDATE: 41, + INVITE_DELETE: 42, + WEBHOOK_CREATE: 50, + WEBHOOK_UPDATE: 51, + WEBHOOK_DELETE: 52, + EMOJI_CREATE: 60, + EMOJI_UPDATE: 61, + EMOJI_DELETE: 62, + MESSAGE_DELETE: 72, +}; + + +/** + * Audit logs entries are held in this class. + */ +class GuildAuditLogs { + constructor(guild, data) { + if (data.users) for (const user of data.users) guild.client.dataManager.newUser(user); + + /** + * Cached webhooks + * @type {Collection} + * @private + */ + this.webhooks = new Collection(); + if (data.webhooks) { + for (const hook of data.webhooks) { + this.webhooks.set(hook.id, new Webhook(guild.client, hook)); + } + } + + /** + * The entries for this guild's audit logs + * @type {Collection} + */ + this.entries = new Collection(); + for (const item of data.audit_log_entries) { + const entry = new GuildAuditLogsEntry(this, guild, item); + this.entries.set(entry.id, entry); + } + } + + /** + * Handles possible promises for entry targets. + * @returns {Promise} + */ + static build(...args) { + const logs = new GuildAuditLogs(...args); + return Promise.all(logs.entries.map(e => e.target)).then(() => logs); + } + + /** + * The target of an entry. It can be one of: + * * A guild + * * A user + * * A role + * * An emoji + * * An invite + * * A webhook + * * An object where the keys represent either the new value or the old value + * @typedef {?Object|Guild|User|Role|Emoji|Invite|Webhook} AuditLogEntryTarget + */ + + /** + * Find target type from entry action. + * @param {number} target The action target + * @returns {?string} + */ + static targetType(target) { + if (target < 10) return Targets.GUILD; + if (target < 20) return Targets.CHANNEL; + if (target < 30) return Targets.USER; + if (target < 40) return Targets.ROLE; + if (target < 50) return Targets.INVITE; + if (target < 60) return Targets.WEBHOOK; + if (target < 70) return Targets.EMOJI; + if (target < 80) return Targets.MESSAGE; + return null; + } + + /** + * The action type of an entry, e.g. `CREATE`. Here are the available types: + * * CREATE + * * DELETE + * * UPDATE + * * ALL + * @typedef {string} AuditLogActionType + */ + + + /** + * Finds the action type from the entry action. + * @param {AuditLogAction} action The action target + * @returns {AuditLogActionType} + */ + static actionType(action) { + if ([ + Actions.CHANNEL_CREATE, + Actions.CHANNEL_OVERWRITE_CREATE, + Actions.MEMBER_BAN_REMOVE, + Actions.ROLE_CREATE, + Actions.INVITE_CREATE, + Actions.WEBHOOK_CREATE, + Actions.EMOJI_CREATE, + ].includes(action)) return 'CREATE'; + + if ([ + Actions.CHANNEL_DELETE, + Actions.CHANNEL_OVERWRITE_DELETE, + Actions.MEMBER_KICK, + Actions.MEMBER_PRUNE, + Actions.MEMBER_BAN_ADD, + Actions.ROLE_DELETE, + Actions.INVITE_DELETE, + Actions.WEBHOOK_DELETE, + Actions.EMOJI_DELETE, + Actions.MESSAGE_DELETE, + ].includes(action)) return 'DELETE'; + + if ([ + Actions.GUILD_UPDATE, + Actions.CHANNEL_UPDATE, + Actions.CHANNEL_OVERWRITE_UPDATE, + Actions.MEMBER_UPDATE, + Actions.MEMBER_ROLE_UPDATE, + Actions.ROLE_UPDATE, + Actions.INVITE_UPDATE, + Actions.WEBHOOK_UPDATE, + Actions.EMOJI_UPDATE, + ].includes(action)) return 'UPDATE'; + + return 'ALL'; + } +} + +/** + * Audit logs entry. + */ +class GuildAuditLogsEntry { + constructor(logs, guild, data) { + const targetType = GuildAuditLogs.targetType(data.action_type); + /** + * The target type of this entry + * @type {AuditLogTargetType} + */ + this.targetType = targetType; + + /** + * The action type of this entry + * @type {AuditLogActionType} + */ + this.actionType = GuildAuditLogs.actionType(data.action_type); + + /** + * Specific action type of this entry in its string representation + * @type {AuditLogAction} + */ + this.action = Object.keys(Actions).find(k => Actions[k] === data.action_type); + + /** + * The reason of this entry + * @type {?string} + */ + this.reason = data.reason || null; + + /** + * The user that executed this entry + * @type {User} + */ + this.executor = guild.client.users.get(data.user_id); + + /** + * An entry in the audit log representing a specific change. + * @typedef {object} AuditLogChange + * @property {string} key The property that was changed, e.g. `nick` for nickname changes + * @property {*} [old] The old value of the change, e.g. for nicknames, the old nickname + * @property {*} [new] The new value of the change, e.g. for nicknames, the new nickname + */ + + /** + * Specific property changes + * @type {AuditLogChange[]} + */ + this.changes = data.changes ? data.changes.map(c => ({ key: c.key, old: c.old_value, new: c.new_value })) : null; + + /** + * The ID of this entry + * @type {Snowflake} + */ + this.id = data.id; + + /** + * Any extra data from the entry + * @type {?Object|Role|GuildMember} + */ + this.extra = null; + if (data.options) { + if (data.action_type === Actions.MEMBER_PRUNE) { + this.extra = { + removed: data.options.members_removed, + days: data.options.delete_member_days, + }; + } else if (data.action_type === Actions.MESSAGE_DELETE) { + this.extra = { + count: data.options.count, + channel: guild.channels.get(data.options.channel_id), + }; + } else { + switch (data.options.type) { + case 'member': + this.extra = guild.members.get(data.options.id); + if (!this.extra) this.extra = { id: data.options.id }; + break; + case 'role': + this.extra = guild.roles.get(data.options.id); + if (!this.extra) this.extra = { id: data.options.id, name: data.options.role_name }; + break; + default: + break; + } + } + } + + if ([Targets.USER, Targets.GUILD].includes(targetType)) { + /** + * The target of this entry + * @type {AuditLogEntryTarget} + */ + this.target = guild.client[`${targetType.toLowerCase()}s`].get(data.target_id); + } else if (targetType === Targets.WEBHOOK) { + this.target = logs.webhooks.get(data.target_id) || + new Webhook(guild.client, + this.changes.reduce((o, c) => { + o[c.key] = c.new || c.old; + return o; + }, { + id: data.target_id, + guild_id: guild.id, + })); + } else if (targetType === Targets.INVITE) { + const changes = this.changes.reduce((o, c) => { + o[c.key] = c.new || c.old; + return o; + }, { + id: data.target_id, + guild, + }); + changes.channel = guild.channels.get(changes.channel_id); + this.target = new Invite(guild.client, changes); + } else if (targetType === Targets.MESSAGE) { + this.target = guild.client.users.get(data.target_id); + } else { + this.target = guild[`${targetType.toLowerCase()}s`].get(data.target_id); + } + } + + /** + * The timestamp this entry was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return Snowflake.deconstruct(this.id).timestamp; + } + + /** + * The time this entry was created + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } +} + +GuildAuditLogs.Actions = Actions; +GuildAuditLogs.Targets = Targets; +GuildAuditLogs.Entry = GuildAuditLogsEntry; + +module.exports = GuildAuditLogs; + + +/***/ }), +/* 48 */ +/***/ (function(module, exports) { + +/** + * A base class for different types of rate limiting handlers for the REST API. + * @private + */ +class RequestHandler { + /** + * @param {RESTManager} restManager The REST manager to use + */ + constructor(restManager) { + /** + * The RESTManager that instantiated this RequestHandler + * @type {RESTManager} + */ + this.restManager = restManager; + + /** + * A list of requests that have yet to be processed + * @type {APIRequest[]} + */ + this.queue = []; + } + + /** + * Whether or not the client is being rate limited on every endpoint + * @type {boolean} + * @readonly + */ + get globalLimit() { + return this.restManager.globallyRateLimited; + } + + set globalLimit(value) { + this.restManager.globallyRateLimited = value; + } + + /** + * Push a new API request into this bucket. + * @param {APIRequest} request The new request to push into the queue + */ + push(request) { + this.queue.push(request); + } + + /** + * Attempts to get this RequestHandler to process its current queue. + */ + handle() {} // eslint-disable-line no-empty-function + + destroy() { + this.queue = []; + } +} + +module.exports = RequestHandler; + + +/***/ }), +/* 49 */ +/***/ (function(module, exports, __webpack_require__) { + +const GuildChannel = __webpack_require__(18); + +/** + * Represents a guild category channel on Discord. + * @extends {GuildChannel} + */ +class CategoryChannel extends GuildChannel { + constructor(guild, data) { + super(guild, data); + this.type = 'category'; + } + /** + * The channels that are part of this category + * @type {?Collection} + * @readonly + */ + get children() { + return this.guild.channels.filter(c => c.parentID === this.id); + } +} + +module.exports = CategoryChannel; + + +/***/ }), +/* 50 */ +/***/ (function(module, exports) { + +/** + * Represents a permission overwrite for a role or member in a guild channel. + */ +class PermissionOverwrites { + constructor(guildChannel, data) { + /** + * The GuildChannel this overwrite is for + * @name PermissionOverwrites#channel + * @type {GuildChannel} + * @readonly + */ + Object.defineProperty(this, 'channel', { value: guildChannel }); + + if (data) this.setup(data); + } + + setup(data) { + /** + * The ID of this overwrite, either a user ID or a role ID + * @type {Snowflake} + */ + this.id = data.id; + + /** + * The type of this overwrite + * @type {string} + */ + this.type = data.type; + + this.deny = data.deny; + this.allow = data.allow; + } + + /** + * Delete this Permission Overwrite. + * @param {string} [reason] Reason for deleting this overwrite + * @returns {Promise} + */ + delete(reason) { + return this.channel.client.rest.methods.deletePermissionOverwrites(this, reason); + } +} + +module.exports = PermissionOverwrites; + + +/***/ }), +/* 51 */ +/***/ (function(module, exports, __webpack_require__) { + +const Channel = __webpack_require__(11); +const TextBasedChannel = __webpack_require__(14); +const Collection = __webpack_require__(3); + +/** + * Represents a direct message channel between two users. + * @extends {Channel} + * @implements {TextBasedChannel} + */ +class DMChannel extends Channel { + constructor(client, data) { + super(client, data); + this.type = 'dm'; + this.messages = new Collection(); + this._typing = new Map(); + } + + setup(data) { + super.setup(data); + + /** + * The recipient on the other end of the DM + * @type {User} + */ + this.recipient = this.client.dataManager.newUser(data.recipients[0]); + + this.lastMessageID = data.last_message_id; + } + + /** + * When concatenated with a string, this automatically concatenates the recipient's mention instead of the + * DM channel object. + * @returns {string} + */ + toString() { + return this.recipient.toString(); + } + + // These are here only for documentation purposes - they are implemented by TextBasedChannel + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendFiles() {} + sendCode() {} + fetchMessage() {} + fetchMessages() {} + fetchPinnedMessages() {} + search() {} + startTyping() {} + stopTyping() {} + get typing() {} + get typingCount() {} + createCollector() {} + createMessageCollector() {} + awaitMessages() {} + // Doesn't work on DM channels; bulkDelete() {} + acknowledge() {} + _cacheMessage() {} +} + +TextBasedChannel.applyToClass(DMChannel, true, ['bulkDelete']); + +module.exports = DMChannel; + + +/***/ }), +/* 52 */ +/***/ (function(module, exports, __webpack_require__) { + +const GuildChannel = __webpack_require__(18); +const TextBasedChannel = __webpack_require__(14); +const Collection = __webpack_require__(3); + +/** + * Represents a guild text channel on Discord. + * @extends {GuildChannel} + * @implements {TextBasedChannel} + */ +class TextChannel extends GuildChannel { + constructor(guild, data) { + super(guild, data); + this.type = 'text'; + this.messages = new Collection(); + this._typing = new Map(); + } + + setup(data) { + super.setup(data); + + /** + * The topic of the text channel + * @type {?string} + */ + this.topic = data.topic; + + /** + * If the Discord considers this channel NSFW + * @type {boolean} + * @readonly + */ + this.nsfw = Boolean(data.nsfw); + + this.lastMessageID = data.last_message_id; + } + + /** + * A collection of members that can see this channel, mapped by their ID + * @type {Collection} + * @readonly + */ + get members() { + const members = new Collection(); + for (const member of this.guild.members.values()) { + if (this.permissionsFor(member).has('READ_MESSAGES')) { + members.set(member.id, member); + } + } + return members; + } + + /** + * Fetch all webhooks for the channel. + * @returns {Promise>} + */ + fetchWebhooks() { + return this.client.rest.methods.getChannelWebhooks(this); + } + + /** + * Create a webhook for the channel. + * @param {string} name The name of the webhook + * @param {BufferResolvable|Base64Resolvable} [avatar] The avatar for the webhook + * @param {string} [reason] Reason for creating this webhook + * @returns {Promise} webhook The created webhook + * @example + * channel.createWebhook('Snek', 'https://i.imgur.com/mI8XcpG.jpg') + * .then(webhook => console.log(`Created webhook ${webhook}`)) + * .catch(console.error) + */ + createWebhook(name, avatar, reason) { + if (typeof avatar === 'string' && avatar.startsWith('data:')) { + return this.client.rest.methods.createWebhook(this, name, avatar, reason); + } else { + return this.client.resolver.resolveImage(avatar).then(data => + this.client.rest.methods.createWebhook(this, name, data, reason) + ); + } + } + + // These are here only for documentation purposes - they are implemented by TextBasedChannel + /* eslint-disable no-empty-function */ + send() {} + sendMessage() {} + sendEmbed() {} + sendFile() {} + sendFiles() {} + sendCode() {} + fetchMessage() {} + fetchMessages() {} + fetchPinnedMessages() {} + search() {} + startTyping() {} + stopTyping() {} + get typing() {} + get typingCount() {} + createCollector() {} + createMessageCollector() {} + awaitMessages() {} + bulkDelete() {} + acknowledge() {} + _cacheMessage() {} +} + +TextBasedChannel.applyToClass(TextChannel, true); + +module.exports = TextChannel; + + +/***/ }), +/* 53 */ +/***/ (function(module, exports, __webpack_require__) { + +const GuildChannel = __webpack_require__(18); +const Collection = __webpack_require__(3); + +/** + * Represents a guild voice channel on Discord. + * @extends {GuildChannel} + */ +class VoiceChannel extends GuildChannel { + constructor(guild, data) { + super(guild, data); + + /** + * The members in this voice channel + * @type {Collection} + */ + this.members = new Collection(); + + this.type = 'voice'; + } + + setup(data) { + super.setup(data); + + /** + * The bitrate of this voice channel + * @type {number} + */ + this.bitrate = data.bitrate * 0.001; + + /** + * The maximum amount of users allowed in this channel - 0 means unlimited. + * @type {number} + */ + this.userLimit = data.user_limit; + } + + /** + * The voice connection for this voice channel, if the client is connected + * @type {?VoiceConnection} + * @readonly + */ + get connection() { + const connection = this.guild.voiceConnection; + if (connection && connection.channel.id === this.id) return connection; + return null; + } + + /** + * Checks if the voice channel is full + * @type {boolean} + * @readonly + */ + get full() { + return this.userLimit > 0 && this.members.size >= this.userLimit; + } + + /** + * Checks if the client has permission join the voice channel + * @type {boolean} + * @readonly + */ + get joinable() { + if (this.client.browser) return false; + if (!this.permissionsFor(this.client.user).has('CONNECT')) return false; + if (this.full && !this.permissionsFor(this.client.user).has('MOVE_MEMBERS')) return false; + return true; + } + + /** + * Checks if the client has permission to send audio to the voice channel + * @type {boolean} + * @readonly + */ + get speakable() { + return this.permissionsFor(this.client.user).has('SPEAK'); + } + + /** + * Sets the bitrate of the channel (in kbps). + * @param {number} bitrate The new bitrate + * @param {string} [reason] Reason for changing the channel's bitrate + * @returns {Promise} + * @example + * // Set the bitrate of a voice channel + * voiceChannel.setBitrate(48) + * .then(vc => console.log(`Set bitrate to ${vc.bitrate}kbps for ${vc.name}`)) + * .catch(console.error); + */ + setBitrate(bitrate, reason) { + bitrate *= 1000; + return this.edit({ bitrate }, reason); + } + + /** + * Sets the user limit of the channel. + * @param {number} userLimit The new user limit + * @param {string} [reason] Reason for changing the user limit + * @returns {Promise} + * @example + * // Set the user limit of a voice channel + * voiceChannel.setUserLimit(42) + * .then(vc => console.log(`Set user limit to ${vc.userLimit} for ${vc.name}`)) + * .catch(console.error); + */ + setUserLimit(userLimit, reason) { + return this.edit({ userLimit }, reason); + } + + /** + * Attempts to join this voice channel. + * @returns {Promise} + * @example + * // Join a voice channel + * voiceChannel.join() + * .then(connection => console.log('Connected!')) + * .catch(console.error); + */ + join() { + if (this.client.browser) return Promise.reject(new Error('Voice connections are not available in browsers.')); + return this.client.voice.joinChannel(this); + } + + /** + * Leaves this voice channel. + * @example + * // Leave a voice channel + * voiceChannel.leave(); + */ + leave() { + if (this.client.browser) return; + const connection = this.client.voice.connections.get(this.guild.id); + if (connection && connection.channel.id === this.id) connection.disconnect(); + } +} + +module.exports = VoiceChannel; + + +/***/ }), +/* 54 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(Buffer) {const browser = typeof window !== 'undefined'; +const EventEmitter = __webpack_require__(19); +const Constants = __webpack_require__(0); +const zlib = __webpack_require__(41); +const PacketManager = __webpack_require__(83); +const erlpack = (function findErlpack() { + try { + const e = __webpack_require__(122); + if (!e.pack) return null; + return e; + } catch (e) { + return null; + } +}()); + +const WebSocket = (function findWebSocket() { + if (browser) return window.WebSocket; // eslint-disable-line no-undef + try { + return __webpack_require__(123); + } catch (e) { + return __webpack_require__(124); + } +}()); + +/** + * Abstracts a WebSocket connection with decoding/encoding for the Discord gateway. + * @private + */ +class WebSocketConnection extends EventEmitter { + /** + * @param {WebSocketManager} manager The WebSocket manager + * @param {string} gateway The WebSocket gateway to connect to + */ + constructor(manager, gateway) { + super(); + /** + * The WebSocket Manager of this connection + * @type {WebSocketManager} + */ + this.manager = manager; + + /** + * The client this belongs to + * @type {Client} + */ + this.client = manager.client; + + /** + * The WebSocket connection itself + * @type {WebSocket} + */ + this.ws = null; + + /** + * The current sequence of the WebSocket + * @type {number} + */ + this.sequence = -1; + + /** + * The current status of the client + * @type {number} + */ + this.status = Constants.Status.IDLE; + + /** + * The Packet Manager of the connection + * @type {WebSocketPacketManager} + */ + this.packetManager = new PacketManager(this); + + /** + * The last time a ping was sent (a timestamp) + * @type {number} + */ + this.lastPingTimestamp = 0; + + /** + * Contains the rate limit queue and metadata + * @type {Object} + */ + this.ratelimit = { + queue: [], + remaining: 120, + total: 120, + time: 60e3, + resetTimer: null, + }; + this.connect(gateway); + + /** + * Events that are disabled (will not be processed) + * @type {Object} + */ + this.disabledEvents = {}; + + /** + * The sequence on WebSocket close + * @type {number} + */ + this.closeSequence = 0; + + /** + * Whether or not the WebSocket is expecting to be closed + * @type {boolean} + */ + this.expectingClose = false; + for (const event of this.client.options.disabledEvents) this.disabledEvents[event] = true; + } + + /** + * Causes the client to be marked as ready and emits the ready event. + * @returns {void} + */ + triggerReady() { + if (this.status === Constants.Status.READY) { + this.debug('Tried to mark self as ready, but already ready'); + return; + } + /** + * Emitted when the client becomes ready to start working. + * @event Client#ready + */ + this.status = Constants.Status.READY; + this.client.emit(Constants.Events.READY); + this.packetManager.handleQueue(); + } + + /** + * Checks whether the client is ready to be marked as ready. + * @returns {void} + */ + checkIfReady() { + if (this.status === Constants.Status.READY || this.status === Constants.Status.NEARLY) return false; + let unavailableGuilds = 0; + for (const guild of this.client.guilds.values()) { + if (!guild.available) unavailableGuilds++; + } + if (unavailableGuilds === 0) { + this.status = Constants.Status.NEARLY; + if (!this.client.options.fetchAllMembers) return this.triggerReady(); + // Fetch all members before marking self as ready + const promises = this.client.guilds.map(g => g.fetchMembers()); + Promise.all(promises) + .then(() => this.triggerReady()) + .catch(e => { + this.debug(`Failed to fetch all members before ready! ${e}`); + this.triggerReady(); + }); + } + return true; + } + + // Util + /** + * Emits a debug message. + * @param {string} message Debug message + * @returns {void} + */ + debug(message) { + if (message instanceof Error) message = message.stack; + return this.manager.debug(`[connection] ${message}`); + } + + /** + * Attempts to serialise data from the WebSocket. + * @param {string|Object} data Data to unpack + * @returns {Object} + */ + unpack(data) { + if (data instanceof ArrayBuffer) data = Buffer.from(new Uint8Array(data)); + + if (erlpack && typeof data !== 'string') return erlpack.unpack(data); + else if (data instanceof Buffer) data = zlib.inflateSync(data).toString(); + + return JSON.parse(data); + } + + /** + * Packs an object ready to be sent. + * @param {Object} data Data to pack + * @returns {string|Buffer} + */ + pack(data) { + return erlpack ? erlpack.pack(data) : JSON.stringify(data); + } + + /** + * Processes the current WebSocket queue. + */ + processQueue() { + if (this.ratelimit.remaining === 0) return; + if (this.ratelimit.queue.length === 0) return; + if (this.ratelimit.remaining === 120) { + this.ratelimit.resetTimer = this.client.setTimeout(() => { + this.ratelimit.remaining = 60; + this.processQueue(); + }, this.ratelimit.time); + } + while (this.ratelimit.remaining > 0) { + const item = this.ratelimit.queue.shift(); + if (!item) return; + this._send(item); + this.ratelimit.remaining--; + } + } + + /** + * Sends data, bypassing the queue. + * @param {Object} data Packet to send + * @returns {void} + */ + _send(data) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { + this.debug(`Tried to send packet ${data} but no WebSocket is available!`); + return; + } + this.ws.send(this.pack(data)); + } + + /** + * Adds data to the queue to be sent. + * @param {Object} data Packet to send + * @returns {void} + */ + send(data) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { + this.debug(`Tried to send packet ${data} but no WebSocket is available!`); + return; + } + this.ratelimit.queue.push(data); + this.processQueue(); + } + + /** + * Creates a connection to a gateway. + * @param {string} gateway The gateway to connect to + * @param {number} [after=0] How long to wait before connecting + * @param {boolean} [force=false] Whether or not to force a new connection even if one already exists + * @returns {boolean} + */ + connect(gateway = this.gateway, after = 0, force = false) { + if (after) return this.client.setTimeout(() => this.connect(gateway, 0, force), after); // eslint-disable-line + if (this.ws && !force) { + this.debug('WebSocket connection already exists'); + return false; + } else if (typeof gateway !== 'string') { + this.debug(`Tried to connect to an invalid gateway: ${gateway}`); + return false; + } + this.expectingClose = false; + this.gateway = gateway; + this.debug(`Connecting to ${gateway}`); + const ws = this.ws = new WebSocket(gateway); + if (browser) ws.binaryType = 'arraybuffer'; + ws.onmessage = this.onMessage.bind(this); + ws.onopen = this.onOpen.bind(this); + ws.onerror = this.onError.bind(this); + ws.onclose = this.onClose.bind(this); + this.status = Constants.Status.CONNECTING; + return true; + } + + /** + * Destroys the connection. + * @returns {boolean} + */ + destroy() { + const ws = this.ws; + if (!ws) { + this.debug('Attempted to destroy WebSocket but no connection exists!'); + return false; + } + this.heartbeat(-1); + this.expectingClose = true; + ws.close(1000); + this.packetManager.handleQueue(); + this.ws = null; + this.status = Constants.Status.DISCONNECTED; + return true; + } + + /** + * Called whenever a message is received. + * @param {Event} event Event received + * @returns {boolean} + */ + onMessage(event) { + let data; + try { + data = this.unpack(event.data); + } catch (err) { + this.emit('debug', err); + } + return this.onPacket(data); + } + + /** + * Sets the current sequence of the connection. + * @param {number} s New sequence + */ + setSequence(s) { + this.sequence = s > this.sequence ? s : this.sequence; + } + + /** + * Called whenever a packet is received. + * @param {Object} packet Received packet + * @returns {boolean} + */ + onPacket(packet) { + if (!packet) { + this.debug('Received null packet'); + return false; + } + this.client.emit('raw', packet); + switch (packet.op) { + case Constants.OPCodes.HELLO: + return this.heartbeat(packet.d.heartbeat_interval); + case Constants.OPCodes.RECONNECT: + return this.reconnect(); + case Constants.OPCodes.INVALID_SESSION: + if (!packet.d) this.sessionID = null; + this.sequence = -1; + this.debug('Session invalidated -- will identify with a new session'); + return this.identify(packet.d ? 2500 : 0); + case Constants.OPCodes.HEARTBEAT_ACK: + return this.ackHeartbeat(); + case Constants.OPCodes.HEARTBEAT: + return this.heartbeat(); + default: + return this.packetManager.handle(packet); + } + } + + /** + * Called whenever a connection is opened to the gateway. + * @param {Event} event Received open event + */ + onOpen(event) { + if (event && event.target && event.target.url) this.gateway = event.target.url; + this.debug(`Connected to gateway ${this.gateway}`); + this.identify(); + } + + /** + * Causes a reconnection to the gateway. + */ + reconnect() { + this.debug('Attemping to reconnect in 5500ms...'); + /** + * Emitted whenever the client tries to reconnect to the WebSocket. + * @event Client#reconnecting + */ + this.client.emit(Constants.Events.RECONNECTING); + this.connect(this.gateway, 5500, true); + } + + /** + * Called whenever an error occurs with the WebSocket. + * @param {Error} error The error that occurred + */ + onError(error) { + if (error && error.message === 'uWs client connection error') { + this.reconnect(); + return; + } + /** + * Emitted whenever the client's WebSocket encounters a connection error. + * @event Client#error + * @param {Error} error The encountered error + */ + this.client.emit(Constants.Events.ERROR, error); + } + + /** + * @external CloseEvent + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent} + */ + + /** + * Called whenever a connection to the gateway is closed. + * @param {CloseEvent} event Close event that was received + */ + onClose(event) { + this.debug(`${this.expectingClose ? 'Client' : 'Server'} closed the WebSocket connection: ${event.code}`); + this.closeSequence = this.sequence; + // Reset the state before trying to fix anything + this.emit('close', event); + this.heartbeat(-1); + // Should we reconnect? + if (event.code === 1000 ? this.expectingClose : Constants.WSCodes[event.code]) { + this.expectingClose = false; + /** + * Emitted when the client's WebSocket disconnects and will no longer attempt to reconnect. + * @event Client#disconnect + * @param {CloseEvent} event The WebSocket close event + */ + this.client.emit(Constants.Events.DISCONNECT, event); + this.debug(Constants.WSCodes[event.code]); + this.destroy(); + return; + } + this.expectingClose = false; + this.reconnect(); + } + + // Heartbeat + /** + * Acknowledges a heartbeat. + */ + ackHeartbeat() { + this.debug(`Heartbeat acknowledged, latency of ${Date.now() - this.lastPingTimestamp}ms`); + this.client._pong(this.lastPingTimestamp); + } + + /** + * Sends a heartbeat or sets an interval for sending heartbeats. + * @param {number} [time] If -1, clears the interval, any other number sets an interval + * If no value is given, a heartbeat will be sent instantly + */ + heartbeat(time) { + if (!isNaN(time)) { + if (time === -1) { + this.debug('Clearing heartbeat interval'); + this.client.clearInterval(this.heartbeatInterval); + this.heartbeatInterval = null; + } else { + this.debug(`Setting a heartbeat interval for ${time}ms`); + this.heartbeatInterval = this.client.setInterval(() => this.heartbeat(), time); + } + return; + } + this.debug('Sending a heartbeat'); + this.lastPingTimestamp = Date.now(); + this.send({ + op: Constants.OPCodes.HEARTBEAT, + d: this.sequence, + }); + } + + // Identification + /** + * Identifies the client on a connection. + * @param {number} [after] How long to wait before identifying + * @returns {void} + */ + identify(after) { + if (after) return this.client.setTimeout(this.identify.bind(this), after); + return this.sessionID ? this.identifyResume() : this.identifyNew(); + } + + /** + * Identifies as a new connection on the gateway. + * @returns {void} + */ + identifyNew() { + if (!this.client.token) { + this.debug('No token available to identify a new session with'); + return; + } + // Clone the generic payload and assign the token + const d = Object.assign({ token: this.client.token }, this.client.options.ws); + + // Sharding stuff + const { shardId, shardCount } = this.client.options; + if (shardCount > 0) d.shard = [Number(shardId), Number(shardCount)]; + + // Send the payload + this.debug('Identifying as a new session'); + this.send({ op: Constants.OPCodes.IDENTIFY, d }); + } + + /** + * Resumes a session on the gateway. + * @returns {void} + */ + identifyResume() { + if (!this.sessionID) { + this.debug('Warning: wanted to resume but session ID not available; identifying as a new session instead'); + return this.identifyNew(); + } + this.debug(`Attempting to resume session ${this.sessionID}`); + + const d = { + token: this.client.token, + session_id: this.sessionID, + seq: this.sequence, + }; + + return this.send({ + op: Constants.OPCodes.RESUME, + d, + }); + } +} + +/** + * Encoding the WebSocket connections will use. + * @type {string} + */ +WebSocketConnection.ENCODING = erlpack ? 'etf' : 'json'; +WebSocketConnection.WebSocket = WebSocket; + +module.exports = WebSocketConnection; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12).Buffer)) + +/***/ }), +/* 55 */ +/***/ (function(module, exports, __webpack_require__) { + +const User = __webpack_require__(9); +const Collection = __webpack_require__(3); +const ClientUserSettings = __webpack_require__(56); +const ClientUserGuildSettings = __webpack_require__(57); +const Constants = __webpack_require__(0); +const util = __webpack_require__(7); + +/** + * Represents the logged in client's Discord user. + * @extends {User} + */ +class ClientUser extends User { + setup(data) { + super.setup(data); + + /** + * Whether or not this account has been verified + * @type {boolean} + */ + this.verified = data.verified; + + /** + * The email of this account + * This is only filled when using a user account. + * @type {?string} + */ + this.email = data.email; + this.localPresence = {}; + this._typing = new Map(); + + /** + * A Collection of friends for the logged in user + * This is only filled when using a user account. + * @type {Collection} + */ + this.friends = new Collection(); + + /** + * A Collection of blocked users for the logged in user + * This is only filled when using a user account. + * @type {Collection} + */ + this.blocked = new Collection(); + + /** + * A Collection of notes for the logged in user + * This is only filled when using a user account. + * @type {Collection} + */ + this.notes = new Collection(); + + /** + * If the user has Discord premium (nitro) + * This is only filled when using a user account. + * @type {?boolean} + */ + this.premium = typeof data.premium === 'boolean' ? data.premium : null; + + /** + * If the user has MFA enabled on their account + * This is only filled when using a user account. + * @type {?boolean} + */ + this.mfaEnabled = typeof data.mfa_enabled === 'boolean' ? data.mfa_enabled : null; + + /** + * If the user has ever used a mobile device on Discord + * This is only filled when using a user account. + * @type {?boolean} + */ + this.mobile = typeof data.mobile === 'boolean' ? data.mobile : null; + + /** + * Various settings for this user + * This is only filled when using a user account. + * @type {?ClientUserSettings} + */ + this.settings = data.user_settings ? new ClientUserSettings(this, data.user_settings) : null; + + /** + * All of the user's guild settings + * This is only filled when using a user account + * @type {Collection} + */ + this.guildSettings = new Collection(); + if (data.user_guild_settings) { + for (const settings of data.user_guild_settings) { + this.guildSettings.set(settings.guild_id, new ClientUserGuildSettings(settings, this.client)); + } + } + } + + edit(data) { + return this.client.rest.methods.updateCurrentUser(data); + } + + /** + * Set the username of the logged in client. + * Changing usernames in Discord is heavily rate limited, with only 2 requests + * every hour. Use this sparingly! + * @param {string} username The new username + * @param {string} [password] Current password (only for user accounts) + * @returns {Promise} + * @example + * // Set username + * client.user.setUsername('discordjs') + * .then(user => console.log(`My new username is ${user.username}`)) + * .catch(console.error); + */ + setUsername(username, password) { + return this.client.rest.methods.updateCurrentUser({ username }, password); + } + + /** + * Changes the email for the client user's account. + * This is only available when using a user account. + * @param {string} email New email to change to + * @param {string} password Current password + * @returns {Promise} + * @example + * // Set email + * client.user.setEmail('bob@gmail.com', 'some amazing password 123') + * .then(user => console.log(`My new email is ${user.email}`)) + * .catch(console.error); + */ + setEmail(email, password) { + return this.client.rest.methods.updateCurrentUser({ email }, password); + } + + /** + * Changes the password for the client user's account. + * This is only available when using a user account. + * @param {string} newPassword New password to change to + * @param {string} oldPassword Current password + * @returns {Promise} + * @example + * // Set password + * client.user.setPassword('some new amazing password 456', 'some amazing password 123') + * .then(user => console.log('New password set!')) + * .catch(console.error); + */ + setPassword(newPassword, oldPassword) { + return this.client.rest.methods.updateCurrentUser({ password: newPassword }, oldPassword); + } + + /** + * Set the avatar of the logged in client. + * @param {BufferResolvable|Base64Resolvable} avatar The new avatar + * @returns {Promise} + * @example + * // Set avatar + * client.user.setAvatar('./avatar.png') + * .then(user => console.log(`New avatar set!`)) + * .catch(console.error); + */ + setAvatar(avatar) { + return this.client.resolver.resolveImage(avatar).then(data => + this.client.rest.methods.updateCurrentUser({ avatar: data }) + ); + } + + /** + * Data resembling a raw Discord presence. + * @typedef {Object} PresenceData + * @property {PresenceStatus} [status] Status of the user + * @property {boolean} [afk] Whether the user is AFK + * @property {Object} [game] Game the user is playing + * @property {string} [game.name] Name of the game + * @property {string} [game.url] Twitch stream URL + * @property {?ActivityType|number} [game.type] Type of the activity + */ + + /** + * Sets the full presence of the client user. + * @param {PresenceData} data Data for the presence + * @returns {Promise} + * @example + * // Set the client user's presence + * client.user.setPresence({ game: { name: 'with discord.js' }, status: 'idle' }) + * .then(console.log) + * .catch(console.error); + */ + setPresence(data) { + // {"op":3,"d":{"status":"dnd","since":0,"game":null,"afk":false}} + return new Promise(resolve => { + let status = this.localPresence.status || this.presence.status; + let game = this.localPresence.game; + let afk = this.localPresence.afk || this.presence.afk; + + if (!game && this.presence.game) { + game = { + name: this.presence.game.name, + type: this.presence.game.type, + url: this.presence.game.url, + }; + } + + if (data.status) { + if (typeof data.status !== 'string') throw new TypeError('Status must be a string'); + if (this.bot) { + status = data.status; + } else { + this.settings.update(Constants.UserSettingsMap.status, data.status); + status = 'invisible'; + } + } + + if (data.game) { + game = data.game; + game.type = game.url && typeof game.type === 'undefined' ? 1 : game.type || 0; + if (typeof game.type === 'string') { + game.type = Constants.ActivityTypes.indexOf(game.type.toUpperCase()); + } + } else if (typeof data.game !== 'undefined') { + game = null; + } + + if (typeof data.afk !== 'undefined') afk = data.afk; + afk = Boolean(afk); + + this.localPresence = { status, game, afk }; + this.localPresence.since = 0; + this.localPresence.game = this.localPresence.game || null; + + this.client.ws.send({ + op: 3, + d: this.localPresence, + }); + + this.client._setPresence(this.id, this.localPresence); + + resolve(this); + }); + } + + /** + * A user's status. Must be one of: + * * `online` + * * `idle` + * * `invisible` + * * `dnd` (do not disturb) + * @typedef {string} PresenceStatus + */ + + /** + * Sets the status of the client user. + * @param {PresenceStatus} status Status to change to + * @returns {Promise} + * @example + * // Set the client user's status + * client.user.setStatus('idle') + * .then(console.log) + * .catch(console.error); + */ + setStatus(status) { + return this.setPresence({ status }); + } + + /** + * Sets the game the client user is playing. + * @param {?string} game Game being played + * @param {?string} [streamingURL] Twitch stream URL + * @returns {Promise} + * @deprecated + */ + setGame(game, streamingURL) { + if (!game) return this.setPresence({ game: null }); + return this.setPresence({ + game: { + name: game, + url: streamingURL, + }, + }); + } + + /** + * Sets the activity the client user is playing. + * @param {?string} name Activity being played + * @param {Object} [options] Options for setting the activity + * @param {string} [options.url] Twitch stream URL + * @param {ActivityType|number} [options.type] Type of the activity + * @returns {Promise} + * @example + * client.user.setActivity('YouTube', { type: 'WATCHING' }) + * .then(presence => console.log(`Activity set to ${presence.game ? presence.game.name : 'none'}`)) + * .catch(console.error); + */ + setActivity(name, { url, type } = {}) { + if (!name) return this.setPresence({ game: null }); + return this.setPresence({ + game: { name, type, url }, + }); + } + + /** + * Sets/removes the AFK flag for the client user. + * @param {boolean} afk Whether or not the user is AFK + * @returns {Promise} + */ + setAFK(afk) { + return this.setPresence({ afk }); + } + + /** + * Fetches messages that mentioned the client's user. + * @param {Object} [options] Options for the fetch + * @param {number} [options.limit=25] Maximum number of mentions to retrieve + * @param {boolean} [options.roles=true] Whether to include role mentions + * @param {boolean} [options.everyone=true] Whether to include everyone/here mentions + * @param {GuildResolvable} [options.guild] Limit the search to a specific guild + * @returns {Promise} + * @example + * // Fetch mentions + * client.user.fetchMentions() + * .then(console.log) + * .catch(console.error); + * @example + * // Fetch mentions from a guild + * client.user.fetchMentions({ + * guild: '222078108977594368' + * }) + * .then(console.log) + * .catch(console.error); + */ + fetchMentions(options = {}) { + return this.client.rest.methods.fetchMentions(options); + } + + /** + * Send a friend request. + * This is only available when using a user account. + * @param {UserResolvable} user The user to send the friend request to + * @returns {Promise} The user the friend request was sent to + */ + addFriend(user) { + user = this.client.resolver.resolveUser(user); + return this.client.rest.methods.addFriend(user); + } + + /** + * Remove a friend. + * This is only available when using a user account. + * @param {UserResolvable} user The user to remove from your friends + * @returns {Promise} The user that was removed + */ + removeFriend(user) { + user = this.client.resolver.resolveUser(user); + return this.client.rest.methods.removeFriend(user); + } + + /** + * Creates a guild. + * This is only available when using a user account. + * @param {string} name The name of the guild + * @param {string} [region] The region for the server + * @param {BufferResolvable|Base64Resolvable} [icon=null] The icon for the guild + * @returns {Promise} The guild that was created + */ + createGuild(name, region, icon = null) { + if (typeof icon === 'string' && icon.startsWith('data:')) { + return this.client.rest.methods.createGuild({ name, icon, region }); + } else { + return this.client.resolver.resolveImage(icon).then(data => + this.client.rest.methods.createGuild({ name, icon: data, region }) + ); + } + } + + /** + * An object containing either a user or access token, and an optional nickname. + * @typedef {Object} GroupDMRecipientOptions + * @property {UserResolvable|Snowflake} [user] User to add to the Group DM + * (only available if a user is creating the DM) + * @property {string} [accessToken] Access token to use to add a user to the Group DM + * (only available if a bot is creating the DM) + * @property {string} [nick] Permanent nickname (only available if a bot is creating the DM) + */ + + /** + * Creates a Group DM. + * @param {GroupDMRecipientOptions[]} recipients The recipients + * @returns {Promise} + * @example + * // Create a Group DM with a token provided from OAuth + * client.user.createGroupDM([{ + * user: '66564597481480192', + * accessToken: token + * }]) + * .then(console.log) + * .catch(console.error); + */ + createGroupDM(recipients) { + return this.client.rest.methods.createGroupDM({ + recipients: recipients.map(u => this.client.resolver.resolveUserID(u.user)), + accessTokens: recipients.map(u => u.accessToken), + nicks: recipients.map(u => u.nick), + }); + } + + /** + * Accepts an invite to join a guild. + * This is only available when using a user account. + * @param {Invite|string} invite Invite or code to accept + * @returns {Promise} Joined guild + */ + acceptInvite(invite) { + return this.client.rest.methods.acceptInvite(invite); + } +} + +ClientUser.prototype.setGame = + util.deprecate(ClientUser.prototype.setGame, 'ClientUser#setGame: use ClientUser#setActivity instead'); + +module.exports = ClientUser; + + +/***/ }), +/* 56 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +/** + * A wrapper around the ClientUser's settings. + */ +class ClientUserSettings { + constructor(user, data) { + this.user = user; + this.patch(data); + } + + /** + * Patch the data contained in this class with new partial data. + * @param {Object} data Data to patch this with + * @returns {void} + * @private + */ + patch(data) { + for (const key of Object.keys(Constants.UserSettingsMap)) { + const value = Constants.UserSettingsMap[key]; + if (!data.hasOwnProperty(key)) continue; + if (typeof value === 'function') { + this[value.name] = value(data[key]); + } else { + this[value] = data[key]; + } + } + } + + /** + * Update a specific property of of user settings. + * @param {string} name Name of property + * @param {*} value Value to patch + * @returns {Promise} + */ + update(name, value) { + return this.user.client.rest.methods.patchUserSettings({ [name]: value }); + } + + /** + * Sets the position at which this guild will appear in the Discord client. + * @param {Guild} guild The guild to move + * @param {number} position Absolute or relative position + * @param {boolean} [relative=false] Whether to position relatively or absolutely + * @returns {Promise} + */ + setGuildPosition(guild, position, relative) { + const temp = Object.assign([], this.guildPositions); + Util.moveElementInArray(temp, guild.id, position, relative); + return this.update('guild_positions', temp).then(() => guild); + } + + /** + * Add a guild to the list of restricted guilds. + * @param {Guild} guild The guild to add + * @returns {Promise} + */ + addRestrictedGuild(guild) { + const temp = Object.assign([], this.restrictedGuilds); + if (temp.includes(guild.id)) return Promise.reject(new Error('Guild is already restricted')); + temp.push(guild.id); + return this.update('restricted_guilds', temp).then(() => guild); + } + + /** + * Remove a guild from the list of restricted guilds. + * @param {Guild} guild The guild to remove + * @returns {Promise} + */ + removeRestrictedGuild(guild) { + const temp = Object.assign([], this.restrictedGuilds); + const index = temp.indexOf(guild.id); + if (index < 0) return Promise.reject(new Error('Guild is not restricted')); + temp.splice(index, 1); + return this.update('restricted_guilds', temp).then(() => guild); + } +} + +module.exports = ClientUserSettings; + + +/***/ }), +/* 57 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); +const Collection = __webpack_require__(3); +const ClientUserChannelOverride = __webpack_require__(85); + +/** + * A wrapper around the ClientUser's guild settings. + */ +class ClientUserGuildSettings { + constructor(data, client) { + /** + * The client that created the instance of the ClientUserGuildSettings + * @name ClientUserGuildSettings#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: client }); + /** + * The ID of the guild this settings are for + * @type {Snowflake} + */ + this.guildID = data.guild_id; + this.channelOverrides = new Collection(); + this.patch(data); + } + + /** + * Patch the data contained in this class with new partial data. + * @param {Object} data Data to patch this with + * @returns {void} + * @private + */ + patch(data) { + for (const key of Object.keys(Constants.UserGuildSettingsMap)) { + const value = Constants.UserGuildSettingsMap[key]; + if (!data.hasOwnProperty(key)) continue; + if (key === 'channel_overrides') { + for (const channel of data[key]) { + this.channelOverrides.set(channel.channel_id, + new ClientUserChannelOverride(channel)); + } + } else if (typeof value === 'function') { + this[value.name] = value(data[key]); + } else { + this[value] = data[key]; + } + } + } + + /** + * Update a specific property of the guild settings. + * @param {string} name Name of property + * @param {value} value Value to patch + * @returns {Promise} + */ + update(name, value) { + return this.client.rest.methods.patchClientUserGuildSettings(this.guildID, { [name]: value }); + } +} + +module.exports = ClientUserGuildSettings; + + +/***/ }), +/* 58 */ +/***/ (function(module, exports, __webpack_require__) { + +const browser = typeof window !== 'undefined'; +const webpack = !!"true"; + +const Discord = __webpack_require__(59); + +module.exports = Discord; +if (browser && webpack) window.Discord = Discord; // eslint-disable-line no-undef +// eslint-disable-next-line no-console +else if (!browser) console.warn('Warning: Attempting to use browser version of Discord.js in a non-browser environment!'); + + +/***/ }), +/* 59 */ +/***/ (function(module, exports, __webpack_require__) { + +const Util = __webpack_require__(4); + +module.exports = { + // "Root" classes (starting points) + Client: __webpack_require__(70), + Shard: __webpack_require__(158), + ShardClientUtil: __webpack_require__(159), + ShardingManager: __webpack_require__(160), + WebhookClient: __webpack_require__(161), + + // Utilities + Collection: __webpack_require__(3), + Constants: __webpack_require__(0), + DiscordAPIError: __webpack_require__(33), + EvaluatedPermissions: __webpack_require__(6), + Permissions: __webpack_require__(6), + Snowflake: __webpack_require__(5), + SnowflakeUtil: __webpack_require__(5), + Util: Util, + util: Util, + version: __webpack_require__(36).version, + + // Shortcuts to Util methods + escapeMarkdown: Util.escapeMarkdown, + fetchRecommendedShards: Util.fetchRecommendedShards, + splitMessage: Util.splitMessage, + + // Structures + Attachment: __webpack_require__(21), + CategoryChannel: __webpack_require__(49), + Channel: __webpack_require__(11), + ClientUser: __webpack_require__(55), + ClientUserSettings: __webpack_require__(56), + Collector: __webpack_require__(29), + DMChannel: __webpack_require__(51), + Emoji: __webpack_require__(16), + Game: __webpack_require__(10).Game, + GroupDMChannel: __webpack_require__(32), + Guild: __webpack_require__(22), + GuildAuditLogs: __webpack_require__(47), + GuildChannel: __webpack_require__(18), + GuildMember: __webpack_require__(17), + Invite: __webpack_require__(30), + Message: __webpack_require__(15), + MessageAttachment: __webpack_require__(39), + MessageCollector: __webpack_require__(44), + MessageEmbed: __webpack_require__(40), + MessageMentions: __webpack_require__(38), + MessageReaction: __webpack_require__(42), + OAuth2Application: __webpack_require__(31), + ClientOAuth2Application: __webpack_require__(31), + PartialGuild: __webpack_require__(45), + PartialGuildChannel: __webpack_require__(46), + PermissionOverwrites: __webpack_require__(50), + Presence: __webpack_require__(10).Presence, + ReactionEmoji: __webpack_require__(28), + ReactionCollector: __webpack_require__(43), + RichEmbed: __webpack_require__(20), + Role: __webpack_require__(8), + TextChannel: __webpack_require__(52), + User: __webpack_require__(9), + VoiceChannel: __webpack_require__(53), + Webhook: __webpack_require__(23), +}; + + +/***/ }), +/* 60 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +exports.byteLength = byteLength +exports.toByteArray = toByteArray +exports.fromByteArray = fromByteArray + +var lookup = [] +var revLookup = [] +var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array + +var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' +for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i] + revLookup[code.charCodeAt(i)] = i +} + +// Support decoding URL-safe base64 strings, as Node.js does. +// See: https://en.wikipedia.org/wiki/Base64#URL_applications +revLookup['-'.charCodeAt(0)] = 62 +revLookup['_'.charCodeAt(0)] = 63 + +function placeHoldersCount (b64) { + var len = b64.length + if (len % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 +} + +function byteLength (b64) { + // base64 is 4/3 + up to two characters of the original data + return (b64.length * 3 / 4) - placeHoldersCount(b64) +} + +function toByteArray (b64) { + var i, l, tmp, placeHolders, arr + var len = b64.length + placeHolders = placeHoldersCount(b64) + + arr = new Arr((len * 3 / 4) - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? len - 4 : len + + var L = 0 + + for (i = 0; i < l; i += 4) { + tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] + arr[L++] = (tmp >> 16) & 0xFF + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + if (placeHolders === 2) { + tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[L++] = tmp & 0xFF + } else if (placeHolders === 1) { + tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + return arr +} + +function tripletToBase64 (num) { + return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] +} + +function encodeChunk (uint8, start, end) { + var tmp + var output = [] + for (var i = start; i < end; i += 3) { + tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF) + output.push(tripletToBase64(tmp)) + } + return output.join('') +} + +function fromByteArray (uint8) { + var tmp + var len = uint8.length + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + var output = '' + var parts = [] + var maxChunkLength = 16383 // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1] + output += lookup[tmp >> 2] + output += lookup[(tmp << 4) & 0x3F] + output += '==' + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) + output += lookup[tmp >> 10] + output += lookup[(tmp >> 4) & 0x3F] + output += lookup[(tmp << 2) & 0x3F] + output += '=' + } + + parts.push(output) + + return parts.join('') +} + + +/***/ }), +/* 61 */ +/***/ (function(module, exports) { + +exports.read = function (buffer, offset, isLE, mLen, nBytes) { + var e, m + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var nBits = -7 + var i = isLE ? (nBytes - 1) : 0 + var d = isLE ? -1 : 1 + var s = buffer[offset + i] + + i += d + + e = s & ((1 << (-nBits)) - 1) + s >>= (-nBits) + nBits += eLen + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + m = e & ((1 << (-nBits)) - 1) + e >>= (-nBits) + nBits += mLen + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + if (e === 0) { + e = 1 - eBias + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity) + } else { + m = m + Math.pow(2, mLen) + e = e - eBias + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen) +} + +exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) + var i = isLE ? 0 : (nBytes - 1) + var d = isLE ? 1 : -1 + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 + + value = Math.abs(value) + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0 + e = eMax + } else { + e = Math.floor(Math.log(value) / Math.LN2) + if (value * (c = Math.pow(2, -e)) < 1) { + e-- + c *= 2 + } + if (e + eBias >= 1) { + value += rt / c + } else { + value += rt * Math.pow(2, 1 - eBias) + } + if (value * c >= 2) { + e++ + c /= 2 + } + + if (e + eBias >= eMax) { + m = 0 + e = eMax + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen) + e = e + eBias + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) + e = 0 + } + } + + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + + e = (e << mLen) | m + eLen += mLen + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + + buffer[offset + i - d] |= s * 128 +} + + +/***/ }), +/* 62 */ +/***/ (function(module, exports) { + +var toString = {}.toString; + +module.exports = Array.isArray || function (arr) { + return toString.call(arr) == '[object Array]'; +}; + + +/***/ }), +/* 63 */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = __webpack_require__(64); + + +/***/ }), +/* 64 */ +/***/ (function(module, exports, __webpack_require__) { + +const browser = typeof window !== 'undefined'; +const querystring = __webpack_require__(35); +const transport = browser ? __webpack_require__(67) : __webpack_require__(68); + +/** + * Snekfetch + * @extends Stream.Readable + * @extends Promise + */ +class Snekfetch extends transport.Extension { + /** + * Options to pass to the Snekfetch constructor + * @typedef {object} SnekfetchOptions + * @memberof Snekfetch + * @property {object} [headers] Headers to initialize the request with + * @property {object|string|Buffer} [data] Data to initialize the request with + * @property {string|Object} [query] Query to intialize the request with + * @property {boolean} [followRedirects=true] If the request should follow redirects + * @property {object} [qs=querystring] Querystring module to use, any object providing + * `stringify` and `parse` for querystrings + * @property {number} [version = 1] The http version to use [1 or 2] + * @property {external:Agent} [agent] Whether to use an http agent + */ + + /** + * Create a request. + * Usually you'll want to do `Snekfetch#method(url [, options])` instead of + * `new Snekfetch(method, url [, options])` + * @param {string} method HTTP method + * @param {string} url URL + * @param {SnekfetchOptions} [opts] Options + */ + constructor(method, url, opts = {}) { + super(); + this.options = Object.assign({ version: 1, qs: querystring, followRedirects: true }, opts); + this.request = transport.buildRequest.call(this, method, url, opts); + if (opts.headers) + this.set(opts.headers); + if (opts.query) + this.query(opts.query); + if (opts.data) + this.send(opts.data); + } + + /** + * Add a query param to the request + * @param {string|Object} name Name of query param or object to add to query + * @param {string} [value] If name is a string value, this will be the value of the query param + * @returns {Snekfetch} This request + */ + query(name, value) { + if (!this.request.query) + this.request.query = {}; + if (name !== null && typeof name === 'object') { + for (const [k, v] of Object.entries(name)) + this.query(k, v); + } else { + this.request.query[name] = value; + } + + return this; + } + + /** + * Add a header to the request + * @param {string|Object} name Name of query param or object to add to headers + * @param {string} [value] If name is a string value, this will be the value of the header + * @returns {Snekfetch} This request + */ + set(name, value) { + if (name !== null && typeof name === 'object') { + for (const key of Object.keys(name)) + this.set(key, name[key]); + } else { + this.request.setHeader(name, value); + } + + return this; + } + + /** + * Attach a form data object + * @param {string} name Name of the form attachment + * @param {string|Object|Buffer} data Data for the attachment + * @param {string} [filename] Optional filename if form attachment name needs to be overridden + * @returns {Snekfetch} This request + */ + attach(...args) { + const form = this.data instanceof transport.FormData ? this.data : this.data = new transport.FormData(); + if (typeof args[0] === 'object') { + for (const [k, v] of Object.entries(args[0])) + this.attach(k, v); + } else { + form.append(...args); + } + + return this; + } + + /** + * Send data with the request + * @param {string|Buffer|Object} data Data to send + * @returns {Snekfetch} This request + */ + send(data) { + if (data instanceof transport.FormData || transport.shouldSendRaw(data)) { + this.data = data; + } else if (data !== null && typeof data === 'object') { + const header = this.request.getHeader('content-type'); + let serialize; + if (header) { + if (header.includes('json')) + serialize = JSON.stringify; + else if (header.includes('urlencoded')) + serialize = this.options.qs.stringify; + } else { + this.set('Content-Type', 'application/json'); + serialize = JSON.stringify; + } + this.data = serialize(data); + } else { + this.data = data; + } + return this; + } + + then(resolver, rejector) { + if (this._response) + return this._response.then(resolver, rejector); + // eslint-disable-next-line no-return-assign + return this._response = transport.finalizeRequest.call(this) + .then(({ response, raw, redirect, headers }) => { + if (redirect) { + let method = this.request.method; + if ([301, 302].includes(response.statusCode)) { + if (method !== 'HEAD') + method = 'GET'; + this.data = null; + } else if (response.statusCode === 303) { + method = 'GET'; + } + + const redirectHeaders = this.request.getHeaders(); + delete redirectHeaders.host; + return new Snekfetch(method, redirect, { + data: this.data, + headers: redirectHeaders, + version: this.options.version, + }); + } + + const statusCode = response.statusCode || response.status; + // forgive me :( + const self = this; // eslint-disable-line consistent-this + /** + * Response from Snekfetch + * @typedef {Object} SnekfetchResponse + * @memberof Snekfetch + * @prop {HTTP.Request} request + * @prop {?string|object|Buffer} body Processed response body + * @prop {string} text Raw response body + * @prop {boolean} ok If the response code is >= 200 and < 300 + * @prop {number} status HTTP status code + * @prop {string} statusText Human readable HTTP status + */ + const res = { + request: this.request, + get body() { + delete res.body; + const type = this.headers['content-type']; + if (type && type.includes('application/json')) { + try { + res.body = JSON.parse(res.text); + } catch (err) { + res.body = res.text; + } + } else if (type && type.includes('application/x-www-form-urlencoded')) { + res.body = self.options.qs.parse(res.text); + } else { + res.body = raw; + } + + return res.body; + }, + text: raw.toString(), + ok: statusCode >= 200 && statusCode < 400, + headers: headers || response.headers, + status: statusCode, + statusText: response.statusText || transport.STATUS_CODES[response.statusCode], + }; + + if (res.ok) { + return res; + } else { + const err = new Error(`${res.status} ${res.statusText}`.trim()); + Object.assign(err, res); + return Promise.reject(err); + } + }) + .then(resolver, rejector); + } + + catch(rejector) { + return this.then(null, rejector); + } + + /** + * End the request + * @param {Function} [cb] Optional callback to handle the response + * @returns {Promise} This request + */ + end(cb) { + return this.then( + (res) => cb ? cb(null, res) : res, + (err) => cb ? cb(err, err.status ? err : null) : Promise.reject(err) + ); + } + + _finalizeRequest() { + if (!this.request) + return; + + if (this.request.method !== 'HEAD') + this.set('Accept-Encoding', 'gzip, deflate'); + if (this.data && this.data.getBoundary) + this.set('Content-Type', `multipart/form-data; boundary=${this.data.getBoundary()}`); + + if (this.request.query) { + const [path, query] = this.request.path.split('?'); + this.request.path = `${path}?${this.options.qs.stringify(this.request.query)}${query ? `&${query}` : ''}`; + } + } +} + +/** + * Create a ((THIS)) request + * @dynamic this.METHODS + * @method Snekfetch.((THIS)lowerCase) + * @param {string} url The url to request + * @param {Snekfetch.snekfetchOptions} [opts] Options + * @returns {Snekfetch} + */ +Snekfetch.METHODS = transport.METHODS.concat('BREW').filter((m) => m !== 'M-SEARCH'); +for (const method of Snekfetch.METHODS) { + Snekfetch[method.toLowerCase()] = function runMethod(url, opts) { + const Constructor = this.prototype instanceof Snekfetch ? this : Snekfetch; + return new Constructor(method, url, opts); + }; +} + +module.exports = Snekfetch; + +/** + * @external Agent + * @see {@link https://nodejs.org/api/http.html#http_class_http_agent} + */ + + +/***/ }), +/* 65 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + + + +// If obj.hasOwnProperty has been overridden, then calling +// obj.hasOwnProperty(prop) will break. +// See: https://github.com/joyent/node/issues/1707 +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +module.exports = function(qs, sep, eq, options) { + sep = sep || '&'; + eq = eq || '='; + var obj = {}; + + if (typeof qs !== 'string' || qs.length === 0) { + return obj; + } + + var regexp = /\+/g; + qs = qs.split(sep); + + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, '%20'), + idx = x.indexOf(eq), + kstr, vstr, k, v; + + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); + } else { + kstr = x; + vstr = ''; + } + + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); + + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; + } + } + + return obj; +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + + +/***/ }), +/* 66 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + + + +var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; + + case 'boolean': + return v ? 'true' : 'false'; + + case 'number': + return isFinite(v) ? v : ''; + + default: + return ''; + } +}; + +module.exports = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; + } + + if (typeof obj === 'object') { + return map(objectKeys(obj), function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (isArray(obj[k])) { + return map(obj[k], function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }).join(sep); + + } + + if (!name) return ''; + return encodeURIComponent(stringifyPrimitive(name)) + eq + + encodeURIComponent(stringifyPrimitive(obj)); +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +function map (xs, f) { + if (xs.map) return xs.map(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + res.push(f(xs[i], i)); + } + return res; +} + +var objectKeys = Object.keys || function (obj) { + var res = []; + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); + } + return res; +}; + + +/***/ }), +/* 67 */ +/***/ (function(module, exports) { + +function buildRequest(method, url) { + return { + method, + path: url, + redirect: this.options.followRedirects ? 'follow' : 'manual', + headers: {}, + setHeader(name, value) { + this.headers[name.toLowerCase()] = value; + }, + getHeader(name) { + return this.headers[name.toLowerCase()]; + }, + }; +} + +function finalizeRequest() { + this._finalizeRequest(); + if (this.data) + this.request.body = this.data; + return window.fetch(this.request.path, this.request) + .then((r) => r.text().then((t) => { + const headers = {}; + for (const [k, v] of r.headers.entries()) + headers[k.toLowerCase()] = v; + return { response: r, raw: t, headers }; + })); +} + +module.exports = { + buildRequest, finalizeRequest, + shouldSendRaw: () => false, + METHODS: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH'], + STATUS_CODES: {}, + Extension: Object, + FormData: window.FormData, +}; + + +/***/ }), +/* 68 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 69 */ +/***/ (function(module, exports) { + +exports.endianness = function () { return 'LE' }; + +exports.hostname = function () { + if (typeof location !== 'undefined') { + return location.hostname + } + else return ''; +}; + +exports.loadavg = function () { return [] }; + +exports.uptime = function () { return 0 }; + +exports.freemem = function () { + return Number.MAX_VALUE; +}; + +exports.totalmem = function () { + return Number.MAX_VALUE; +}; + +exports.cpus = function () { return [] }; + +exports.type = function () { return 'Browser' }; + +exports.release = function () { + if (typeof navigator !== 'undefined') { + return navigator.appVersion; + } + return ''; +}; + +exports.networkInterfaces += exports.getNetworkInterfaces += function () { return {} }; + +exports.arch = function () { return 'javascript' }; + +exports.platform = function () { return 'browser' }; + +exports.tmpdir = exports.tmpDir = function () { + return '/tmp'; +}; + +exports.EOL = '\n'; + +exports.homedir = function () { + return '/' +}; + + +/***/ }), +/* 70 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(process) {const EventEmitter = __webpack_require__(19); +const Constants = __webpack_require__(0); +const Permissions = __webpack_require__(6); +const Util = __webpack_require__(4); +const RESTManager = __webpack_require__(37); +const ClientDataManager = __webpack_require__(81); +const ClientManager = __webpack_require__(82); +const ClientDataResolver = __webpack_require__(27); +const ClientVoiceManager = __webpack_require__(125); +const WebSocketManager = __webpack_require__(126); +const ActionsManager = __webpack_require__(127); +const Collection = __webpack_require__(3); +const Presence = __webpack_require__(10).Presence; +const ShardClientUtil = __webpack_require__(156); +const VoiceBroadcast = __webpack_require__(157); + +/** + * The main hub for interacting with the Discord API, and the starting point for any bot. + * @extends {EventEmitter} + */ +class Client extends EventEmitter { + /** + * @param {ClientOptions} [options] Options for the client + */ + constructor(options = {}) { + super(); + + // Obtain shard details from environment + if (!options.shardId && 'SHARD_ID' in Object({"__DISCORD_WEBPACK__":"true"})) options.shardId = Number(Object({"__DISCORD_WEBPACK__":"true"}).SHARD_ID); + if (!options.shardCount && 'SHARD_COUNT' in Object({"__DISCORD_WEBPACK__":"true"})) options.shardCount = Number(Object({"__DISCORD_WEBPACK__":"true"}).SHARD_COUNT); + + /** + * The options the client was instantiated with + * @type {ClientOptions} + */ + this.options = Util.mergeDefault(Constants.DefaultOptions, options); + this._validateOptions(); + + /** + * The REST manager of the client + * @type {RESTManager} + * @private + */ + this.rest = new RESTManager(this); + + /** + * The data manager of the client + * @type {ClientDataManager} + * @private + */ + this.dataManager = new ClientDataManager(this); + + /** + * The manager of the client + * @type {ClientManager} + * @private + */ + this.manager = new ClientManager(this); + + /** + * The WebSocket manager of the client + * @type {WebSocketManager} + * @private + */ + this.ws = new WebSocketManager(this); + + /** + * The data resolver of the client + * @type {ClientDataResolver} + * @private + */ + this.resolver = new ClientDataResolver(this); + + /** + * The action manager of the client + * @type {ActionsManager} + * @private + */ + this.actions = new ActionsManager(this); + + /** + * The voice manager of the client (`null` in browsers) + * @type {?ClientVoiceManager} + * @private + */ + this.voice = !this.browser ? new ClientVoiceManager(this) : null; + + /** + * The shard helpers for the client + * (only if the process was spawned as a child, such as from a {@link ShardingManager}) + * @type {?ShardClientUtil} + */ + this.shard = process.send ? ShardClientUtil.singleton(this) : null; + + /** + * All of the {@link User} objects that have been cached at any point, mapped by their IDs + * @type {Collection} + */ + this.users = new Collection(); + + /** + * All of the guilds the client is currently handling, mapped by their IDs - + * as long as sharding isn't being used, this will be *every* guild the bot is a member of + * @type {Collection} + */ + this.guilds = new Collection(); + + /** + * All of the {@link Channel}s that the client is currently handling, mapped by their IDs - + * as long as sharding isn't being used, this will be *every* channel in *every* guild, and all DM channels + * @type {Collection} + */ + this.channels = new Collection(); + + /** + * Presences that have been received for the client user's friends, mapped by user IDs + * This is only filled when using a user account. + * @type {Collection} + */ + this.presences = new Collection(); + + Object.defineProperty(this, 'token', { writable: true }); + if (!this.token && 'CLIENT_TOKEN' in Object({"__DISCORD_WEBPACK__":"true"})) { + /** + * Authorization token for the logged in user/bot + * This should be kept private at all times. + * @type {?string} + */ + this.token = Object({"__DISCORD_WEBPACK__":"true"}).CLIENT_TOKEN; + } else { + this.token = null; + } + + /** + * User that the client is logged in as + * @type {?ClientUser} + */ + this.user = null; + + /** + * Time at which the client was last regarded as being in the `READY` state + * (each time the client disconnects and successfully reconnects, this will be overwritten) + * @type {?Date} + */ + this.readyAt = null; + + /** + * Active voice broadcasts that have been created + * @type {VoiceBroadcast[]} + */ + this.broadcasts = []; + + /** + * Previous heartbeat pings of the websocket (most recent first, limited to three elements) + * @type {number[]} + */ + this.pings = []; + + /** + * Timeouts set by {@link Client#setTimeout} that are still active + * @type {Set} + * @private + */ + this._timeouts = new Set(); + + /** + * Intervals set by {@link Client#setInterval} that are still active + * @type {Set} + * @private + */ + this._intervals = new Set(); + + if (this.options.messageSweepInterval > 0) { + this.setInterval(this.sweepMessages.bind(this), this.options.messageSweepInterval * 1000); + } + } + + /** + * Timestamp of the latest ping's start time + * @type {number} + * @private + */ + get _pingTimestamp() { + return this.ws.connection ? this.ws.connection.lastPingTimestamp : 0; + } + + /** + * Current status of the client's connection to Discord + * @type {?number} + * @readonly + */ + get status() { + return this.ws.connection.status; + } + + /** + * How long it has been since the client last entered the `READY` state in milliseconds + * @type {?number} + * @readonly + */ + get uptime() { + return this.readyAt ? Date.now() - this.readyAt : null; + } + + /** + * Average heartbeat ping of the websocket, obtained by averaging the {@link Client#pings} property + * @type {number} + * @readonly + */ + get ping() { + return this.pings.reduce((prev, p) => prev + p, 0) / this.pings.length; + } + + /** + * All active voice connections that have been established, mapped by guild ID + * @type {Collection} + * @readonly + */ + get voiceConnections() { + if (this.browser) return new Collection(); + return this.voice.connections; + } + + /** + * All custom emojis that the client has access to, mapped by their IDs + * @type {Collection} + * @readonly + */ + get emojis() { + const emojis = new Collection(); + for (const guild of this.guilds.values()) { + for (const emoji of guild.emojis.values()) emojis.set(emoji.id, emoji); + } + return emojis; + } + + /** + * Timestamp of the time the client was last `READY` at + * @type {?number} + * @readonly + */ + get readyTimestamp() { + return this.readyAt ? this.readyAt.getTime() : null; + } + + /** + * Whether the client is in a browser environment + * @type {boolean} + * @readonly + */ + get browser() { + return typeof window !== 'undefined'; + } + + /** + * Creates a voice broadcast. + * @returns {VoiceBroadcast} + */ + createVoiceBroadcast() { + const broadcast = new VoiceBroadcast(this); + this.broadcasts.push(broadcast); + return broadcast; + } + + /** + * Logs the client in, establishing a websocket connection to Discord. + * Both bot and regular user accounts are supported, but it is highly recommended to use a bot account whenever + * possible. User accounts are subject to harsher ratelimits and other restrictions that don't apply to bot accounts. + * Bot accounts also have access to many features that user accounts cannot utilise. User accounts that are found to + * be abusing/overusing the API will be banned, locking you out of Discord entirely. + * @param {string} token Token of the account to log in with + * @returns {Promise} Token of the account used + * @example + * client.login('my token'); + */ + login(token) { + return this.rest.methods.login(token); + } + + /** + * Logs out, terminates the connection to Discord, and destroys the client. + * @returns {Promise} + */ + destroy() { + for (const t of this._timeouts) clearTimeout(t); + for (const i of this._intervals) clearInterval(i); + this._timeouts.clear(); + this._intervals.clear(); + return this.manager.destroy(); + } + + /** + * Requests a sync of guild data with Discord. + * This can be done automatically every 30 seconds by enabling {@link ClientOptions#sync}. + * This is only available when using a user account. + * @param {Guild[]|Collection} [guilds=this.guilds] An array or collection of guilds to sync + */ + syncGuilds(guilds = this.guilds) { + if (this.user.bot) return; + this.ws.send({ + op: 12, + d: guilds instanceof Collection ? guilds.keyArray() : guilds.map(g => g.id), + }); + } + + /** + * Obtains a user from Discord, or the user cache if it's already available. + * This is only available when using a bot account. + * @param {Snowflake} id ID of the user + * @param {boolean} [cache=true] Whether to cache the new user object if it isn't already + * @returns {Promise} + */ + fetchUser(id, cache = true) { + if (this.users.has(id)) return Promise.resolve(this.users.get(id)); + return this.rest.methods.getUser(id, cache); + } + + /** + * Obtains an invite from Discord. + * @param {InviteResolvable} invite Invite code or URL + * @returns {Promise} + */ + fetchInvite(invite) { + const code = this.resolver.resolveInviteCode(invite); + return this.rest.methods.getInvite(code); + } + + /** + * Obtains a webhook from Discord. + * @param {Snowflake} id ID of the webhook + * @param {string} [token] Token for the webhook + * @returns {Promise} + */ + fetchWebhook(id, token) { + return this.rest.methods.getWebhook(id, token); + } + + /** + * Obtains the available voice regions from Discord. + * @returns {Collection} + */ + fetchVoiceRegions() { + return this.rest.methods.fetchVoiceRegions(); + } + + /** + * Sweeps all text-based channels' messages and removes the ones older than the max message lifetime. + * If the message has been edited, the time of the edit is used rather than the time of the original message. + * @param {number} [lifetime=this.options.messageCacheLifetime] Messages that are older than this (in seconds) + * will be removed from the caches. The default is based on {@link ClientOptions#messageCacheLifetime} + * @returns {number} Amount of messages that were removed from the caches, + * or -1 if the message cache lifetime is unlimited + */ + sweepMessages(lifetime = this.options.messageCacheLifetime) { + if (typeof lifetime !== 'number' || isNaN(lifetime)) throw new TypeError('The lifetime must be a number.'); + if (lifetime <= 0) { + this.emit('debug', 'Didn\'t sweep messages - lifetime is unlimited'); + return -1; + } + + const lifetimeMs = lifetime * 1000; + const now = Date.now(); + let channels = 0; + let messages = 0; + + for (const channel of this.channels.values()) { + if (!channel.messages) continue; + channels++; + + for (const message of channel.messages.values()) { + if (now - (message.editedTimestamp || message.createdTimestamp) > lifetimeMs) { + channel.messages.delete(message.id); + messages++; + } + } + } + + this.emit('debug', `Swept ${messages} messages older than ${lifetime} seconds in ${channels} text-based channels`); + return messages; + } + + /** + * Obtains the OAuth Application of the bot from Discord. + * @param {Snowflake} [id='@me'] ID of application to fetch + * @returns {Promise} + */ + fetchApplication(id = '@me') { + return this.rest.methods.getApplication(id); + } + + /** + * Generates a link that can be used to invite the bot to a guild. + * This is only available when using a bot account. + * @param {PermissionResolvable[]|number} [permissions] Permissions to request + * @returns {Promise} + * @example + * client.generateInvite(['SEND_MESSAGES', 'MANAGE_GUILD', 'MENTION_EVERYONE']) + * .then(link => { + * console.log(`Generated bot invite link: ${link}`); + * }); + */ + generateInvite(permissions) { + if (permissions) { + if (permissions instanceof Array) permissions = Permissions.resolve(permissions); + } else { + permissions = 0; + } + return this.fetchApplication().then(application => + `https://discordapp.com/oauth2/authorize?client_id=${application.id}&permissions=${permissions}&scope=bot` + ); + } + + /** + * Sets a timeout that will be automatically cancelled if the client is destroyed. + * @param {Function} fn Function to execute + * @param {number} delay Time to wait before executing (in milliseconds) + * @param {...*} args Arguments for the function + * @returns {Timeout} + */ + setTimeout(fn, delay, ...args) { + const timeout = setTimeout(() => { + fn(...args); + this._timeouts.delete(timeout); + }, delay); + this._timeouts.add(timeout); + return timeout; + } + + /** + * Clears a timeout. + * @param {Timeout} timeout Timeout to cancel + */ + clearTimeout(timeout) { + clearTimeout(timeout); + this._timeouts.delete(timeout); + } + + /** + * Sets an interval that will be automatically cancelled if the client is destroyed. + * @param {Function} fn Function to execute + * @param {number} delay Time to wait before executing (in milliseconds) + * @param {...*} args Arguments for the function + * @returns {Timeout} + */ + setInterval(fn, delay, ...args) { + const interval = setInterval(fn, delay, ...args); + this._intervals.add(interval); + return interval; + } + + /** + * Clears an interval. + * @param {Timeout} interval Interval to cancel + */ + clearInterval(interval) { + clearInterval(interval); + this._intervals.delete(interval); + } + + /** + * Adds a ping to {@link Client#pings}. + * @param {number} startTime Starting time of the ping + * @private + */ + _pong(startTime) { + this.pings.unshift(Date.now() - startTime); + if (this.pings.length > 3) this.pings.length = 3; + this.ws.lastHeartbeatAck = true; + } + + /** + * Adds/updates a friend's presence in {@link Client#presences}. + * @param {Snowflake} id ID of the user + * @param {Object} presence Raw presence object from Discord + * @private + */ + _setPresence(id, presence) { + if (this.presences.has(id)) { + this.presences.get(id).update(presence); + return; + } + this.presences.set(id, new Presence(presence)); + } + + /** + * Calls {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval} on a script + * with the client as `this`. + * @param {string} script Script to eval + * @returns {*} + * @private + */ + _eval(script) { + return eval(script); + } + + /** + * Validates the client options. + * @param {ClientOptions} [options=this.options] Options to validate + * @private + */ + _validateOptions(options = this.options) { + if (typeof options.shardCount !== 'number' || isNaN(options.shardCount)) { + throw new TypeError('The shardCount option must be a number.'); + } + if (typeof options.shardId !== 'number' || isNaN(options.shardId)) { + throw new TypeError('The shardId option must be a number.'); + } + if (options.shardCount < 0) throw new RangeError('The shardCount option must be at least 0.'); + if (options.shardId < 0) throw new RangeError('The shardId option must be at least 0.'); + if (options.shardId !== 0 && options.shardId >= options.shardCount) { + throw new RangeError('The shardId option must be less than shardCount.'); + } + if (typeof options.messageCacheMaxSize !== 'number' || isNaN(options.messageCacheMaxSize)) { + throw new TypeError('The messageCacheMaxSize option must be a number.'); + } + if (typeof options.messageCacheLifetime !== 'number' || isNaN(options.messageCacheLifetime)) { + throw new TypeError('The messageCacheLifetime option must be a number.'); + } + if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) { + throw new TypeError('The messageSweepInterval option must be a number.'); + } + if (typeof options.fetchAllMembers !== 'boolean') { + throw new TypeError('The fetchAllMembers option must be a boolean.'); + } + if (typeof options.disableEveryone !== 'boolean') { + throw new TypeError('The disableEveryone option must be a boolean.'); + } + if (typeof options.restWsBridgeTimeout !== 'number' || isNaN(options.restWsBridgeTimeout)) { + throw new TypeError('The restWsBridgeTimeout option must be a number.'); + } + if (!(options.disabledEvents instanceof Array)) throw new TypeError('The disabledEvents option must be an Array.'); + } +} + +module.exports = Client; + +/** + * Emitted for general warnings. + * @event Client#warn + * @param {string} info The warning + */ + +/** + * Emitted for general debugging information. + * @event Client#debug + * @param {string} info The debug information + */ + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(13))) + +/***/ }), +/* 71 */ +/***/ (function(module, exports) { + +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; +} + +/***/ }), +/* 72 */ +/***/ (function(module, exports) { + +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } +} + + +/***/ }), +/* 73 */ +/***/ (function(module, exports, __webpack_require__) { + +/* WEBPACK VAR INJECTION */(function(process) {const Constants = __webpack_require__(0); + +class UserAgentManager { + constructor() { + this.build(this.constructor.DEFAULT); + } + + set({ url, version } = {}) { + this.build({ + url: url || this.constructor.DFEAULT.url, + version: version || this.constructor.DEFAULT.version, + }); + } + + build(ua) { + this.userAgent = `DiscordBot (${ua.url}, ${ua.version}) Node.js/${process.version}`; + } +} + +UserAgentManager.DEFAULT = { + url: Constants.Package.homepage.split('#')[0], + version: Constants.Package.version, +}; + +module.exports = UserAgentManager; + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(13))) + +/***/ }), +/* 74 */ +/***/ (function(module, exports, __webpack_require__) { + +const querystring = __webpack_require__(35); +const long = __webpack_require__(25); +const Permissions = __webpack_require__(6); +const Constants = __webpack_require__(0); +const Endpoints = Constants.Endpoints; +const Collection = __webpack_require__(3); +const Util = __webpack_require__(4); + +const User = __webpack_require__(9); +const GuildMember = __webpack_require__(17); +const Message = __webpack_require__(15); +const Role = __webpack_require__(8); +const Invite = __webpack_require__(30); +const Webhook = __webpack_require__(23); +const UserProfile = __webpack_require__(75); +const OAuth2Application = __webpack_require__(31); +const Channel = __webpack_require__(11); +const GroupDMChannel = __webpack_require__(32); +const Guild = __webpack_require__(22); +const VoiceRegion = __webpack_require__(77); +const GuildAuditLogs = __webpack_require__(47); + +class RESTMethods { + constructor(restManager) { + this.rest = restManager; + this.client = restManager.client; + this._ackToken = null; + } + + login(token = this.client.token) { + return new Promise((resolve, reject) => { + if (typeof token !== 'string') throw new Error(Constants.Errors.INVALID_TOKEN); + token = token.replace(/^Bot\s*/i, ''); + this.client.manager.connectToWebSocket(token, resolve, reject); + }); + } + + logout() { + return this.rest.makeRequest('post', Endpoints.logout, true, {}); + } + + getGateway(bot = false) { + return this.rest.makeRequest('get', bot ? Endpoints.gateway.bot : Endpoints.gateway, true); + } + + fetchVoiceRegions(guildID) { + let endpoint; + if (guildID) endpoint = Endpoints.Guild(guildID).voiceRegions; + else endpoint = Endpoints.voiceRegions; + return this.rest.makeRequest('get', endpoint, true).then(res => { + const regions = new Collection(); + for (const region of res) regions.set(region.id, new VoiceRegion(region)); + return regions; + }); + } + + sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split, code, reply } = {}, files = null) { + return new Promise((resolve, reject) => { // eslint-disable-line complexity + if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content); + + // The nonce has to be a uint64 :< + if (typeof nonce !== 'undefined') { + nonce = parseInt(nonce); + if (isNaN(nonce) || nonce < 0) throw new RangeError('Message nonce must fit in an unsigned 64-bit integer.'); + } + + if (content) { + if (split && typeof split !== 'object') split = {}; + + // Wrap everything in a code block + if (typeof code !== 'undefined' && (typeof code !== 'boolean' || code === true)) { + content = Util.escapeMarkdown(this.client.resolver.resolveString(content), true); + content = `\`\`\`${typeof code !== 'boolean' ? code || '' : ''}\n${content}\n\`\`\``; + if (split) { + split.prepend = `\`\`\`${typeof code !== 'boolean' ? code || '' : ''}\n`; + split.append = '\n```'; + } + } + + // Add zero-width spaces to @everyone/@here + if (disableEveryone || (typeof disableEveryone === 'undefined' && this.client.options.disableEveryone)) { + content = content.replace(/@(everyone|here)/g, '@\u200b$1'); + } + + // Add the reply prefix + if (reply && !(channel instanceof User || channel instanceof GuildMember) && channel.type !== 'dm') { + const id = this.client.resolver.resolveUserID(reply); + const mention = `<@${reply instanceof GuildMember && reply.nickname ? '!' : ''}${id}>`; + content = `${mention}${content ? `, ${content}` : ''}`; + if (split) split.prepend = `${mention}, ${split.prepend || ''}`; + } + + // Split the content + if (split) content = Util.splitMessage(content, split); + } else if (reply && !(channel instanceof User || channel instanceof GuildMember) && channel.type !== 'dm') { + const id = this.client.resolver.resolveUserID(reply); + content = `<@${reply instanceof GuildMember && reply.nickname ? '!' : ''}${id}>`; + } + + const send = chan => { + if (content instanceof Array) { + const messages = []; + (function sendChunk(list, index) { + const options = index === list.length - 1 ? { tts, embed, files } : { tts }; + chan.send(list[index], options).then(message => { + messages.push(message); + if (index >= list.length - 1) return resolve(messages); + return sendChunk(list, ++index); + }).catch(reject); + }(content, 0)); + } else { + this.rest.makeRequest('post', Endpoints.Channel(chan).messages, true, { + content, tts, nonce, embed, + }, files).then(data => resolve(this.client.actions.MessageCreate.handle(data).message), reject); + } + }; + + if (channel instanceof User || channel instanceof GuildMember) this.createDM(channel).then(send, reject); + else send(channel); + }); + } + + updateMessage(message, content, { embed, code, reply } = {}) { + if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content); + + // Wrap everything in a code block + if (typeof code !== 'undefined' && (typeof code !== 'boolean' || code === true)) { + content = Util.escapeMarkdown(this.client.resolver.resolveString(content), true); + content = `\`\`\`${typeof code !== 'boolean' ? code || '' : ''}\n${content}\n\`\`\``; + } + + // Add the reply prefix + if (reply && message.channel.type !== 'dm') { + const id = this.client.resolver.resolveUserID(reply); + const mention = `<@${reply instanceof GuildMember && reply.nickname ? '!' : ''}${id}>`; + content = `${mention}${content ? `, ${content}` : ''}`; + } + + return this.rest.makeRequest('patch', Endpoints.Message(message), true, { + content, embed, + }).then(data => this.client.actions.MessageUpdate.handle(data).updated); + } + + deleteMessage(message) { + return this.rest.makeRequest('delete', Endpoints.Message(message), true) + .then(() => + this.client.actions.MessageDelete.handle({ + id: message.id, + channel_id: message.channel.id, + }).message + ); + } + + ackMessage(message) { + return this.rest.makeRequest('post', Endpoints.Message(message).ack, true, { token: this._ackToken }).then(res => { + if (res.token) this._ackToken = res.token; + return message; + }); + } + + ackTextChannel(channel) { + return this.rest.makeRequest('post', Endpoints.Channel(channel).Message(channel.lastMessageID).ack, true, { + token: this._ackToken, + }).then(res => { + if (res.token) this._ackToken = res.token; + return channel; + }); + } + + ackGuild(guild) { + return this.rest.makeRequest('post', Endpoints.Guild(guild).ack, true).then(() => guild); + } + + bulkDeleteMessages(channel, messages) { + return this.rest.makeRequest('post', Endpoints.Channel(channel).messages.bulkDelete, true, { + messages: messages.map(m => m.id), + }).then(() => + this.client.actions.MessageDeleteBulk.handle({ + channel_id: channel.id, + messages, + }).messages + ); + } + + search(target, options) { + if (typeof options === 'string') options = { content: options }; + if (options.before) { + if (!(options.before instanceof Date)) options.before = new Date(options.before); + options.maxID = long.fromNumber(options.before.getTime() - 14200704e5).shiftLeft(22).toString(); + } + if (options.after) { + if (!(options.after instanceof Date)) options.after = new Date(options.after); + options.minID = long.fromNumber(options.after.getTime() - 14200704e5).shiftLeft(22).toString(); + } + if (options.during) { + if (!(options.during instanceof Date)) options.during = new Date(options.during); + const t = options.during.getTime() - 14200704e5; + options.minID = long.fromNumber(t).shiftLeft(22).toString(); + options.maxID = long.fromNumber(t + 86400000).shiftLeft(22).toString(); + } + if (options.channel) options.channel = this.client.resolver.resolveChannelID(options.channel); + if (options.author) options.author = this.client.resolver.resolveUserID(options.author); + if (options.mentions) options.mentions = this.client.resolver.resolveUserID(options.options.mentions); + options = { + content: options.content, + max_id: options.maxID, + min_id: options.minID, + has: options.has, + channel_id: options.channel, + author_id: options.author, + author_type: options.authorType, + context_size: options.contextSize, + sort_by: options.sortBy, + sort_order: options.sortOrder, + limit: options.limit, + offset: options.offset, + mentions: options.mentions, + mentions_everyone: options.mentionsEveryone, + link_hostname: options.linkHostname, + embed_provider: options.embedProvider, + embed_type: options.embedType, + attachment_filename: options.attachmentFilename, + attachment_extension: options.attachmentExtension, + include_nsfw: options.nsfw, + }; + + for (const key in options) if (options[key] === undefined) delete options[key]; + const queryString = (querystring.stringify(options).match(/[^=&?]+=[^=&?]+/g) || []).join('&'); + + let endpoint; + if (target instanceof Channel) { + endpoint = Endpoints.Channel(target).search; + } else if (target instanceof Guild) { + endpoint = Endpoints.Guild(target).search; + } else { + throw new TypeError('Target must be a TextChannel, DMChannel, GroupDMChannel, or Guild.'); + } + return this.rest.makeRequest('get', `${endpoint}?${queryString}`, true).then(body => { + const messages = body.messages.map(x => + x.map(m => new Message(this.client.channels.get(m.channel_id), m, this.client)) + ); + return { + totalResults: body.total_results, + messages, + }; + }); + } + + createChannel(guild, channelName, channelType, overwrites, reason) { + if (overwrites instanceof Collection || overwrites instanceof Array) { + overwrites = overwrites.map(overwrite => { + let allow = overwrite.allow || overwrite._allowed; + let deny = overwrite.deny || overwrite._denied; + if (allow instanceof Array) allow = Permissions.resolve(allow); + if (deny instanceof Array) deny = Permissions.resolve(deny); + + const role = this.client.resolver.resolveRole(guild, overwrite.id); + if (role) { + overwrite.id = role.id; + overwrite.type = 'role'; + } else { + overwrite.id = this.client.resolver.resolveUserID(overwrite.id); + overwrite.type = 'member'; + } + + return { + allow, + deny, + type: overwrite.type, + id: overwrite.id, + }; + }); + } + return this.rest.makeRequest('post', Endpoints.Guild(guild).channels, true, { + name: channelName, + type: channelType ? Constants.ChannelTypes[channelType.toUpperCase()] : 'text', + permission_overwrites: overwrites, + }, undefined, reason).then(data => this.client.actions.ChannelCreate.handle(data).channel); + } + + createDM(recipient) { + const dmChannel = this.getExistingDM(recipient); + if (dmChannel) return Promise.resolve(dmChannel); + return this.rest.makeRequest('post', Endpoints.User(this.client.user).channels, true, { + recipient_id: recipient.id, + }).then(data => this.client.actions.ChannelCreate.handle(data).channel); + } + + createGroupDM(options) { + const data = this.client.user.bot ? + { access_tokens: options.accessTokens, nicks: options.nicks } : + { recipients: options.recipients }; + return this.rest.makeRequest('post', Endpoints.User('@me').channels, true, data) + .then(res => new GroupDMChannel(this.client, res)); + } + + addUserToGroupDM(channel, options) { + const data = this.client.user.bot ? + { nick: options.nick, access_token: options.accessToken } : + { recipient: options.id }; + return this.rest.makeRequest('put', Endpoints.Channel(channel).Recipient(options.id), true, data) + .then(() => channel); + } + + removeUserFromGroupDM(channel, userId) { + return this.rest.makeRequest('delete', Endpoints.Channel(channel).Recipient(userId), true) + .then(() => channel); + } + + updateGroupDMChannel(channel, _data) { + const data = {}; + data.name = _data.name; + data.icon = _data.icon; + return this.rest.makeRequest('patch', Endpoints.Channel(channel), true, data).then(() => channel); + } + + getExistingDM(recipient) { + return this.client.channels.find(channel => + channel.recipient && channel.recipient.id === recipient.id + ); + } + + deleteChannel(channel, reason) { + if (channel instanceof User || channel instanceof GuildMember) channel = this.getExistingDM(channel); + if (!channel) return Promise.reject(new Error('No channel to delete.')); + return this.rest.makeRequest('delete', Endpoints.Channel(channel), true, undefined, undefined, reason) + .then(data => { + data.id = channel.id; + return this.client.actions.ChannelDelete.handle(data).channel; + }); + } + + updateChannel(channel, _data, reason) { + const data = {}; + data.name = (_data.name || channel.name).trim(); + data.topic = _data.topic || channel.topic; + data.position = _data.position || channel.position; + data.bitrate = _data.bitrate || (channel.bitrate ? channel.bitrate * 1000 : undefined); + data.user_limit = typeof _data.userLimit !== 'undefined' ? _data.userLimit : channel.userLimit; + data.parent_id = _data.parent || (channel.parent ? channel.parent.id : undefined); + return this.rest.makeRequest('patch', Endpoints.Channel(channel), true, data, undefined, reason).then(newData => + this.client.actions.ChannelUpdate.handle(newData).updated + ); + } + + leaveGuild(guild) { + if (guild.ownerID === this.client.user.id) return Promise.reject(new Error('Guild is owned by the client.')); + return this.rest.makeRequest('delete', Endpoints.User('@me').Guild(guild.id), true).then(() => + this.client.actions.GuildDelete.handle({ id: guild.id }).guild + ); + } + + createGuild(options) { + options.icon = this.client.resolver.resolveBase64(options.icon) || null; + options.region = options.region || 'us-central'; + return new Promise((resolve, reject) => { + this.rest.makeRequest('post', Endpoints.guilds, true, options).then(data => { + if (this.client.guilds.has(data.id)) return resolve(this.client.guilds.get(data.id)); + + const handleGuild = guild => { + if (guild.id === data.id) { + this.client.removeListener(Constants.Events.GUILD_CREATE, handleGuild); + this.client.clearTimeout(timeout); + resolve(guild); + } + }; + this.client.on(Constants.Events.GUILD_CREATE, handleGuild); + + const timeout = this.client.setTimeout(() => { + this.client.removeListener(Constants.Events.GUILD_CREATE, handleGuild); + reject(new Error('Took too long to receive guild data.')); + }, 10000); + return undefined; + }, reject); + }); + } + + // Untested but probably will work + deleteGuild(guild) { + return this.rest.makeRequest('delete', Endpoints.Guild(guild), true).then(() => + this.client.actions.GuildDelete.handle({ id: guild.id }).guild + ); + } + + getUser(userID, cache) { + return this.rest.makeRequest('get', Endpoints.User(userID), true).then(data => { + if (cache) return this.client.actions.UserGet.handle(data).user; + else return new User(this.client, data); + }); + } + + updateCurrentUser(_data, password) { + const user = this.client.user; + const data = {}; + data.username = _data.username || user.username; + data.avatar = typeof _data.avatar === 'undefined' ? user.avatar : this.client.resolver.resolveBase64(_data.avatar); + if (!user.bot) { + data.email = _data.email || user.email; + data.password = password; + if (_data.new_password) data.new_password = _data.newPassword; + } + return this.rest.makeRequest('patch', Endpoints.User('@me'), true, data).then(newData => + this.client.actions.UserUpdate.handle(newData).updated + ); + } + + updateGuild(guild, data, reason) { + return this.rest.makeRequest('patch', Endpoints.Guild(guild), true, data, undefined, reason).then(newData => + this.client.actions.GuildUpdate.handle(newData).updated + ); + } + + kickGuildMember(guild, member, reason) { + return this.rest.makeRequest( + 'delete', Endpoints.Guild(guild).Member(member), true, + undefined, undefined, reason) + .then(() => + this.client.actions.GuildMemberRemove.handle({ + guild_id: guild.id, + user: member.user, + }).member + ); + } + + createGuildRole(guild, data, reason) { + if (data.color) data.color = this.client.resolver.resolveColor(data.color); + if (data.permissions) data.permissions = Permissions.resolve(data.permissions); + return this.rest.makeRequest('post', Endpoints.Guild(guild).roles, true, data, undefined, reason).then(r => { + const { role } = this.client.actions.GuildRoleCreate.handle({ + guild_id: guild.id, + role: r, + }); + if (data.position) return role.setPosition(data.position, reason); + return role; + }); + } + + deleteGuildRole(role, reason) { + return this.rest.makeRequest( + 'delete', Endpoints.Guild(role.guild).Role(role.id), true, + undefined, undefined, reason) + .then(() => + this.client.actions.GuildRoleDelete.handle({ + guild_id: role.guild.id, + role_id: role.id, + }).role + ); + } + + setChannelOverwrite(channel, payload) { + return this.rest.makeRequest('put', `${Endpoints.Channel(channel).permissions}/${payload.id}`, true, payload); + } + + deletePermissionOverwrites(overwrite, reason) { + return this.rest.makeRequest( + 'delete', `${Endpoints.Channel(overwrite.channel).permissions}/${overwrite.id}`, + true, undefined, undefined, reason + ).then(() => overwrite); + } + + getChannelMessages(channel, payload = {}) { + const params = []; + if (payload.limit) params.push(`limit=${payload.limit}`); + if (payload.around) params.push(`around=${payload.around}`); + else if (payload.before) params.push(`before=${payload.before}`); + else if (payload.after) params.push(`after=${payload.after}`); + + let endpoint = Endpoints.Channel(channel).messages; + if (params.length > 0) endpoint += `?${params.join('&')}`; + return this.rest.makeRequest('get', endpoint, true); + } + + getChannelMessage(channel, messageID) { + const msg = channel.messages.get(messageID); + if (msg) return Promise.resolve(msg); + return this.rest.makeRequest('get', Endpoints.Channel(channel).Message(messageID), true); + } + + putGuildMember(guild, user, options) { + options.access_token = options.accessToken; + if (options.roles) { + const roles = options.roles; + if (roles instanceof Collection || (roles instanceof Array && roles[0] instanceof Role)) { + options.roles = roles.map(role => role.id); + } + } + return this.rest.makeRequest('put', Endpoints.Guild(guild).Member(user.id), true, options) + .then(data => this.client.actions.GuildMemberGet.handle(guild, data).member); + } + + getGuildMember(guild, user, cache) { + return this.rest.makeRequest('get', Endpoints.Guild(guild).Member(user.id), true).then(data => { + if (cache) return this.client.actions.GuildMemberGet.handle(guild, data).member; + else return new GuildMember(guild, data); + }); + } + + updateGuildMember(member, data, reason) { + if (data.channel) { + data.channel_id = this.client.resolver.resolveChannel(data.channel).id; + data.channel = null; + } + if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role); + + let endpoint = Endpoints.Member(member); + // Fix your endpoints, discord ;-; + if (member.id === this.client.user.id) { + const keys = Object.keys(data); + if (keys.length === 1 && keys[0] === 'nick') { + endpoint = Endpoints.Member(member).nickname; + } + } + + return this.rest.makeRequest('patch', endpoint, true, data, undefined, reason).then(newData => + member.guild._updateMember(member, newData).mem + ); + } + + addMemberRole(member, role, reason) { + return new Promise((resolve, reject) => { + if (member._roles.includes(role.id)) return resolve(member); + + const listener = (oldMember, newMember) => { + if (!oldMember._roles.includes(role.id) && newMember._roles.includes(role.id)) { + this.client.removeListener(Constants.Events.GUILD_MEMBER_UPDATE, listener); + resolve(newMember); + } + }; + + this.client.on(Constants.Events.GUILD_MEMBER_UPDATE, listener); + const timeout = this.client.setTimeout(() => + this.client.removeListener(Constants.Events.GUILD_MEMBER_UPDATE, listener), 10e3); + + return this.rest.makeRequest('put', Endpoints.Member(member).Role(role.id), true, undefined, undefined, reason) + .catch(err => { + this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener); + this.client.clearTimeout(timeout); + reject(err); + }); + }); + } + + removeMemberRole(member, role, reason) { + return new Promise((resolve, reject) => { + if (!member._roles.includes(role.id)) return resolve(member); + + const listener = (oldMember, newMember) => { + if (oldMember._roles.includes(role.id) && !newMember._roles.includes(role.id)) { + this.client.removeListener(Constants.Events.GUILD_MEMBER_UPDATE, listener); + resolve(newMember); + } + }; + + this.client.on(Constants.Events.GUILD_MEMBER_UPDATE, listener); + const timeout = this.client.setTimeout(() => + this.client.removeListener(Constants.Events.GUILD_MEMBER_UPDATE, listener), 10e3); + + return this.rest.makeRequest('delete', Endpoints.Member(member).Role(role.id), true, undefined, undefined, reason) + .catch(err => { + this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener); + this.client.clearTimeout(timeout); + reject(err); + }); + }); + } + + sendTyping(channelID) { + return this.rest.makeRequest('post', Endpoints.Channel(channelID).typing, true); + } + + banGuildMember(guild, member, options) { + const id = this.client.resolver.resolveUserID(member); + if (!id) return Promise.reject(new Error('Couldn\'t resolve the user ID to ban.')); + + const url = `${Endpoints.Guild(guild).bans}/${id}?${querystring.stringify(options)}`; + return this.rest.makeRequest('put', url, true).then(() => { + if (member instanceof GuildMember) return member; + const user = this.client.resolver.resolveUser(id); + if (user) { + member = this.client.resolver.resolveGuildMember(guild, user); + return member || user; + } + return id; + }); + } + + unbanGuildMember(guild, member, reason) { + return new Promise((resolve, reject) => { + const id = this.client.resolver.resolveUserID(member); + if (!id) throw new Error('Couldn\'t resolve the user ID to unban.'); + + const listener = (eGuild, eUser) => { + if (eGuild.id === guild.id && eUser.id === id) { + this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener); + this.client.clearTimeout(timeout); + resolve(eUser); + } + }; + this.client.on(Constants.Events.GUILD_BAN_REMOVE, listener); + + const timeout = this.client.setTimeout(() => { + this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener); + reject(new Error('Took too long to receive the ban remove event.')); + }, 10000); + + this.rest.makeRequest('delete', `${Endpoints.Guild(guild).bans}/${id}`, true, undefined, undefined, reason) + .catch(err => { + this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener); + this.client.clearTimeout(timeout); + reject(err); + }); + }); + } + + getGuildBans(guild) { + return this.rest.makeRequest('get', Endpoints.Guild(guild).bans, true).then(bans => + bans.reduce((collection, ban) => { + collection.set(ban.user.id, { + reason: ban.reason, + user: this.client.dataManager.newUser(ban.user), + }); + return collection; + }, new Collection()) + ); + } + + updateGuildRole(role, _data, reason) { + const data = {}; + data.name = _data.name || role.name; + data.position = typeof _data.position !== 'undefined' ? _data.position : role.position; + data.color = this.client.resolver.resolveColor(_data.color || role.color); + data.hoist = typeof _data.hoist !== 'undefined' ? _data.hoist : role.hoist; + data.mentionable = typeof _data.mentionable !== 'undefined' ? _data.mentionable : role.mentionable; + + if (_data.permissions) data.permissions = Permissions.resolve(_data.permissions); + else data.permissions = role.permissions; + + return this.rest.makeRequest('patch', Endpoints.Guild(role.guild).Role(role.id), true, data, undefined, reason) + .then(_role => + this.client.actions.GuildRoleUpdate.handle({ + role: _role, + guild_id: role.guild.id, + }).updated + ); + } + + pinMessage(message) { + return this.rest.makeRequest('put', Endpoints.Channel(message.channel).Pin(message.id), true) + .then(() => message); + } + + unpinMessage(message) { + return this.rest.makeRequest('delete', Endpoints.Channel(message.channel).Pin(message.id), true) + .then(() => message); + } + + getChannelPinnedMessages(channel) { + return this.rest.makeRequest('get', Endpoints.Channel(channel).pins, true); + } + + createChannelInvite(channel, options, reason) { + const payload = {}; + payload.temporary = options.temporary; + payload.max_age = options.maxAge; + payload.max_uses = options.maxUses; + payload.unique = options.unique; + return this.rest.makeRequest('post', Endpoints.Channel(channel).invites, true, payload, undefined, reason) + .then(invite => new Invite(this.client, invite)); + } + + deleteInvite(invite, reason) { + return this.rest.makeRequest('delete', Endpoints.Invite(invite.code), true, undefined, undefined, reason) + .then(() => invite); + } + + getInvite(code) { + return this.rest.makeRequest('get', Endpoints.Invite(code), true).then(invite => + new Invite(this.client, invite) + ); + } + + getGuildInvites(guild) { + return this.rest.makeRequest('get', Endpoints.Guild(guild).invites, true).then(inviteItems => { + const invites = new Collection(); + for (const inviteItem of inviteItems) { + const invite = new Invite(this.client, inviteItem); + invites.set(invite.code, invite); + } + return invites; + }); + } + + pruneGuildMembers(guild, days, dry, reason) { + return this.rest.makeRequest(dry ? + 'get' : + 'post', + `${Endpoints.Guild(guild).prune}?days=${days}`, true, undefined, undefined, reason) + .then(data => data.pruned); + } + + createEmoji(guild, image, name, roles, reason) { + const data = { image, name }; + if (roles) data.roles = roles.map(r => r.id ? r.id : r); + return this.rest.makeRequest('post', Endpoints.Guild(guild).emojis, true, data, undefined, reason) + .then(emoji => this.client.actions.GuildEmojiCreate.handle(guild, emoji).emoji); + } + + updateEmoji(emoji, _data, reason) { + const data = {}; + if (_data.name) data.name = _data.name; + if (_data.roles) data.roles = _data.roles.map(r => r.id ? r.id : r); + return this.rest.makeRequest('patch', Endpoints.Guild(emoji.guild).Emoji(emoji.id), true, data, undefined, reason) + .then(newEmoji => this.client.actions.GuildEmojiUpdate.handle(emoji, newEmoji).emoji); + } + + deleteEmoji(emoji, reason) { + return this.rest.makeRequest('delete', Endpoints.Guild(emoji.guild).Emoji(emoji.id), true, undefined, reason) + .then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data); + } + + getGuildAuditLogs(guild, options = {}) { + if (options.before && options.before instanceof GuildAuditLogs.Entry) options.before = options.before.id; + if (options.after && options.after instanceof GuildAuditLogs.Entry) options.after = options.after.id; + if (typeof options.type === 'string') options.type = GuildAuditLogs.Actions[options.type]; + + const queryString = (querystring.stringify({ + before: options.before, + after: options.after, + limit: options.limit, + user_id: this.client.resolver.resolveUserID(options.user), + action_type: options.type, + }).match(/[^=&?]+=[^=&?]+/g) || []).join('&'); + + return this.rest.makeRequest('get', `${Endpoints.Guild(guild).auditLogs}?${queryString}`, true) + .then(data => GuildAuditLogs.build(guild, data)); + } + + getWebhook(id, token) { + return this.rest.makeRequest('get', Endpoints.Webhook(id, token), !token).then(data => + new Webhook(this.client, data) + ); + } + + getGuildWebhooks(guild) { + return this.rest.makeRequest('get', Endpoints.Guild(guild).webhooks, true).then(data => { + const hooks = new Collection(); + for (const hook of data) hooks.set(hook.id, new Webhook(this.client, hook)); + return hooks; + }); + } + + getChannelWebhooks(channel) { + return this.rest.makeRequest('get', Endpoints.Channel(channel).webhooks, true).then(data => { + const hooks = new Collection(); + for (const hook of data) hooks.set(hook.id, new Webhook(this.client, hook)); + return hooks; + }); + } + + createWebhook(channel, name, avatar, reason) { + return this.rest.makeRequest('post', Endpoints.Channel(channel).webhooks, true, { name, avatar }, undefined, reason) + .then(data => new Webhook(this.client, data)); + } + + editWebhook(webhook, name, avatar) { + return this.rest.makeRequest('patch', Endpoints.Webhook(webhook.id, webhook.token), false, { + name, + avatar, + }).then(data => { + webhook.name = data.name; + webhook.avatar = data.avatar; + return webhook; + }); + } + + deleteWebhook(webhook, reason) { + return this.rest.makeRequest( + 'delete', Endpoints.Webhook(webhook.id, webhook.token), + false, undefined, undefined, reason); + } + + sendWebhookMessage(webhook, content, { avatarURL, tts, embeds, username } = {}, files = null) { + return new Promise((resolve, reject) => { + username = username || webhook.name; + + if (content instanceof Array) { + const messages = []; + (function sendChunk(list, index) { + const options = index === list.length - 1 ? { tts, embeds, files } : { tts }; + webhook.send(list[index], options).then(message => { + messages.push(message); + if (index >= list.length - 1) return resolve(messages); + return sendChunk(list, ++index); + }).catch(reject); + }(content, 0)); + } else { + this.rest.makeRequest('post', `${Endpoints.Webhook(webhook.id, webhook.token)}?wait=true`, false, { + username, + avatar_url: avatarURL, + content, + tts, + embeds, + }, files).then(data => { + if (!this.client.channels) resolve(data); + else resolve(this.client.actions.MessageCreate.handle(data).message); + }, reject); + } + }); + } + + sendSlackWebhookMessage(webhook, body) { + return this.rest.makeRequest( + 'post', `${Endpoints.Webhook(webhook.id, webhook.token)}/slack?wait=true`, false, body + ); + } + + fetchUserProfile(user) { + return this.rest.makeRequest('get', Endpoints.User(user).profile, true).then(data => + new UserProfile(user, data) + ); + } + + fetchMentions(options) { + if (options.guild instanceof Guild) options.guild = options.guild.id; + Util.mergeDefault({ limit: 25, roles: true, everyone: true, guild: null }, options); + + return this.rest.makeRequest( + 'get', Endpoints.User('@me').Mentions(options.limit, options.roles, options.everyone, options.guild), true + ).then(data => data.map(m => new Message(this.client.channels.get(m.channel_id), m, this.client))); + } + + addFriend(user) { + return this.rest.makeRequest('post', Endpoints.User('@me'), true, { + username: user.username, + discriminator: user.discriminator, + }).then(() => user); + } + + removeFriend(user) { + return this.rest.makeRequest('delete', Endpoints.User('@me').Relationship(user.id), true) + .then(() => user); + } + + blockUser(user) { + return this.rest.makeRequest('put', Endpoints.User('@me').Relationship(user.id), true, { type: 2 }) + .then(() => user); + } + + unblockUser(user) { + return this.rest.makeRequest('delete', Endpoints.User('@me').Relationship(user.id), true) + .then(() => user); + } + + updateChannelPositions(guildID, channels) { + const data = new Array(channels.length); + for (let i = 0; i < channels.length; i++) { + data[i] = { + id: this.client.resolver.resolveChannelID(channels[i].channel), + position: channels[i].position, + }; + } + + return this.rest.makeRequest('patch', Endpoints.Guild(guildID).channels, true, data).then(() => + this.client.actions.GuildChannelsPositionUpdate.handle({ + guild_id: guildID, + channels, + }).guild + ); + } + + setRolePositions(guildID, roles) { + return this.rest.makeRequest('patch', Endpoints.Guild(guildID).roles, true, roles).then(() => + this.client.actions.GuildRolesPositionUpdate.handle({ + guild_id: guildID, + roles, + }).guild + ); + } + + setChannelPositions(guildID, channels) { + return this.rest.makeRequest('patch', Endpoints.Guild(guildID).channels, true, channels).then(() => + this.client.actions.GuildChannelsPositionUpdate.handle({ + guild_id: guildID, + channels, + }).guild + ); + } + + addMessageReaction(message, emoji) { + return this.rest.makeRequest( + 'put', Endpoints.Message(message).Reaction(emoji).User('@me'), true + ).then(() => + message._addReaction(Util.parseEmoji(emoji), message.client.user) + ); + } + + removeMessageReaction(message, emoji, userID) { + const endpoint = Endpoints.Message(message).Reaction(emoji).User(userID === this.client.user.id ? '@me' : userID); + return this.rest.makeRequest('delete', endpoint, true).then(() => + this.client.actions.MessageReactionRemove.handle({ + user_id: userID, + message_id: message.id, + emoji: Util.parseEmoji(emoji), + channel_id: message.channel.id, + }).reaction + ); + } + + removeMessageReactions(message) { + return this.rest.makeRequest('delete', Endpoints.Message(message).reactions, true) + .then(() => message); + } + + getMessageReactionUsers(message, emoji, options) { + const queryString = (querystring.stringify(options).match(/[^=&?]+=[^=&?]+/g) || []).join('&'); + + return this.rest.makeRequest('get', `${Endpoints.Message(message).Reaction(emoji)}?${queryString}`, true); + } + + getApplication(id) { + return this.rest.makeRequest('get', Endpoints.OAUTH2.Application(id), true).then(app => + new OAuth2Application(this.client, app) + ); + } + + resetApplication(id) { + return this.rest.makeRequest('post', Endpoints.OAUTH2.Application(id).resetToken, true) + .then(() => this.rest.makeRequest('post', Endpoints.OAUTH2.Application(id).resetSecret, true)) + .then(app => new OAuth2Application(this.client, app)); + } + + setNote(user, note) { + return this.rest.makeRequest('put', Endpoints.User(user).note, true, { note }).then(() => user); + } + + acceptInvite(code) { + if (code.id) code = code.id; + return new Promise((resolve, reject) => + this.rest.makeRequest('post', Endpoints.Invite(code), true).then(res => { + const handler = guild => { + if (guild.id === res.id) { + resolve(guild); + this.client.removeListener(Constants.Events.GUILD_CREATE, handler); + } + }; + this.client.on(Constants.Events.GUILD_CREATE, handler); + this.client.setTimeout(() => { + this.client.removeListener(Constants.Events.GUILD_CREATE, handler); + reject(new Error('Accepting invite timed out')); + }, 120e3); + }) + ); + } + + patchUserSettings(data) { + return this.rest.makeRequest('patch', Constants.Endpoints.User('@me').settings, true, data); + } + + patchClientUserGuildSettings(guildID, data) { + return this.rest.makeRequest('patch', Constants.Endpoints.User('@me').Guild(guildID).settings, true, data); + } +} + +module.exports = RESTMethods; + + +/***/ }), +/* 75 */ +/***/ (function(module, exports, __webpack_require__) { + +const Collection = __webpack_require__(3); +const UserConnection = __webpack_require__(76); + +/** + * Represents a user's profile on Discord. + */ +class UserProfile { + constructor(user, data) { + /** + * The owner of the profile + * @type {User} + */ + this.user = user; + + /** + * The client that created the instance of the UserProfile + * @name UserProfile#client + * @type {Client} + * @readonly + */ + Object.defineProperty(this, 'client', { value: user.client }); + + /** + * The guilds that the client user and the user share + * @type {Collection} + */ + this.mutualGuilds = new Collection(); + + /** + * The user's connections + * @type {Collection} + */ + this.connections = new Collection(); + + this.setup(data); + } + + setup(data) { + /** + * If the user has Discord Premium + * @type {boolean} + */ + this.premium = data.premium; + + /** + * The date since which the user has had Discord Premium + * @type {?Date} + */ + this.premiumSince = data.premium_since ? new Date(data.premium_since) : null; + + for (const guild of data.mutual_guilds) { + if (this.client.guilds.has(guild.id)) { + this.mutualGuilds.set(guild.id, this.client.guilds.get(guild.id)); + } + } + for (const connection of data.connected_accounts) { + this.connections.set(connection.id, new UserConnection(this.user, connection)); + } + } +} + +module.exports = UserProfile; + + +/***/ }), +/* 76 */ +/***/ (function(module, exports) { + +/** + * Represents a user connection (or "platform identity"). + */ +class UserConnection { + constructor(user, data) { + /** + * The user that owns the connection + * @type {User} + */ + this.user = user; + + this.setup(data); + } + + setup(data) { + /** + * The type of the connection + * @type {string} + */ + this.type = data.type; + + /** + * The username of the connection account + * @type {string} + */ + this.name = data.name; + + /** + * The id of the connection account + * @type {string} + */ + this.id = data.id; + + /** + * Whether the connection is revoked + * @type {boolean} + */ + this.revoked = data.revoked; + + /** + * Partial server integrations (not yet implemented) + * @type {Object[]} + */ + this.integrations = data.integrations; + } +} + +module.exports = UserConnection; + + +/***/ }), +/* 77 */ +/***/ (function(module, exports) { + +/** + * Represents a Discord voice region for guilds. + */ +class VoiceRegion { + constructor(data) { + /** + * The ID of the region + * @type {string} + */ + this.id = data.id; + + /** + * Name of the region + * @type {string} + */ + this.name = data.name; + + /** + * Whether the region is VIP-only + * @type {boolean} + */ + this.vip = data.vip; + + /** + * Whether the region is deprecated + * @type {boolean} + */ + this.deprecated = data.deprecated; + + /** + * Whether the region is optimal + * @type {boolean} + */ + this.optimal = data.optimal; + + /** + * Whether the region is custom + * @type {boolean} + */ + this.custom = data.custom; + + /** + * A sample hostname for what a connection might look like + * @type {string} + */ + this.sampleHostname = data.sample_hostname; + } +} + +module.exports = VoiceRegion; + + +/***/ }), +/* 78 */ +/***/ (function(module, exports, __webpack_require__) { + +const RequestHandler = __webpack_require__(48); +const DiscordAPIError = __webpack_require__(33); + +/** + * Handles API Requests sequentially, i.e. we wait until the current request is finished before moving onto + * the next. This plays a _lot_ nicer in terms of avoiding 429's when there is more than one session of the account, + * but it can be slower. + * @extends {RequestHandler} + * @private + */ +class SequentialRequestHandler extends RequestHandler { + /** + * @param {RESTManager} restManager The REST manager to use + * @param {string} endpoint The endpoint to handle + */ + constructor(restManager, endpoint) { + super(restManager, endpoint); + + /** + * The endpoint that this handler is handling + * @type {string} + */ + this.endpoint = endpoint; + + /** + * The time difference between Discord's Dates and the local computer's Dates. A positive number means the local + * computer's time is ahead of Discord's + * @type {number} + */ + this.timeDifference = 0; + + /** + * Whether the queue is being processed or not + * @type {boolean} + */ + this.busy = false; + } + + push(request) { + super.push(request); + this.handle(); + } + + /** + * Performs a request then resolves a promise to indicate its readiness for a new request. + * @param {APIRequest} item The item to execute + * @returns {Promise} + */ + execute(item) { + this.busy = true; + return new Promise(resolve => { + item.request.gen().end((err, res) => { + if (res && res.headers) { + this.requestLimit = Number(res.headers['x-ratelimit-limit']); + this.requestResetTime = Number(res.headers['x-ratelimit-reset']) * 1000; + this.requestRemaining = Number(res.headers['x-ratelimit-remaining']); + this.timeDifference = Date.now() - new Date(res.headers.date).getTime(); + } + if (err) { + if (err.status === 429) { + this.queue.unshift(item); + this.restManager.client.setTimeout(() => { + this.globalLimit = false; + resolve(); + }, Number(res.headers['retry-after']) + this.restManager.client.options.restTimeOffset); + if (res.headers['x-ratelimit-global']) this.globalLimit = true; + } else if (err.status >= 500 && err.status < 600) { + this.queue.unshift(item); + this.restManager.client.setTimeout(resolve, 1e3 + this.restManager.client.options.restTimeOffset); + } else { + item.reject(err.status >= 400 && err.status < 500 ? new DiscordAPIError(res.request.path, res.body) : err); + resolve(err); + } + } else { + this.globalLimit = false; + const data = res && res.body ? res.body : {}; + item.resolve(data); + if (this.requestRemaining === 0) { + this.restManager.client.setTimeout( + () => resolve(data), + this.requestResetTime - Date.now() + this.timeDifference + this.restManager.client.options.restTimeOffset + ); + } else { + resolve(data); + } + } + }); + }); + } + + handle() { + super.handle(); + if (this.busy || this.remaining === 0 || this.queue.length === 0 || this.globalLimit) return; + this.execute(this.queue.shift()).then(() => { + this.busy = false; + this.handle(); + }); + } +} + +module.exports = SequentialRequestHandler; + + +/***/ }), +/* 79 */ +/***/ (function(module, exports, __webpack_require__) { + +const RequestHandler = __webpack_require__(48); +const DiscordAPIError = __webpack_require__(33); + +class BurstRequestHandler extends RequestHandler { + constructor(restManager, endpoint) { + super(restManager, endpoint); + + this.client = restManager.client; + + this.limit = Infinity; + this.resetTime = null; + this.remaining = 1; + this.timeDifference = 0; + + this.resetTimeout = null; + } + + push(request) { + super.push(request); + this.handle(); + } + + execute(item) { + if (!item) return; + item.request.gen().end((err, res) => { + if (res && res.headers) { + this.limit = Number(res.headers['x-ratelimit-limit']); + this.resetTime = Number(res.headers['x-ratelimit-reset']) * 1000; + this.remaining = Number(res.headers['x-ratelimit-remaining']); + this.timeDifference = Date.now() - new Date(res.headers.date).getTime(); + } + if (err) { + if (err.status === 429) { + this.queue.unshift(item); + if (res.headers['x-ratelimit-global']) this.globalLimit = true; + if (this.resetTimeout) return; + this.resetTimeout = this.client.setTimeout(() => { + this.remaining = this.limit; + this.globalLimit = false; + this.handle(); + this.resetTimeout = null; + }, Number(res.headers['retry-after']) + this.client.options.restTimeOffset); + } else if (err.status >= 500 && err.status < 600) { + this.queue.unshift(item); + this.resetTimeout = this.client.setTimeout(() => { + this.handle(); + this.resetTimeout = null; + }, 1e3 + this.client.options.restTimeOffset); + } else { + item.reject(err.status >= 400 && err.status < 500 ? new DiscordAPIError(res.request.path, res.body) : err); + this.handle(); + } + } else { + this.globalLimit = false; + const data = res && res.body ? res.body : {}; + item.resolve(data); + this.handle(); + } + }); + } + + handle() { + super.handle(); + if (this.remaining <= 0 || this.queue.length === 0 || this.globalLimit) return; + this.execute(this.queue.shift()); + this.remaining--; + this.handle(); + } +} + +module.exports = BurstRequestHandler; + + +/***/ }), +/* 80 */ +/***/ (function(module, exports, __webpack_require__) { + +const snekfetch = __webpack_require__(24); +const Constants = __webpack_require__(0); + +class APIRequest { + constructor(rest, method, path, auth, data, files, reason) { + this.rest = rest; + this.client = rest.client; + this.method = method; + this.path = path.toString(); + this.auth = auth; + this.data = data; + this.files = files; + this.route = this.getRoute(this.path); + this.reason = reason; + } + + getRoute(url) { + let route = url.split('?')[0]; + if (route.includes('/channels/') || route.includes('/guilds/')) { + const startInd = route.includes('/channels/') ? route.indexOf('/channels/') : route.indexOf('/guilds/'); + const majorID = route.substring(startInd).split('/')[2]; + route = route.replace(/(\d{8,})/g, ':id').replace(':id', majorID); + } + return route; + } + + getAuth() { + if (this.client.token && this.client.user && this.client.user.bot) { + return `Bot ${this.client.token}`; + } else if (this.client.token) { + return this.client.token; + } + throw new Error(Constants.Errors.NO_TOKEN); + } + + gen() { + const API = `${this.client.options.http.host}/api/v${this.client.options.http.version}`; + const request = snekfetch[this.method](`${API}${this.path}`); + if (this.auth) request.set('Authorization', this.getAuth()); + if (this.reason) request.set('X-Audit-Log-Reason', encodeURIComponent(this.reason)); + if (!this.rest.client.browser) request.set('User-Agent', this.rest.userAgentManager.userAgent); + if (this.files) { + for (const file of this.files) if (file && file.file) request.attach(file.name, file.file, file.name); + if (typeof this.data !== 'undefined') request.attach('payload_json', JSON.stringify(this.data)); + } else if (this.data) { + request.send(this.data); + } + return request; + } +} + +module.exports = APIRequest; + + +/***/ }), +/* 81 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); +const Guild = __webpack_require__(22); +const User = __webpack_require__(9); +const CategoryChannel = __webpack_require__(49); +const DMChannel = __webpack_require__(51); +const Emoji = __webpack_require__(16); +const TextChannel = __webpack_require__(52); +const VoiceChannel = __webpack_require__(53); +const GuildChannel = __webpack_require__(18); +const GroupDMChannel = __webpack_require__(32); + +class ClientDataManager { + constructor(client) { + this.client = client; + } + + get pastReady() { + return this.client.ws.connection.status === Constants.Status.READY; + } + + newGuild(data) { + const already = this.client.guilds.has(data.id); + const guild = new Guild(this.client, data); + this.client.guilds.set(guild.id, guild); + if (this.pastReady && !already) { + /** + * Emitted whenever the client joins a guild. + * @event Client#guildCreate + * @param {Guild} guild The created guild + */ + if (this.client.options.fetchAllMembers) { + guild.fetchMembers().then(() => { this.client.emit(Constants.Events.GUILD_CREATE, guild); }); + } else { + this.client.emit(Constants.Events.GUILD_CREATE, guild); + } + } + + return guild; + } + + newUser(data) { + if (this.client.users.has(data.id)) return this.client.users.get(data.id); + const user = new User(this.client, data); + this.client.users.set(user.id, user); + return user; + } + + newChannel(data, guild) { + const already = this.client.channels.has(data.id); + let channel; + if (data.type === Constants.ChannelTypes.DM) { + channel = new DMChannel(this.client, data); + } else if (data.type === Constants.ChannelTypes.GROUP_DM) { + channel = new GroupDMChannel(this.client, data); + } else { + guild = guild || this.client.guilds.get(data.guild_id); + if (guild) { + if (data.type === Constants.ChannelTypes.TEXT) { + channel = new TextChannel(guild, data); + guild.channels.set(channel.id, channel); + } else if (data.type === Constants.ChannelTypes.VOICE) { + channel = new VoiceChannel(guild, data); + guild.channels.set(channel.id, channel); + } else if (data.type === Constants.ChannelTypes.CATEGORY) { + channel = new CategoryChannel(guild, data); + guild.channels.set(channel.id, channel); + } + } + } + + if (channel && !already) { + if (this.pastReady) this.client.emit(Constants.Events.CHANNEL_CREATE, channel); + this.client.channels.set(channel.id, channel); + return channel; + } else if (already) { + return channel; + } + + return null; + } + + newEmoji(data, guild) { + const already = guild.emojis.has(data.id); + if (data && !already) { + let emoji = new Emoji(guild, data); + this.client.emit(Constants.Events.GUILD_EMOJI_CREATE, emoji); + guild.emojis.set(emoji.id, emoji); + return emoji; + } else if (already) { + return guild.emojis.get(data.id); + } + + return null; + } + + killEmoji(emoji) { + if (!(emoji instanceof Emoji && emoji.guild)) return; + this.client.emit(Constants.Events.GUILD_EMOJI_DELETE, emoji); + emoji.guild.emojis.delete(emoji.id); + } + + killGuild(guild) { + const already = this.client.guilds.has(guild.id); + this.client.guilds.delete(guild.id); + if (already && this.pastReady) this.client.emit(Constants.Events.GUILD_DELETE, guild); + } + + killUser(user) { + this.client.users.delete(user.id); + } + + killChannel(channel) { + this.client.channels.delete(channel.id); + if (channel instanceof GuildChannel) channel.guild.channels.delete(channel.id); + } + + updateGuild(currentGuild, newData) { + const oldGuild = Util.cloneObject(currentGuild); + currentGuild.setup(newData); + if (this.pastReady) this.client.emit(Constants.Events.GUILD_UPDATE, oldGuild, currentGuild); + } + + updateChannel(currentChannel, newData) { + currentChannel.setup(newData); + } + + updateEmoji(currentEmoji, newData) { + const oldEmoji = Util.cloneObject(currentEmoji); + currentEmoji.setup(newData); + this.client.emit(Constants.Events.GUILD_EMOJI_UPDATE, oldEmoji, currentEmoji); + return currentEmoji; + } +} + +module.exports = ClientDataManager; + + +/***/ }), +/* 82 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); +const WebSocketConnection = __webpack_require__(54); + +/** + * Manages the state and background tasks of the client. + * @private + */ +class ClientManager { + constructor(client) { + /** + * The client that instantiated this Manager + * @type {Client} + */ + this.client = client; + + /** + * The heartbeat interval + * @type {?number} + */ + this.heartbeatInterval = null; + } + + /** + * The status of the client + * @type {number} + */ + get status() { + return this.connection ? this.connection.status : Constants.Status.IDLE; + } + + /** + * Connects the client to the WebSocket. + * @param {string} token The authorization token + * @param {Function} resolve Function to run when connection is successful + * @param {Function} reject Function to run when connection fails + */ + connectToWebSocket(token, resolve, reject) { + this.client.emit(Constants.Events.DEBUG, `Authenticated using token ${token}`); + this.client.token = token; + const timeout = this.client.setTimeout(() => reject(new Error(Constants.Errors.TOOK_TOO_LONG)), 1000 * 300); + this.client.rest.methods.getGateway().then(res => { + const protocolVersion = Constants.DefaultOptions.ws.version; + const gateway = `${res.url}/?v=${protocolVersion}&encoding=${WebSocketConnection.ENCODING}`; + this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`); + this.client.ws.connect(gateway); + this.client.ws.connection.once('close', event => { + if (event.code === 4004) reject(new Error(Constants.Errors.BAD_LOGIN)); + if (event.code === 4010) reject(new Error(Constants.Errors.INVALID_SHARD)); + if (event.code === 4011) reject(new Error(Constants.Errors.SHARDING_REQUIRED)); + }); + this.client.once(Constants.Events.READY, () => { + resolve(token); + this.client.clearTimeout(timeout); + }); + }, reject); + } + + destroy() { + this.client.ws.destroy(); + this.client.rest.destroy(); + if (!this.client.user) return Promise.resolve(); + if (this.client.user.bot) { + this.client.token = null; + return Promise.resolve(); + } else { + return this.client.rest.methods.logout().then(() => { + this.client.token = null; + }); + } + } +} + +module.exports = ClientManager; + + +/***/ }), +/* 83 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); + +const BeforeReadyWhitelist = [ + Constants.WSEvents.READY, + Constants.WSEvents.RESUMED, + Constants.WSEvents.GUILD_CREATE, + Constants.WSEvents.GUILD_DELETE, + Constants.WSEvents.GUILD_MEMBERS_CHUNK, + Constants.WSEvents.GUILD_MEMBER_ADD, + Constants.WSEvents.GUILD_MEMBER_REMOVE, +]; + +class WebSocketPacketManager { + constructor(connection) { + this.ws = connection; + this.handlers = {}; + this.queue = []; + + this.register(Constants.WSEvents.READY, __webpack_require__(84)); + this.register(Constants.WSEvents.RESUMED, __webpack_require__(86)); + this.register(Constants.WSEvents.GUILD_CREATE, __webpack_require__(87)); + this.register(Constants.WSEvents.GUILD_DELETE, __webpack_require__(88)); + this.register(Constants.WSEvents.GUILD_UPDATE, __webpack_require__(89)); + this.register(Constants.WSEvents.GUILD_BAN_ADD, __webpack_require__(90)); + this.register(Constants.WSEvents.GUILD_BAN_REMOVE, __webpack_require__(91)); + this.register(Constants.WSEvents.GUILD_MEMBER_ADD, __webpack_require__(92)); + this.register(Constants.WSEvents.GUILD_MEMBER_REMOVE, __webpack_require__(93)); + this.register(Constants.WSEvents.GUILD_MEMBER_UPDATE, __webpack_require__(94)); + this.register(Constants.WSEvents.GUILD_ROLE_CREATE, __webpack_require__(95)); + this.register(Constants.WSEvents.GUILD_ROLE_DELETE, __webpack_require__(96)); + this.register(Constants.WSEvents.GUILD_ROLE_UPDATE, __webpack_require__(97)); + this.register(Constants.WSEvents.GUILD_EMOJIS_UPDATE, __webpack_require__(98)); + this.register(Constants.WSEvents.GUILD_MEMBERS_CHUNK, __webpack_require__(99)); + this.register(Constants.WSEvents.CHANNEL_CREATE, __webpack_require__(100)); + this.register(Constants.WSEvents.CHANNEL_DELETE, __webpack_require__(101)); + this.register(Constants.WSEvents.CHANNEL_UPDATE, __webpack_require__(102)); + this.register(Constants.WSEvents.CHANNEL_PINS_UPDATE, __webpack_require__(103)); + this.register(Constants.WSEvents.PRESENCE_UPDATE, __webpack_require__(104)); + this.register(Constants.WSEvents.USER_UPDATE, __webpack_require__(105)); + this.register(Constants.WSEvents.USER_NOTE_UPDATE, __webpack_require__(106)); + this.register(Constants.WSEvents.USER_SETTINGS_UPDATE, __webpack_require__(107)); + this.register(Constants.WSEvents.USER_GUILD_SETTINGS_UPDATE, __webpack_require__(108)); + this.register(Constants.WSEvents.VOICE_STATE_UPDATE, __webpack_require__(109)); + this.register(Constants.WSEvents.TYPING_START, __webpack_require__(110)); + this.register(Constants.WSEvents.MESSAGE_CREATE, __webpack_require__(111)); + this.register(Constants.WSEvents.MESSAGE_DELETE, __webpack_require__(112)); + this.register(Constants.WSEvents.MESSAGE_UPDATE, __webpack_require__(113)); + this.register(Constants.WSEvents.MESSAGE_DELETE_BULK, __webpack_require__(114)); + this.register(Constants.WSEvents.VOICE_SERVER_UPDATE, __webpack_require__(115)); + this.register(Constants.WSEvents.GUILD_SYNC, __webpack_require__(116)); + this.register(Constants.WSEvents.RELATIONSHIP_ADD, __webpack_require__(117)); + this.register(Constants.WSEvents.RELATIONSHIP_REMOVE, __webpack_require__(118)); + this.register(Constants.WSEvents.MESSAGE_REACTION_ADD, __webpack_require__(119)); + this.register(Constants.WSEvents.MESSAGE_REACTION_REMOVE, __webpack_require__(120)); + this.register(Constants.WSEvents.MESSAGE_REACTION_REMOVE_ALL, __webpack_require__(121)); + } + + get client() { + return this.ws.client; + } + + register(event, Handler) { + this.handlers[event] = new Handler(this); + } + + handleQueue() { + this.queue.forEach((element, index) => { + this.handle(this.queue[index], true); + this.queue.splice(index, 1); + }); + } + + handle(packet, queue = false) { + if (packet.op === Constants.OPCodes.HEARTBEAT_ACK) { + this.ws.client._pong(this.ws.client._pingTimestamp); + this.ws.lastHeartbeatAck = true; + this.ws.client.emit('debug', 'Heartbeat acknowledged'); + } else if (packet.op === Constants.OPCodes.HEARTBEAT) { + this.client.ws.send({ + op: Constants.OPCodes.HEARTBEAT, + d: this.client.ws.sequence, + }); + this.ws.client.emit('debug', 'Received gateway heartbeat'); + } + + if (this.ws.status === Constants.Status.RECONNECTING) { + this.ws.reconnecting = false; + this.ws.checkIfReady(); + } + + this.ws.setSequence(packet.s); + + if (this.ws.disabledEvents[packet.t] !== undefined) return false; + + if (this.ws.status !== Constants.Status.READY) { + if (BeforeReadyWhitelist.indexOf(packet.t) === -1) { + this.queue.push(packet); + return false; + } + } + + if (!queue && this.queue.length > 0) this.handleQueue(); + if (this.handlers[packet.t]) return this.handlers[packet.t].handle(packet); + return false; + } +} + +module.exports = WebSocketPacketManager; + + +/***/ }), +/* 84 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +const ClientUser = __webpack_require__(55); + +class ReadyHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + + client.ws.heartbeat(); + + data.user.user_settings = data.user_settings; + data.user.user_guild_settings = data.user_guild_settings; + + const clientUser = new ClientUser(client, data.user); + client.user = clientUser; + client.readyAt = new Date(); + client.users.set(clientUser.id, clientUser); + + for (const guild of data.guilds) if (!client.guilds.has(guild.id)) client.dataManager.newGuild(guild); + for (const privateDM of data.private_channels) client.dataManager.newChannel(privateDM); + + for (const relation of data.relationships) { + const user = client.dataManager.newUser(relation.user); + if (relation.type === 1) { + client.user.friends.set(user.id, user); + } else if (relation.type === 2) { + client.user.blocked.set(user.id, user); + } + } + + data.presences = data.presences || []; + for (const presence of data.presences) { + client.dataManager.newUser(presence.user); + client._setPresence(presence.user.id, presence); + } + + if (data.notes) { + for (const user in data.notes) { + let note = data.notes[user]; + if (!note.length) note = null; + + client.user.notes.set(user, note); + } + } + + if (!client.user.bot && client.options.sync) client.setInterval(client.syncGuilds.bind(client), 30000); + + if (!client.users.has('1')) { + client.dataManager.newUser({ + id: '1', + username: 'Clyde', + discriminator: '0000', + avatar: 'https://discordapp.com/assets/f78426a064bc9dd24847519259bc42af.png', + bot: true, + status: 'online', + game: null, + verified: true, + }); + } + + const t = client.setTimeout(() => { + client.ws.connection.triggerReady(); + }, 1200 * data.guilds.length); + + client.setMaxListeners(data.guilds.length + 10); + + client.once('ready', () => { + client.syncGuilds(); + client.setMaxListeners(10); + client.clearTimeout(t); + }); + + const ws = this.packetManager.ws; + + ws.sessionID = data.session_id; + ws._trace = data._trace; + client.emit('debug', `READY ${ws._trace.join(' -> ')} ${ws.sessionID}`); + ws.checkIfReady(); + } +} + +module.exports = ReadyHandler; + + +/***/ }), +/* 85 */ +/***/ (function(module, exports, __webpack_require__) { + +const Constants = __webpack_require__(0); + +/** + * A wrapper around the ClientUser's channel overrides. + */ +class ClientUserChannelOverride { + constructor(data) { + this.patch(data); + } + + /** + * Patch the data contained in this class with new partial data. + * @param {Object} data Data to patch this with + * @returns {void} + * @private + */ + patch(data) { + for (const key of Object.keys(Constants.UserChannelOverrideMap)) { + const value = Constants.UserChannelOverrideMap[key]; + if (!data.hasOwnProperty(key)) continue; + if (typeof value === 'function') { + this[value.name] = value(data[key]); + } else { + this[value] = data[key]; + } + } + } +} + +module.exports = ClientUserChannelOverride; + + +/***/ }), +/* 86 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +class ResumedHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const ws = client.ws.connection; + + ws._trace = packet.d._trace; + + ws.status = Constants.Status.READY; + this.packetManager.handleQueue(); + + const replayed = ws.sequence - ws.closeSequence; + + ws.debug(`RESUMED ${ws._trace.join(' -> ')} | replayed ${replayed} events.`); + client.emit(Constants.Events.RESUME, replayed); + ws.heartbeat(); + } +} + +/** + * Emitted whenever a WebSocket resumes. + * @event Client#resume + * @param {number} replayed The number of events that were replayed + */ + +module.exports = ResumedHandler; + + +/***/ }), +/* 87 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class GuildCreateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + + const guild = client.guilds.get(data.id); + if (guild) { + if (!guild.available && !data.unavailable) { + // A newly available guild + guild.setup(data); + this.packetManager.ws.checkIfReady(); + } + } else { + // A new guild + client.dataManager.newGuild(data); + } + } +} + +module.exports = GuildCreateHandler; + + +/***/ }), +/* 88 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +class GuildDeleteHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const response = client.actions.GuildDelete.handle(data); + if (response.guild) client.emit(Constants.Events.GUILD_DELETE, response.guild); + } +} + +/** + * Emitted whenever a guild is deleted/left. + * @event Client#guildDelete + * @param {Guild} guild The guild that was deleted + */ + +module.exports = GuildDeleteHandler; + + +/***/ }), +/* 89 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class GuildUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildUpdate.handle(data); + } +} + +module.exports = GuildUpdateHandler; + + +/***/ }), +/* 90 */ +/***/ (function(module, exports, __webpack_require__) { + +// ##untested handler## + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +class GuildBanAddHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const guild = client.guilds.get(data.guild_id); + const user = client.users.get(data.user.id); + if (guild && user) client.emit(Constants.Events.GUILD_BAN_ADD, guild, user); + } +} + +/** + * Emitted whenever a member is banned from a guild. + * @event Client#guildBanAdd + * @param {Guild} guild The guild that the ban occurred in + * @param {User} user The user that was banned + */ + +module.exports = GuildBanAddHandler; + + +/***/ }), +/* 91 */ +/***/ (function(module, exports, __webpack_require__) { + +// ##untested handler## + +const AbstractHandler = __webpack_require__(1); + +class GuildBanRemoveHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildBanRemove.handle(data); + } +} + +/** + * Emitted whenever a member is unbanned from a guild. + * @event Client#guildBanRemove + * @param {Guild} guild The guild that the unban occurred in + * @param {User} user The user that was unbanned + */ + +module.exports = GuildBanRemoveHandler; + + +/***/ }), +/* 92 */ +/***/ (function(module, exports, __webpack_require__) { + +// ##untested handler## + +const AbstractHandler = __webpack_require__(1); + +class GuildMemberAddHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const guild = client.guilds.get(data.guild_id); + if (guild) { + guild.memberCount++; + guild._addMember(data); + } + } +} + +module.exports = GuildMemberAddHandler; + + +/***/ }), +/* 93 */ +/***/ (function(module, exports, __webpack_require__) { + +// ##untested handler## + +const AbstractHandler = __webpack_require__(1); + +class GuildMemberRemoveHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildMemberRemove.handle(data); + } +} + +module.exports = GuildMemberRemoveHandler; + + +/***/ }), +/* 94 */ +/***/ (function(module, exports, __webpack_require__) { + +// ##untested handler## + +const AbstractHandler = __webpack_require__(1); + +class GuildMemberUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + + const guild = client.guilds.get(data.guild_id); + if (guild) { + const member = guild.members.get(data.user.id); + if (member) guild._updateMember(member, data); + } + } +} + +module.exports = GuildMemberUpdateHandler; + + +/***/ }), +/* 95 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class GuildRoleCreateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildRoleCreate.handle(data); + } +} + +module.exports = GuildRoleCreateHandler; + + +/***/ }), +/* 96 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class GuildRoleDeleteHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildRoleDelete.handle(data); + } +} + +module.exports = GuildRoleDeleteHandler; + + +/***/ }), +/* 97 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class GuildRoleUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildRoleUpdate.handle(data); + } +} + +module.exports = GuildRoleUpdateHandler; + + +/***/ }), +/* 98 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class GuildEmojisUpdate extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildEmojisUpdate.handle(data); + } +} + +module.exports = GuildEmojisUpdate; + + +/***/ }), +/* 99 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); +// Uncomment in v12 +// const Collection = require('../../../../util/Collection'); + +class GuildMembersChunkHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const guild = client.guilds.get(data.guild_id); + if (!guild) return; + + // Uncomment in v12 + // const members = new Collection(); + // + // for (const member of data.members) members.set(member.id, guild._addMember(member, false)); + + const members = data.members.map(member => guild._addMember(member, false)); + + client.emit(Constants.Events.GUILD_MEMBERS_CHUNK, members, guild); + + client.ws.lastHeartbeatAck = true; + } +} + +/** + * Emitted whenever a chunk of guild members is received (all members come from the same guild). + * @event Client#guildMembersChunk + * @param {GuildMember[]} members The members in the chunk + * @param {Guild} guild The guild related to the member chunk + */ + +module.exports = GuildMembersChunkHandler; + + +/***/ }), +/* 100 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class ChannelCreateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.ChannelCreate.handle(data); + } +} + +/** + * Emitted whenever a channel is created. + * @event Client#channelCreate + * @param {Channel} channel The channel that was created + */ + +module.exports = ChannelCreateHandler; + + +/***/ }), +/* 101 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +const Constants = __webpack_require__(0); + +class ChannelDeleteHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const response = client.actions.ChannelDelete.handle(data); + if (response.channel) client.emit(Constants.Events.CHANNEL_DELETE, response.channel); + } +} + +/** + * Emitted whenever a channel is deleted. + * @event Client#channelDelete + * @param {Channel} channel The channel that was deleted + */ + +module.exports = ChannelDeleteHandler; + + +/***/ }), +/* 102 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class ChannelUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.ChannelUpdate.handle(data); + } +} + +module.exports = ChannelUpdateHandler; + + +/***/ }), +/* 103 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +/* +{ t: 'CHANNEL_PINS_UPDATE', + s: 666, + op: 0, + d: + { last_pin_timestamp: '2016-08-28T17:37:13.171774+00:00', + channel_id: '314866471639044027' } } +*/ + +class ChannelPinsUpdate extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const channel = client.channels.get(data.channel_id); + const time = new Date(data.last_pin_timestamp); + if (channel && time) client.emit(Constants.Events.CHANNEL_PINS_UPDATE, channel, time); + } +} + +/** + * Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event, not much information + * can be provided easily here - you need to manually check the pins yourself. + * @event Client#channelPinsUpdate + * @param {Channel} channel The channel that the pins update occured in + * @param {Date} time The time of the pins update + */ + +module.exports = ChannelPinsUpdate; + + +/***/ }), +/* 104 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +class PresenceUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + let user = client.users.get(data.user.id); + const guild = client.guilds.get(data.guild_id); + + // Step 1 + if (!user) { + if (data.user.username) { + user = client.dataManager.newUser(data.user); + } else { + return; + } + } + + const oldUser = Util.cloneObject(user); + user.patch(data.user); + if (!user.equals(oldUser)) { + client.emit(Constants.Events.USER_UPDATE, oldUser, user); + } + + if (guild) { + let member = guild.members.get(user.id); + if (!member && data.status !== 'offline') { + member = guild._addMember({ + user, + roles: data.roles, + deaf: false, + mute: false, + }, false); + client.emit(Constants.Events.GUILD_MEMBER_AVAILABLE, member); + } + if (member) { + if (client.listenerCount(Constants.Events.PRESENCE_UPDATE) === 0) { + guild._setPresence(user.id, data); + return; + } + const oldMember = Util.cloneObject(member); + if (member.presence) { + oldMember.frozenPresence = Util.cloneObject(member.presence); + } + guild._setPresence(user.id, data); + client.emit(Constants.Events.PRESENCE_UPDATE, oldMember, member); + } else { + guild._setPresence(user.id, data); + } + } + } +} + +/** + * Emitted whenever a guild member's presence changes, or they change one of their details. + * @event Client#presenceUpdate + * @param {GuildMember} oldMember The member before the presence update + * @param {GuildMember} newMember The member after the presence update + */ + +/** + * Emitted whenever a user's details (e.g. username) are changed. + * @event Client#userUpdate + * @param {User} oldUser The user before the update + * @param {User} newUser The user after the update + */ + +/** + * Emitted whenever a member becomes available in a large guild. + * @event Client#guildMemberAvailable + * @param {GuildMember} member The member that became available + */ + +module.exports = PresenceUpdateHandler; + + +/***/ }), +/* 105 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class UserUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.UserUpdate.handle(data); + } +} + +module.exports = UserUpdateHandler; + + +/***/ }), +/* 106 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class UserNoteUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + + client.actions.UserNoteUpdate.handle(data); + } +} + +module.exports = UserNoteUpdateHandler; + + +/***/ }), +/* 107 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +class UserSettingsUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + client.user.settings.patch(packet.d); + client.emit(Constants.Events.USER_SETTINGS_UPDATE, client.user.settings); + } +} + +/** + * Emitted when the client user's settings update. + * @event Client#clientUserSettingsUpdate + * @param {ClientUserSettings} clientUserSettings The new client user settings + */ + +module.exports = UserSettingsUpdateHandler; + + +/***/ }), +/* 108 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); +const ClientUserGuildSettings = __webpack_require__(57); + +class UserGuildSettingsUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const settings = client.user.guildSettings.get(packet.d.guild_id); + if (settings) settings.patch(packet.d); + else client.user.guildSettings.set(packet.d.guild_id, new ClientUserGuildSettings(packet.d, client)); + client.emit(Constants.Events.USER_GUILD_SETTINGS_UPDATE, client.user.guildSettings.get(packet.d.guild_id)); + } +} + +/** + * Emitted whenever the client user's settings update. + * @event Client#clientUserGuildSettingsUpdate + * @param {ClientUserGuildSettings} clientUserGuildSettings The new client user guild settings + */ + +module.exports = UserGuildSettingsUpdateHandler; + + +/***/ }), +/* 109 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +class VoiceStateUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + + const guild = client.guilds.get(data.guild_id); + if (guild) { + const member = guild.members.get(data.user_id); + if (member) { + const oldVoiceChannelMember = Util.cloneObject(member); + if (member.voiceChannel && member.voiceChannel.id !== data.channel_id) { + member.voiceChannel.members.delete(oldVoiceChannelMember.id); + } + + // If the member left the voice channel, unset their speaking property + if (!data.channel_id) member.speaking = null; + + if (member.user.id === client.user.id && data.channel_id) { + client.emit('self.voiceStateUpdate', data); + } + + const newChannel = client.channels.get(data.channel_id); + if (newChannel) { + newChannel.members.set(member.id, member); + member.guild.channels.set(data.channel_id, newChannel); + } + + member.serverMute = data.mute; + member.serverDeaf = data.deaf; + member.selfMute = data.self_mute; + member.selfDeaf = data.self_deaf; + member.voiceSessionID = data.session_id; + member.voiceChannelID = data.channel_id; + client.emit(Constants.Events.VOICE_STATE_UPDATE, oldVoiceChannelMember, member); + } + } + } +} + +/** + * Emitted whenever a user changes voice state - e.g. joins/leaves a channel, mutes/unmutes. + * @event Client#voiceStateUpdate + * @param {GuildMember} oldMember The member before the voice state update + * @param {GuildMember} newMember The member after the voice state update + */ + +module.exports = VoiceStateUpdateHandler; + + +/***/ }), +/* 110 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +class TypingStartHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const channel = client.channels.get(data.channel_id); + const user = client.users.get(data.user_id); + const timestamp = new Date(data.timestamp * 1000); + + if (channel && user) { + if (channel.type === 'voice') { + client.emit(Constants.Events.WARN, `Discord sent a typing packet to voice channel ${channel.id}`); + return; + } + if (channel._typing.has(user.id)) { + const typing = channel._typing.get(user.id); + typing.lastTimestamp = timestamp; + typing.resetTimeout(tooLate(channel, user)); + } else { + channel._typing.set(user.id, new TypingData(client, timestamp, timestamp, tooLate(channel, user))); + client.emit(Constants.Events.TYPING_START, channel, user); + } + } + } +} + +class TypingData { + constructor(client, since, lastTimestamp, _timeout) { + this.client = client; + this.since = since; + this.lastTimestamp = lastTimestamp; + this._timeout = _timeout; + } + + resetTimeout(_timeout) { + this.client.clearTimeout(this._timeout); + this._timeout = _timeout; + } + + get elapsedTime() { + return Date.now() - this.since; + } +} + +function tooLate(channel, user) { + return channel.client.setTimeout(() => { + channel.client.emit(Constants.Events.TYPING_STOP, channel, user, channel._typing.get(user.id)); + channel._typing.delete(user.id); + }, 6000); +} + +/** + * Emitted whenever a user starts typing in a channel. + * @event Client#typingStart + * @param {Channel} channel The channel the user started typing in + * @param {User} user The user that started typing + */ + +/** + * Emitted whenever a user stops typing in a channel. + * @event Client#typingStop + * @param {Channel} channel The channel the user stopped typing in + * @param {User} user The user that stopped typing + */ + +module.exports = TypingStartHandler; + + +/***/ }), +/* 111 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +class MessageCreateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const response = client.actions.MessageCreate.handle(data); + if (response.message) client.emit(Constants.Events.MESSAGE_CREATE, response.message); + } +} + +/** + * Emitted whenever a message is created. + * @event Client#message + * @param {Message} message The created message + */ + +module.exports = MessageCreateHandler; + + +/***/ }), +/* 112 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); +const Constants = __webpack_require__(0); + +class MessageDeleteHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + const response = client.actions.MessageDelete.handle(data); + if (response.message) client.emit(Constants.Events.MESSAGE_DELETE, response.message); + } +} + +/** + * Emitted whenever a message is deleted. + * @event Client#messageDelete + * @param {Message} message The deleted message + */ + +module.exports = MessageDeleteHandler; + + +/***/ }), +/* 113 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class MessageUpdateHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.MessageUpdate.handle(data); + } +} + +module.exports = MessageUpdateHandler; + + +/***/ }), +/* 114 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class MessageDeleteBulkHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.MessageDeleteBulk.handle(data); + } +} + +/** + * Emitted whenever messages are deleted in bulk. + * @event Client#messageDeleteBulk + * @param {Collection} messages The deleted messages, mapped by their ID + */ + +module.exports = MessageDeleteBulkHandler; + + +/***/ }), +/* 115 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +/* +{ + "token": "my_token", + "guild_id": "41771983423143937", + "endpoint": "smart.loyal.discord.gg" +} +*/ + +class VoiceServerUpdate extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.emit('self.voiceServer', data); + } +} + +module.exports = VoiceServerUpdate; + + +/***/ }), +/* 116 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class GuildSyncHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.GuildSync.handle(data); + } +} + +module.exports = GuildSyncHandler; + + +/***/ }), +/* 117 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class RelationshipAddHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + if (data.type === 1) { + client.fetchUser(data.id).then(user => { + client.user.friends.set(user.id, user); + }); + } else if (data.type === 2) { + client.fetchUser(data.id).then(user => { + client.user.blocked.set(user.id, user); + }); + } + } +} + +module.exports = RelationshipAddHandler; + + +/***/ }), +/* 118 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class RelationshipRemoveHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + if (data.type === 2) { + if (client.user.blocked.has(data.id)) { + client.user.blocked.delete(data.id); + } + } else if (data.type === 1) { + if (client.user.friends.has(data.id)) { + client.user.friends.delete(data.id); + } + } + } +} + +module.exports = RelationshipRemoveHandler; + + +/***/ }), +/* 119 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class MessageReactionAddHandler extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.MessageReactionAdd.handle(data); + } +} + +module.exports = MessageReactionAddHandler; + + +/***/ }), +/* 120 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class MessageReactionRemove extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.MessageReactionRemove.handle(data); + } +} + +module.exports = MessageReactionRemove; + + +/***/ }), +/* 121 */ +/***/ (function(module, exports, __webpack_require__) { + +const AbstractHandler = __webpack_require__(1); + +class MessageReactionRemoveAll extends AbstractHandler { + handle(packet) { + const client = this.packetManager.client; + const data = packet.d; + client.actions.MessageReactionRemoveAll.handle(data); + } +} + +module.exports = MessageReactionRemoveAll; + + +/***/ }), +/* 122 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 123 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 124 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 125 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 126 */ +/***/ (function(module, exports, __webpack_require__) { + +const EventEmitter = __webpack_require__(19).EventEmitter; +const Constants = __webpack_require__(0); +const WebSocketConnection = __webpack_require__(54); + +/** + * WebSocket Manager of the client. + * @private + */ +class WebSocketManager extends EventEmitter { + constructor(client) { + super(); + /** + * The client that instantiated this WebSocketManager + * @type {Client} + */ + this.client = client; + + /** + * The WebSocket connection of this manager + * @type {?WebSocketConnection} + */ + this.connection = null; + } + + /** + * Sends a heartbeat on the available connection. + * @returns {void} + */ + heartbeat() { + if (!this.connection) return this.debug('No connection to heartbeat'); + return this.connection.heartbeat(); + } + + /** + * Emits a debug event. + * @param {string} message Debug message + * @returns {void} + */ + debug(message) { + return this.client.emit('debug', `[ws] ${message}`); + } + + /** + * Destroy the client. + * @returns {void} Whether or not destruction was successful + */ + destroy() { + if (!this.connection) { + this.debug('Attempted to destroy WebSocket but no connection exists!'); + return false; + } + return this.connection.destroy(); + } + + /** + * Send a packet on the available WebSocket. + * @param {Object} packet Packet to send + * @returns {void} + */ + send(packet) { + if (!this.connection) { + this.debug('No connection to websocket'); + return; + } + this.connection.send(packet); + } + + /** + * Connects the client to a gateway. + * @param {string} gateway The gateway to connect to + * @returns {boolean} + */ + connect(gateway) { + if (!this.connection) { + this.connection = new WebSocketConnection(this, gateway); + return true; + } + switch (this.connection.status) { + case Constants.Status.IDLE: + case Constants.Status.DISCONNECTED: + this.connection.connect(gateway, 5500); + return true; + default: + this.debug(`Couldn't connect to ${gateway} as the websocket is at state ${this.connection.status}`); + return false; + } + } +} + +module.exports = WebSocketManager; + + +/***/ }), +/* 127 */ +/***/ (function(module, exports, __webpack_require__) { + +class ActionsManager { + constructor(client) { + this.client = client; + + this.register(__webpack_require__(128)); + this.register(__webpack_require__(129)); + this.register(__webpack_require__(130)); + this.register(__webpack_require__(131)); + this.register(__webpack_require__(132)); + this.register(__webpack_require__(133)); + this.register(__webpack_require__(134)); + this.register(__webpack_require__(135)); + this.register(__webpack_require__(136)); + this.register(__webpack_require__(137)); + this.register(__webpack_require__(138)); + this.register(__webpack_require__(139)); + this.register(__webpack_require__(140)); + this.register(__webpack_require__(141)); + this.register(__webpack_require__(142)); + this.register(__webpack_require__(143)); + this.register(__webpack_require__(144)); + this.register(__webpack_require__(145)); + this.register(__webpack_require__(146)); + this.register(__webpack_require__(147)); + this.register(__webpack_require__(148)); + this.register(__webpack_require__(149)); + this.register(__webpack_require__(150)); + this.register(__webpack_require__(151)); + this.register(__webpack_require__(152)); + this.register(__webpack_require__(153)); + this.register(__webpack_require__(154)); + this.register(__webpack_require__(155)); + } + + register(Action) { + this[Action.name.replace(/Action$/, '')] = new Action(this.client); + } +} + +module.exports = ActionsManager; + + +/***/ }), +/* 128 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Message = __webpack_require__(15); + +class MessageCreateAction extends Action { + handle(data) { + const client = this.client; + + const channel = client.channels.get((data instanceof Array ? data[0] : data).channel_id); + const user = client.users.get((data instanceof Array ? data[0] : data).author.id); + if (channel) { + const member = channel.guild ? channel.guild.member(user) : null; + if (data instanceof Array) { + const messages = new Array(data.length); + for (let i = 0; i < data.length; i++) { + messages[i] = channel._cacheMessage(new Message(channel, data[i], client)); + } + const lastMessage = messages[messages.length - 1]; + channel.lastMessageID = lastMessage.id; + channel.lastMessage = lastMessage; + if (user) { + user.lastMessageID = lastMessage.id; + user.lastMessage = lastMessage; + } + if (member) { + member.lastMessageID = lastMessage.id; + member.lastMessage = lastMessage; + } + return { + messages, + }; + } else { + const message = channel._cacheMessage(new Message(channel, data, client)); + channel.lastMessageID = data.id; + channel.lastMessage = message; + if (user) { + user.lastMessageID = data.id; + user.lastMessage = message; + } + if (member) { + member.lastMessageID = data.id; + member.lastMessage = message; + } + return { + message, + }; + } + } + + return { + message: null, + }; + } +} + +module.exports = MessageCreateAction; + + +/***/ }), +/* 129 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class MessageDeleteAction extends Action { + constructor(client) { + super(client); + this.deleted = new Map(); + } + + handle(data) { + const client = this.client; + const channel = client.channels.get(data.channel_id); + let message; + + if (channel) { + message = channel.messages.get(data.id); + if (message) { + channel.messages.delete(message.id); + this.deleted.set(channel.id + message.id, message); + this.scheduleForDeletion(channel.id, message.id); + } else { + message = this.deleted.get(channel.id + data.id) || null; + } + } + + return { message }; + } + + scheduleForDeletion(channelID, messageID) { + this.client.setTimeout(() => this.deleted.delete(channelID + messageID), + this.client.options.restWsBridgeTimeout); + } +} + +module.exports = MessageDeleteAction; + + +/***/ }), +/* 130 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Collection = __webpack_require__(3); +const Constants = __webpack_require__(0); + +class MessageDeleteBulkAction extends Action { + handle(data) { + const messages = new Collection(); + + if (!data.messages) { + const channel = this.client.channels.get(data.channel_id); + for (const id of data.ids) { + const message = channel.messages.get(id); + if (message) messages.set(message.id, message); + } + } else { + for (const msg of data.messages) { + messages.set(msg.id, msg); + } + } + + if (messages.size > 0) this.client.emit(Constants.Events.MESSAGE_BULK_DELETE, messages); + return { messages }; + } +} + +module.exports = MessageDeleteBulkAction; + + +/***/ }), +/* 131 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +class MessageUpdateAction extends Action { + handle(data) { + const client = this.client; + + const channel = client.channels.get(data.channel_id); + if (channel) { + const message = channel.messages.get(data.id); + if (message) { + message.patch(data); + client.emit(Constants.Events.MESSAGE_UPDATE, message._edits[0], message); + return { + old: message._edits[0], + updated: message, + }; + } + + return { + old: message, + updated: message, + }; + } + + return { + old: null, + updated: null, + }; + } +} + +/** + * Emitted whenever a message is updated - e.g. embed or content change. + * @event Client#messageUpdate + * @param {Message} oldMessage The message before the update + * @param {Message} newMessage The message after the update + */ + +module.exports = MessageUpdateAction; + + +/***/ }), +/* 132 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +/* +{ user_id: 'id', + message_id: 'id', + emoji: { name: '�', id: null }, + channel_id: 'id' } } +*/ + +class MessageReactionAdd extends Action { + handle(data) { + const user = this.client.users.get(data.user_id); + if (!user) return false; + // Verify channel + const channel = this.client.channels.get(data.channel_id); + if (!channel || channel.type === 'voice') return false; + // Verify message + const message = channel.messages.get(data.message_id); + if (!message) return false; + if (!data.emoji) return false; + // Verify reaction + const reaction = message._addReaction(data.emoji, user); + if (reaction) this.client.emit(Constants.Events.MESSAGE_REACTION_ADD, reaction, user); + + return { message, reaction, user }; + } +} + +/** + * Emitted whenever a reaction is added to a message. + * @event Client#messageReactionAdd + * @param {MessageReaction} messageReaction The reaction object + * @param {User} user The user that applied the emoji or reaction emoji + */ + +module.exports = MessageReactionAdd; + + +/***/ }), +/* 133 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +/* +{ user_id: 'id', + message_id: 'id', + emoji: { name: '�', id: null }, + channel_id: 'id' } } +*/ + +class MessageReactionRemove extends Action { + handle(data) { + const user = this.client.users.get(data.user_id); + if (!user) return false; + // Verify channel + const channel = this.client.channels.get(data.channel_id); + if (!channel || channel.type === 'voice') return false; + // Verify message + const message = channel.messages.get(data.message_id); + if (!message) return false; + if (!data.emoji) return false; + // Verify reaction + const reaction = message._removeReaction(data.emoji, user); + if (reaction) this.client.emit(Constants.Events.MESSAGE_REACTION_REMOVE, reaction, user); + + return { message, reaction, user }; + } +} + +/** + * Emitted whenever a reaction is removed from a message. + * @event Client#messageReactionRemove + * @param {MessageReaction} messageReaction The reaction object + * @param {User} user The user that removed the emoji or reaction emoji + */ + +module.exports = MessageReactionRemove; + + +/***/ }), +/* 134 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +class MessageReactionRemoveAll extends Action { + handle(data) { + const channel = this.client.channels.get(data.channel_id); + if (!channel || channel.type === 'voice') return false; + + const message = channel.messages.get(data.message_id); + if (!message) return false; + + message._clearReactions(); + this.client.emit(Constants.Events.MESSAGE_REACTION_REMOVE_ALL, message); + + return { message }; + } +} + +/** + * Emitted whenever all reactions are removed from a message. + * @event Client#messageReactionRemoveAll + * @param {Message} message The message the reactions were removed from + */ + +module.exports = MessageReactionRemoveAll; + + +/***/ }), +/* 135 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class ChannelCreateAction extends Action { + handle(data) { + const client = this.client; + const channel = client.dataManager.newChannel(data); + return { channel }; + } +} + +module.exports = ChannelCreateAction; + + +/***/ }), +/* 136 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class ChannelDeleteAction extends Action { + constructor(client) { + super(client); + this.deleted = new Map(); + } + + handle(data) { + const client = this.client; + + let channel = client.channels.get(data.id); + if (channel) { + client.dataManager.killChannel(channel); + this.deleted.set(channel.id, channel); + this.scheduleForDeletion(channel.id); + } else { + channel = this.deleted.get(data.id) || null; + } + + return { channel }; + } + + scheduleForDeletion(id) { + this.client.setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout); + } +} + +module.exports = ChannelDeleteAction; + + +/***/ }), +/* 137 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +class ChannelUpdateAction extends Action { + handle(data) { + const client = this.client; + + const channel = client.channels.get(data.id); + if (channel) { + const oldChannel = Util.cloneObject(channel); + channel.setup(data); + client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel); + return { + old: oldChannel, + updated: channel, + }; + } + + return { + old: null, + updated: null, + }; + } +} + +/** + * Emitted whenever a channel is updated - e.g. name change, topic change. + * @event Client#channelUpdate + * @param {Channel} oldChannel The channel before the update + * @param {Channel} newChannel The channel after the update + */ + +module.exports = ChannelUpdateAction; + + +/***/ }), +/* 138 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +class GuildDeleteAction extends Action { + constructor(client) { + super(client); + this.deleted = new Map(); + } + + handle(data) { + const client = this.client; + + let guild = client.guilds.get(data.id); + if (guild) { + for (const channel of guild.channels.values()) { + if (channel.type === 'text') channel.stopTyping(true); + } + + if (guild.available && data.unavailable) { + // Guild is unavailable + guild.available = false; + client.emit(Constants.Events.GUILD_UNAVAILABLE, guild); + + // Stops the GuildDelete packet thinking a guild was actually deleted, + // handles emitting of event itself + return { + guild: null, + }; + } + + for (const channel of guild.channels.values()) this.client.channels.delete(channel.id); + if (guild.voiceConnection) guild.voiceConnection.disconnect(); + + // Delete guild + client.guilds.delete(guild.id); + this.deleted.set(guild.id, guild); + this.scheduleForDeletion(guild.id); + } else { + guild = this.deleted.get(data.id) || null; + } + + return { guild }; + } + + scheduleForDeletion(id) { + this.client.setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout); + } +} + +/** + * Emitted whenever a guild becomes unavailable, likely due to a server outage. + * @event Client#guildUnavailable + * @param {Guild} guild The guild that has become unavailable + */ + +module.exports = GuildDeleteAction; + + +/***/ }), +/* 139 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +class GuildUpdateAction extends Action { + handle(data) { + const client = this.client; + + const guild = client.guilds.get(data.id); + if (guild) { + const oldGuild = Util.cloneObject(guild); + guild.setup(data); + client.emit(Constants.Events.GUILD_UPDATE, oldGuild, guild); + return { + old: oldGuild, + updated: guild, + }; + } + + return { + old: null, + updated: null, + }; + } +} + +/** + * Emitted whenever a guild is updated - e.g. name change. + * @event Client#guildUpdate + * @param {Guild} oldGuild The guild before the update + * @param {Guild} newGuild The guild after the update + */ + +module.exports = GuildUpdateAction; + + +/***/ }), +/* 140 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class GuildMemberGetAction extends Action { + handle(guild, data) { + const member = guild._addMember(data, false); + return { member }; + } +} + +module.exports = GuildMemberGetAction; + + +/***/ }), +/* 141 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +class GuildMemberRemoveAction extends Action { + constructor(client) { + super(client); + this.deleted = new Map(); + } + + handle(data) { + const client = this.client; + const guild = client.guilds.get(data.guild_id); + let member = null; + if (guild) { + member = guild.members.get(data.user.id); + if (member) { + guild.memberCount--; + guild._removeMember(member); + this.deleted.set(guild.id + data.user.id, member); + if (client.status === Constants.Status.READY) client.emit(Constants.Events.GUILD_MEMBER_REMOVE, member); + this.scheduleForDeletion(guild.id, data.user.id); + } else { + member = this.deleted.get(guild.id + data.user.id) || null; + } + } + return { guild, member }; + } + + scheduleForDeletion(guildID, userID) { + this.client.setTimeout(() => this.deleted.delete(guildID + userID), this.client.options.restWsBridgeTimeout); + } +} + +/** + * Emitted whenever a member leaves a guild, or is kicked. + * @event Client#guildMemberRemove + * @param {GuildMember} member The member that has left/been kicked from the guild + */ + +module.exports = GuildMemberRemoveAction; + + +/***/ }), +/* 142 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +class GuildBanRemove extends Action { + handle(data) { + const client = this.client; + const guild = client.guilds.get(data.guild_id); + const user = client.dataManager.newUser(data.user); + if (guild && user) client.emit(Constants.Events.GUILD_BAN_REMOVE, guild, user); + } +} + +module.exports = GuildBanRemove; + + +/***/ }), +/* 143 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); +const Role = __webpack_require__(8); + +class GuildRoleCreate extends Action { + handle(data) { + const client = this.client; + const guild = client.guilds.get(data.guild_id); + let role; + if (guild) { + const already = guild.roles.has(data.role.id); + role = new Role(guild, data.role); + guild.roles.set(role.id, role); + if (!already) client.emit(Constants.Events.GUILD_ROLE_CREATE, role); + } + return { role }; + } +} + +/** + * Emitted whenever a role is created. + * @event Client#roleCreate + * @param {Role} role The role that was created + */ + +module.exports = GuildRoleCreate; + + +/***/ }), +/* 144 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +class GuildRoleDeleteAction extends Action { + constructor(client) { + super(client); + this.deleted = new Map(); + } + + handle(data) { + const client = this.client; + const guild = client.guilds.get(data.guild_id); + let role; + + if (guild) { + role = guild.roles.get(data.role_id); + if (role) { + guild.roles.delete(data.role_id); + this.deleted.set(guild.id + data.role_id, role); + this.scheduleForDeletion(guild.id, data.role_id); + client.emit(Constants.Events.GUILD_ROLE_DELETE, role); + } else { + role = this.deleted.get(guild.id + data.role_id) || null; + } + } + + return { role }; + } + + scheduleForDeletion(guildID, roleID) { + this.client.setTimeout(() => this.deleted.delete(guildID + roleID), this.client.options.restWsBridgeTimeout); + } +} + +/** + * Emitted whenever a guild role is deleted. + * @event Client#roleDelete + * @param {Role} role The role that was deleted + */ + +module.exports = GuildRoleDeleteAction; + + +/***/ }), +/* 145 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +class GuildRoleUpdateAction extends Action { + handle(data) { + const client = this.client; + const guild = client.guilds.get(data.guild_id); + + if (guild) { + const roleData = data.role; + let oldRole = null; + + const role = guild.roles.get(roleData.id); + if (role) { + oldRole = Util.cloneObject(role); + role.setup(data.role); + client.emit(Constants.Events.GUILD_ROLE_UPDATE, oldRole, role); + } + + return { + old: oldRole, + updated: role, + }; + } + + return { + old: null, + updated: null, + }; + } +} + +/** + * Emitted whenever a guild role is updated. + * @event Client#roleUpdate + * @param {Role} oldRole The role before the update + * @param {Role} newRole The role after the update + */ + +module.exports = GuildRoleUpdateAction; + + +/***/ }), +/* 146 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class UserGetAction extends Action { + handle(data) { + const client = this.client; + const user = client.dataManager.newUser(data); + return { user }; + } +} + +module.exports = UserGetAction; + + +/***/ }), +/* 147 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +class UserUpdateAction extends Action { + handle(data) { + const client = this.client; + + if (client.user) { + if (client.user.equals(data)) { + return { + old: client.user, + updated: client.user, + }; + } + + const oldUser = Util.cloneObject(client.user); + client.user.patch(data); + client.emit(Constants.Events.USER_UPDATE, oldUser, client.user); + return { + old: oldUser, + updated: client.user, + }; + } + + return { + old: null, + updated: null, + }; + } +} + +module.exports = UserUpdateAction; + + +/***/ }), +/* 148 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); +const Constants = __webpack_require__(0); + +class UserNoteUpdateAction extends Action { + handle(data) { + const client = this.client; + + const oldNote = client.user.notes.get(data.id); + const note = data.note.length ? data.note : null; + + client.user.notes.set(data.id, note); + + client.emit(Constants.Events.USER_NOTE_UPDATE, data.id, oldNote, note); + + return { + old: oldNote, + updated: note, + }; + } +} + +/** + * Emitted whenever a note is updated. + * @event Client#userNoteUpdate + * @param {User} user The user the note belongs to + * @param {string} oldNote The note content before the update + * @param {string} newNote The note content after the update + */ + +module.exports = UserNoteUpdateAction; + + +/***/ }), +/* 149 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class GuildSync extends Action { + handle(data) { + const client = this.client; + + const guild = client.guilds.get(data.id); + if (guild) { + if (data.presences) { + for (const presence of data.presences) guild._setPresence(presence.user.id, presence); + } + + if (data.members) { + for (const syncMember of data.members) { + const member = guild.members.get(syncMember.user.id); + if (member) { + guild._updateMember(member, syncMember); + } else { + guild._addMember(syncMember, false); + } + } + } + + if ('large' in data) guild.large = data.large; + } + } +} + +module.exports = GuildSync; + + +/***/ }), +/* 150 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class GuildEmojiCreateAction extends Action { + handle(guild, createdEmoji) { + const client = this.client; + const emoji = client.dataManager.newEmoji(createdEmoji, guild); + return { emoji }; + } +} + +/** + * Emitted whenever a custom emoji is created in a guild. + * @event Client#emojiCreate + * @param {Emoji} emoji The emoji that was created + */ + +module.exports = GuildEmojiCreateAction; + + +/***/ }), +/* 151 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class GuildEmojiDeleteAction extends Action { + handle(emoji) { + const client = this.client; + client.dataManager.killEmoji(emoji); + return { emoji }; + } +} + +/** + * Emitted whenever a custom guild emoji is deleted. + * @event Client#emojiDelete + * @param {Emoji} emoji The emoji that was deleted + */ + +module.exports = GuildEmojiDeleteAction; + + +/***/ }), +/* 152 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class GuildEmojiUpdateAction extends Action { + handle(oldEmoji, newEmoji) { + const emoji = this.client.dataManager.updateEmoji(oldEmoji, newEmoji); + return { emoji }; + } +} + +/** + * Emitted whenever a custom guild emoji is updated. + * @event Client#emojiUpdate + * @param {Emoji} oldEmoji The old emoji + * @param {Emoji} newEmoji The new emoji + */ + +module.exports = GuildEmojiUpdateAction; + + +/***/ }), +/* 153 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +function mappify(iterable) { + const map = new Map(); + for (const x of iterable) map.set(...x); + return map; +} + +class GuildEmojisUpdateAction extends Action { + handle(data) { + const guild = this.client.guilds.get(data.guild_id); + if (!guild || !guild.emojis) return; + + const deletions = mappify(guild.emojis.entries()); + + for (const emoji of data.emojis) { + // Determine type of emoji event + const cachedEmoji = guild.emojis.get(emoji.id); + if (cachedEmoji) { + deletions.delete(emoji.id); + if (!cachedEmoji.equals(emoji, true)) { + // Emoji updated + this.client.actions.GuildEmojiUpdate.handle(cachedEmoji, emoji); + } + } else { + // Emoji added + this.client.actions.GuildEmojiCreate.handle(guild, emoji); + } + } + + for (const emoji of deletions.values()) { + // Emoji deleted + this.client.actions.GuildEmojiDelete.handle(emoji); + } + } +} + +module.exports = GuildEmojisUpdateAction; + + +/***/ }), +/* 154 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class GuildRolesPositionUpdate extends Action { + handle(data) { + const client = this.client; + + const guild = client.guilds.get(data.guild_id); + if (guild) { + for (const partialRole of data.roles) { + const role = guild.roles.get(partialRole.id); + if (role) role.position = partialRole.position; + } + } + + return { guild }; + } +} + +module.exports = GuildRolesPositionUpdate; + + +/***/ }), +/* 155 */ +/***/ (function(module, exports, __webpack_require__) { + +const Action = __webpack_require__(2); + +class GuildChannelsPositionUpdate extends Action { + handle(data) { + const client = this.client; + + const guild = client.guilds.get(data.guild_id); + if (guild) { + for (const partialChannel of data.channels) { + const channel = guild.channels.get(partialChannel.id); + if (channel) channel.position = partialChannel.position; + } + } + + return { guild }; + } +} + +module.exports = GuildChannelsPositionUpdate; + + +/***/ }), +/* 156 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 157 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 158 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 159 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 160 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 161 */ +/***/ (function(module, exports, __webpack_require__) { + +const Webhook = __webpack_require__(23); +const RESTManager = __webpack_require__(37); +const ClientDataResolver = __webpack_require__(27); +const Constants = __webpack_require__(0); +const Util = __webpack_require__(4); + +/** + * The webhook client. + * @extends {Webhook} + */ +class WebhookClient extends Webhook { + /** + * @param {Snowflake} id ID of the webhook + * @param {string} token Token of the webhook + * @param {ClientOptions} [options] Options for the client + * @example + * // Create a new webhook and send a message + * const hook = new Discord.WebhookClient('1234', 'abcdef'); + * hook.sendMessage('This will send a message').catch(console.error); + */ + constructor(id, token, options) { + super(null, id, token); + + /** + * The options the client was instantiated with + * @type {ClientOptions} + */ + this.options = Util.mergeDefault(Constants.DefaultOptions, options); + + /** + * The REST manager of the client + * @type {RESTManager} + * @private + */ + this.rest = new RESTManager(this); + + /** + * The data resolver of the client + * @type {ClientDataResolver} + * @private + */ + this.resolver = new ClientDataResolver(this); + + /** + * Timeouts set by {@link WebhookClient#setTimeout} that are still active + * @type {Set} + * @private + */ + this._timeouts = new Set(); + + /** + * Intervals set by {@link WebhookClient#setInterval} that are still active + * @type {Set} + * @private + */ + this._intervals = new Set(); + } + + /** + * Sets a timeout that will be automatically cancelled if the client is destroyed. + * @param {Function} fn Function to execute + * @param {number} delay Time to wait before executing (in milliseconds) + * @param {...*} args Arguments for the function + * @returns {Timeout} + */ + setTimeout(fn, delay, ...args) { + const timeout = setTimeout(() => { + fn(...args); + this._timeouts.delete(timeout); + }, delay); + this._timeouts.add(timeout); + return timeout; + } + + /** + * Clears a timeout. + * @param {Timeout} timeout Timeout to cancel + */ + clearTimeout(timeout) { + clearTimeout(timeout); + this._timeouts.delete(timeout); + } + + /** + * Sets an interval that will be automatically cancelled if the client is destroyed. + * @param {Function} fn Function to execute + * @param {number} delay Time to wait before executing (in milliseconds) + * @param {...*} args Arguments for the function + * @returns {Timeout} + */ + setInterval(fn, delay, ...args) { + const interval = setInterval(fn, delay, ...args); + this._intervals.add(interval); + return interval; + } + + /** + * Clears an interval. + * @param {Timeout} interval Interval to cancel + */ + clearInterval(interval) { + clearInterval(interval); + this._intervals.delete(interval); + } + + + /** + * Destroys the client. + */ + destroy() { + for (const t of this._timeouts) clearTimeout(t); + for (const i of this._intervals) clearInterval(i); + this._timeouts.clear(); + this._intervals.clear(); + } +} + +module.exports = WebhookClient; + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/discord.11.3.1.min.js b/discord.11.3.1.min.js new file mode 100644 index 00000000..8162bf5b --- /dev/null +++ b/discord.11.3.1.min.js @@ -0,0 +1 @@ +!function(e){var t={};function s(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,s),n.l=!0,n.exports}s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:i})},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=58)}([function(e,t,s){(function(e){t.Package=s(36),t.DefaultOptions={apiRequestMethod:"sequential",shardId:0,shardCount:0,messageCacheMaxSize:200,messageCacheLifetime:0,messageSweepInterval:0,fetchAllMembers:!1,disableEveryone:!1,sync:!1,restWsBridgeTimeout:5e3,disabledEvents:[],restTimeOffset:500,ws:{large_threshold:250,compress:"browser"!==s(69).platform(),properties:{$os:e?e.platform:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""},version:6},http:{version:7,host:"https://discordapp.com",cdn:"https://cdn.discordapp.com"}},t.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"},t.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 i=t.Endpoints={User:e=>{e.id&&(e=e.id);const t=`/users/${e}`;return{toString:()=>t,channels:`${t}/channels`,profile:`${t}/profile`,relationships:`${t}/relationships`,settings:`${t}/settings`,Relationship:e=>`${t}/relationships/${e}`,Guild:e=>({toString:()=>`${t}/guilds/${e}`,settings:`${t}/guilds/${e}/settings`}),Note:e=>`${t}/notes/${e}`,Mentions:(e,s,i,n)=>`${t}/mentions?limit=${e}&roles=${s}&everyone=${i}${n?`&guild_id=${n}`:""}`,Avatar:(t,s)=>"1"===e?s:i.CDN(t).Avatar(e,s)}},guilds:"/guilds",Guild:e=>{e.id&&(e=e.id);const t=`/guilds/${e}`;return{toString:()=>t,prune:`${t}/prune`,embed:`${t}/embed`,bans:`${t}/bans`,integrations:`${t}/integrations`,members:`${t}/members`,channels:`${t}/channels`,invites:`${t}/invites`,roles:`${t}/roles`,emojis:`${t}/emojis`,search:`${t}/messages/search`,voiceRegions:`${t}/regions`,webhooks:`${t}/webhooks`,ack:`${t}/ack`,settings:`${t}/settings`,auditLogs:`${t}/audit-logs`,Emoji:e=>`${t}/emojis/${e}`,Icon:(t,s)=>i.CDN(t).Icon(e,s),Splash:(t,s)=>i.CDN(t).Splash(e,s),Role:e=>`${t}/roles/${e}`,Member:e=>{e.id&&(e=e.id);const s=`${t}/members/${e}`;return{toString:()=>s,Role:e=>`${s}/roles/${e}`,nickname:`${t}/members/@me/nick`}}}},channels:"/channels",Channel:e=>{e.id&&(e=e.id);const t=`/channels/${e}`;return{toString:()=>t,messages:{toString:()=>`${t}/messages`,bulkDelete:`${t}/messages/bulk-delete`},invites:`${t}/invites`,typing:`${t}/typing`,permissions:`${t}/permissions`,webhooks:`${t}/webhooks`,search:`${t}/messages/search`,pins:`${t}/pins`,Icon:(t,s)=>i.CDN(t).GDMIcon(e,s),Pin:e=>`${t}/pins/${e}`,Recipient:e=>`${t}/recipients/${e}`,Message:e=>{e.id&&(e=e.id);const s=`${t}/messages/${e}`;return{toString:()=>s,reactions:`${s}/reactions`,ack:`${s}/ack`,Reaction:e=>{const t=`${s}/reactions/${e}`;return{toString:()=>t,User:e=>`${t}/${e}`}}}}}},Message:e=>t.Endpoints.Channel(e.channel).Message(e),Member:e=>t.Endpoints.Guild(e.guild).Member(e),CDN:e=>({Emoji:(t,s="png")=>`${e}/emojis/${t}.${s}`,Asset:t=>`${e}/assets/${t}`,Avatar:(t,s)=>`${e}/avatars/${t}/${s}.${s.startsWith("a_")?"gif":"png?size=2048"}`,Icon:(t,s)=>`${e}/icons/${t}/${s}.jpg`,GDMIcon:(t,s)=>`${e}/channel-icons/${t}/${s}.jpg?size=2048`,Splash:(t,s)=>`${e}/splashes/${t}/${s}.jpg`}),OAUTH2:{Application:e=>{const t=`/oauth2/applications/${e}`;return{toString:()=>t,resetSecret:`${t}/reset`,resetToken:`${t}/bot/reset`}},App:e=>`/oauth2/authorize?client_id=${e}`},login:"/auth/login",logout:"/auth/logout",voiceRegions:"/voice/regions",gateway:{toString:()=>"/gateway",bot:"/gateway/bot"},Invite:e=>`/invite/${e}?with_counts=true`,inviteLink:e=>`https://discord.gg/${e}`,Webhook:(e,t)=>`/webhooks/${e}${t?`/${t}`:""}`};t.Status={READY:0,CONNECTING:1,RECONNECTING:2,IDLE:3,NEARLY:4,DISCONNECTED:5},t.VoiceStatus={CONNECTED:0,CONNECTING:1,AUTHENTICATING:2,RECONNECTING:3,DISCONNECTED:4},t.ChannelTypes={TEXT:0,DM:1,VOICE:2,GROUP_DM:3,CATEGORY:4},t.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},t.VoiceOPCodes={IDENTIFY:0,SELECT_PROTOCOL:1,READY:2,HEARTBEAT:3,SESSION_DESCRIPTION:4,SPEAKING:5},t.Events={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_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",USER_SETTINGS_UPDATE:"clientUserSettingsUpdate",USER_GUILD_SETTINGS_UPDATE:"clientUserGuildSettingsUpdate",PRESENCE_UPDATE:"presenceUpdate",VOICE_STATE_UPDATE:"voiceStateUpdate",TYPING_START:"typingStart",TYPING_STOP:"typingStop",DISCONNECT:"disconnect",RECONNECTING:"reconnecting",ERROR:"error",WARN:"warn",DEBUG:"debug"},t.ActivityTypes=["PLAYING","STREAMING","LISTENING","WATCHING"],t.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_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",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"},t.MessageTypes=["DEFAULT","RECIPIENT_ADD","RECIPIENT_REMOVE","CALL","CHANNEL_NAME_CHANGE","CHANNEL_ICON_CHANGE","PINS_ADD","GUILD_MEMBER_JOIN"],t.MessageNotificationTypes=["EVERYTHING","MENTIONS","NOTHING","INHERIT"],t.DefaultAvatars={BLURPLE:"6debd47ed13483642cf09e832ed0bc1b",GREY:"322c936a8c8be1b803cd94861bdfa868",GREEN:"dd4dbc0016779df1378e7812eabaa04d",ORANGE:"0e291f67c9274a1abdddeb3fd919cbaa",RED:"1cbd08c76f8af6dddce02c5138971129"},t.ExplicitContentFilterTypes=["DISABLED","NON_FRIENDS","FRIENDS_AND_NON_FRIENDS"],t.UserSettingsMap={convert_emoticons:"convertEmoticons",default_guilds_restricted:"defaultGuildsRestricted",detect_platform_accounts:"detectPlatformAccounts",developer_mode:"developerMode",enable_tts_command:"enableTTSCommand",theme:"theme",status:"status",show_current_game:"showCurrentGame",inline_attachment_media:"inlineAttachmentMedia",inline_embed_media:"inlineEmbedMedia",locale:"locale",message_display_compact:"messageDisplayCompact",render_reactions:"renderReactions",guild_positions:"guildPositions",restricted_guilds:"restrictedGuilds",explicit_content_filter:function(e){return t.ExplicitContentFilterTypes[e]},friend_source_flags:function(e){return{all:e.all||!1,mutualGuilds:!!e.all||(e.mutual_guilds||!1),mutualFriends:!!e.all||(e.mutualFriends||!1)}}},t.UserGuildSettingsMap={message_notifications:function(e){return t.MessageNotificationTypes[e]},mobile_push:"mobilePush",muted:"muted",suppress_everyone:"suppressEveryone",channel_overrides:"channelOverrides"},t.UserChannelOverrideMap={message_notifications:function(e){return t.MessageNotificationTypes[e]},muted:"muted"},t.Colors={DEFAULT:0,AQUA:1752220,GREEN:3066993,BLUE:3447003,PURPLE:10181046,GOLD:15844367,ORANGE:15105570,RED:15158332,GREY:9807270,NAVY:3426654,DARK_AQUA:1146986,DARK_GREEN:2067276,DARK_BLUE:2123412,DARK_PURPLE:7419530,DARK_GOLD:12745742,DARK_ORANGE:11027200,DARK_RED:10038562,DARK_GREY:9936031,DARKER_GREY:8359053,LIGHT_GREY:12370112,DARK_NAVY:2899536,BLURPLE:7506394,GREYPLE:10070709,DARK_BUT_NOT_BLACK:2895667,NOT_QUITE_BLACK:2303786},t.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,BOT_PROHIBITED_ENDPOINT:20001,BOT_ONLY_ENDPOINT:20002,MAXIMUM_GUILDS:30001,MAXIMUM_FRIENDS:30002,MAXIMUM_PINS:30003,MAXIMUM_ROLES:30005,MAXIMUM_REACTIONS:30010,UNAUTHORIZED:40001,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,CANNOT_EXECUTE_ON_SYSTEM_MESSAGE:50021,BULK_DELETE_MESSAGE_TOO_OLD:50034,INVITE_ACCEPTED_TO_GUILD_NOT_CONTANING_BOT:50036,REACTION_BLOCKED:90001}}).call(t,s(13))},function(e,t){e.exports=class AbstractHandler{constructor(e){this.packetManager=e}handle(e){return e}}},function(e,t){e.exports=class GenericAction{constructor(e){this.client=e}handle(e){return e}}},function(e,t){class Collection extends Map{constructor(e){super(e),Object.defineProperty(this,"_array",{value:null,writable:!0,configurable:!0}),Object.defineProperty(this,"_keyArray",{value:null,writable:!0,configurable:!0})}set(e,t){return this._array=null,this._keyArray=null,super.set(e,t)}delete(e){return this._array=null,this._keyArray=null,super.delete(e)}array(){return this._array&&this._array.length===this.size||(this._array=[...this.values()]),this._array}keyArray(){return this._keyArray&&this._keyArray.length===this.size||(this._keyArray=[...this.keys()]),this._keyArray}first(e){if(void 0===e)return this.values().next().value;if("number"!=typeof e)throw new TypeError("The count must be a number.");if(!Number.isInteger(e)||e<1)throw new RangeError("The count must be an integer greater than 0.");e=Math.min(this.size,e);const t=new Array(e),s=this.values();for(let i=0;i{const i=e.get(s);return i!==t||void 0===i&&!e.has(s)}))}sort(e=((e,t)=>+(e>t)||+(e===t)-1)){return new Collection([...this.entries()].sort((t,s)=>e(t[1],s[1],t[0],s[0])))}}e.exports=Collection},function(e,t,s){(function(t){const i=s(24),n=s(0),r=n.DefaultOptions.http;e.exports=class Util{constructor(){throw new Error(`The ${this.constructor.name} class may not be instantiated.`)}static splitMessage(e,{maxLength:t=1950,char:s="\n",prepend:i="",append:n=""}={}){if(e.length<=t)return e;const r=e.split(s);if(1===r.length)throw new Error("Message exceeds the max length and contains no split characters.");const o=[""];let a=0;for(let e=0;et&&(o[a]+=n,o.push(i),a++),o[a]+=(o[a].length>0&&o[a]!==i?s:"")+r[e];return o}static escapeMarkdown(e,t=!1,s=!1){return t?e.replace(/```/g,"`​``"):s?e.replace(/\\(`|\\)/g,"$1").replace(/(`|\\)/g,"\\$1"):e.replace(/\\(\*|_|`|~|\\)/g,"$1").replace(/(\*|_|`|~|\\)/g,"\\$1")}static fetchRecommendedShards(e,t=1e3){return new Promise((s,o)=>{if(!e)throw new Error("A token must be provided.");i.get(`${r.host}/api/v${r.version}${n.Endpoints.gateway.bot}`).set("Authorization",`Bot ${e.replace(/^Bot\s*/i,"")}`).end((e,i)=>{e&&o(e),s(i.body.shards*(1e3/t))})})}static parseEmoji(e){if(e.includes("%")&&(e=decodeURIComponent(e)),!e.includes(":"))return{animated:!1,name:e,id:null};const t=e.match(/?/);return t?{animated:Boolean(t[1]),name:t[2],id:t[3]}:null}static arraysEqual(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(const s of e){const e=t.indexOf(s);-1!==e&&t.splice(e,1)}return 0===t.length}static cloneObject(e){return Object.assign(Object.create(e),e)}static mergeDefault(e,t){if(!t)return e;for(const s in e)!{}.hasOwnProperty.call(t,s)?t[s]=e[s]:t[s]===Object(t[s])&&(t[s]=this.mergeDefault(e[s],t[s]));return t}static convertToBuffer(e){return"string"==typeof e&&(e=this.str2ab(e)),t.from(e)}static str2ab(e){const t=new ArrayBuffer(2*e.length),s=new Uint16Array(t);for(var i=0,n=e.length;i-1&&s=t?String(e):(String(s).repeat(t)+e).slice(-t)}e.exports=class SnowflakeUtil{constructor(){throw new Error(`The ${this.constructor.name} class may not be instantiated.`)}static generate(){r>=4095&&(r=0);const e=`${o((Date.now()-n).toString(2),42)}0000100000${o((r++).toString(2),12)}`;return i.fromString(e,2).toString()}static deconstruct(e){const t=o(i.fromString(e).toString(2),64),s={timestamp:parseInt(t.substring(0,42),2)+n,workerID:parseInt(t.substring(42,47),2),processID:parseInt(t.substring(47,52),2),increment:parseInt(t.substring(52,64),2),binary:t};return Object.defineProperty(s,"date",{get:function(){return new Date(this.timestamp)},enumerable:!0}),s}}},function(e,t,s){const i=s(0),n=s(7);class Permissions{constructor(e,t){t="object"!=typeof e||e instanceof Array?e:t,this._member="object"==typeof e?e:null,this.bitfield="number"==typeof t?t:this.constructor.resolve(t)}get member(){return this._member}set member(e){this._member=e}get raw(){return this.bitfield}set raw(e){this.bitfield=e}has(e,t=!0){return e instanceof Array?e.every(e=>this.has(e,t)):(e=this.constructor.resolve(e),!!(t&&(this.bitfield&this.constructor.FLAGS.ADMINISTRATOR)>0)||(this.bitfield&e)===e)}missing(e,t=!0){return e.filter(e=>!this.has(e,t))}add(...e){let t=0;for(let s=0;sthis.resolve(e)).reduce((e,t)=>e|t,0);if("string"==typeof e&&(e=this.FLAGS[e]),"number"!=typeof e||e<1)throw new RangeError(i.Errors.NOT_A_PERMISSION);return e}}Permissions.FLAGS={CREATE_INSTANT_INVITE:1,KICK_MEMBERS:2,BAN_MEMBERS:4,ADMINISTRATOR:8,MANAGE_CHANNELS:16,MANAGE_GUILD:32,ADD_REACTIONS:64,VIEW_AUDIT_LOG:128,VIEW_CHANNEL:1024,READ_MESSAGES:1024,SEND_MESSAGES:2048,SEND_TTS_MESSAGES:4096,MANAGE_MESSAGES:8192,EMBED_LINKS:16384,ATTACH_FILES:32768,READ_MESSAGE_HISTORY:65536,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},Permissions.ALL=Object.keys(Permissions.FLAGS).reduce((e,t)=>e|Permissions.FLAGS[t],0),Permissions.DEFAULT=104324097,Permissions.prototype.hasPermission=n.deprecate(Permissions.prototype.hasPermission,"EvaluatedPermissions#hasPermission is deprecated, use Permissions#has instead"),Permissions.prototype.hasPermissions=n.deprecate(Permissions.prototype.hasPermissions,"EvaluatedPermissions#hasPermissions is deprecated, use Permissions#has instead"),Permissions.prototype.missingPermissions=n.deprecate(Permissions.prototype.missingPermissions,"EvaluatedPermissions#missingPermissions is deprecated, use Permissions#missing instead"),Object.defineProperty(Permissions.prototype,"member",{get:n.deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype,"member").get,"EvaluatedPermissions#member is deprecated")}),e.exports=Permissions},function(e,t,s){(function(e,i){var n=/%[sdj%]/g;t.format=function(e){if(!E(e)){for(var t=[],s=0;s=r)return e;switch(e){case"%s":return String(i[s++]);case"%d":return Number(i[s++]);case"%j":try{return JSON.stringify(i[s++])}catch(e){return"[Circular]"}default:return e}}),h=i[s];s=3&&(i.depth=arguments[2]),arguments.length>=4&&(i.colors=arguments[3]),g(s)?i.showHidden=s:s&&t._extend(i,s),_(i.showHidden)&&(i.showHidden=!1),_(i.depth)&&(i.depth=2),_(i.colors)&&(i.colors=!1),_(i.customInspect)&&(i.customInspect=!0),i.colors&&(i.stylize=h),c(i,e,i.depth)}function h(e,t){var s=a.styles[t];return s?"["+a.colors[s][0]+"m"+e+"["+a.colors[s][1]+"m":e}function l(e,t){return e}function c(e,s,i){if(e.customInspect&&s&&A(s.inspect)&&s.inspect!==t.inspect&&(!s.constructor||s.constructor.prototype!==s)){var n=s.inspect(i,e);return E(n)||(n=c(e,n,i)),n}var r=function(e,t){if(_(t))return e.stylize("undefined","undefined");if(E(t)){var s="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(s,"string")}if(f(t))return e.stylize(""+t,"number");if(g(t))return e.stylize(""+t,"boolean");if(p(t))return e.stylize("null","null")}(e,s);if(r)return r;var o=Object.keys(s),a=function(e){var t={};return e.forEach(function(e,s){t[e]=!0}),t}(o);if(e.showHidden&&(o=Object.getOwnPropertyNames(s)),w(s)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return u(s);if(0===o.length){if(A(s)){var h=s.name?": "+s.name:"";return e.stylize("[Function"+h+"]","special")}if(v(s))return e.stylize(RegExp.prototype.toString.call(s),"regexp");if(y(s))return e.stylize(Date.prototype.toString.call(s),"date");if(w(s))return u(s)}var l,b="",T=!1,R=["{","}"];(m(s)&&(T=!0,R=["[","]"]),A(s))&&(b=" [Function"+(s.name?": "+s.name:"")+"]");return v(s)&&(b=" "+RegExp.prototype.toString.call(s)),y(s)&&(b=" "+Date.prototype.toUTCString.call(s)),w(s)&&(b=" "+u(s)),0!==o.length||T&&0!=s.length?i<0?v(s)?e.stylize(RegExp.prototype.toString.call(s),"regexp"):e.stylize("[Object]","special"):(e.seen.push(s),l=T?function(e,t,s,i,n){for(var r=[],o=0,a=t.length;o=0&&0,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return s[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+s[1];return s[0]+t+" "+e.join(", ")+" "+s[1]}(l,b,R)):R[0]+b+R[1]}function u(e){return"["+Error.prototype.toString.call(e)+"]"}function d(e,t,s,i,n,r){var o,a,h;if((h=Object.getOwnPropertyDescriptor(t,n)||{value:t[n]}).get?a=h.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):h.set&&(a=e.stylize("[Setter]","special")),D(i,n)||(o="["+n+"]"),a||(e.seen.indexOf(h.value)<0?(a=p(s)?c(e,h.value,null):c(e,h.value,s-1)).indexOf("\n")>-1&&(a=r?a.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n")):a=e.stylize("[Circular]","special")),_(o)){if(r&&n.match(/^\d+$/))return a;(o=JSON.stringify(""+n)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+a}function m(e){return Array.isArray(e)}function g(e){return"boolean"==typeof e}function p(e){return null===e}function f(e){return"number"==typeof e}function E(e){return"string"==typeof e}function _(e){return void 0===e}function v(e){return b(e)&&"[object RegExp]"===T(e)}function b(e){return"object"==typeof e&&null!==e}function y(e){return b(e)&&"[object Date]"===T(e)}function w(e){return b(e)&&("[object Error]"===T(e)||e instanceof Error)}function A(e){return"function"==typeof e}function T(e){return Object.prototype.toString.call(e)}function R(e){return e<10?"0"+e.toString(10):e.toString(10)}t.debuglog=function(e){if(_(r)&&(r=Object({__DISCORD_WEBPACK__:"true"}).NODE_DEBUG||""),e=e.toUpperCase(),!o[e])if(new RegExp("\\b"+e+"\\b","i").test(r)){var s=i.pid;o[e]=function(){var i=t.format.apply(t,arguments);console.error("%s %d: %s",e,s,i)}}else o[e]=function(){};return o[e]},t.inspect=a,a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},a.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=m,t.isBoolean=g,t.isNull=p,t.isNullOrUndefined=function(e){return null==e},t.isNumber=f,t.isString=E,t.isSymbol=function(e){return"symbol"==typeof e},t.isUndefined=_,t.isRegExp=v,t.isObject=b,t.isDate=y,t.isError=w,t.isFunction=A,t.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||void 0===e},t.isBuffer=s(71);var M=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function D(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.log=function(){var e,s;console.log("%s - %s",(e=new Date,s=[R(e.getHours()),R(e.getMinutes()),R(e.getSeconds())].join(":"),[e.getDate(),M[e.getMonth()],s].join(" ")),t.format.apply(t,arguments))},t.inherits=s(72),t._extend=function(e,t){if(!t||!b(t))return e;for(var s=Object.keys(t),i=s.length;i--;)e[s[i]]=t[s[i]];return e}}).call(t,s(34),s(13))},function(e,t,s){const i=s(5),n=s(6),r=s(7);class Role{constructor(e,t){Object.defineProperty(this,"client",{value:e.client}),this.guild=e,t&&this.setup(t)}setup(e){this.id=e.id,this.name=e.name,this.color=e.color,this.hoist=e.hoist,this.position=e.position,this.permissions=e.permissions,this.managed=e.managed,this.mentionable=e.mentionable}get createdTimestamp(){return i.deconstruct(this.id).timestamp}get createdAt(){return new Date(this.createdTimestamp)}get hexColor(){let e=this.color.toString(16);for(;e.length<6;)e=`0${e}`;return`#${e}`}get members(){return this.guild.members.filter(e=>e.roles.has(this.id))}get editable(){if(this.managed)return!1;const e=this.guild.member(this.client.user);return!!e.permissions.has(n.FLAGS.MANAGE_ROLES_OR_PERMISSIONS)&&e.highestRole.comparePositionTo(this)>0}get calculatedPosition(){const e=this.guild._sortedRoles;return e.array().indexOf(e.get(this.id))}serialize(){return new n(this.permissions).serialize()}hasPermission(e,t=!1,s){return new n(this.permissions).has(e,void 0!==s?s:!t)}hasPermissions(e,t=!1){return new n(this.permissions).has(e,!t)}comparePositionTo(e){return this.constructor.comparePositions(this,e)}edit(e,t){return this.client.rest.methods.updateGuildRole(this,e,t)}setName(e,t){return this.edit({name:e},t)}setColor(e,t){return this.edit({color:e},t)}setHoist(e,t){return this.edit({hoist:e},t)}setPosition(e,t){return this.guild.setRolePosition(this,e,t).then(()=>this)}setPermissions(e,t){return this.edit({permissions:e},t)}setMentionable(e,t){return this.edit({mentionable:e},t)}delete(e){return this.client.rest.methods.deleteGuildRole(this,e)}equals(e){return e&&this.id===e.id&&this.name===e.name&&this.color===e.color&&this.hoist===e.hoist&&this.position===e.position&&this.permissions===e.permissions&&this.managed===e.managed}toString(){return this.id===this.guild.id?"@everyone":`<@&${this.id}>`}static comparePositions(e,t){return e.position===t.position?t.id-e.id:e.position-t.position}}Role.prototype.hasPermissions=r.deprecate(Role.prototype.hasPermissions,"Role#hasPermissions is deprecated - use Role#hasPermission instead, it now takes an array"),e.exports=Role},function(e,t,s){const i=s(14),n=s(0),r=s(10).Presence,o=s(5);class User{constructor(e,t){Object.defineProperty(this,"client",{value:e}),t&&this.setup(t)}setup(e){this.id=e.id,this.username=e.username,this.discriminator=e.discriminator,this.avatar=e.avatar,this.bot=Boolean(e.bot),this.lastMessageID=null,this.lastMessage=null}patch(e){for(const t of["id","username","discriminator","avatar","bot"])void 0!==e[t]&&(this[t]=e[t]);e.token&&(this.client.token=e.token)}get createdTimestamp(){return o.deconstruct(this.id).timestamp}get createdAt(){return new Date(this.createdTimestamp)}get presence(){if(this.client.presences.has(this.id))return this.client.presences.get(this.id);for(const e of this.client.guilds.values())if(e.presences.has(this.id))return e.presences.get(this.id);return new r}get avatarURL(){return this.avatar?n.Endpoints.User(this).Avatar(this.client.options.http.cdn,this.avatar):null}get defaultAvatarURL(){const e=Object.keys(n.DefaultAvatars),t=e[this.discriminator%e.length];return n.Endpoints.CDN(this.client.options.http.host).Asset(`${n.DefaultAvatars[t]}.png`)}get displayAvatarURL(){return this.avatarURL||this.defaultAvatarURL}get tag(){return`${this.username}#${this.discriminator}`}get note(){return this.client.user.notes.get(this.id)||null}typingIn(e){return(e=this.client.resolver.resolveChannel(e))._typing.has(this.id)}typingSinceIn(e){return(e=this.client.resolver.resolveChannel(e))._typing.has(this.id)?new Date(e._typing.get(this.id).since):null}typingDurationIn(e){return(e=this.client.resolver.resolveChannel(e))._typing.has(this.id)?e._typing.get(this.id).elapsedTime:-1}get dmChannel(){return this.client.channels.filter(e=>"dm"===e.type).find(e=>e.recipient.id===this.id)}createDM(){return this.client.rest.methods.createDM(this)}deleteDM(){return this.client.rest.methods.deleteChannel(this)}addFriend(){return this.client.rest.methods.addFriend(this)}removeFriend(){return this.client.rest.methods.removeFriend(this)}block(){return this.client.rest.methods.blockUser(this)}unblock(){return this.client.rest.methods.unblockUser(this)}fetchProfile(){return this.client.rest.methods.fetchUserProfile(this)}setNote(e){return this.client.rest.methods.setNote(this,e)}equals(e){return e&&this.id===e.id&&this.username===e.username&&this.discriminator===e.discriminator&&this.avatar===e.avatar&&this.bot===Boolean(e.bot)}toString(){return`<@${this.id}>`}send(){}sendMessage(){}sendEmbed(){}sendFile(){}sendCode(){}}i.applyToClass(User),e.exports=User},function(e,t){class Game{constructor(e){this.name=e.name,this.type=e.type,this.url=e.url||null}get streaming(){return 1===this.type}equals(e){return this===e||e&&this.name===e.name&&this.type===e.type&&this.url===e.url}}t.Presence=class Presence{constructor(e={}){this.status=e.status||"offline",this.game=e.game?new Game(e.game):null}update(e){this.status=e.status||this.status,this.game=e.game?new Game(e.game):null}equals(e){return this===e||(e&&this.status===e.status&&this.game?this.game.equals(e.game):!e.game)}},t.Game=Game},function(e,t,s){const i=s(5);e.exports=class Channel{constructor(e,t){Object.defineProperty(this,"client",{value:e}),this.type=null,t&&this.setup(t)}setup(e){this.id=e.id}get createdTimestamp(){return i.deconstruct(this.id).timestamp}get createdAt(){return new Date(this.createdTimestamp)}delete(){return this.client.rest.methods.deleteChannel(this)}}},function(e,t,s){"use strict";(function(e){var i=s(60),n=s(61),r=s(62);function o(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(o()=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|e}function g(e,t){if(h.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var s=e.length;if(0===s)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return s;case"utf8":case"utf-8":case void 0:return B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*s;case"hex":return s>>>1;case"base64":return $(e).length;default:if(i)return B(e).length;t=(""+t).toLowerCase(),i=!0}}function p(e,t,s){var i=e[t];e[t]=e[s],e[s]=i}function f(e,t,s,i,n){if(0===e.length)return-1;if("string"==typeof s?(i=s,s=0):s>2147483647?s=2147483647:s<-2147483648&&(s=-2147483648),s=+s,isNaN(s)&&(s=n?0:e.length-1),s<0&&(s=e.length+s),s>=e.length){if(n)return-1;s=e.length-1}else if(s<0){if(!n)return-1;s=0}if("string"==typeof t&&(t=h.from(t,i)),h.isBuffer(t))return 0===t.length?-1:E(e,t,s,i,n);if("number"==typeof t)return t&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(e,t,s):Uint8Array.prototype.lastIndexOf.call(e,t,s):E(e,[t],s,i,n);throw new TypeError("val must be string, number or Buffer")}function E(e,t,s,i,n){var r,o=1,a=e.length,h=t.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(e.length<2||t.length<2)return-1;o=2,a/=2,h/=2,s/=2}function l(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(n){var c=-1;for(r=s;ra&&(s=a-h),r=s;r>=0;r--){for(var u=!0,d=0;dn&&(i=n):i=n;var r=t.length;if(r%2!=0)throw new TypeError("Invalid hex string");i>r/2&&(i=r/2);for(var o=0;o>8,n=s%256,r.push(n),r.push(i);return r}(t,e.length-s),e,s,i)}function T(e,t,s){return 0===t&&s===e.length?i.fromByteArray(e):i.fromByteArray(e.slice(t,s))}function R(e,t,s){s=Math.min(e.length,s);for(var i=[],n=t;n239?4:l>223?3:l>191?2:1;if(n+u<=s)switch(u){case 1:l<128&&(c=l);break;case 2:128==(192&(r=e[n+1]))&&(h=(31&l)<<6|63&r)>127&&(c=h);break;case 3:r=e[n+1],o=e[n+2],128==(192&r)&&128==(192&o)&&(h=(15&l)<<12|(63&r)<<6|63&o)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:r=e[n+1],o=e[n+2],a=e[n+3],128==(192&r)&&128==(192&o)&&128==(192&a)&&(h=(15&l)<<18|(63&r)<<12|(63&o)<<6|63&a)>65535&&h<1114112&&(c=h)}null===c?(c=65533,u=1):c>65535&&(c-=65536,i.push(c>>>10&1023|55296),c=56320|1023&c),i.push(c),n+=u}return function(e){var t=e.length;if(t<=M)return String.fromCharCode.apply(String,e);var s="",i=0;for(;ithis.length)return"";if((void 0===s||s>this.length)&&(s=this.length),s<=0)return"";if((s>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,s);case"utf8":case"utf-8":return R(this,t,s);case"ascii":return D(this,t,s);case"latin1":case"binary":return S(this,t,s);case"base64":return T(this,t,s);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,s);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}.apply(this,arguments)},h.prototype.equals=function(e){if(!h.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===h.compare(this,e)},h.prototype.inspect=function(){var e="",s=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,s).match(/.{2}/g).join(" "),this.length>s&&(e+=" ... ")),""},h.prototype.compare=function(e,t,s,i,n){if(!h.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===s&&(s=e?e.length:0),void 0===i&&(i=0),void 0===n&&(n=this.length),t<0||s>e.length||i<0||n>this.length)throw new RangeError("out of range index");if(i>=n&&t>=s)return 0;if(i>=n)return-1;if(t>=s)return 1;if(t>>>=0,s>>>=0,i>>>=0,n>>>=0,this===e)return 0;for(var r=n-i,o=s-t,a=Math.min(r,o),l=this.slice(i,n),c=e.slice(t,s),u=0;un)&&(s=n),e.length>0&&(s<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var r=!1;;)switch(i){case"hex":return _(this,e,t,s);case"utf8":case"utf-8":return v(this,e,t,s);case"ascii":return b(this,e,t,s);case"latin1":case"binary":return y(this,e,t,s);case"base64":return w(this,e,t,s);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,s);default:if(r)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),r=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var M=4096;function D(e,t,s){var i="";s=Math.min(e.length,s);for(var n=t;ni)&&(s=i);for(var n="",r=t;rs)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,s,i,n,r){if(!h.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>n||te.length)throw new RangeError("Index out of range")}function O(e,t,s,i){t<0&&(t=65535+t+1);for(var n=0,r=Math.min(e.length-s,2);n>>8*(i?n:1-n)}function L(e,t,s,i){t<0&&(t=4294967295+t+1);for(var n=0,r=Math.min(e.length-s,4);n>>8*(i?n:3-n)&255}function k(e,t,s,i,n,r){if(s+i>e.length)throw new RangeError("Index out of range");if(s<0)throw new RangeError("Index out of range")}function P(e,t,s,i,r){return r||k(e,0,s,4),n.write(e,t,s,i,23,4),s+4}function G(e,t,s,i,r){return r||k(e,0,s,8),n.write(e,t,s,i,52,8),s+8}h.prototype.slice=function(e,t){var s,i=this.length;if(e=~~e,t=void 0===t?i:~~t,e<0?(e+=i)<0&&(e=0):e>i&&(e=i),t<0?(t+=i)<0&&(t=0):t>i&&(t=i),t0&&(n*=256);)i+=this[e+--t]*n;return i},h.prototype.readUInt8=function(e,t){return t||U(e,1,this.length),this[e]},h.prototype.readUInt16LE=function(e,t){return t||U(e,2,this.length),this[e]|this[e+1]<<8},h.prototype.readUInt16BE=function(e,t){return t||U(e,2,this.length),this[e]<<8|this[e+1]},h.prototype.readUInt32LE=function(e,t){return t||U(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},h.prototype.readUInt32BE=function(e,t){return t||U(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},h.prototype.readIntLE=function(e,t,s){e|=0,t|=0,s||U(e,t,this.length);for(var i=this[e],n=1,r=0;++r=(n*=128)&&(i-=Math.pow(2,8*t)),i},h.prototype.readIntBE=function(e,t,s){e|=0,t|=0,s||U(e,t,this.length);for(var i=t,n=1,r=this[e+--i];i>0&&(n*=256);)r+=this[e+--i]*n;return r>=(n*=128)&&(r-=Math.pow(2,8*t)),r},h.prototype.readInt8=function(e,t){return t||U(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},h.prototype.readInt16LE=function(e,t){t||U(e,2,this.length);var s=this[e]|this[e+1]<<8;return 32768&s?4294901760|s:s},h.prototype.readInt16BE=function(e,t){t||U(e,2,this.length);var s=this[e+1]|this[e]<<8;return 32768&s?4294901760|s:s},h.prototype.readInt32LE=function(e,t){return t||U(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},h.prototype.readInt32BE=function(e,t){return t||U(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},h.prototype.readFloatLE=function(e,t){return t||U(e,4,this.length),n.read(this,e,!0,23,4)},h.prototype.readFloatBE=function(e,t){return t||U(e,4,this.length),n.read(this,e,!1,23,4)},h.prototype.readDoubleLE=function(e,t){return t||U(e,8,this.length),n.read(this,e,!0,52,8)},h.prototype.readDoubleBE=function(e,t){return t||U(e,8,this.length),n.read(this,e,!1,52,8)},h.prototype.writeUIntLE=function(e,t,s,i){(e=+e,t|=0,s|=0,i)||N(this,e,t,s,Math.pow(2,8*s)-1,0);var n=1,r=0;for(this[t]=255&e;++r=0&&(r*=256);)this[t+n]=e/r&255;return t+s},h.prototype.writeUInt8=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,1,255,0),h.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},h.prototype.writeUInt16LE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},h.prototype.writeUInt16BE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},h.prototype.writeUInt32LE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):L(this,e,t,!0),t+4},h.prototype.writeUInt32BE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):L(this,e,t,!1),t+4},h.prototype.writeIntLE=function(e,t,s,i){if(e=+e,t|=0,!i){var n=Math.pow(2,8*s-1);N(this,e,t,s,n-1,-n)}var r=0,o=1,a=0;for(this[t]=255&e;++r>0)-a&255;return t+s},h.prototype.writeIntBE=function(e,t,s,i){if(e=+e,t|=0,!i){var n=Math.pow(2,8*s-1);N(this,e,t,s,n-1,-n)}var r=s-1,o=1,a=0;for(this[t+r]=255&e;--r>=0&&(o*=256);)e<0&&0===a&&0!==this[t+r+1]&&(a=1),this[t+r]=(e/o>>0)-a&255;return t+s},h.prototype.writeInt8=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,1,127,-128),h.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},h.prototype.writeInt16LE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},h.prototype.writeInt16BE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},h.prototype.writeInt32LE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):L(this,e,t,!0),t+4},h.prototype.writeInt32BE=function(e,t,s){return e=+e,t|=0,s||N(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):L(this,e,t,!1),t+4},h.prototype.writeFloatLE=function(e,t,s){return P(this,e,t,!0,s)},h.prototype.writeFloatBE=function(e,t,s){return P(this,e,t,!1,s)},h.prototype.writeDoubleLE=function(e,t,s){return G(this,e,t,!0,s)},h.prototype.writeDoubleBE=function(e,t,s){return G(this,e,t,!1,s)},h.prototype.copy=function(e,t,s,i){if(s||(s=0),i||0===i||(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t=0;--n)e[n+t]=this[n+s];else if(r<1e3||!h.TYPED_ARRAY_SUPPORT)for(n=0;n>>=0,s=void 0===s?this.length:s>>>0,e||(e=0),"number"==typeof e)for(r=t;r55295&&s<57344){if(!n){if(s>56319){(t-=3)>-1&&r.push(239,191,189);continue}if(o+1===i){(t-=3)>-1&&r.push(239,191,189);continue}n=s;continue}if(s<56320){(t-=3)>-1&&r.push(239,191,189),n=s;continue}s=65536+(n-55296<<10|s-56320)}else n&&(t-=3)>-1&&r.push(239,191,189);if(n=null,s<128){if((t-=1)<0)break;r.push(s)}else if(s<2048){if((t-=2)<0)break;r.push(s>>6|192,63&s|128)}else if(s<65536){if((t-=3)<0)break;r.push(s>>12|224,s>>6&63|128,63&s|128)}else{if(!(s<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;r.push(s>>18|240,s>>12&63|128,s>>6&63|128,63&s|128)}}return r}function $(e){return i.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(x,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function q(e,t,s,i){for(var n=0;n=t.length||n>=e.length);++n)t[n+s]=e[n];return n}}).call(t,s(34))},function(e,t){var s,i,n=e.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(e){if(s===setTimeout)return setTimeout(e,0);if((s===r||!s)&&setTimeout)return s=setTimeout,setTimeout(e,0);try{return s(e,0)}catch(t){try{return s.call(null,e,0)}catch(t){return s.call(this,e,0)}}}!function(){try{s="function"==typeof setTimeout?setTimeout:r}catch(e){s=r}try{i="function"==typeof clearTimeout?clearTimeout:o}catch(e){i=o}}();var h,l=[],c=!1,u=-1;function d(){c&&h&&(c=!1,h.length?l=h.concat(l):u=-1,l.length&&m())}function m(){if(!c){var e=a(d);c=!0;for(var t=l.length;t;){for(h=l,l=[];++u1)for(var s=1;sthis.client.resolver.resolveFile(e.attachment).then(t=>(e.file=t,e)))).then(e=>this.client.rest.methods.sendMessage(this,t,s,e))}return this.client.rest.methods.sendMessage(this,t,s)}fetchMessage(e){return this.client.user.bot?this.client.rest.methods.getChannelMessage(this,e).then(e=>{const t=e instanceof n?e:new n(this,e,this.client);return this._cacheMessage(t),t}):this.fetchMessages({limit:1,around:e}).then(t=>{const s=t.get(e);if(!s)throw new Error("Message not found.");return s})}fetchMessages(e={}){return this.client.rest.methods.getChannelMessages(this,e).then(e=>{const t=new o;for(const s of e){const e=new n(this,s,this.client);t.set(s.id,e),this._cacheMessage(e)}return t})}fetchPinnedMessages(){return this.client.rest.methods.getChannelPinnedMessages(this).then(e=>{const t=new o;for(const s of e){const e=new n(this,s,this.client);t.set(s.id,e),this._cacheMessage(e)}return t})}search(e={}){return this.client.rest.methods.search(this,e)}startTyping(e){if(void 0!==e&&e<1)throw new RangeError("Count must be at least 1.");if(this.client.user._typing.has(this.id)){const t=this.client.user._typing.get(this.id);return void(t.count=e||t.count+1)}const t={count:e||1,interval:this.client.setInterval(()=>{this.client.rest.methods.sendTyping(this.id).catch(()=>{this.client.clearInterval(t.interval),this.client.user._typing.delete(this.id)})},9e3)};this.client.rest.methods.sendTyping(this.id).catch(()=>{this.client.clearInterval(t.interval),this.client.user._typing.delete(this.id)}),this.client.user._typing.set(this.id,t)}stopTyping(e=!1){if(this.client.user._typing.has(this.id)){const t=this.client.user._typing.get(this.id);t.count--,(t.count<=0||e)&&(this.client.clearInterval(t.interval),this.client.user._typing.delete(this.id))}}get typing(){return this.client.user._typing.has(this.id)}get typingCount(){return this.client.user._typing.has(this.id)?this.client.user._typing.get(this.id).count:0}createCollector(e,t){return this.createMessageCollector(e,t)}createMessageCollector(e,t={}){return new r(this,e,t)}awaitMessages(e,t={}){return new Promise((s,i)=>{this.createCollector(e,t).once("end",(e,n)=>{t.errors&&t.errors.includes(n)?i(e):s(e)})})}bulkDelete(e,t=!1){if(e instanceof o&&(e=[...e.values()]),e instanceof Array)return t&&(e=e.filter(e=>Date.now()-l.deconstruct(e.id).date.getTime()<12096e5)),0===e.length?new o:1===e.length?e[0].delete().then(()=>new o([[e[0].id,e[0]]])):this.client.rest.methods.bulkDeleteMessages(this,e);if(!isNaN(e))return this.fetchMessages({limit:e}).then(e=>this.bulkDelete(e,t));throw new TypeError("The messages must be an Array, Collection, or number.")}acknowledge(){return this.lastMessageID?this.client.rest.methods.ackTextChannel(this):Promise.resolve(this)}_cacheMessage(e){const t=this.client.options.messageCacheMaxSize;return 0===t?null:(this.messages.size>=t&&t>0&&this.messages.delete(this.messages.firstKey()),this.messages.set(e.id,e),e)}}const u={sendMessage(e,t){return this.send(e,t)},sendEmbed(e,t,s){return s||"object"!=typeof t||t instanceof Array?s||(s={}):(s=t,t=""),this.send(t,Object.assign(s,{embed:e}))},sendFiles(e,t,s={}){return this.send(t,Object.assign(s,{files:e}))},sendFile(e,t,s,i={}){return this.send({files:[{attachment:e,name:t}],content:s,options:i})},sendCode(e,t,s={}){return this.send(t,Object.assign(s,{code:e}))}};for(const e of Object.keys(u))TextBasedChannel.prototype[e]=c.deprecate(u[e],`TextChannel#${e}: use TextChannel#send instead`);t.applyToClass=((e,t=!1,s=[])=>{const i=["send","sendMessage","sendEmbed","sendFile","sendFiles","sendCode"];t&&i.push("_cacheMessage","acknowledge","fetchMessages","fetchMessage","search","bulkDelete","startTyping","stopTyping","typing","typingCount","fetchPinnedMessages","createCollector","createMessageCollector","awaitMessages");for(const t of i)s.includes(t)||Object.defineProperty(e.prototype,t,Object.getOwnPropertyDescriptor(TextBasedChannel.prototype,t))})}).call(t,s(12).Buffer)},function(e,t,s){const i=s(38),n=s(39),r=s(40),o=s(20),a=s(42),h=s(43),l=s(4),c=s(3),u=s(0),d=s(6);let m;e.exports=class Message{constructor(e,t,s){Object.defineProperty(this,"client",{value:s}),this.channel=e,t&&this.setup(t)}setup(e){this.id=e.id,this.type=u.MessageTypes[e.type],this.content=e.content,this.author=this.client.dataManager.newUser(e.author),this.member=this.guild&&this.guild.member(this.author)||null,this.pinned=e.pinned,this.tts=e.tts,this.nonce=e.nonce,this.system=6===e.type,this.embeds=e.embeds.map(e=>new r(this,e)),this.attachments=new c;for(const t of e.attachments)this.attachments.set(t.id,new n(this,t));if(this.createdTimestamp=new Date(e.timestamp).getTime(),this.editedTimestamp=e.edited_timestamp?new Date(e.edited_timestamp).getTime():null,this.reactions=new c,e.reactions&&e.reactions.length>0)for(const t of e.reactions){const e=t.emoji.id?`${t.emoji.name}:${t.emoji.id}`:t.emoji.name;this.reactions.set(e,new a(this,t.emoji,t.count,t.me))}this.mentions=new i(this,e.mentions,e.mention_roles,e.mention_everyone),this.webhookID=e.webhook_id||null,this.hit="boolean"==typeof e.hit?e.hit:null,this._edits=[]}patch(e){const t=l.cloneObject(this);if(this._edits.unshift(t),this.editedTimestamp=new Date(e.edited_timestamp).getTime(),"content"in e&&(this.content=e.content),"pinned"in e&&(this.pinned=e.pinned),"tts"in e&&(this.tts=e.tts),this.embeds="embeds"in e?e.embeds.map(e=>new r(this,e)):this.embeds.slice(),"attachments"in e){this.attachments=new c;for(const t of e.attachments)this.attachments.set(t.id,new n(this,t))}else this.attachments=new c(this.attachments);this.mentions=new i(this,"mentions"in e?e.mentions:this.mentions.users,"mentions_roles"in e?e.mentions_roles:this.mentions.roles,"mention_everyone"in e?e.mention_everyone:this.mentions.everyone)}get createdAt(){return new Date(this.createdTimestamp)}get editedAt(){return this.editedTimestamp?new Date(this.editedTimestamp):null}get guild(){return this.channel.guild||null}get cleanContent(){return this.content.replace(/@(everyone|here)/g,"@​$1").replace(/<@!?[0-9]+>/g,e=>{const t=e.replace(/<|!|>|@/g,"");if("dm"===this.channel.type||"group"===this.channel.type)return this.client.users.has(t)?`@${this.client.users.get(t).username}`:e;const s=this.channel.guild.members.get(t);if(s)return s.nickname?`@${s.nickname}`:`@${s.user.username}`;{const s=this.client.users.get(t);return s?`@${s.username}`:e}}).replace(/<#[0-9]+>/g,e=>{const t=this.client.channels.get(e.replace(/<|#|>/g,""));return t?`#${t.name}`:e}).replace(/<@&[0-9]+>/g,e=>{if("dm"===this.channel.type||"group"===this.channel.type)return e;const t=this.guild.roles.get(e.replace(/<|@|>|&/g,""));return t?`@${t.name}`:e})}createReactionCollector(e,t={}){return new h(this,e,t)}awaitReactions(e,t={}){return new Promise((s,i)=>{this.createReactionCollector(e,t).once("end",(e,n)=>{t.errors&&t.errors.includes(n)?i(e):s(e)})})}get edits(){const e=this._edits.slice();return e.unshift(this),e}get editable(){return this.author.id===this.client.user.id}get deletable(){return this.author.id===this.client.user.id||this.guild&&this.channel.permissionsFor(this.client.user).has(d.FLAGS.MANAGE_MESSAGES)}get pinnable(){return!this.guild||this.channel.permissionsFor(this.client.user).has(d.FLAGS.MANAGE_MESSAGES)}isMentioned(e){return e=e&&e.id?e.id:e,this.mentions.users.has(e)||this.mentions.channels.has(e)||this.mentions.roles.has(e)}isMemberMentioned(e){return m||(m=s(17)),!!this.mentions.everyone||!!this.mentions.users.has(e.id)||!!(e instanceof m&&e.roles.some(e=>this.mentions.roles.has(e.id)))}edit(e,t){return t||"object"!=typeof e||e instanceof Array?t||(t={}):(t=e,e=""),t instanceof o&&(t={embed:t}),this.client.rest.methods.updateMessage(this,e,t)}editCode(e,t){return t=l.escapeMarkdown(this.client.resolver.resolveString(t),!0),this.edit(`\`\`\`${e||""}\n${t}\n\`\`\``)}pin(){return this.client.rest.methods.pinMessage(this)}unpin(){return this.client.rest.methods.unpinMessage(this)}react(e){if(!(e=this.client.resolver.resolveEmojiIdentifier(e)))throw new TypeError("Emoji must be a string or Emoji/ReactionEmoji");return this.client.rest.methods.addMessageReaction(this,e)}clearReactions(){return this.client.rest.methods.removeMessageReactions(this)}delete(e=0){return e<=0?this.client.rest.methods.deleteMessage(this):new Promise(t=>{this.client.setTimeout(()=>{t(this.delete())},e)})}reply(e,t){return t||"object"!=typeof e||e instanceof Array?t||(t={}):(t=e,e=""),this.channel.send(e,Object.assign(t,{reply:this.member||this.author}))}acknowledge(){return this.client.rest.methods.ackMessage(this)}fetchWebhook(){return this.webhookID?this.client.fetchWebhook(this.webhookID):Promise.reject(new Error("The message was not sent by a webhook."))}equals(e,t){if(!e)return!1;if(!e.author&&!e.attachments)return this.id===e.id&&this.embeds.length===e.embeds.length;let s=this.id===e.id&&this.author.id===e.author.id&&this.content===e.content&&this.tts===e.tts&&this.nonce===e.nonce&&this.embeds.length===e.embeds.length&&this.attachments.length===e.attachments.length;return s&&t&&(s=this.mentions.everyone===e.mentions.everyone&&this.createdTimestamp===new Date(t.timestamp).getTime()&&this.editedTimestamp===new Date(t.edited_timestamp).getTime()),s}toString(){return this.content}_addReaction(e,t){const s=e.id?`${e.name}:${e.id}`:e.name;let i;return this.reactions.has(s)?(i=this.reactions.get(s)).me||(i.me=t.id===this.client.user.id):(i=new a(this,e,0,t.id===this.client.user.id),this.reactions.set(s,i)),i.users.has(t.id)||(i.users.set(t.id,t),i.count++),i}_removeReaction(e,t){const s=e.id?`${e.name}:${e.id}`:e.name;if(this.reactions.has(s)){const e=this.reactions.get(s);if(e.users.has(t.id))return e.users.delete(t.id),e.count--,t.id===this.client.user.id&&(e.me=!1),e.count<=0&&this.reactions.delete(s),e}return null}_clearReactions(){this.reactions.clear()}}},function(e,t,s){const i=s(0),n=s(3),r=s(5);class Emoji{constructor(e,t){Object.defineProperty(this,"client",{value:e.client}),this.guild=e,this.setup(t)}setup(e){this.id=e.id,this.name=e.name,this.requiresColons=e.require_colons,this.managed=e.managed,this.animated=e.animated,this._roles=e.roles}get createdTimestamp(){return r.deconstruct(this.id).timestamp}get createdAt(){return new Date(this.createdTimestamp)}get roles(){const e=new n;for(const t of this._roles)this.guild.roles.has(t)&&e.set(t,this.guild.roles.get(t));return e}get url(){return i.Endpoints.CDN(this.client.options.http.cdn).Emoji(this.id,this.animated?"gif":"png")}get identifier(){return this.id?`${this.name}:${this.id}`:encodeURIComponent(this.name)}edit(e,t){return this.client.rest.methods.updateEmoji(this,e,t)}setName(e,t){return this.edit({name:e},t)}addRestrictedRole(e){return this.addRestrictedRoles([e])}addRestrictedRoles(e){const t=new n(this.roles);for(const s of e)this.guild.roles.has(s.id)&&t.set(s.id,s);return this.edit({roles:t})}removeRestrictedRole(e){return this.removeRestrictedRoles([e])}removeRestrictedRoles(e){const t=new n(this.roles);for(const s of e)t.has(s.id)&&t.delete(s.id);return this.edit({roles:t})}toString(){return this.id&&this.requiresColons?`<${this.animated?"a":""}:${this.name}:${this.id}>`:this.name}equals(e){return e instanceof Emoji?e.id===this.id&&e.name===this.name&&e.managed===this.managed&&e.requiresColons===this.requiresColons:e.id===this.id&&e.name===this.name}}e.exports=Emoji},function(e,t,s){const i=s(14),n=s(8),r=s(6),o=s(3),a=s(10).Presence,h=s(7);class GuildMember{constructor(e,t){Object.defineProperty(this,"client",{value:e.client}),this.guild=e,this.user={},this._roles=[],t&&this.setup(t),this.lastMessageID=null,this.lastMessage=null}setup(e){this.serverDeaf=e.deaf,this.serverMute=e.mute,this.selfMute=e.self_mute,this.selfDeaf=e.self_deaf,this.voiceSessionID=e.session_id,this.voiceChannelID=e.channel_id,this.speaking=!1,this.nickname=e.nick||null,this.joinedTimestamp=new Date(e.joined_at).getTime(),this.user=e.user,this._roles=e.roles}get joinedAt(){return new Date(this.joinedTimestamp)}get presence(){return this.frozenPresence||this.guild.presences.get(this.id)||new a}get roles(){const e=new o,t=this.guild.roles.get(this.guild.id);t&&e.set(t.id,t);for(const t of this._roles){const s=this.guild.roles.get(t);s&&e.set(s.id,s)}return e}get highestRole(){return this.roles.reduce((e,t)=>!e||t.comparePositionTo(e)>0?t:e)}get colorRole(){const e=this.roles.filter(e=>e.color);return e.size?e.reduce((e,t)=>!e||t.comparePositionTo(e)>0?t:e):null}get displayColor(){const e=this.colorRole;return e&&e.color||0}get displayHexColor(){const e=this.colorRole;return e&&e.hexColor||"#000000"}get hoistRole(){const e=this.roles.filter(e=>e.hoist);return e.size?e.reduce((e,t)=>!e||t.comparePositionTo(e)>0?t:e):null}get mute(){return this.selfMute||this.serverMute}get deaf(){return this.selfDeaf||this.serverDeaf}get voiceChannel(){return this.guild.channels.get(this.voiceChannelID)}get id(){return this.user.id}get displayName(){return this.nickname||this.user.username}get permissions(){if(this.user.id===this.guild.ownerID)return new r(this,r.ALL);let e=0;const t=this.roles;for(const s of t.values())e|=s.permissions;return new r(this,e)}get kickable(){if(this.user.id===this.guild.ownerID)return!1;if(this.user.id===this.client.user.id)return!1;const e=this.guild.member(this.client.user);return!!e.permissions.has(r.FLAGS.KICK_MEMBERS)&&e.highestRole.comparePositionTo(this.highestRole)>0}get bannable(){if(this.user.id===this.guild.ownerID)return!1;if(this.user.id===this.client.user.id)return!1;const e=this.guild.member(this.client.user);return!!e.permissions.has(r.FLAGS.BAN_MEMBERS)&&e.highestRole.comparePositionTo(this.highestRole)>0}permissionsIn(e){if(!(e=this.client.resolver.resolveChannel(e))||!e.guild)throw new Error("Could not resolve channel to a guild channel.");return e.permissionsFor(this)}hasPermission(e,t=!1,s,i){return void 0===s&&(s=!t),void 0===i&&(i=!t),!(!i||this.user.id!==this.guild.ownerID)||this.roles.some(t=>t.hasPermission(e,void 0,s))}hasPermissions(e,t=!1){return!t&&this.user.id===this.guild.ownerID||this.hasPermission(e,t)}missingPermissions(e,t=!1){return this.permissions.missing(e,t)}edit(e,t){return this.client.rest.methods.updateGuildMember(this,e,t)}setMute(e,t){return this.edit({mute:e},t)}setDeaf(e,t){return this.edit({deaf:e},t)}setVoiceChannel(e){return this.edit({channel:e})}setRoles(e,t){return this.edit({roles:e},t)}addRole(e,t){return e instanceof n||(e=this.guild.roles.get(e)),e?this.client.rest.methods.addMemberRole(this,e,t):Promise.reject(new TypeError("Supplied parameter was neither a Role nor a Snowflake."))}addRoles(e,t){let s;if(e instanceof o){s=this._roles.slice();for(const t of e.values())s.push(t.id)}else s=this._roles.concat(e);return this.edit({roles:s},t)}removeRole(e,t){return e instanceof n||(e=this.guild.roles.get(e)),e?this.client.rest.methods.removeMemberRole(this,e,t):Promise.reject(new TypeError("Supplied parameter was neither a Role nor a Snowflake."))}removeRoles(e,t){const s=this._roles.slice();if(e instanceof o)for(const t of e.values()){const e=s.indexOf(t.id);e>=0&&s.splice(e,1)}else for(const t of e){const e=s.indexOf(t instanceof n?t.id:t);e>=0&&s.splice(e,1)}return this.edit({roles:s},t)}setNickname(e,t){return this.edit({nick:e},t)}createDM(){return this.user.createDM()}deleteDM(){return this.user.deleteDM()}kick(e){return this.client.rest.methods.kickGuildMember(this.guild,this,e)}ban(e){return this.guild.ban(this,e)}toString(){return`<@${this.nickname?"!":""}${this.user.id}>`}send(){}sendMessage(){}sendEmbed(){}sendFile(){}sendCode(){}}i.applyToClass(GuildMember),GuildMember.prototype.hasPermissions=h.deprecate(GuildMember.prototype.hasPermissions,"GuildMember#hasPermissions is deprecated - use GuildMember#hasPermission, it now takes an array"),e.exports=GuildMember},function(e,t,s){const i=s(11),n=s(8),r=s(50),o=s(6),a=s(3),h=s(0);e.exports=class GuildChannel extends i{constructor(e,t){super(e.client,t),this.guild=e}setup(e){if(super.setup(e),this.name=e.name,this.position=e.position,this.parentID=e.parent_id,this.permissionOverwrites=new a,e.permission_overwrites)for(const t of e.permission_overwrites)this.permissionOverwrites.set(t.id,new r(this,t))}get calculatedPosition(){const e=this.guild._sortedChannels(this.type);return e.array().indexOf(e.get(this.id))}get parent(){return this.guild.channels.get(this.parentID)||null}permissionsFor(e){if(!(e=this.client.resolver.resolveGuildMember(this.guild,e)))return null;if(e.id===this.guild.ownerID)return new o(e,o.ALL);let t=0;const s=e.roles;for(const e of s.values())t|=e.permissions;if(Boolean(t&o.FLAGS.ADMINISTRATOR))return new o(o.ALL);const i=this.overwritesFor(e,!0,s);i.everyone&&(t&=~i.everyone.deny,t|=i.everyone.allow);let n=0;for(const e of i.roles)t&=~e.deny,n|=e.allow;return t|=n,i.member&&(t&=~i.member.deny,t|=i.member.allow),new o(e,t)}overwritesFor(e,t=!1,s=null){if(t||(e=this.client.resolver.resolveGuildMember(this.guild,e)),!e)return[];s=s||e.roles;const i=[];let n,r;for(const t of this.permissionOverwrites.values())t.id===this.guild.id?r=t:s.has(t.id)?i.push(t):t.id===e.id&&(n=t);return{everyone:r,roles:i,member:n}}overwritePermissions(e,t,s){const i={allow:0,deny:0};if(e instanceof n)i.type="role";else if(this.guild.roles.has(e))e=this.guild.roles.get(e),i.type="role";else if(e=this.client.resolver.resolveUser(e),i.type="member",!e)return Promise.reject(new TypeError("Supplied parameter was neither a User nor a Role."));i.id=e.id;const r=this.permissionOverwrites.get(e.id);r&&(i.allow=r.allow,i.deny=r.deny);for(const e in t)!0===t[e]?(i.allow|=o.FLAGS[e]||0,i.deny&=~(o.FLAGS[e]||0)):!1===t[e]?(i.allow&=~(o.FLAGS[e]||0),i.deny|=o.FLAGS[e]||0):null===t[e]&&(i.allow&=~(o.FLAGS[e]||0),i.deny&=~(o.FLAGS[e]||0));return this.client.rest.methods.setChannelOverwrite(this,i,s).then(()=>this)}edit(e,t){return this.client.rest.methods.updateChannel(this,e,t).then(()=>this)}setName(e,t){return this.edit({name:e},t)}setPosition(e,t){return this.guild.setChannelPosition(this,e,t)}setParent(e,t){return e=this.client.resolver.resolveChannelID(e),this.edit({parent:e},t)}setTopic(e,t){return this.edit({topic:e},t)}createInvite(e={},t){return this.client.rest.methods.createChannelInvite(this,e,t)}clone(e=this.name,t=!0,s=!0,i){return this.guild.createChannel(e,this.type,t?this.permissionOverwrites:[],i).then(e=>s?e.setTopic(this.topic):e)}delete(e){return this.client.rest.methods.deleteChannel(this,e)}equals(e){let t=e&&this.id===e.id&&this.type===e.type&&this.topic===e.topic&&this.position===e.position&&this.name===e.name;return t&&(t=this.permissionOverwrites&&e.permissionOverwrites?this.permissionOverwrites.equals(e.permissionOverwrites):!this.permissionOverwrites&&!e.permissionOverwrites),t}get deletable(){return this.id!==this.guild.id&&this.permissionsFor(this.client.user).has(o.FLAGS.MANAGE_CHANNELS)}get muted(){if(this.client.user.bot)return null;try{return this.client.user.guildSettings.get(this.guild.id).channelOverrides.get(this.id).muted}catch(e){return!1}}get messageNotifications(){if(this.client.user.bot)return null;try{return this.client.user.guildSettings.get(this.guild.id).channelOverrides.get(this.id).messageNotifications}catch(e){return h.MessageNotificationTypes[3]}}toString(){return`<#${this.id}>`}}},function(e,t){function s(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function n(e){return"object"==typeof e&&null!==e}function r(e){return void 0===e}e.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0,s.defaultMaxListeners=10,s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},s.prototype.emit=function(e){var t,s,o,a,h,l;if(this._events||(this._events={}),"error"===e&&(!this._events.error||n(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}if(r(s=this._events[e]))return!1;if(i(s))switch(arguments.length){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),s.apply(this,a)}else if(n(s))for(a=Array.prototype.slice.call(arguments,1),o=(l=s.slice()).length,h=0;h0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},s.prototype.on=s.prototype.addListener,s.prototype.once=function(e,t){if(!i(t))throw TypeError("listener must be a function");var s=!1;function n(){this.removeListener(e,n),s||(s=!0,t.apply(this,arguments))}return n.listener=t,this.on(e,n),this},s.prototype.removeListener=function(e,t){var s,r,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(o=(s=this._events[e]).length,r=-1,s===t||i(s.listener)&&s.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(n(s)){for(a=o;a-- >0;)if(s[a]===t||s[a].listener&&s[a].listener===t){r=a;break}if(r<0)return this;1===s.length?(s.length=0,delete this._events[e]):s.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},s.prototype.removeAllListeners=function(e){var t,s;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i(s=this._events[e]))this.removeListener(e,s);else if(s)for(;s.length;)this.removeListener(e,s[s.length-1]);return delete this._events[e],this},s.prototype.listeners=function(e){return this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},s.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},s.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,s){const i=s(21);let n;function r(e){return"string"==typeof e?e:e instanceof Array?e.join("\n"):String(e)}e.exports=class RichEmbed{constructor(e={}){this.title=e.title,this.description=e.description,this.url=e.url,this.color=e.color,this.author=e.author,this.timestamp=e.timestamp,this.fields=e.fields||[],this.thumbnail=e.thumbnail,this.image=e.image,this.footer=e.footer,this.file=e.file}setTitle(e){if((e=r(e)).length>256)throw new RangeError("RichEmbed titles may not exceed 256 characters.");return this.title=e,this}setDescription(e){if((e=r(e)).length>2048)throw new RangeError("RichEmbed descriptions may not exceed 2048 characters.");return this.description=e,this}setURL(e){return this.url=e,this}setColor(e){return n||(n=s(27)),this.color=n.resolveColor(e),this}setAuthor(e,t,s){return this.author={name:r(e),icon_url:t,url:s},this}setTimestamp(e=new Date){return this.timestamp=e,this}addField(e,t,s=!1){if(this.fields.length>=25)throw new RangeError("RichEmbeds may not exceed 25 fields.");if((e=r(e)).length>256)throw new RangeError("RichEmbed field names may not exceed 256 characters.");if(!/\S/.test(e))throw new RangeError("RichEmbed field names may not be empty.");if((t=r(t)).length>1024)throw new RangeError("RichEmbed field values may not exceed 1024 characters.");if(!/\S/.test(t))throw new RangeError("RichEmbed field values may not be empty.");return this.fields.push({name:e,value:t,inline:s}),this}addBlankField(e=!1){return this.addField("​","​",e)}setThumbnail(e){return this.thumbnail={url:e},this}setImage(e){return this.image={url:e},this}setFooter(e,t){if((e=r(e)).length>2048)throw new RangeError("RichEmbed footer text may not exceed 2048 characters.");return this.footer={text:e,icon_url:t},this}attachFile(e){if(this.file)throw new RangeError("You may not upload more than one file at once.");return e instanceof i&&(e=e.file),this.file=e,this}}},function(e,t){e.exports=class Attachment{constructor(e,t){this.file=null,t?this.setAttachment(e,t):this._attach(e)}get name(){return this.file.name}get attachment(){return this.file.attachment}setAttachment(e,t){return this.file={attachment:e,name:t},this}setFile(e){return this.file={attachment:e},this}setName(e){return this.file.name=e,this}_attach(e,t){"string"==typeof e?this.file=e:this.setAttachment(e,t)}}},function(e,t,s){const i=s(7),n=s(25),r=s(9),o=s(8),a=s(16),h=s(10).Presence,l=s(17),c=s(0),u=s(3),d=s(4),m=s(5);class Guild{constructor(e,t){Object.defineProperty(this,"client",{value:e}),this.members=new u,this.channels=new u,this.roles=new u,this.presences=new u,t&&(t.unavailable?(this.available=!1,this.id=t.id):(this.setup(t),t.channels||(this.available=!1)))}setup(e){if(this.name=e.name,this.icon=e.icon,this.splash=e.splash,this.region=e.region,this.memberCount=e.member_count||this.memberCount,this.large=Boolean("large"in e?e.large:this.large),this.features=e.features,this.applicationID=e.application_id,this.afkTimeout=e.afk_timeout,this.afkChannelID=e.afk_channel_id,this.systemChannelID=e.system_channel_id,this.embedEnabled=e.embed_enabled,this.verificationLevel=e.verification_level,this.explicitContentFilter=e.explicit_content_filter,this.joinedTimestamp=e.joined_at?new Date(e.joined_at).getTime():this.joinedTimestamp,this.id=e.id,this.available=!e.unavailable,this.features=e.features||this.features||[],e.members){this.members.clear();for(const t of e.members)this._addMember(t,!1)}if(e.owner_id&&(this.ownerID=e.owner_id),e.channels){this.channels.clear();for(const t of e.channels)this.client.dataManager.newChannel(t,this)}if(e.roles){this.roles.clear();for(const t of e.roles){const e=new o(this,t);this.roles.set(e.id,e)}}if(e.presences)for(const t of e.presences)this._setPresence(t.user.id,t);if(this._rawVoiceStates=new u,e.voice_states)for(const t of e.voice_states){this._rawVoiceStates.set(t.user_id,t);const e=this.members.get(t.user_id);e&&(e.serverMute=t.mute,e.serverDeaf=t.deaf,e.selfMute=t.self_mute,e.selfDeaf=t.self_deaf,e.voiceSessionID=t.session_id,e.voiceChannelID=t.channel_id,this.channels.get(t.channel_id).members.set(e.user.id,e))}if(this.emojis)this.client.actions.GuildEmojisUpdate.handle({guild_id:this.id,emojis:e.emojis});else{this.emojis=new u;for(const t of e.emojis)this.emojis.set(t.id,new a(this,t))}}get createdTimestamp(){return m.deconstruct(this.id).timestamp}get createdAt(){return new Date(this.createdTimestamp)}get joinedAt(){return new Date(this.joinedTimestamp)}get iconURL(){return this.icon?c.Endpoints.Guild(this).Icon(this.client.options.http.cdn,this.icon):null}get nameAcronym(){return this.name.replace(/\w+/g,e=>e[0]).replace(/\s/g,"")}get splashURL(){return this.splash?c.Endpoints.Guild(this).Splash(this.client.options.http.cdn,this.splash):null}get owner(){return this.members.get(this.ownerID)}get afkChannel(){return this.client.channels.get(this.afkChannelID)||null}get systemChannel(){return this.client.channels.get(this.systemChannelID)||null}get voiceConnection(){return this.client.browser?null:this.client.voice.connections.get(this.id)||null}get position(){return this.client.user.bot?null:this.client.user.settings.guildPositions?this.client.user.settings.guildPositions.indexOf(this.id):null}get muted(){if(this.client.user.bot)return null;try{return this.client.user.guildSettings.get(this.id).muted}catch(e){return!1}}get messageNotifications(){if(this.client.user.bot)return null;try{return this.client.user.guildSettings.get(this.id).messageNotifications}catch(e){return null}}get mobilePush(){if(this.client.user.bot)return null;try{return this.client.user.guildSettings.get(this.id).mobilePush}catch(e){return!1}}get suppressEveryone(){if(this.client.user.bot)return null;try{return this.client.user.guildSettings.get(this.id).suppressEveryone}catch(e){return null}}get defaultRole(){return this.roles.get(this.id)}get me(){return this.members.get(this.client.user.id)}get _sortedRoles(){return this._sortPositionWithID(this.roles)}member(e){return this.client.resolver.resolveGuildMember(this,e)}fetchBans(){return this.client.rest.methods.getGuildBans(this).then(e=>{const t=new u;for(const s of e.values())t.set(s.user.id,s.user);return t})}fetchInvites(){return this.client.rest.methods.getGuildInvites(this)}fetchWebhooks(){return this.client.rest.methods.getGuildWebhooks(this)}fetchVoiceRegions(){return this.client.rest.methods.fetchVoiceRegions(this.id)}fetchAuditLogs(e){return this.client.rest.methods.getGuildAuditLogs(this,e)}addMember(e,t){return this.members.has(e.id)?Promise.resolve(this.members.get(e.id)):this.client.rest.methods.putGuildMember(this,e,t)}fetchMember(e,t=!0){return(e=this.client.resolver.resolveUser(e))?this.members.has(e.id)?Promise.resolve(this.members.get(e.id)):this.client.rest.methods.getGuildMember(this,e,t):Promise.reject(new Error("Invalid or uncached id provided."))}fetchMembers(e="",t=0){return new Promise((s,i)=>{if(this.memberCount===this.members.size)return void s(this);this.client.ws.send({op:c.OPCodes.REQUEST_GUILD_MEMBERS,d:{guild_id:this.id,query:e,limit:t}});const n=(e,t)=>{t.id===this.id&&(this.memberCount===this.members.size||e.length<1e3)&&(this.client.removeListener(c.Events.GUILD_MEMBERS_CHUNK,n),s(this))};this.client.on(c.Events.GUILD_MEMBERS_CHUNK,n),this.client.setTimeout(()=>i(new Error("Members didn't arrive in time.")),12e4)})}search(e={}){return this.client.rest.methods.search(this,e)}edit(e,t){const s={};return e.name&&(s.name=e.name),e.region&&(s.region=e.region),void 0!==e.verificationLevel&&(s.verification_level=Number(e.verificationLevel)),void 0!==e.afkChannel&&(s.afk_channel_id=this.client.resolver.resolveChannelID(e.afkChannel)),void 0!==e.systemChannel&&(s.system_channel_id=this.client.resolver.resolveChannelID(e.systemChannel)),e.afkTimeout&&(s.afk_timeout=Number(e.afkTimeout)),void 0!==e.icon&&(s.icon=e.icon),e.owner&&(s.owner_id=this.client.resolver.resolveUser(e.owner).id),void 0!==e.splash&&(s.splash=e.splash),void 0!==e.explicitContentFilter&&(s.explicit_content_filter=Number(e.explicitContentFilter)),this.client.rest.methods.updateGuild(this,s,t)}setExplicitContentFilter(e,t){return this.edit({explicitContentFilter:e},t)}setName(e,t){return this.edit({name:e},t)}setRegion(e,t){return this.edit({region:e},t)}setVerificationLevel(e,t){return this.edit({verificationLevel:e},t)}setAFKChannel(e,t){return this.edit({afkChannel:e},t)}setSystemChannel(e,t){return this.edit({systemChannel:e},t)}setAFKTimeout(e,t){return this.edit({afkTimeout:e},t)}setIcon(e,t){return this.client.resolver.resolveImage(e).then(e=>this.edit({icon:e,reason:t}))}setOwner(e,t){return this.edit({owner:e},t)}setSplash(e){return this.client.resolver.resolveImage(e).then(e=>this.edit({splash:e}))}setPosition(e,t){return this.client.user.bot?Promise.reject(new Error("Setting guild position is only available for user accounts")):this.client.user.settings.setGuildPosition(this,e,t)}acknowledge(){return this.client.rest.methods.ackGuild(this)}allowDMs(e){const t=this.client.user.settings;return e?t.removeRestrictedGuild(this):t.addRestrictedGuild(this)}ban(e,t={}){return"number"==typeof t?t={reason:null,"delete-message-days":t}:"string"==typeof t&&(t={reason:t,"delete-message-days":0}),t.days&&(t["delete-message-days"]=t.days),this.client.rest.methods.banGuildMember(this,e,t)}unban(e,t){return this.client.rest.methods.unbanGuildMember(this,e,t)}pruneMembers(e,t=!1,s){if("number"!=typeof e)throw new TypeError("Days must be a number.");return this.client.rest.methods.pruneGuildMembers(this,e,t,s)}sync(){this.client.user.bot||this.client.syncGuilds([this])}createChannel(e,t,s,i){return this.client.rest.methods.createChannel(this,e,t,s,i)}setChannelPositions(e){return this.client.rest.methods.updateChannelPositions(this.id,e)}createRole(e={},t){return this.client.rest.methods.createGuildRole(this,e,t)}createEmoji(e,t,s,i){return"string"==typeof e&&e.startsWith("data:")?this.client.rest.methods.createEmoji(this,e,t,s,i):this.client.resolver.resolveImage(e).then(e=>this.client.rest.methods.createEmoji(this,e,t,s,i))}deleteEmoji(e,t){return e instanceof a||(e=this.emojis.get(e)),this.client.rest.methods.deleteEmoji(e,t)}leave(){return this.client.rest.methods.leaveGuild(this)}delete(){return this.client.rest.methods.deleteGuild(this)}equals(e){let t=e&&this.id===e.id&&this.available===!e.unavailable&&this.splash===e.splash&&this.region===e.region&&this.name===e.name&&this.memberCount===e.member_count&&this.large===e.large&&this.icon===e.icon&&d.arraysEqual(this.features,e.features)&&this.ownerID===e.owner_id&&this.verificationLevel===e.verification_level&&this.embedEnabled===e.embed_enabled;return t&&(this.embedChannel?this.embedChannel.id!==e.embed_channel_id&&(t=!1):e.embed_channel_id&&(t=!1)),t}toString(){return this.name}_addMember(e,t=!0){const s=this.members.has(e.user.id);e.user instanceof r||(e.user=this.client.dataManager.newUser(e.user)),e.joined_at=e.joined_at||0;const i=new l(this,e);if(this.members.set(i.id,i),this._rawVoiceStates&&this._rawVoiceStates.has(i.user.id)){const e=this._rawVoiceStates.get(i.user.id);i.serverMute=e.mute,i.serverDeaf=e.deaf,i.selfMute=e.self_mute,i.selfDeaf=e.self_deaf,i.voiceSessionID=e.session_id,i.voiceChannelID=e.channel_id,this.client.channels.has(e.channel_id)?this.client.channels.get(e.channel_id).members.set(i.user.id,i):this.client.emit("warn",`Member ${i.id} added in guild ${this.id} with an uncached voice channel`)}return this.client.ws.connection.status===c.Status.READY&&t&&!s&&this.client.emit(c.Events.GUILD_MEMBER_ADD,i),i}_updateMember(e,t){const s=d.cloneObject(e);t.roles&&(e._roles=t.roles),void 0!==t.nick&&(e.nickname=t.nick);const i=e.nickname!==s.nickname||!d.arraysEqual(e._roles,s._roles);return this.client.ws.connection.status===c.Status.READY&&i&&this.client.emit(c.Events.GUILD_MEMBER_UPDATE,s,e),{old:s,mem:e}}_removeMember(e){this.members.delete(e.id)}_memberSpeakUpdate(e,t){const s=this.members.get(e);s&&s.speaking!==t&&(s.speaking=t,this.client.emit(c.Events.GUILD_MEMBER_SPEAKING,s,t))}_setPresence(e,t){this.presences.get(e)?this.presences.get(e).update(t):this.presences.set(e,new h(t))}setRolePosition(e,t,s=!1){if("string"==typeof e&&!(e=this.roles.get(e)))return Promise.reject(new Error("Supplied role is not a role or snowflake."));if(t=Number(t),isNaN(t))return Promise.reject(new Error("Supplied position is not a number."));let i=this._sortedRoles.array();return d.moveElementInArray(i,e,t,s),i=i.map((e,t)=>({id:e.id,position:t})),this.client.rest.methods.setRolePositions(this.id,i)}setChannelPosition(e,t,s=!1){if("string"==typeof e&&!(e=this.channels.get(e)))return Promise.reject(new Error("Supplied channel is not a channel or snowflake."));if(t=Number(t),isNaN(t))return Promise.reject(new Error("Supplied position is not a number."));let i=this._sortedChannels(e.type).array();return d.moveElementInArray(i,e,t,s),i=i.map((e,t)=>({id:e.id,position:t})),this.client.rest.methods.setChannelPositions(this.id,i)}_sortedChannels(e){return this._sortPositionWithID(this.channels.filter(t=>"voice"===e&&"voice"===t.type||("voice"!==e&&"voice"!==t.type||e===t.type)))}_sortPositionWithID(e){return e.sort((e,t)=>e.position!==t.position?e.position-t.position:n.fromString(e.id).sub(n.fromString(t.id)).toNumber())}}Object.defineProperty(Guild.prototype,"defaultChannel",{get:i.deprecate(function(){return this.channels.get(this.id)},"Guild#defaultChannel: This property is obsolete, will be removed in v12.0.0, and may not function as expected.")}),e.exports=Guild},function(e,t,s){(function(t){const i=s(26),n=s(4),r=s(21),o=s(20);e.exports=class Webhook{constructor(e,t,s){e?(Object.defineProperty(this,"client",{value:e}),t&&this.setup(t)):(this.id=t,this.token=s,Object.defineProperty(this,"client",{value:this}))}setup(e){this.name=e.name,this.token=e.token,this.avatar=e.avatar,this.id=e.id,this.guildID=e.guild_id,this.channelID=e.channel_id,e.user?this.owner=this.client.users?this.client.users.get(e.user.id):e.user:this.owner=null}send(e,s){if(s||"object"!=typeof e||e instanceof Array?s||(s={}):(s=e,e=""),s instanceof r&&(s={files:[s]}),s instanceof o&&(s={embeds:[s]}),e){e=this.client.resolver.resolveString(e);let{split:t,code:i,disableEveryone:r}=s;t&&"object"!=typeof t&&(t={}),void 0===i||"boolean"==typeof i&&!0!==i||(e=n.escapeMarkdown(e,!0),e=`\`\`\`${"boolean"!=typeof i&&i||""}\n${e}\n\`\`\``,t&&(t.prepend=`\`\`\`${"boolean"!=typeof i&&i||""}\n`,t.append="\n```")),(r||void 0===r&&this.client.options.disableEveryone)&&(e=e.replace(/@(everyone|here)/g,"@​$1")),t&&(e=n.splitMessage(e,t))}if(s.file&&(s.files?s.files.push(s.file):s.files=[s.file]),s.embeds){const e=[];for(const t of s.embeds)t.file&&e.push(t.file);s.files?s.files.push(...e):s.files=e}if(s.files){for(let e=0;ethis.client.resolver.resolveFile(e.attachment).then(t=>(e.file=t,e)))).then(t=>this.client.rest.methods.sendWebhookMessage(this,e,s,t))}return this.client.rest.methods.sendWebhookMessage(this,e,s)}sendMessage(e,t={}){return this.send(e,t)}sendFile(e,t,s,i={}){return this.send(s,Object.assign(i,{file:{attachment:e,name:t}}))}sendCode(e,t,s={}){return this.send(t,Object.assign(s,{code:e}))}sendSlackMessage(e){return this.client.rest.methods.sendSlackWebhookMessage(this,e)}edit(e=this.name,t){return t?this.client.resolver.resolveImage(t).then(t=>this.client.rest.methods.editWebhook(this,e,t)):this.client.rest.methods.editWebhook(this,e)}delete(e){return this.client.rest.methods.deleteWebhook(this,e)}}}).call(t,s(12).Buffer)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),s.d(t,"delete",function(){return d});var i=s(63),n=s.n(i);t.default=n.a;const r=n.a.version;t.version=r;const o=n.a.METHODS;t.METHODS=o;const a=n.a.acl;t.acl=a;const h=n.a.bind;t.bind=h;const l=n.a.checkout;t.checkout=l;const c=n.a.connect;t.connect=c;const u=n.a.copy;t.copy=u;const d=n.a.delete,m=n.a.get;t.get=m;const g=n.a.head;t.head=g;const p=n.a.link;t.link=p;const f=n.a.lock;t.lock=f;const E=n.a.merge;t.merge=E;const _=n.a.mkactivity;t.mkactivity=_;const v=n.a.mkcalendar;t.mkcalendar=v;const b=n.a.mkcol;t.mkcol=b;const y=n.a.move;t.move=y;const w=n.a.notify;t.notify=w;const A=n.a.options;t.options=A;const T=n.a.patch;t.patch=T;const R=n.a.post;t.post=R;const M=n.a.propfind;t.propfind=M;const D=n.a.proppatch;t.proppatch=D;const S=n.a.purge;t.purge=S;const C=n.a.put;t.put=C;const I=n.a.rebind;t.rebind=I;const U=n.a.report;t.report=U;const N=n.a.search;t.search=N;const O=n.a.subscribe;t.subscribe=O;const L=n.a.trace;t.trace=L;const k=n.a.unbind;t.unbind=k;const P=n.a.unlink;t.unlink=P;const G=n.a.unlock;t.unlock=G;const x=n.a.unsubscribe;t.unsubscribe=x;const j=n.a.brew;t.brew=j},function(e,t){e.exports=i;var s=null;try{s=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}function i(e,t,s){this.low=0|e,this.high=0|t,this.unsigned=!!s}function n(e){return!0===(e&&e.__isLong__)}i.prototype.__isLong__,Object.defineProperty(i.prototype,"__isLong__",{value:!0}),i.isLong=n;var r={},o={};function a(e,t){var s,i,n;return t?(n=0<=(e>>>=0)&&e<256)&&(i=o[e])?i:(s=l(e,(0|e)<0?-1:0,!0),n&&(o[e]=s),s):(n=-128<=(e|=0)&&e<128)&&(i=r[e])?i:(s=l(e,e<0?-1:0,!1),n&&(r[e]=s),s)}function h(e,t){if(isNaN(e))return t?_:E;if(t){if(e<0)return _;if(e>=g)return A}else{if(e<=-p)return T;if(e+1>=p)return w}return e<0?h(-e,t).neg():l(e%m|0,e/m|0,t)}function l(e,t,s){return new i(e,t,s)}i.fromInt=a,i.fromNumber=h,i.fromBits=l;var c=Math.pow;function u(e,t,s){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return E;if("number"==typeof t?(s=t,t=!1):t=!!t,(s=s||10)<2||360)throw Error("interior hyphen");if(0===i)return u(e.substring(1),t,s).neg();for(var n=h(c(s,8)),r=E,o=0;o>>0:this.low},R.toNumber=function(){return this.unsigned?(this.high>>>0)*m+(this.low>>>0):this.high*m+(this.low>>>0)},R.toString=function(e){if((e=e||10)<2||36>>0).toString(e);if((r=a).isZero())return l+o;for(;l.length<6;)l="0"+l;o=""+l+o}},R.getHighBits=function(){return this.high},R.getHighBitsUnsigned=function(){return this.high>>>0},R.getLowBits=function(){return this.low},R.getLowBitsUnsigned=function(){return this.low>>>0},R.getNumBitsAbs=function(){if(this.isNegative())return this.eq(T)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<=0},R.isOdd=function(){return 1==(1&this.low)},R.isEven=function(){return 0==(1&this.low)},R.equals=function(e){return n(e)||(e=d(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},R.eq=R.equals,R.notEquals=function(e){return!this.eq(e)},R.neq=R.notEquals,R.ne=R.notEquals,R.lessThan=function(e){return this.comp(e)<0},R.lt=R.lessThan,R.lessThanOrEqual=function(e){return this.comp(e)<=0},R.lte=R.lessThanOrEqual,R.le=R.lessThanOrEqual,R.greaterThan=function(e){return this.comp(e)>0},R.gt=R.greaterThan,R.greaterThanOrEqual=function(e){return this.comp(e)>=0},R.gte=R.greaterThanOrEqual,R.ge=R.greaterThanOrEqual,R.compare=function(e){if(n(e)||(e=d(e)),this.eq(e))return 0;var t=this.isNegative(),s=e.isNegative();return t&&!s?-1:!t&&s?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},R.comp=R.compare,R.negate=function(){return!this.unsigned&&this.eq(T)?T:this.not().add(v)},R.neg=R.negate,R.add=function(e){n(e)||(e=d(e));var t=this.high>>>16,s=65535&this.high,i=this.low>>>16,r=65535&this.low,o=e.high>>>16,a=65535&e.high,h=e.low>>>16,c=0,u=0,m=0,g=0;return m+=(g+=r+(65535&e.low))>>>16,u+=(m+=i+h)>>>16,c+=(u+=s+a)>>>16,c+=t+o,l((m&=65535)<<16|(g&=65535),(c&=65535)<<16|(u&=65535),this.unsigned)},R.subtract=function(e){return n(e)||(e=d(e)),this.add(e.neg())},R.sub=R.subtract,R.multiply=function(e){if(this.isZero())return E;if(n(e)||(e=d(e)),s)return l(s.mul(this.low,this.high,e.low,e.high),s.get_high(),this.unsigned);if(e.isZero())return E;if(this.eq(T))return e.isOdd()?T:E;if(e.eq(T))return this.isOdd()?T:E;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(f)&&e.lt(f))return h(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,i=65535&this.high,r=this.low>>>16,o=65535&this.low,a=e.high>>>16,c=65535&e.high,u=e.low>>>16,m=65535&e.low,g=0,p=0,_=0,v=0;return _+=(v+=o*m)>>>16,p+=(_+=r*m)>>>16,_&=65535,p+=(_+=o*u)>>>16,g+=(p+=i*m)>>>16,p&=65535,g+=(p+=r*u)>>>16,p&=65535,g+=(p+=o*c)>>>16,g+=t*m+i*u+r*c+o*a,l((_&=65535)<<16|(v&=65535),(g&=65535)<<16|(p&=65535),this.unsigned)},R.mul=R.multiply,R.divide=function(e){if(n(e)||(e=d(e)),e.isZero())throw Error("division by zero");var t,i,r;if(s)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?l((this.unsigned?s.div_u:s.div_s)(this.low,this.high,e.low,e.high),s.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?_:E;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return _;if(e.gt(this.shru(1)))return b;r=_}else{if(this.eq(T))return e.eq(v)||e.eq(y)?T:e.eq(T)?v:(t=this.shr(1).div(e).shl(1)).eq(E)?e.isNegative()?v:y:(i=this.sub(e.mul(t)),r=t.add(i.div(e)));else if(e.eq(T))return this.unsigned?_:E;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=E}for(i=this;i.gte(e);){t=Math.max(1,Math.floor(i.toNumber()/e.toNumber()));for(var o=Math.ceil(Math.log(t)/Math.LN2),a=o<=48?1:c(2,o-48),u=h(t),m=u.mul(e);m.isNegative()||m.gt(i);)m=(u=h(t-=a,this.unsigned)).mul(e);u.isZero()&&(u=v),r=r.add(u),i=i.sub(m)}return r},R.div=R.divide,R.modulo=function(e){return n(e)||(e=d(e)),s?l((this.unsigned?s.rem_u:s.rem_s)(this.low,this.high,e.low,e.high),s.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},R.mod=R.modulo,R.rem=R.modulo,R.not=function(){return l(~this.low,~this.high,this.unsigned)},R.and=function(e){return n(e)||(e=d(e)),l(this.low&e.low,this.high&e.high,this.unsigned)},R.or=function(e){return n(e)||(e=d(e)),l(this.low|e.low,this.high|e.high,this.unsigned)},R.xor=function(e){return n(e)||(e=d(e)),l(this.low^e.low,this.high^e.high,this.unsigned)},R.shiftLeft=function(e){return n(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?l(this.low<>>32-e,this.unsigned):l(0,this.low<>>e|this.high<<32-e,this.high>>e,this.unsigned):l(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},R.shr=R.shiftRight,R.shiftRightUnsigned=function(e){if(n(e)&&(e=e.toInt()),0===(e&=63))return this;var t=this.high;return e<32?l(this.low>>>e|t<<32-e,t>>>e,this.unsigned):l(32===e?t:t>>>e-32,0,this.unsigned)},R.shru=R.shiftRightUnsigned,R.shr_u=R.shiftRightUnsigned,R.toSigned=function(){return this.unsigned?l(this.low,this.high,!1):this},R.toUnsigned=function(){return this.unsigned?this:l(this.low,this.high,!0)},R.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},R.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},R.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},i.fromBytes=function(e,t,s){return s?i.fromBytesLE(e,t):i.fromBytesBE(e,t)},i.fromBytesLE=function(e,t){return new i(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},i.fromBytesBE=function(e,t){return new i(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)}},function(e,t,s){(function(e){function s(e,t){for(var s=0,i=e.length-1;i>=0;i--){var n=e[i];"."===n?e.splice(i,1):".."===n?(e.splice(i,1),s++):s&&(e.splice(i,1),s--)}if(t)for(;s--;s)e.unshift("..");return e}var i=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,n=function(e){return i.exec(e).slice(1)};function r(e,t){if(e.filter)return e.filter(t);for(var s=[],i=0;i=-1&&!i;n--){var o=n>=0?arguments[n]:e.cwd();if("string"!=typeof o)throw new TypeError("Arguments to path.resolve must be strings");o&&(t=o+"/"+t,i="/"===o.charAt(0))}return t=s(r(t.split("/"),function(e){return!!e}),!i).join("/"),(i?"/":"")+t||"."},t.normalize=function(e){var i=t.isAbsolute(e),n="/"===o(e,-1);return(e=s(r(e.split("/"),function(e){return!!e}),!i).join("/"))||i||(e="."),e&&n&&(e+="/"),(i?"/":"")+e},t.isAbsolute=function(e){return"/"===e.charAt(0)},t.join=function(){var e=Array.prototype.slice.call(arguments,0);return t.normalize(r(e,function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},t.relative=function(e,s){function i(e){for(var t=0;t=0&&""===e[s];s--);return t>s?[]:e.slice(t,s-t+1)}e=t.resolve(e).substr(1),s=t.resolve(s).substr(1);for(var n=i(e.split("/")),r=i(s.split("/")),o=Math.min(n.length,r.length),a=o,h=0;h{if(/^https?:\/\//.test(e))r.get(e).end((e,i)=>e?o(e):i.body instanceof t?s(i.body):o(new TypeError("The response body isn't a Buffer.")));else{const t=i.resolve(e);n.stat(t,(e,i)=>e?o(e):i&&i.isFile()?(n.readFile(t,(e,t)=>{e?o(e):s(t)}),null):o(new Error(`The file could not be found: ${t}`)))}}):e.pipe&&"function"==typeof e.pipe?new Promise((s,i)=>{const n=[];e.once("error",i),e.on("data",e=>n.push(e)),e.once("end",()=>s(t.concat(n)))}):Promise.reject(new TypeError("The resource must be a string or Buffer."))}resolveEmojiIdentifier(e){return e instanceof m||e instanceof g?e.identifier:"string"==typeof e?this.client.emojis.has(e)?this.client.emojis.get(e).identifier:e.includes("%")?e:encodeURIComponent(e):null}static resolveColor(e){if("string"==typeof e){if("RANDOM"===e)return Math.floor(16777216*Math.random());if("DEFAULT"===e)return 0;e=o.Colors[e]||parseInt(e.replace("#",""),16)}else e instanceof Array&&(e=(e[0]<<16)+(e[1]<<8)+e[2]);if(e<0||e>16777215)throw new RangeError("Color must be within the range 0 - 16777215 (0xFFFFFF).");if(e&&isNaN(e))throw new TypeError("Unable to convert color to a number.");return e}resolveColor(e){return this.constructor.resolveColor(e)}}}).call(t,s(12).Buffer)},function(e,t){e.exports=class ReactionEmoji{constructor(e,t,s){this.reaction=e,this.name=t,this.id=s}get identifier(){return this.id?`${this.name}:${this.id}`:encodeURIComponent(this.name)}toString(){return this.id?`<:${this.name}:${this.id}>`:this.name}}},function(e,t,s){const i=s(3),n=s(19).EventEmitter;e.exports=class Collector extends n{constructor(e,t,s={}){super(),Object.defineProperty(this,"client",{value:e}),this.filter=t,this.options=s,this.collected=new i,this.ended=!1,this._timeout=null,this.listener=this._handle.bind(this),s.time&&(this._timeout=this.client.setTimeout(()=>this.stop("time"),s.time))}_handle(...e){const t=this.handle(...e);if(!t||!this.filter(...e,this.collected))return;this.collected.set(t.key,t.value),this.emit("collect",t.value,this);const s=this.postCheck(...e);s&&this.stop(s)}get next(){return new Promise((e,t)=>{if(this.ended)return void t(this.collected);const s=()=>{this.removeListener("collect",i),this.removeListener("end",n)},i=t=>{s(),e(t)},n=()=>{s(),t(this.collected)};this.on("collect",i),this.on("end",n)})}stop(e="user"){this.ended||(this._timeout&&this.client.clearTimeout(this._timeout),this.ended=!0,this.cleanup(),this.emit("end",this.collected,e))}handle(){}postCheck(){}cleanup(){}}},function(e,t,s){const i=s(45),n=s(46),r=s(0);e.exports=class Invite{constructor(e,t){Object.defineProperty(this,"client",{value:e}),this.setup(t)}setup(e){this.guild=this.client.guilds.get(e.guild.id)||new i(this.client,e.guild),this.code=e.code,this.presenceCount=e.approximate_presence_count,this.memberCount=e.approximate_member_count,this.textChannelCount=e.guild.text_channel_count,this.voiceChannelCount=e.guild.voice_channel_count,this.temporary=e.temporary,this.maxAge=e.max_age,this.uses=e.uses,this.maxUses=e.max_uses,e.inviter&&(this.inviter=this.client.dataManager.newUser(e.inviter)),this.channel=this.client.channels.get(e.channel.id)||new n(this.client,e.channel),this.createdTimestamp=new Date(e.created_at).getTime()}get createdAt(){return new Date(this.createdTimestamp)}get expiresTimestamp(){return this.createdTimestamp+1e3*this.maxAge}get expiresAt(){return new Date(this.expiresTimestamp)}get url(){return r.Endpoints.inviteLink(this.code)}delete(e){return this.client.rest.methods.deleteInvite(this,e)}toString(){return this.url}}},function(e,t,s){const i=s(5);e.exports=class OAuth2Application{constructor(e,t){Object.defineProperty(this,"client",{value:e}),this.setup(t)}setup(e){this.id=e.id,this.name=e.name,this.description=e.description,this.icon=e.icon,this.iconURL=`https://cdn.discordapp.com/app-icons/${this.id}/${this.icon}.jpg`,this.rpcOrigins=e.rpc_origins,this.redirectURIs=e.redirect_uris,this.botRequireCodeGrant=e.bot_require_code_grant,this.botPublic=e.bot_public,this.rpcApplicationState=e.rpc_application_state,this.bot=e.bot,this.flags=e.flags,this.secret=e.secret,e.owner&&(this.owner=this.client.dataManager.newUser(e.owner))}get createdTimestamp(){return i.deconstruct(this.id).timestamp}get createdAt(){return new Date(this.createdTimestamp)}reset(){return this.client.rest.methods.resetApplication(this.id)}toString(){return this.name}}},function(e,t,s){const i=s(11),n=s(14),r=s(3),o=s(0);class GroupDMChannel extends i{constructor(e,t){super(e,t),this.type="group",this.messages=new r,this._typing=new Map}setup(e){if(super.setup(e),this.name=e.name,this.icon=e.icon,this.ownerID=e.owner_id,this.managed=e.managed,this.applicationID=e.application_id,e.nicks&&(this.nicks=new r(e.nicks.map(e=>[e.id,e.nick]))),this.recipients||(this.recipients=new r),e.recipients)for(const t of e.recipients){const e=this.client.dataManager.newUser(t);this.recipients.set(e.id,e)}this.lastMessageID=e.last_message_id}get owner(){return this.client.users.get(this.ownerID)}get iconURL(){return this.icon?o.Endpoints.Channel(this).Icon(this.client.options.http.cdn,this.icon):null}edit(e){const t={};return e.name&&(t.name=e.name),void 0!==e.icon&&(t.icon=e.icon),this.client.rest.methods.updateGroupDMChannel(this,t)}equals(e){const t=e&&this.id===e.id&&this.name===e.name&&this.icon===e.icon&&this.ownerID===e.ownerID;return t?this.recipients.equals(e.recipients):t}addUser(e,t){return this.client.rest.methods.addUserToGroupDM(this,{nick:t,id:this.client.resolver.resolveUserID(e),accessToken:e})}setIcon(e){return this.client.resolver.resolveImage(e).then(e=>this.edit({icon:e}))}setName(e){return this.edit({name:e})}removeUser(e){const t=this.client.resolver.resolveUserID(e);return this.client.rest.methods.removeUserFromGroupDM(this,t)}toString(){return this.name}send(){}sendMessage(){}sendEmbed(){}sendFile(){}sendFiles(){}sendCode(){}fetchMessage(){}fetchMessages(){}fetchPinnedMessages(){}search(){}startTyping(){}stopTyping(){}get typing(){}get typingCount(){}createCollector(){}createMessageCollector(){}awaitMessages(){}acknowledge(){}_cacheMessage(){}}n.applyToClass(GroupDMChannel,!0,["bulkDelete"]),e.exports=GroupDMChannel},function(e,t){e.exports=class DiscordAPIError extends Error{constructor(e,t){super();const s=this.constructor.flattenErrors(t.errors||t).join("\n");this.name="DiscordAPIError",this.message=t.message&&s?`${t.message}\n${s}`:t.message||s,this.path=e,this.code=t.code}static flattenErrors(e,t=""){let s=[];for(const i of Object.keys(e)){if("message"===i)continue;const n=t?isNaN(i)?`${t}.${i}`:`${t}[${i}]`:i;e[i]._errors?s.push(`${n}: ${e[i]._errors.map(e=>e.message).join(" ")}`):e[i].code||e[i].message?s.push(`${e[i].code?`${e[i].code}: `:""}: ${e[i].message}`.trim()):"string"==typeof e[i]?s.push(e[i]):s=s.concat(this.flattenErrors(e[i],n))}return s}}},function(e,t){var s;s=function(){return this}();try{s=s||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(s=window)}e.exports=s},function(e,t,s){"use strict";t.decode=t.parse=s(65),t.encode=t.stringify=s(66)},function(e,t){e.exports={name:"discord.js",version:"11.3.1",description:"A powerful library for interacting with the Discord API",main:"./src/index",types:"./typings/index.d.ts",scripts:{test:"npm run lint && npm run docs:test",docs:"docgen --source src --custom docs/index.yml --output docs/docs.json","docs:test":"docgen --source src --custom docs/index.yml",lint:"eslint src","lint:fix":"eslint --fix src",webpack:"parallel-webpack"},repository:{type:"git",url:"git+https://github.com/discordjs/discord.js.git"},keywords:["discord","api","bot","client","node","discordapp"],author:"Amish Shah ",license:"Apache-2.0",bugs:{url:"https://github.com/discordjs/discord.js/issues"},homepage:"https://github.com/discordjs/discord.js#readme",runkitExampleFilename:"./docs/examples/ping.js",dependencies:{long:"^4.0.0","prism-media":"^0.0.2",snekfetch:"^3.6.4",tweetnacl:"^1.0.0",ws:"^4.0.0"},peerDependencies:{bufferutil:"^3.0.3",erlpack:"discordapp/erlpack","node-opus":"^0.2.7",opusscript:"^0.0.6",sodium:"^2.0.3","libsodium-wrappers":"^0.7.3",uws:"^9.14.0"},devDependencies:{"@types/node":"^9.4.6","discord.js-docgen":"discordjs/docgen",eslint:"^4.18.0","parallel-webpack":"^2.2.0","uglifyjs-webpack-plugin":"^1.2.0",webpack:"^3.11.0"},engines:{node:">=6.0.0"},browser:{ws:!1,uws:!1,erlpack:!1,"prism-media":!1,opusscript:!1,"node-opus":!1,tweetnacl:!1,sodium:!1,"src/sharding/Shard.js":!1,"src/sharding/ShardClientUtil.js":!1,"src/sharding/ShardingManager.js":!1,"src/client/voice/dispatcher/StreamDispatcher.js":!1,"src/client/voice/opus/BaseOpusEngine.js":!1,"src/client/voice/opus/NodeOpusEngine.js":!1,"src/client/voice/opus/OpusEngineList.js":!1,"src/client/voice/opus/OpusScriptEngine.js":!1,"src/client/voice/pcm/ConverterEngine.js":!1,"src/client/voice/pcm/ConverterEngineList.js":!1,"src/client/voice/pcm/FfmpegConverterEngine.js":!1,"src/client/voice/player/AudioPlayer.js":!1,"src/client/voice/receiver/VoiceReadable.js":!1,"src/client/voice/receiver/VoiceReceiver.js":!1,"src/client/voice/util/Secretbox.js":!1,"src/client/voice/util/SecretKey.js":!1,"src/client/voice/util/VolumeInterface.js":!1,"src/client/voice/ClientVoiceManager.js":!1,"src/client/voice/VoiceBroadcast.js":!1,"src/client/voice/VoiceConnection.js":!1,"src/client/voice/VoiceUDPClient.js":!1,"src/client/voice/VoiceWebSocket.js":!1}}},function(e,t,s){const i=s(73),n=s(74),r=s(78),o=s(79),a=s(80),h=s(0);e.exports=class RESTManager{constructor(e){this.client=e,this.handlers={},this.userAgentManager=new i(this),this.methods=new n(this),this.rateLimitedEndpoints={},this.globallyRateLimited=!1}destroy(){for(const e of Object.values(this.handlers))e.destroy&&e.destroy()}push(e,t){return new Promise((s,i)=>{e.push({request:t,resolve:s,reject:i})})}getRequestHandler(){switch(this.client.options.apiRequestMethod){case"sequential":return r;case"burst":return o;default:throw new Error(h.Errors.INVALID_RATE_LIMIT_METHOD)}}makeRequest(e,t,s,i,n,r){const o=new a(this,e,t,s,i,n,r);if(!this.handlers[o.route]){const e=this.getRequestHandler();this.handlers[o.route]=new e(this,o.route)}return this.push(this.handlers[o.route],o)}}},function(e,t,s){const i=s(3);class MessageMentions{constructor(e,t,s,n){if(this.everyone=Boolean(n),t)if(t instanceof i)this.users=new i(t);else{this.users=new i;for(const s of t){let t=e.client.users.get(s.id);t||(t=e.client.dataManager.newUser(s)),this.users.set(t.id,t)}}else this.users=new i;if(s)if(s instanceof i)this.roles=new i(s);else{this.roles=new i;for(const t of s){const s=e.channel.guild.roles.get(t);s&&this.roles.set(s.id,s)}}else this.roles=new i;this._content=e.content,this._client=e.client,this._guild=e.channel.guild,this._members=null,this._channels=null}get members(){return this._members?this._members:this._guild?(this._members=new i,this.users.forEach(e=>{const t=this._guild.member(e);t&&this._members.set(t.user.id,t)}),this._members):null}get channels(){if(this._channels)return this._channels;let e;for(this._channels=new i;null!==(e=this.constructor.CHANNELS_PATTERN.exec(this._content));){const t=this._client.channels.get(e[1]);t&&this._channels.set(t.id,t)}return this._channels}}MessageMentions.EVERYONE_PATTERN=/@(everyone|here)/g,MessageMentions.USERS_PATTERN=/<@!?[0-9]+>/g,MessageMentions.ROLES_PATTERN=/<@&[0-9]+>/g,MessageMentions.CHANNELS_PATTERN=/<#([0-9]+)>/g,e.exports=MessageMentions},function(e,t){e.exports=class MessageAttachment{constructor(e,t){Object.defineProperty(this,"client",{value:e.client}),this.message=e,this.setup(t)}setup(e){this.id=e.id,this.filename=e.filename,this.filesize=e.size,this.url=e.url,this.proxyURL=e.proxy_url,this.height=e.height,this.width=e.width}}},function(e,t){class MessageEmbed{constructor(e,t){Object.defineProperty(this,"client",{value:e.client}),this.message=e,this.setup(t)}setup(e){if(this.type=e.type,this.title=e.title,this.description=e.description,this.url=e.url,this.color=e.color,this.fields=[],e.fields)for(const t of e.fields)this.fields.push(new MessageEmbedField(this,t));this.timestamp=e.timestamp,this.thumbnail=e.thumbnail?new MessageEmbedThumbnail(this,e.thumbnail):null,this.image=e.image?new MessageEmbedImage(this,e.image):null,this.video=e.video?new MessageEmbedVideo(this,e.video):null,this.author=e.author?new MessageEmbedAuthor(this,e.author):null,this.provider=e.provider?new MessageEmbedProvider(this,e.provider):null,this.footer=e.footer?new MessageEmbedFooter(this,e.footer):null}get createdAt(){return new Date(this.createdTimestamp)}get hexColor(){let e=this.color.toString(16);for(;e.length<6;)e=`0${e}`;return`#${e}`}}class MessageEmbedThumbnail{constructor(e,t){this.embed=e,this.setup(t)}setup(e){this.url=e.url,this.proxyURL=e.proxy_url,this.height=e.height,this.width=e.width}}class MessageEmbedImage{constructor(e,t){this.embed=e,this.setup(t)}setup(e){this.url=e.url,this.proxyURL=e.proxy_url,this.height=e.height,this.width=e.width}}class MessageEmbedVideo{constructor(e,t){this.embed=e,this.setup(t)}setup(e){this.url=e.url,this.height=e.height,this.width=e.width}}class MessageEmbedProvider{constructor(e,t){this.embed=e,this.setup(t)}setup(e){this.name=e.name,this.url=e.url}}class MessageEmbedAuthor{constructor(e,t){this.embed=e,this.setup(t)}setup(e){this.name=e.name,this.url=e.url,this.iconURL=e.icon_url}}class MessageEmbedField{constructor(e,t){this.embed=e,this.setup(t)}setup(e){this.name=e.name,this.value=e.value,this.inline=e.inline}}class MessageEmbedFooter{constructor(e,t){this.embed=e,this.setup(t)}setup(e){this.text=e.text,this.iconURL=e.icon_url,this.proxyIconUrl=e.proxy_icon_url}}MessageEmbed.Thumbnail=MessageEmbedThumbnail,MessageEmbed.Image=MessageEmbedImage,MessageEmbed.Video=MessageEmbedVideo,MessageEmbed.Provider=MessageEmbedProvider,MessageEmbed.Author=MessageEmbedAuthor,MessageEmbed.Field=MessageEmbedField,MessageEmbed.Footer=MessageEmbedFooter,e.exports=MessageEmbed},function(e,t){},function(e,t,s){const i=s(3),n=s(16),r=s(28);e.exports=class MessageReaction{constructor(e,t,s,n){this.message=e,this.me=n,this.count=s||0,this.users=new i,this._emoji=new r(this,t.name,t.id)}get emoji(){if(this._emoji instanceof n)return this._emoji;if(this._emoji.id){const e=this.message.client.emojis;if(e.has(this._emoji.id)){const t=e.get(this._emoji.id);return this._emoji=t,t}}return this._emoji}remove(e=this.message.client.user){const t=this.message,s=this.message.client.resolver.resolveUserID(e);return s?t.client.rest.methods.removeMessageReaction(t,this.emoji.identifier,s):Promise.reject(new Error("Couldn't resolve the user ID to remove from the reaction."))}fetchUsers(e=100,{after:t,before:s}={}){const i=this.message;return i.client.rest.methods.getMessageReactionUsers(i,this.emoji.identifier,{after:t,before:s,limit:e}).then(e=>{for(const t of e){const e=this.message.client.dataManager.newUser(t);this.users.set(e.id,e)}return this.users})}}},function(e,t,s){const i=s(29),n=s(3);e.exports=class ReactionCollector extends i{constructor(e,t,s={}){super(e.client,t,s),this.message=e,this.users=new n,this.total=0,this.client.on("messageReactionAdd",this.listener)}handle(e){return e.message.id!==this.message.id?null:{key:e.emoji.id||e.emoji.name,value:e}}postCheck(e,t){return this.users.set(t.id,t),this.options.max&&++this.total>=this.options.max?"limit":this.options.maxEmojis&&this.collected.size>=this.options.maxEmojis?"emojiLimit":this.options.maxUsers&&this.users.size>=this.options.maxUsers?"userLimit":null}cleanup(){this.client.removeListener("messageReactionAdd",this.listener)}}},function(e,t,s){const i=s(29),n=s(7);e.exports=class MessageCollector extends i{constructor(e,t,s={}){super(e.client,t,s),this.channel=e,this.received=0,this.client.on("message",this.listener),this.options.max&&(this.options.maxProcessed=this.options.max),this.options.maxMatches&&(this.options.max=this.options.maxMatches),this._reEmitter=(e=>{this.emit("message",e)}),this.on("collect",this._reEmitter)}on(e,t){"message"===e&&(t=n.deprecate(t,'MessageCollector will soon no longer emit "message", use "collect" instead')),super.on(e,t)}handle(e){return e.channel.id!==this.channel.id?null:(this.received++,{key:e.id,value:e})}postCheck(){return this.options.maxMatches&&this.collected.size>=this.options.max?"matchesLimit":this.options.max&&this.received>=this.options.maxProcessed?"limit":null}cleanup(){this.removeListener("collect",this._reEmitter),this.client.removeListener("message",this.listener)}}},function(e,t){e.exports=class PartialGuild{constructor(e,t){Object.defineProperty(this,"client",{value:e}),this.setup(t)}setup(e){this.id=e.id,this.name=e.name,this.icon=e.icon,this.splash=e.splash}}},function(e,t,s){const i=s(0);e.exports=class PartialGuildChannel{constructor(e,t){Object.defineProperty(this,"client",{value:e}),this.setup(t)}setup(e){this.id=e.id,this.name=e.name,this.type=i.ChannelTypes.TEXT===e.type?"text":"voice"}}},function(e,t,s){const i=s(3),n=s(5),r=s(23),o=s(30),a={ALL:"ALL",GUILD:"GUILD",CHANNEL:"CHANNEL",USER:"USER",ROLE:"ROLE",INVITE:"INVITE",WEBHOOK:"WEBHOOK",EMOJI:"EMOJI",MESSAGE:"MESSAGE"},h={ALL:null,GUILD_UPDATE:1,CHANNEL_CREATE:10,CHANNEL_UPDATE:11,CHANNEL_DELETE:12,CHANNEL_OVERWRITE_CREATE:13,CHANNEL_OVERWRITE_UPDATE:14,CHANNEL_OVERWRITE_DELETE:15,MEMBER_KICK:20,MEMBER_PRUNE:21,MEMBER_BAN_ADD:22,MEMBER_BAN_REMOVE:23,MEMBER_UPDATE:24,MEMBER_ROLE_UPDATE:25,ROLE_CREATE:30,ROLE_UPDATE:31,ROLE_DELETE:32,INVITE_CREATE:40,INVITE_UPDATE:41,INVITE_DELETE:42,WEBHOOK_CREATE:50,WEBHOOK_UPDATE:51,WEBHOOK_DELETE:52,EMOJI_CREATE:60,EMOJI_UPDATE:61,EMOJI_DELETE:62,MESSAGE_DELETE:72};class GuildAuditLogs{constructor(e,t){if(t.users)for(const s of t.users)e.client.dataManager.newUser(s);if(this.webhooks=new i,t.webhooks)for(const s of t.webhooks)this.webhooks.set(s.id,new r(e.client,s));this.entries=new i;for(const s of t.audit_log_entries){const t=new GuildAuditLogsEntry(this,e,s);this.entries.set(t.id,t)}}static build(...e){const t=new GuildAuditLogs(...e);return Promise.all(t.entries.map(e=>e.target)).then(()=>t)}static targetType(e){return e<10?a.GUILD:e<20?a.CHANNEL:e<30?a.USER:e<40?a.ROLE:e<50?a.INVITE:e<60?a.WEBHOOK:e<70?a.EMOJI:e<80?a.MESSAGE:null}static actionType(e){return[h.CHANNEL_CREATE,h.CHANNEL_OVERWRITE_CREATE,h.MEMBER_BAN_REMOVE,h.ROLE_CREATE,h.INVITE_CREATE,h.WEBHOOK_CREATE,h.EMOJI_CREATE].includes(e)?"CREATE":[h.CHANNEL_DELETE,h.CHANNEL_OVERWRITE_DELETE,h.MEMBER_KICK,h.MEMBER_PRUNE,h.MEMBER_BAN_ADD,h.ROLE_DELETE,h.INVITE_DELETE,h.WEBHOOK_DELETE,h.EMOJI_DELETE,h.MESSAGE_DELETE].includes(e)?"DELETE":[h.GUILD_UPDATE,h.CHANNEL_UPDATE,h.CHANNEL_OVERWRITE_UPDATE,h.MEMBER_UPDATE,h.MEMBER_ROLE_UPDATE,h.ROLE_UPDATE,h.INVITE_UPDATE,h.WEBHOOK_UPDATE,h.EMOJI_UPDATE].includes(e)?"UPDATE":"ALL"}}class GuildAuditLogsEntry{constructor(e,t,s){const i=GuildAuditLogs.targetType(s.action_type);if(this.targetType=i,this.actionType=GuildAuditLogs.actionType(s.action_type),this.action=Object.keys(h).find(e=>h[e]===s.action_type),this.reason=s.reason||null,this.executor=t.client.users.get(s.user_id),this.changes=s.changes?s.changes.map(e=>({key:e.key,old:e.old_value,new:e.new_value})):null,this.id=s.id,this.extra=null,s.options)if(s.action_type===h.MEMBER_PRUNE)this.extra={removed:s.options.members_removed,days:s.options.delete_member_days};else if(s.action_type===h.MESSAGE_DELETE)this.extra={count:s.options.count,channel:t.channels.get(s.options.channel_id)};else switch(s.options.type){case"member":this.extra=t.members.get(s.options.id),this.extra||(this.extra={id:s.options.id});break;case"role":this.extra=t.roles.get(s.options.id),this.extra||(this.extra={id:s.options.id,name:s.options.role_name})}if([a.USER,a.GUILD].includes(i))this.target=t.client[`${i.toLowerCase()}s`].get(s.target_id);else if(i===a.WEBHOOK)this.target=e.webhooks.get(s.target_id)||new r(t.client,this.changes.reduce((e,t)=>(e[t.key]=t.new||t.old,e),{id:s.target_id,guild_id:t.id}));else if(i===a.INVITE){const e=this.changes.reduce((e,t)=>(e[t.key]=t.new||t.old,e),{id:s.target_id,guild:t});e.channel=t.channels.get(e.channel_id),this.target=new o(t.client,e)}else i===a.MESSAGE?this.target=t.client.users.get(s.target_id):this.target=t[`${i.toLowerCase()}s`].get(s.target_id)}get createdTimestamp(){return n.deconstruct(this.id).timestamp}get createdAt(){return new Date(this.createdTimestamp)}}GuildAuditLogs.Actions=h,GuildAuditLogs.Targets=a,GuildAuditLogs.Entry=GuildAuditLogsEntry,e.exports=GuildAuditLogs},function(e,t){e.exports=class RequestHandler{constructor(e){this.restManager=e,this.queue=[]}get globalLimit(){return this.restManager.globallyRateLimited}set globalLimit(e){this.restManager.globallyRateLimited=e}push(e){this.queue.push(e)}handle(){}destroy(){this.queue=[]}}},function(e,t,s){const i=s(18);e.exports=class CategoryChannel extends i{constructor(e,t){super(e,t),this.type="category"}get children(){return this.guild.channels.filter(e=>e.parentID===this.id)}}},function(e,t){e.exports=class PermissionOverwrites{constructor(e,t){Object.defineProperty(this,"channel",{value:e}),t&&this.setup(t)}setup(e){this.id=e.id,this.type=e.type,this.deny=e.deny,this.allow=e.allow}delete(e){return this.channel.client.rest.methods.deletePermissionOverwrites(this,e)}}},function(e,t,s){const i=s(11),n=s(14),r=s(3);class DMChannel extends i{constructor(e,t){super(e,t),this.type="dm",this.messages=new r,this._typing=new Map}setup(e){super.setup(e),this.recipient=this.client.dataManager.newUser(e.recipients[0]),this.lastMessageID=e.last_message_id}toString(){return this.recipient.toString()}send(){}sendMessage(){}sendEmbed(){}sendFile(){}sendFiles(){}sendCode(){}fetchMessage(){}fetchMessages(){}fetchPinnedMessages(){}search(){}startTyping(){}stopTyping(){}get typing(){}get typingCount(){}createCollector(){}createMessageCollector(){}awaitMessages(){}acknowledge(){}_cacheMessage(){}}n.applyToClass(DMChannel,!0,["bulkDelete"]),e.exports=DMChannel},function(e,t,s){const i=s(18),n=s(14),r=s(3);class TextChannel extends i{constructor(e,t){super(e,t),this.type="text",this.messages=new r,this._typing=new Map}setup(e){super.setup(e),this.topic=e.topic,this.nsfw=Boolean(e.nsfw),this.lastMessageID=e.last_message_id}get members(){const e=new r;for(const t of this.guild.members.values())this.permissionsFor(t).has("READ_MESSAGES")&&e.set(t.id,t);return e}fetchWebhooks(){return this.client.rest.methods.getChannelWebhooks(this)}createWebhook(e,t,s){return"string"==typeof t&&t.startsWith("data:")?this.client.rest.methods.createWebhook(this,e,t,s):this.client.resolver.resolveImage(t).then(t=>this.client.rest.methods.createWebhook(this,e,t,s))}send(){}sendMessage(){}sendEmbed(){}sendFile(){}sendFiles(){}sendCode(){}fetchMessage(){}fetchMessages(){}fetchPinnedMessages(){}search(){}startTyping(){}stopTyping(){}get typing(){}get typingCount(){}createCollector(){}createMessageCollector(){}awaitMessages(){}bulkDelete(){}acknowledge(){}_cacheMessage(){}}n.applyToClass(TextChannel,!0),e.exports=TextChannel},function(e,t,s){const i=s(18),n=s(3);e.exports=class VoiceChannel extends i{constructor(e,t){super(e,t),this.members=new n,this.type="voice"}setup(e){super.setup(e),this.bitrate=.001*e.bitrate,this.userLimit=e.user_limit}get connection(){const e=this.guild.voiceConnection;return e&&e.channel.id===this.id?e:null}get full(){return this.userLimit>0&&this.members.size>=this.userLimit}get joinable(){return!(this.client.browser||!this.permissionsFor(this.client.user).has("CONNECT")||this.full&&!this.permissionsFor(this.client.user).has("MOVE_MEMBERS"))}get speakable(){return this.permissionsFor(this.client.user).has("SPEAK")}setBitrate(e,t){return e*=1e3,this.edit({bitrate:e},t)}setUserLimit(e,t){return this.edit({userLimit:e},t)}join(){return this.client.browser?Promise.reject(new Error("Voice connections are not available in browsers.")):this.client.voice.joinChannel(this)}leave(){if(this.client.browser)return;const e=this.client.voice.connections.get(this.guild.id);e&&e.channel.id===this.id&&e.disconnect()}}},function(e,t,s){(function(t){const i="undefined"!=typeof window,n=s(19),r=s(0),o=s(41),a=s(83),h=function(){try{const e=s(122);return e.pack?e:null}catch(e){return null}}(),l=function(){if(i)return window.WebSocket;try{return s(123)}catch(e){return s(124)}}();class WebSocketConnection extends n{constructor(e,t){super(),this.manager=e,this.client=e.client,this.ws=null,this.sequence=-1,this.status=r.Status.IDLE,this.packetManager=new a(this),this.lastPingTimestamp=0,this.ratelimit={queue:[],remaining:120,total:120,time:6e4,resetTimer:null},this.connect(t),this.disabledEvents={},this.closeSequence=0,this.expectingClose=!1;for(const e of this.client.options.disabledEvents)this.disabledEvents[e]=!0}triggerReady(){this.status!==r.Status.READY?(this.status=r.Status.READY,this.client.emit(r.Events.READY),this.packetManager.handleQueue()):this.debug("Tried to mark self as ready, but already ready")}checkIfReady(){if(this.status===r.Status.READY||this.status===r.Status.NEARLY)return!1;let e=0;for(const t of this.client.guilds.values())t.available||e++;if(0===e){if(this.status=r.Status.NEARLY,!this.client.options.fetchAllMembers)return this.triggerReady();const e=this.client.guilds.map(e=>e.fetchMembers());Promise.all(e).then(()=>this.triggerReady()).catch(e=>{this.debug(`Failed to fetch all members before ready! ${e}`),this.triggerReady()})}return!0}debug(e){return e instanceof Error&&(e=e.stack),this.manager.debug(`[connection] ${e}`)}unpack(e){return e instanceof ArrayBuffer&&(e=t.from(new Uint8Array(e))),h&&"string"!=typeof e?h.unpack(e):(e instanceof t&&(e=o.inflateSync(e).toString()),JSON.parse(e))}pack(e){return h?h.pack(e):JSON.stringify(e)}processQueue(){if(0!==this.ratelimit.remaining&&0!==this.ratelimit.queue.length)for(120===this.ratelimit.remaining&&(this.ratelimit.resetTimer=this.client.setTimeout(()=>{this.ratelimit.remaining=60,this.processQueue()},this.ratelimit.time));this.ratelimit.remaining>0;){const e=this.ratelimit.queue.shift();if(!e)return;this._send(e),this.ratelimit.remaining--}}_send(e){this.ws&&this.ws.readyState===l.OPEN?this.ws.send(this.pack(e)):this.debug(`Tried to send packet ${e} but no WebSocket is available!`)}send(e){this.ws&&this.ws.readyState===l.OPEN?(this.ratelimit.queue.push(e),this.processQueue()):this.debug(`Tried to send packet ${e} but no WebSocket is available!`)}connect(e=this.gateway,t=0,s=!1){if(t)return this.client.setTimeout(()=>this.connect(e,0,s),t);if(this.ws&&!s)return this.debug("WebSocket connection already exists"),!1;if("string"!=typeof e)return this.debug(`Tried to connect to an invalid gateway: ${e}`),!1;this.expectingClose=!1,this.gateway=e,this.debug(`Connecting to ${e}`);const n=this.ws=new l(e);return i&&(n.binaryType="arraybuffer"),n.onmessage=this.onMessage.bind(this),n.onopen=this.onOpen.bind(this),n.onerror=this.onError.bind(this),n.onclose=this.onClose.bind(this),this.status=r.Status.CONNECTING,!0}destroy(){const e=this.ws;return e?(this.heartbeat(-1),this.expectingClose=!0,e.close(1e3),this.packetManager.handleQueue(),this.ws=null,this.status=r.Status.DISCONNECTED,!0):(this.debug("Attempted to destroy WebSocket but no connection exists!"),!1)}onMessage(e){let t;try{t=this.unpack(e.data)}catch(e){this.emit("debug",e)}return this.onPacket(t)}setSequence(e){this.sequence=e>this.sequence?e:this.sequence}onPacket(e){if(!e)return this.debug("Received null packet"),!1;switch(this.client.emit("raw",e),e.op){case r.OPCodes.HELLO:return this.heartbeat(e.d.heartbeat_interval);case r.OPCodes.RECONNECT:return this.reconnect();case r.OPCodes.INVALID_SESSION:return e.d||(this.sessionID=null),this.sequence=-1,this.debug("Session invalidated -- will identify with a new session"),this.identify(e.d?2500:0);case r.OPCodes.HEARTBEAT_ACK:return this.ackHeartbeat();case r.OPCodes.HEARTBEAT:return this.heartbeat();default:return this.packetManager.handle(e)}}onOpen(e){e&&e.target&&e.target.url&&(this.gateway=e.target.url),this.debug(`Connected to gateway ${this.gateway}`),this.identify()}reconnect(){this.debug("Attemping to reconnect in 5500ms..."),this.client.emit(r.Events.RECONNECTING),this.connect(this.gateway,5500,!0)}onError(e){e&&"uWs client connection error"===e.message?this.reconnect():this.client.emit(r.Events.ERROR,e)}onClose(e){if(this.debug(`${this.expectingClose?"Client":"Server"} closed the WebSocket connection: ${e.code}`),this.closeSequence=this.sequence,this.emit("close",e),this.heartbeat(-1),1e3===e.code?this.expectingClose:r.WSCodes[e.code])return this.expectingClose=!1,this.client.emit(r.Events.DISCONNECT,e),this.debug(r.WSCodes[e.code]),void this.destroy();this.expectingClose=!1,this.reconnect()}ackHeartbeat(){this.debug(`Heartbeat acknowledged, latency of ${Date.now()-this.lastPingTimestamp}ms`),this.client._pong(this.lastPingTimestamp)}heartbeat(e){isNaN(e)?(this.debug("Sending a heartbeat"),this.lastPingTimestamp=Date.now(),this.send({op:r.OPCodes.HEARTBEAT,d:this.sequence})):-1===e?(this.debug("Clearing heartbeat interval"),this.client.clearInterval(this.heartbeatInterval),this.heartbeatInterval=null):(this.debug(`Setting a heartbeat interval for ${e}ms`),this.heartbeatInterval=this.client.setInterval(()=>this.heartbeat(),e))}identify(e){return e?this.client.setTimeout(this.identify.bind(this),e):this.sessionID?this.identifyResume():this.identifyNew()}identifyNew(){if(!this.client.token)return void this.debug("No token available to identify a new session with");const e=Object.assign({token:this.client.token},this.client.options.ws),{shardId:t,shardCount:s}=this.client.options;s>0&&(e.shard=[Number(t),Number(s)]),this.debug("Identifying as a new session"),this.send({op:r.OPCodes.IDENTIFY,d:e})}identifyResume(){if(!this.sessionID)return this.debug("Warning: wanted to resume but session ID not available; identifying as a new session instead"),this.identifyNew();this.debug(`Attempting to resume session ${this.sessionID}`);const e={token:this.client.token,session_id:this.sessionID,seq:this.sequence};return this.send({op:r.OPCodes.RESUME,d:e})}}WebSocketConnection.ENCODING=h?"etf":"json",WebSocketConnection.WebSocket=l,e.exports=WebSocketConnection}).call(t,s(12).Buffer)},function(e,t,s){const i=s(9),n=s(3),r=s(56),o=s(57),a=s(0),h=s(7);class ClientUser extends i{setup(e){if(super.setup(e),this.verified=e.verified,this.email=e.email,this.localPresence={},this._typing=new Map,this.friends=new n,this.blocked=new n,this.notes=new n,this.premium="boolean"==typeof e.premium?e.premium:null,this.mfaEnabled="boolean"==typeof e.mfa_enabled?e.mfa_enabled:null,this.mobile="boolean"==typeof e.mobile?e.mobile:null,this.settings=e.user_settings?new r(this,e.user_settings):null,this.guildSettings=new n,e.user_guild_settings)for(const t of e.user_guild_settings)this.guildSettings.set(t.guild_id,new o(t,this.client))}edit(e){return this.client.rest.methods.updateCurrentUser(e)}setUsername(e,t){return this.client.rest.methods.updateCurrentUser({username:e},t)}setEmail(e,t){return this.client.rest.methods.updateCurrentUser({email:e},t)}setPassword(e,t){return this.client.rest.methods.updateCurrentUser({password:e},t)}setAvatar(e){return this.client.resolver.resolveImage(e).then(e=>this.client.rest.methods.updateCurrentUser({avatar:e}))}setPresence(e){return new Promise(t=>{let s=this.localPresence.status||this.presence.status,i=this.localPresence.game,n=this.localPresence.afk||this.presence.afk;if(!i&&this.presence.game&&(i={name:this.presence.game.name,type:this.presence.game.type,url:this.presence.game.url}),e.status){if("string"!=typeof e.status)throw new TypeError("Status must be a string");this.bot?s=e.status:(this.settings.update(a.UserSettingsMap.status,e.status),s="invisible")}e.game?((i=e.game).type=i.url&&void 0===i.type?1:i.type||0,"string"==typeof i.type&&(i.type=a.ActivityTypes.indexOf(i.type.toUpperCase()))):void 0!==e.game&&(i=null),void 0!==e.afk&&(n=e.afk),n=Boolean(n),this.localPresence={status:s,game:i,afk:n},this.localPresence.since=0,this.localPresence.game=this.localPresence.game||null,this.client.ws.send({op:3,d:this.localPresence}),this.client._setPresence(this.id,this.localPresence),t(this)})}setStatus(e){return this.setPresence({status:e})}setGame(e,t){return e?this.setPresence({game:{name:e,url:t}}):this.setPresence({game:null})}setActivity(e,{url:t,type:s}={}){return e?this.setPresence({game:{name:e,type:s,url:t}}):this.setPresence({game:null})}setAFK(e){return this.setPresence({afk:e})}fetchMentions(e={}){return this.client.rest.methods.fetchMentions(e)}addFriend(e){return e=this.client.resolver.resolveUser(e),this.client.rest.methods.addFriend(e)}removeFriend(e){return e=this.client.resolver.resolveUser(e),this.client.rest.methods.removeFriend(e)}createGuild(e,t,s=null){return"string"==typeof s&&s.startsWith("data:")?this.client.rest.methods.createGuild({name:e,icon:s,region:t}):this.client.resolver.resolveImage(s).then(s=>this.client.rest.methods.createGuild({name:e,icon:s,region:t}))}createGroupDM(e){return this.client.rest.methods.createGroupDM({recipients:e.map(e=>this.client.resolver.resolveUserID(e.user)),accessTokens:e.map(e=>e.accessToken),nicks:e.map(e=>e.nick)})}acceptInvite(e){return this.client.rest.methods.acceptInvite(e)}}ClientUser.prototype.setGame=h.deprecate(ClientUser.prototype.setGame,"ClientUser#setGame: use ClientUser#setActivity instead"),e.exports=ClientUser},function(e,t,s){const i=s(0),n=s(4);e.exports=class ClientUserSettings{constructor(e,t){this.user=e,this.patch(t)}patch(e){for(const t of Object.keys(i.UserSettingsMap)){const s=i.UserSettingsMap[t];e.hasOwnProperty(t)&&("function"==typeof s?this[s.name]=s(e[t]):this[s]=e[t])}}update(e,t){return this.user.client.rest.methods.patchUserSettings({[e]:t})}setGuildPosition(e,t,s){const i=Object.assign([],this.guildPositions);return n.moveElementInArray(i,e.id,t,s),this.update("guild_positions",i).then(()=>e)}addRestrictedGuild(e){const t=Object.assign([],this.restrictedGuilds);return t.includes(e.id)?Promise.reject(new Error("Guild is already restricted")):(t.push(e.id),this.update("restricted_guilds",t).then(()=>e))}removeRestrictedGuild(e){const t=Object.assign([],this.restrictedGuilds),s=t.indexOf(e.id);return s<0?Promise.reject(new Error("Guild is not restricted")):(t.splice(s,1),this.update("restricted_guilds",t).then(()=>e))}}},function(e,t,s){const i=s(0),n=s(3),r=s(85);e.exports=class ClientUserGuildSettings{constructor(e,t){Object.defineProperty(this,"client",{value:t}),this.guildID=e.guild_id,this.channelOverrides=new n,this.patch(e)}patch(e){for(const t of Object.keys(i.UserGuildSettingsMap)){const s=i.UserGuildSettingsMap[t];if(e.hasOwnProperty(t))if("channel_overrides"===t)for(const s of e[t])this.channelOverrides.set(s.channel_id,new r(s));else"function"==typeof s?this[s.name]=s(e[t]):this[s]=e[t]}}update(e,t){return this.client.rest.methods.patchClientUserGuildSettings(this.guildID,{[e]:t})}}},function(e,t,s){const i="undefined"!=typeof window,n=s(59);e.exports=n,i?window.Discord=n:i||console.warn("Warning: Attempting to use browser version of Discord.js in a non-browser environment!")},function(e,t,s){const i=s(4);e.exports={Client:s(70),Shard:s(158),ShardClientUtil:s(159),ShardingManager:s(160),WebhookClient:s(161),Collection:s(3),Constants:s(0),DiscordAPIError:s(33),EvaluatedPermissions:s(6),Permissions:s(6),Snowflake:s(5),SnowflakeUtil:s(5),Util:i,util:i,version:s(36).version,escapeMarkdown:i.escapeMarkdown,fetchRecommendedShards:i.fetchRecommendedShards,splitMessage:i.splitMessage,Attachment:s(21),CategoryChannel:s(49),Channel:s(11),ClientUser:s(55),ClientUserSettings:s(56),Collector:s(29),DMChannel:s(51),Emoji:s(16),Game:s(10).Game,GroupDMChannel:s(32),Guild:s(22),GuildAuditLogs:s(47),GuildChannel:s(18),GuildMember:s(17),Invite:s(30),Message:s(15),MessageAttachment:s(39),MessageCollector:s(44),MessageEmbed:s(40),MessageMentions:s(38),MessageReaction:s(42),OAuth2Application:s(31),ClientOAuth2Application:s(31),PartialGuild:s(45),PartialGuildChannel:s(46),PermissionOverwrites:s(50),Presence:s(10).Presence,ReactionEmoji:s(28),ReactionCollector:s(43),RichEmbed:s(20),Role:s(8),TextChannel:s(52),User:s(9),VoiceChannel:s(53),Webhook:s(23)}},function(e,t,s){"use strict";t.byteLength=function(e){return 3*e.length/4-l(e)},t.toByteArray=function(e){var t,s,i,o,a,h=e.length;o=l(e),a=new r(3*h/4-o),s=o>0?h-4:h;var c=0;for(t=0;t>16&255,a[c++]=i>>8&255,a[c++]=255&i;2===o?(i=n[e.charCodeAt(t)]<<2|n[e.charCodeAt(t+1)]>>4,a[c++]=255&i):1===o&&(i=n[e.charCodeAt(t)]<<10|n[e.charCodeAt(t+1)]<<4|n[e.charCodeAt(t+2)]>>2,a[c++]=i>>8&255,a[c++]=255&i);return a},t.fromByteArray=function(e){for(var t,s=e.length,n=s%3,r="",o=[],a=0,h=s-n;ah?h:a+16383));1===n?(t=e[s-1],r+=i[t>>2],r+=i[t<<4&63],r+="=="):2===n&&(t=(e[s-2]<<8)+e[s-1],r+=i[t>>10],r+=i[t>>4&63],r+=i[t<<2&63],r+="=");return o.push(r),o.join("")};for(var i=[],n=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,h=o.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function c(e,t,s){for(var n,r,o=[],a=t;a>18&63]+i[r>>12&63]+i[r>>6&63]+i[63&r]);return o.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,s,i,n){var r,o,a=8*n-i-1,h=(1<>1,c=-7,u=s?n-1:0,d=s?-1:1,m=e[t+u];for(u+=d,r=m&(1<<-c)-1,m>>=-c,c+=a;c>0;r=256*r+e[t+u],u+=d,c-=8);for(o=r&(1<<-c)-1,r>>=-c,c+=i;c>0;o=256*o+e[t+u],u+=d,c-=8);if(0===r)r=1-l;else{if(r===h)return o?NaN:1/0*(m?-1:1);o+=Math.pow(2,i),r-=l}return(m?-1:1)*o*Math.pow(2,r-i)},t.write=function(e,t,s,i,n,r){var o,a,h,l=8*r-n-1,c=(1<>1,d=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,m=i?0:r-1,g=i?1:-1,p=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),(t+=o+u>=1?d/h:d*Math.pow(2,1-u))*h>=2&&(o++,h/=2),o+u>=c?(a=0,o=c):o+u>=1?(a=(t*h-1)*Math.pow(2,n),o+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,n),o=0));n>=8;e[s+m]=255&a,m+=g,a/=256,n-=8);for(o=o<0;e[s+m]=255&o,m+=g,o/=256,l-=8);e[s+m-g]|=128*p}},function(e,t){var s={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==s.call(e)}},function(e,t,s){e.exports=s(64)},function(e,t,s){const i="undefined"!=typeof window,n=s(35),r=s(i?67:68);class Snekfetch extends r.Extension{constructor(e,t,s={}){super(),this.options=Object.assign({version:1,qs:n,followRedirects:!0},s),this.request=r.buildRequest.call(this,e,t,s),s.headers&&this.set(s.headers),s.query&&this.query(s.query),s.data&&this.send(s.data)}query(e,t){if(this.request.query||(this.request.query={}),null!==e&&"object"==typeof e)for(const[t,s]of Object.entries(e))this.query(t,s);else this.request.query[e]=t;return this}set(e,t){if(null!==e&&"object"==typeof e)for(const t of Object.keys(e))this.set(t,e[t]);else this.request.setHeader(e,t);return this}attach(...e){const t=this.data instanceof r.FormData?this.data:this.data=new r.FormData;if("object"==typeof e[0])for(const[t,s]of Object.entries(e[0]))this.attach(t,s);else t.append(...e);return this}send(e){if(e instanceof r.FormData||r.shouldSendRaw(e))this.data=e;else if(null!==e&&"object"==typeof e){const t=this.request.getHeader("content-type");let s;t?t.includes("json")?s=JSON.stringify:t.includes("urlencoded")&&(s=this.options.qs.stringify):(this.set("Content-Type","application/json"),s=JSON.stringify),this.data=s(e)}else this.data=e;return this}then(e,t){return this._response?this._response.then(e,t):this._response=r.finalizeRequest.call(this).then(({response:e,raw:t,redirect:s,headers:i})=>{if(s){let t=this.request.method;[301,302].includes(e.statusCode)?("HEAD"!==t&&(t="GET"),this.data=null):303===e.statusCode&&(t="GET");const i=this.request.getHeaders();return delete i.host,new Snekfetch(t,s,{data:this.data,headers:i,version:this.options.version})}const n=e.statusCode||e.status,o=this,a={request:this.request,get body(){delete a.body;const e=this.headers["content-type"];if(e&&e.includes("application/json"))try{a.body=JSON.parse(a.text)}catch(e){a.body=a.text}else e&&e.includes("application/x-www-form-urlencoded")?a.body=o.options.qs.parse(a.text):a.body=t;return a.body},text:t.toString(),ok:n>=200&&n<400,headers:i||e.headers,status:n,statusText:e.statusText||r.STATUS_CODES[e.statusCode]};if(a.ok)return a;{const e=new Error(`${a.status} ${a.statusText}`.trim());return Object.assign(e,a),Promise.reject(e)}}).then(e,t)}catch(e){return this.then(null,e)}end(e){return this.then(t=>e?e(null,t):t,t=>e?e(t,t.status?t:null):Promise.reject(t))}_finalizeRequest(){if(this.request&&("HEAD"!==this.request.method&&this.set("Accept-Encoding","gzip, deflate"),this.data&&this.data.getBoundary&&this.set("Content-Type",`multipart/form-data; boundary=${this.data.getBoundary()}`),this.request.query)){const[e,t]=this.request.path.split("?");this.request.path=`${e}?${this.options.qs.stringify(this.request.query)}${t?`&${t}`:""}`}}}Snekfetch.METHODS=r.METHODS.concat("BREW").filter(e=>"M-SEARCH"!==e);for(const e of Snekfetch.METHODS)Snekfetch[e.toLowerCase()]=function(t,s){return new(this.prototype instanceof Snekfetch?this:Snekfetch)(e,t,s)};e.exports=Snekfetch},function(e,t,s){"use strict";function i(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,s,r){t=t||"&",s=s||"=";var o={};if("string"!=typeof e||0===e.length)return o;var a=/\+/g;e=e.split(t);var h=1e3;r&&"number"==typeof r.maxKeys&&(h=r.maxKeys);var l=e.length;h>0&&l>h&&(l=h);for(var c=0;c=0?(u=p.substr(0,f),d=p.substr(f+1)):(u=p,d=""),m=decodeURIComponent(u),g=decodeURIComponent(d),i(o,m)?n(o[m])?o[m].push(g):o[m]=[o[m],g]:o[m]=g}return o};var n=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,s){"use strict";var i=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,s,a){return t=t||"&",s=s||"=",null===e&&(e=void 0),"object"==typeof e?r(o(e),function(o){var a=encodeURIComponent(i(o))+s;return n(e[o])?r(e[o],function(e){return a+encodeURIComponent(i(e))}).join(t):a+encodeURIComponent(i(e[o]))}).join(t):a?encodeURIComponent(i(a))+s+encodeURIComponent(i(e)):""};var n=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function r(e,t){if(e.map)return e.map(t);for(var s=[],i=0;ie.text().then(t=>{const s={};for(const[t,i]of e.headers.entries())s[t.toLowerCase()]=i;return{response:e,raw:t,headers:s}}))},shouldSendRaw:()=>!1,METHODS:["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","PATCH"],STATUS_CODES:{},Extension:Object,FormData:window.FormData}},function(e,t){},function(e,t){t.endianness=function(){return"LE"},t.hostname=function(){return"undefined"!=typeof location?location.hostname:""},t.loadavg=function(){return[]},t.uptime=function(){return 0},t.freemem=function(){return Number.MAX_VALUE},t.totalmem=function(){return Number.MAX_VALUE},t.cpus=function(){return[]},t.type=function(){return"Browser"},t.release=function(){return"undefined"!=typeof navigator?navigator.appVersion:""},t.networkInterfaces=t.getNetworkInterfaces=function(){return{}},t.arch=function(){return"javascript"},t.platform=function(){return"browser"},t.tmpdir=t.tmpDir=function(){return"/tmp"},t.EOL="\n",t.homedir=function(){return"/"}},function(module,exports,__webpack_require__){(function(process){const EventEmitter=__webpack_require__(19),Constants=__webpack_require__(0),Permissions=__webpack_require__(6),Util=__webpack_require__(4),RESTManager=__webpack_require__(37),ClientDataManager=__webpack_require__(81),ClientManager=__webpack_require__(82),ClientDataResolver=__webpack_require__(27),ClientVoiceManager=__webpack_require__(125),WebSocketManager=__webpack_require__(126),ActionsManager=__webpack_require__(127),Collection=__webpack_require__(3),Presence=__webpack_require__(10).Presence,ShardClientUtil=__webpack_require__(156),VoiceBroadcast=__webpack_require__(157);class Client extends EventEmitter{constructor(e={}){super(),!e.shardId&&"SHARD_ID"in Object({__DISCORD_WEBPACK__:"true"})&&(e.shardId=Number(Object({__DISCORD_WEBPACK__:"true"}).SHARD_ID)),!e.shardCount&&"SHARD_COUNT"in Object({__DISCORD_WEBPACK__:"true"})&&(e.shardCount=Number(Object({__DISCORD_WEBPACK__:"true"}).SHARD_COUNT)),this.options=Util.mergeDefault(Constants.DefaultOptions,e),this._validateOptions(),this.rest=new RESTManager(this),this.dataManager=new ClientDataManager(this),this.manager=new ClientManager(this),this.ws=new WebSocketManager(this),this.resolver=new ClientDataResolver(this),this.actions=new ActionsManager(this),this.voice=this.browser?null:new ClientVoiceManager(this),this.shard=process.send?ShardClientUtil.singleton(this):null,this.users=new Collection,this.guilds=new Collection,this.channels=new Collection,this.presences=new Collection,Object.defineProperty(this,"token",{writable:!0}),!this.token&&"CLIENT_TOKEN"in Object({__DISCORD_WEBPACK__:"true"})?this.token=Object({__DISCORD_WEBPACK__:"true"}).CLIENT_TOKEN:this.token=null,this.user=null,this.readyAt=null,this.broadcasts=[],this.pings=[],this._timeouts=new Set,this._intervals=new Set,this.options.messageSweepInterval>0&&this.setInterval(this.sweepMessages.bind(this),1e3*this.options.messageSweepInterval)}get _pingTimestamp(){return this.ws.connection?this.ws.connection.lastPingTimestamp:0}get status(){return this.ws.connection.status}get uptime(){return this.readyAt?Date.now()-this.readyAt:null}get ping(){return this.pings.reduce((e,t)=>e+t,0)/this.pings.length}get voiceConnections(){return this.browser?new Collection:this.voice.connections}get emojis(){const e=new Collection;for(const t of this.guilds.values())for(const s of t.emojis.values())e.set(s.id,s);return e}get readyTimestamp(){return this.readyAt?this.readyAt.getTime():null}get browser(){return"undefined"!=typeof window}createVoiceBroadcast(){const e=new VoiceBroadcast(this);return this.broadcasts.push(e),e}login(e){return this.rest.methods.login(e)}destroy(){for(const e of this._timeouts)clearTimeout(e);for(const e of this._intervals)clearInterval(e);return this._timeouts.clear(),this._intervals.clear(),this.manager.destroy()}syncGuilds(e=this.guilds){this.user.bot||this.ws.send({op:12,d:e instanceof Collection?e.keyArray():e.map(e=>e.id)})}fetchUser(e,t=!0){return this.users.has(e)?Promise.resolve(this.users.get(e)):this.rest.methods.getUser(e,t)}fetchInvite(e){const t=this.resolver.resolveInviteCode(e);return this.rest.methods.getInvite(t)}fetchWebhook(e,t){return this.rest.methods.getWebhook(e,t)}fetchVoiceRegions(){return this.rest.methods.fetchVoiceRegions()}sweepMessages(e=this.options.messageCacheLifetime){if("number"!=typeof e||isNaN(e))throw new TypeError("The lifetime must be a number.");if(e<=0)return this.emit("debug","Didn't sweep messages - lifetime is unlimited"),-1;const t=1e3*e,s=Date.now();let i=0,n=0;for(const e of this.channels.values())if(e.messages){i++;for(const i of e.messages.values())s-(i.editedTimestamp||i.createdTimestamp)>t&&(e.messages.delete(i.id),n++)}return this.emit("debug",`Swept ${n} messages older than ${e} seconds in ${i} text-based channels`),n}fetchApplication(e="@me"){return this.rest.methods.getApplication(e)}generateInvite(e){return e?e instanceof Array&&(e=Permissions.resolve(e)):e=0,this.fetchApplication().then(t=>`https://discordapp.com/oauth2/authorize?client_id=${t.id}&permissions=${e}&scope=bot`)}setTimeout(e,t,...s){const i=setTimeout(()=>{e(...s),this._timeouts.delete(i)},t);return this._timeouts.add(i),i}clearTimeout(e){clearTimeout(e),this._timeouts.delete(e)}setInterval(e,t,...s){const i=setInterval(e,t,...s);return this._intervals.add(i),i}clearInterval(e){clearInterval(e),this._intervals.delete(e)}_pong(e){this.pings.unshift(Date.now()-e),this.pings.length>3&&(this.pings.length=3),this.ws.lastHeartbeatAck=!0}_setPresence(e,t){this.presences.has(e)?this.presences.get(e).update(t):this.presences.set(e,new Presence(t))}_eval(script){return eval(script)}_validateOptions(e=this.options){if("number"!=typeof e.shardCount||isNaN(e.shardCount))throw new TypeError("The shardCount option must be a number.");if("number"!=typeof e.shardId||isNaN(e.shardId))throw new TypeError("The shardId option must be a number.");if(e.shardCount<0)throw new RangeError("The shardCount option must be at least 0.");if(e.shardId<0)throw new RangeError("The shardId option must be at least 0.");if(0!==e.shardId&&e.shardId>=e.shardCount)throw new RangeError("The shardId option must be less than shardCount.");if("number"!=typeof e.messageCacheMaxSize||isNaN(e.messageCacheMaxSize))throw new TypeError("The messageCacheMaxSize option must be a number.");if("number"!=typeof e.messageCacheLifetime||isNaN(e.messageCacheLifetime))throw new TypeError("The messageCacheLifetime option must be a number.");if("number"!=typeof e.messageSweepInterval||isNaN(e.messageSweepInterval))throw new TypeError("The messageSweepInterval option must be a number.");if("boolean"!=typeof e.fetchAllMembers)throw new TypeError("The fetchAllMembers option must be a boolean.");if("boolean"!=typeof e.disableEveryone)throw new TypeError("The disableEveryone option must be a boolean.");if("number"!=typeof e.restWsBridgeTimeout||isNaN(e.restWsBridgeTimeout))throw new TypeError("The restWsBridgeTimeout option must be a number.");if(!(e.disabledEvents instanceof Array))throw new TypeError("The disabledEvents option must be an Array.")}}module.exports=Client}).call(exports,__webpack_require__(13))},function(e,t){e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var s=function(){};s.prototype=t.prototype,e.prototype=new s,e.prototype.constructor=e}},function(e,t,s){(function(t){const i=s(0);class UserAgentManager{constructor(){this.build(this.constructor.DEFAULT)}set({url:e,version:t}={}){this.build({url:e||this.constructor.DFEAULT.url,version:t||this.constructor.DEFAULT.version})}build(e){this.userAgent=`DiscordBot (${e.url}, ${e.version}) Node.js/${t.version}`}}UserAgentManager.DEFAULT={url:i.Package.homepage.split("#")[0],version:i.Package.version},e.exports=UserAgentManager}).call(t,s(13))},function(e,t,s){const i=s(35),n=s(25),r=s(6),o=s(0),a=o.Endpoints,h=s(3),l=s(4),c=s(9),u=s(17),d=s(15),m=s(8),g=s(30),p=s(23),f=s(75),E=s(31),_=s(11),v=s(32),b=s(22),y=s(77),w=s(47);e.exports=class RESTMethods{constructor(e){this.rest=e,this.client=e.client,this._ackToken=null}login(e=this.client.token){return new Promise((t,s)=>{if("string"!=typeof e)throw new Error(o.Errors.INVALID_TOKEN);e=e.replace(/^Bot\s*/i,""),this.client.manager.connectToWebSocket(e,t,s)})}logout(){return this.rest.makeRequest("post",a.logout,!0,{})}getGateway(e=!1){return this.rest.makeRequest("get",e?a.gateway.bot:a.gateway,!0)}fetchVoiceRegions(e){let t;return t=e?a.Guild(e).voiceRegions:a.voiceRegions,this.rest.makeRequest("get",t,!0).then(e=>{const t=new h;for(const s of e)t.set(s.id,new y(s));return t})}sendMessage(e,t,{tts:s,nonce:i,embed:n,disableEveryone:r,split:o,code:h,reply:d}={},m=null){return new Promise((g,p)=>{if(void 0!==t&&(t=this.client.resolver.resolveString(t)),void 0!==i&&(i=parseInt(i),isNaN(i)||i<0))throw new RangeError("Message nonce must fit in an unsigned 64-bit integer.");if(t){if(o&&"object"!=typeof o&&(o={}),void 0===h||"boolean"==typeof h&&!0!==h||(t=l.escapeMarkdown(this.client.resolver.resolveString(t),!0),t=`\`\`\`${"boolean"!=typeof h&&h||""}\n${t}\n\`\`\``,o&&(o.prepend=`\`\`\`${"boolean"!=typeof h&&h||""}\n`,o.append="\n```")),(r||void 0===r&&this.client.options.disableEveryone)&&(t=t.replace(/@(everyone|here)/g,"@​$1")),d&&!(e instanceof c||e instanceof u)&&"dm"!==e.type){const e=this.client.resolver.resolveUserID(d),s=`<@${d instanceof u&&d.nickname?"!":""}${e}>`;t=`${s}${t?`, ${t}`:""}`,o&&(o.prepend=`${s}, ${o.prepend||""}`)}o&&(t=l.splitMessage(t,o))}else if(d&&!(e instanceof c||e instanceof u)&&"dm"!==e.type){const e=this.client.resolver.resolveUserID(d);t=`<@${d instanceof u&&d.nickname?"!":""}${e}>`}const f=e=>{if(t instanceof Array){const i=[];!function t(r,o){const a=o===r.length-1?{tts:s,embed:n,files:m}:{tts:s};e.send(r[o],a).then(e=>(i.push(e),o>=r.length-1?g(i):t(r,++o))).catch(p)}(t,0)}else this.rest.makeRequest("post",a.Channel(e).messages,!0,{content:t,tts:s,nonce:i,embed:n},m).then(e=>g(this.client.actions.MessageCreate.handle(e).message),p)};e instanceof c||e instanceof u?this.createDM(e).then(f,p):f(e)})}updateMessage(e,t,{embed:s,code:i,reply:n}={}){if(void 0!==t&&(t=this.client.resolver.resolveString(t)),void 0===i||"boolean"==typeof i&&!0!==i||(t=l.escapeMarkdown(this.client.resolver.resolveString(t),!0),t=`\`\`\`${"boolean"!=typeof i&&i||""}\n${t}\n\`\`\``),n&&"dm"!==e.channel.type){const e=this.client.resolver.resolveUserID(n);t=`${`<@${n instanceof u&&n.nickname?"!":""}${e}>`}${t?`, ${t}`:""}`}return this.rest.makeRequest("patch",a.Message(e),!0,{content:t,embed:s}).then(e=>this.client.actions.MessageUpdate.handle(e).updated)}deleteMessage(e){return this.rest.makeRequest("delete",a.Message(e),!0).then(()=>this.client.actions.MessageDelete.handle({id:e.id,channel_id:e.channel.id}).message)}ackMessage(e){return this.rest.makeRequest("post",a.Message(e).ack,!0,{token:this._ackToken}).then(t=>(t.token&&(this._ackToken=t.token),e))}ackTextChannel(e){return this.rest.makeRequest("post",a.Channel(e).Message(e.lastMessageID).ack,!0,{token:this._ackToken}).then(t=>(t.token&&(this._ackToken=t.token),e))}ackGuild(e){return this.rest.makeRequest("post",a.Guild(e).ack,!0).then(()=>e)}bulkDeleteMessages(e,t){return this.rest.makeRequest("post",a.Channel(e).messages.bulkDelete,!0,{messages:t.map(e=>e.id)}).then(()=>this.client.actions.MessageDeleteBulk.handle({channel_id:e.id,messages:t}).messages)}search(e,t){if("string"==typeof t&&(t={content:t}),t.before&&(t.before instanceof Date||(t.before=new Date(t.before)),t.maxID=n.fromNumber(t.before.getTime()-14200704e5).shiftLeft(22).toString()),t.after&&(t.after instanceof Date||(t.after=new Date(t.after)),t.minID=n.fromNumber(t.after.getTime()-14200704e5).shiftLeft(22).toString()),t.during){t.during instanceof Date||(t.during=new Date(t.during));const e=t.during.getTime()-14200704e5;t.minID=n.fromNumber(e).shiftLeft(22).toString(),t.maxID=n.fromNumber(e+864e5).shiftLeft(22).toString()}t.channel&&(t.channel=this.client.resolver.resolveChannelID(t.channel)),t.author&&(t.author=this.client.resolver.resolveUserID(t.author)),t.mentions&&(t.mentions=this.client.resolver.resolveUserID(t.options.mentions)),t={content:t.content,max_id:t.maxID,min_id:t.minID,has:t.has,channel_id:t.channel,author_id:t.author,author_type:t.authorType,context_size:t.contextSize,sort_by:t.sortBy,sort_order:t.sortOrder,limit:t.limit,offset:t.offset,mentions:t.mentions,mentions_everyone:t.mentionsEveryone,link_hostname:t.linkHostname,embed_provider:t.embedProvider,embed_type:t.embedType,attachment_filename:t.attachmentFilename,attachment_extension:t.attachmentExtension,include_nsfw:t.nsfw};for(const e in t)void 0===t[e]&&delete t[e];const s=(i.stringify(t).match(/[^=&?]+=[^=&?]+/g)||[]).join("&");let r;if(e instanceof _)r=a.Channel(e).search;else{if(!(e instanceof b))throw new TypeError("Target must be a TextChannel, DMChannel, GroupDMChannel, or Guild.");r=a.Guild(e).search}return this.rest.makeRequest("get",`${r}?${s}`,!0).then(e=>{const t=e.messages.map(e=>e.map(e=>new d(this.client.channels.get(e.channel_id),e,this.client)));return{totalResults:e.total_results,messages:t}})}createChannel(e,t,s,i,n){return(i instanceof h||i instanceof Array)&&(i=i.map(t=>{let s=t.allow||t._allowed,i=t.deny||t._denied;s instanceof Array&&(s=r.resolve(s)),i instanceof Array&&(i=r.resolve(i));const n=this.client.resolver.resolveRole(e,t.id);return n?(t.id=n.id,t.type="role"):(t.id=this.client.resolver.resolveUserID(t.id),t.type="member"),{allow:s,deny:i,type:t.type,id:t.id}})),this.rest.makeRequest("post",a.Guild(e).channels,!0,{name:t,type:s?o.ChannelTypes[s.toUpperCase()]:"text",permission_overwrites:i},void 0,n).then(e=>this.client.actions.ChannelCreate.handle(e).channel)}createDM(e){const t=this.getExistingDM(e);return t?Promise.resolve(t):this.rest.makeRequest("post",a.User(this.client.user).channels,!0,{recipient_id:e.id}).then(e=>this.client.actions.ChannelCreate.handle(e).channel)}createGroupDM(e){const t=this.client.user.bot?{access_tokens:e.accessTokens,nicks:e.nicks}:{recipients:e.recipients};return this.rest.makeRequest("post",a.User("@me").channels,!0,t).then(e=>new v(this.client,e))}addUserToGroupDM(e,t){const s=this.client.user.bot?{nick:t.nick,access_token:t.accessToken}:{recipient:t.id};return this.rest.makeRequest("put",a.Channel(e).Recipient(t.id),!0,s).then(()=>e)}removeUserFromGroupDM(e,t){return this.rest.makeRequest("delete",a.Channel(e).Recipient(t),!0).then(()=>e)}updateGroupDMChannel(e,t){const s={};return s.name=t.name,s.icon=t.icon,this.rest.makeRequest("patch",a.Channel(e),!0,s).then(()=>e)}getExistingDM(e){return this.client.channels.find(t=>t.recipient&&t.recipient.id===e.id)}deleteChannel(e,t){return(e instanceof c||e instanceof u)&&(e=this.getExistingDM(e)),e?this.rest.makeRequest("delete",a.Channel(e),!0,void 0,void 0,t).then(t=>(t.id=e.id,this.client.actions.ChannelDelete.handle(t).channel)):Promise.reject(new Error("No channel to delete."))}updateChannel(e,t,s){const i={};return i.name=(t.name||e.name).trim(),i.topic=t.topic||e.topic,i.position=t.position||e.position,i.bitrate=t.bitrate||(e.bitrate?1e3*e.bitrate:void 0),i.user_limit=void 0!==t.userLimit?t.userLimit:e.userLimit,i.parent_id=t.parent||(e.parent?e.parent.id:void 0),this.rest.makeRequest("patch",a.Channel(e),!0,i,void 0,s).then(e=>this.client.actions.ChannelUpdate.handle(e).updated)}leaveGuild(e){return e.ownerID===this.client.user.id?Promise.reject(new Error("Guild is owned by the client.")):this.rest.makeRequest("delete",a.User("@me").Guild(e.id),!0).then(()=>this.client.actions.GuildDelete.handle({id:e.id}).guild)}createGuild(e){return e.icon=this.client.resolver.resolveBase64(e.icon)||null,e.region=e.region||"us-central",new Promise((t,s)=>{this.rest.makeRequest("post",a.guilds,!0,e).then(e=>{if(this.client.guilds.has(e.id))return t(this.client.guilds.get(e.id));const i=s=>{s.id===e.id&&(this.client.removeListener(o.Events.GUILD_CREATE,i),this.client.clearTimeout(n),t(s))};this.client.on(o.Events.GUILD_CREATE,i);const n=this.client.setTimeout(()=>{this.client.removeListener(o.Events.GUILD_CREATE,i),s(new Error("Took too long to receive guild data."))},1e4)},s)})}deleteGuild(e){return this.rest.makeRequest("delete",a.Guild(e),!0).then(()=>this.client.actions.GuildDelete.handle({id:e.id}).guild)}getUser(e,t){return this.rest.makeRequest("get",a.User(e),!0).then(e=>t?this.client.actions.UserGet.handle(e).user:new c(this.client,e))}updateCurrentUser(e,t){const s=this.client.user,i={};return i.username=e.username||s.username,i.avatar=void 0===e.avatar?s.avatar:this.client.resolver.resolveBase64(e.avatar),s.bot||(i.email=e.email||s.email,i.password=t,e.new_password&&(i.new_password=e.newPassword)),this.rest.makeRequest("patch",a.User("@me"),!0,i).then(e=>this.client.actions.UserUpdate.handle(e).updated)}updateGuild(e,t,s){return this.rest.makeRequest("patch",a.Guild(e),!0,t,void 0,s).then(e=>this.client.actions.GuildUpdate.handle(e).updated)}kickGuildMember(e,t,s){return this.rest.makeRequest("delete",a.Guild(e).Member(t),!0,void 0,void 0,s).then(()=>this.client.actions.GuildMemberRemove.handle({guild_id:e.id,user:t.user}).member)}createGuildRole(e,t,s){return t.color&&(t.color=this.client.resolver.resolveColor(t.color)),t.permissions&&(t.permissions=r.resolve(t.permissions)),this.rest.makeRequest("post",a.Guild(e).roles,!0,t,void 0,s).then(i=>{const{role:n}=this.client.actions.GuildRoleCreate.handle({guild_id:e.id,role:i});return t.position?n.setPosition(t.position,s):n})}deleteGuildRole(e,t){return this.rest.makeRequest("delete",a.Guild(e.guild).Role(e.id),!0,void 0,void 0,t).then(()=>this.client.actions.GuildRoleDelete.handle({guild_id:e.guild.id,role_id:e.id}).role)}setChannelOverwrite(e,t){return this.rest.makeRequest("put",`${a.Channel(e).permissions}/${t.id}`,!0,t)}deletePermissionOverwrites(e,t){return this.rest.makeRequest("delete",`${a.Channel(e.channel).permissions}/${e.id}`,!0,void 0,void 0,t).then(()=>e)}getChannelMessages(e,t={}){const s=[];t.limit&&s.push(`limit=${t.limit}`),t.around?s.push(`around=${t.around}`):t.before?s.push(`before=${t.before}`):t.after&&s.push(`after=${t.after}`);let i=a.Channel(e).messages;return s.length>0&&(i+=`?${s.join("&")}`),this.rest.makeRequest("get",i,!0)}getChannelMessage(e,t){const s=e.messages.get(t);return s?Promise.resolve(s):this.rest.makeRequest("get",a.Channel(e).Message(t),!0)}putGuildMember(e,t,s){if(s.access_token=s.accessToken,s.roles){const e=s.roles;(e instanceof h||e instanceof Array&&e[0]instanceof m)&&(s.roles=e.map(e=>e.id))}return this.rest.makeRequest("put",a.Guild(e).Member(t.id),!0,s).then(t=>this.client.actions.GuildMemberGet.handle(e,t).member)}getGuildMember(e,t,s){return this.rest.makeRequest("get",a.Guild(e).Member(t.id),!0).then(t=>s?this.client.actions.GuildMemberGet.handle(e,t).member:new u(e,t))}updateGuildMember(e,t,s){t.channel&&(t.channel_id=this.client.resolver.resolveChannel(t.channel).id,t.channel=null),t.roles&&(t.roles=t.roles.map(e=>e instanceof m?e.id:e));let i=a.Member(e);if(e.id===this.client.user.id){const s=Object.keys(t);1===s.length&&"nick"===s[0]&&(i=a.Member(e).nickname)}return this.rest.makeRequest("patch",i,!0,t,void 0,s).then(t=>e.guild._updateMember(e,t).mem)}addMemberRole(e,t,s){return new Promise((i,n)=>{if(e._roles.includes(t.id))return i(e);const r=(e,s)=>{!e._roles.includes(t.id)&&s._roles.includes(t.id)&&(this.client.removeListener(o.Events.GUILD_MEMBER_UPDATE,r),i(s))};this.client.on(o.Events.GUILD_MEMBER_UPDATE,r);const h=this.client.setTimeout(()=>this.client.removeListener(o.Events.GUILD_MEMBER_UPDATE,r),1e4);return this.rest.makeRequest("put",a.Member(e).Role(t.id),!0,void 0,void 0,s).catch(e=>{this.client.removeListener(o.Events.GUILD_BAN_REMOVE,r),this.client.clearTimeout(h),n(e)})})}removeMemberRole(e,t,s){return new Promise((i,n)=>{if(!e._roles.includes(t.id))return i(e);const r=(e,s)=>{e._roles.includes(t.id)&&!s._roles.includes(t.id)&&(this.client.removeListener(o.Events.GUILD_MEMBER_UPDATE,r),i(s))};this.client.on(o.Events.GUILD_MEMBER_UPDATE,r);const h=this.client.setTimeout(()=>this.client.removeListener(o.Events.GUILD_MEMBER_UPDATE,r),1e4);return this.rest.makeRequest("delete",a.Member(e).Role(t.id),!0,void 0,void 0,s).catch(e=>{this.client.removeListener(o.Events.GUILD_BAN_REMOVE,r),this.client.clearTimeout(h),n(e)})})}sendTyping(e){return this.rest.makeRequest("post",a.Channel(e).typing,!0)}banGuildMember(e,t,s){const n=this.client.resolver.resolveUserID(t);if(!n)return Promise.reject(new Error("Couldn't resolve the user ID to ban."));const r=`${a.Guild(e).bans}/${n}?${i.stringify(s)}`;return this.rest.makeRequest("put",r,!0).then(()=>{if(t instanceof u)return t;const s=this.client.resolver.resolveUser(n);return s?(t=this.client.resolver.resolveGuildMember(e,s))||s:n})}unbanGuildMember(e,t,s){return new Promise((i,n)=>{const r=this.client.resolver.resolveUserID(t);if(!r)throw new Error("Couldn't resolve the user ID to unban.");const h=(t,s)=>{t.id===e.id&&s.id===r&&(this.client.removeListener(o.Events.GUILD_BAN_REMOVE,h),this.client.clearTimeout(l),i(s))};this.client.on(o.Events.GUILD_BAN_REMOVE,h);const l=this.client.setTimeout(()=>{this.client.removeListener(o.Events.GUILD_BAN_REMOVE,h),n(new Error("Took too long to receive the ban remove event."))},1e4);this.rest.makeRequest("delete",`${a.Guild(e).bans}/${r}`,!0,void 0,void 0,s).catch(e=>{this.client.removeListener(o.Events.GUILD_BAN_REMOVE,h),this.client.clearTimeout(l),n(e)})})}getGuildBans(e){return this.rest.makeRequest("get",a.Guild(e).bans,!0).then(e=>e.reduce((e,t)=>(e.set(t.user.id,{reason:t.reason,user:this.client.dataManager.newUser(t.user)}),e),new h))}updateGuildRole(e,t,s){const i={};return i.name=t.name||e.name,i.position=void 0!==t.position?t.position:e.position,i.color=this.client.resolver.resolveColor(t.color||e.color),i.hoist=void 0!==t.hoist?t.hoist:e.hoist,i.mentionable=void 0!==t.mentionable?t.mentionable:e.mentionable,t.permissions?i.permissions=r.resolve(t.permissions):i.permissions=e.permissions,this.rest.makeRequest("patch",a.Guild(e.guild).Role(e.id),!0,i,void 0,s).then(t=>this.client.actions.GuildRoleUpdate.handle({role:t,guild_id:e.guild.id}).updated)}pinMessage(e){return this.rest.makeRequest("put",a.Channel(e.channel).Pin(e.id),!0).then(()=>e)}unpinMessage(e){return this.rest.makeRequest("delete",a.Channel(e.channel).Pin(e.id),!0).then(()=>e)}getChannelPinnedMessages(e){return this.rest.makeRequest("get",a.Channel(e).pins,!0)}createChannelInvite(e,t,s){const i={};return i.temporary=t.temporary,i.max_age=t.maxAge,i.max_uses=t.maxUses,i.unique=t.unique,this.rest.makeRequest("post",a.Channel(e).invites,!0,i,void 0,s).then(e=>new g(this.client,e))}deleteInvite(e,t){return this.rest.makeRequest("delete",a.Invite(e.code),!0,void 0,void 0,t).then(()=>e)}getInvite(e){return this.rest.makeRequest("get",a.Invite(e),!0).then(e=>new g(this.client,e))}getGuildInvites(e){return this.rest.makeRequest("get",a.Guild(e).invites,!0).then(e=>{const t=new h;for(const s of e){const e=new g(this.client,s);t.set(e.code,e)}return t})}pruneGuildMembers(e,t,s,i){return this.rest.makeRequest(s?"get":"post",`${a.Guild(e).prune}?days=${t}`,!0,void 0,void 0,i).then(e=>e.pruned)}createEmoji(e,t,s,i,n){const r={image:t,name:s};return i&&(r.roles=i.map(e=>e.id?e.id:e)),this.rest.makeRequest("post",a.Guild(e).emojis,!0,r,void 0,n).then(t=>this.client.actions.GuildEmojiCreate.handle(e,t).emoji)}updateEmoji(e,t,s){const i={};return t.name&&(i.name=t.name),t.roles&&(i.roles=t.roles.map(e=>e.id?e.id:e)),this.rest.makeRequest("patch",a.Guild(e.guild).Emoji(e.id),!0,i,void 0,s).then(t=>this.client.actions.GuildEmojiUpdate.handle(e,t).emoji)}deleteEmoji(e,t){return this.rest.makeRequest("delete",a.Guild(e.guild).Emoji(e.id),!0,void 0,t).then(()=>this.client.actions.GuildEmojiDelete.handle(e).data)}getGuildAuditLogs(e,t={}){t.before&&t.before instanceof w.Entry&&(t.before=t.before.id),t.after&&t.after instanceof w.Entry&&(t.after=t.after.id),"string"==typeof t.type&&(t.type=w.Actions[t.type]);const s=(i.stringify({before:t.before,after:t.after,limit:t.limit,user_id:this.client.resolver.resolveUserID(t.user),action_type:t.type}).match(/[^=&?]+=[^=&?]+/g)||[]).join("&");return this.rest.makeRequest("get",`${a.Guild(e).auditLogs}?${s}`,!0).then(t=>w.build(e,t))}getWebhook(e,t){return this.rest.makeRequest("get",a.Webhook(e,t),!t).then(e=>new p(this.client,e))}getGuildWebhooks(e){return this.rest.makeRequest("get",a.Guild(e).webhooks,!0).then(e=>{const t=new h;for(const s of e)t.set(s.id,new p(this.client,s));return t})}getChannelWebhooks(e){return this.rest.makeRequest("get",a.Channel(e).webhooks,!0).then(e=>{const t=new h;for(const s of e)t.set(s.id,new p(this.client,s));return t})}createWebhook(e,t,s,i){return this.rest.makeRequest("post",a.Channel(e).webhooks,!0,{name:t,avatar:s},void 0,i).then(e=>new p(this.client,e))}editWebhook(e,t,s){return this.rest.makeRequest("patch",a.Webhook(e.id,e.token),!1,{name:t,avatar:s}).then(t=>(e.name=t.name,e.avatar=t.avatar,e))}deleteWebhook(e,t){return this.rest.makeRequest("delete",a.Webhook(e.id,e.token),!1,void 0,void 0,t)}sendWebhookMessage(e,t,{avatarURL:s,tts:i,embeds:n,username:r}={},o=null){return new Promise((h,l)=>{if(r=r||e.name,t instanceof Array){const s=[];!function t(r,a){const c=a===r.length-1?{tts:i,embeds:n,files:o}:{tts:i};e.send(r[a],c).then(e=>(s.push(e),a>=r.length-1?h(s):t(r,++a))).catch(l)}(t,0)}else this.rest.makeRequest("post",`${a.Webhook(e.id,e.token)}?wait=true`,!1,{username:r,avatar_url:s,content:t,tts:i,embeds:n},o).then(e=>{this.client.channels?h(this.client.actions.MessageCreate.handle(e).message):h(e)},l)})}sendSlackWebhookMessage(e,t){return this.rest.makeRequest("post",`${a.Webhook(e.id,e.token)}/slack?wait=true`,!1,t)}fetchUserProfile(e){return this.rest.makeRequest("get",a.User(e).profile,!0).then(t=>new f(e,t))}fetchMentions(e){return e.guild instanceof b&&(e.guild=e.guild.id),l.mergeDefault({limit:25,roles:!0,everyone:!0,guild:null},e),this.rest.makeRequest("get",a.User("@me").Mentions(e.limit,e.roles,e.everyone,e.guild),!0).then(e=>e.map(e=>new d(this.client.channels.get(e.channel_id),e,this.client)))}addFriend(e){return this.rest.makeRequest("post",a.User("@me"),!0,{username:e.username,discriminator:e.discriminator}).then(()=>e)}removeFriend(e){return this.rest.makeRequest("delete",a.User("@me").Relationship(e.id),!0).then(()=>e)}blockUser(e){return this.rest.makeRequest("put",a.User("@me").Relationship(e.id),!0,{type:2}).then(()=>e)}unblockUser(e){return this.rest.makeRequest("delete",a.User("@me").Relationship(e.id),!0).then(()=>e)}updateChannelPositions(e,t){const s=new Array(t.length);for(let e=0;ethis.client.actions.GuildChannelsPositionUpdate.handle({guild_id:e,channels:t}).guild)}setRolePositions(e,t){return this.rest.makeRequest("patch",a.Guild(e).roles,!0,t).then(()=>this.client.actions.GuildRolesPositionUpdate.handle({guild_id:e,roles:t}).guild)}setChannelPositions(e,t){return this.rest.makeRequest("patch",a.Guild(e).channels,!0,t).then(()=>this.client.actions.GuildChannelsPositionUpdate.handle({guild_id:e,channels:t}).guild)}addMessageReaction(e,t){return this.rest.makeRequest("put",a.Message(e).Reaction(t).User("@me"),!0).then(()=>e._addReaction(l.parseEmoji(t),e.client.user))}removeMessageReaction(e,t,s){const i=a.Message(e).Reaction(t).User(s===this.client.user.id?"@me":s);return this.rest.makeRequest("delete",i,!0).then(()=>this.client.actions.MessageReactionRemove.handle({user_id:s,message_id:e.id,emoji:l.parseEmoji(t),channel_id:e.channel.id}).reaction)}removeMessageReactions(e){return this.rest.makeRequest("delete",a.Message(e).reactions,!0).then(()=>e)}getMessageReactionUsers(e,t,s){const n=(i.stringify(s).match(/[^=&?]+=[^=&?]+/g)||[]).join("&");return this.rest.makeRequest("get",`${a.Message(e).Reaction(t)}?${n}`,!0)}getApplication(e){return this.rest.makeRequest("get",a.OAUTH2.Application(e),!0).then(e=>new E(this.client,e))}resetApplication(e){return this.rest.makeRequest("post",a.OAUTH2.Application(e).resetToken,!0).then(()=>this.rest.makeRequest("post",a.OAUTH2.Application(e).resetSecret,!0)).then(e=>new E(this.client,e))}setNote(e,t){return this.rest.makeRequest("put",a.User(e).note,!0,{note:t}).then(()=>e)}acceptInvite(e){return e.id&&(e=e.id),new Promise((t,s)=>this.rest.makeRequest("post",a.Invite(e),!0).then(e=>{const i=s=>{s.id===e.id&&(t(s),this.client.removeListener(o.Events.GUILD_CREATE,i))};this.client.on(o.Events.GUILD_CREATE,i),this.client.setTimeout(()=>{this.client.removeListener(o.Events.GUILD_CREATE,i),s(new Error("Accepting invite timed out"))},12e4)}))}patchUserSettings(e){return this.rest.makeRequest("patch",o.Endpoints.User("@me").settings,!0,e)}patchClientUserGuildSettings(e,t){return this.rest.makeRequest("patch",o.Endpoints.User("@me").Guild(e).settings,!0,t)}}},function(e,t,s){const i=s(3),n=s(76);e.exports=class UserProfile{constructor(e,t){this.user=e,Object.defineProperty(this,"client",{value:e.client}),this.mutualGuilds=new i,this.connections=new i,this.setup(t)}setup(e){this.premium=e.premium,this.premiumSince=e.premium_since?new Date(e.premium_since):null;for(const t of e.mutual_guilds)this.client.guilds.has(t.id)&&this.mutualGuilds.set(t.id,this.client.guilds.get(t.id));for(const t of e.connected_accounts)this.connections.set(t.id,new n(this.user,t))}}},function(e,t){e.exports=class UserConnection{constructor(e,t){this.user=e,this.setup(t)}setup(e){this.type=e.type,this.name=e.name,this.id=e.id,this.revoked=e.revoked,this.integrations=e.integrations}}},function(e,t){e.exports=class VoiceRegion{constructor(e){this.id=e.id,this.name=e.name,this.vip=e.vip,this.deprecated=e.deprecated,this.optimal=e.optimal,this.custom=e.custom,this.sampleHostname=e.sample_hostname}}},function(e,t,s){const i=s(48),n=s(33);e.exports=class SequentialRequestHandler extends i{constructor(e,t){super(e,t),this.endpoint=t,this.timeDifference=0,this.busy=!1}push(e){super.push(e),this.handle()}execute(e){return this.busy=!0,new Promise(t=>{e.request.gen().end((s,i)=>{if(i&&i.headers&&(this.requestLimit=Number(i.headers["x-ratelimit-limit"]),this.requestResetTime=1e3*Number(i.headers["x-ratelimit-reset"]),this.requestRemaining=Number(i.headers["x-ratelimit-remaining"]),this.timeDifference=Date.now()-new Date(i.headers.date).getTime()),s)429===s.status?(this.queue.unshift(e),this.restManager.client.setTimeout(()=>{this.globalLimit=!1,t()},Number(i.headers["retry-after"])+this.restManager.client.options.restTimeOffset),i.headers["x-ratelimit-global"]&&(this.globalLimit=!0)):s.status>=500&&s.status<600?(this.queue.unshift(e),this.restManager.client.setTimeout(t,1e3+this.restManager.client.options.restTimeOffset)):(e.reject(s.status>=400&&s.status<500?new n(i.request.path,i.body):s),t(s));else{this.globalLimit=!1;const s=i&&i.body?i.body:{};e.resolve(s),0===this.requestRemaining?this.restManager.client.setTimeout(()=>t(s),this.requestResetTime-Date.now()+this.timeDifference+this.restManager.client.options.restTimeOffset):t(s)}})})}handle(){super.handle(),this.busy||0===this.remaining||0===this.queue.length||this.globalLimit||this.execute(this.queue.shift()).then(()=>{this.busy=!1,this.handle()})}}},function(e,t,s){const i=s(48),n=s(33);e.exports=class BurstRequestHandler extends i{constructor(e,t){super(e,t),this.client=e.client,this.limit=1/0,this.resetTime=null,this.remaining=1,this.timeDifference=0,this.resetTimeout=null}push(e){super.push(e),this.handle()}execute(e){e&&e.request.gen().end((t,s)=>{if(s&&s.headers&&(this.limit=Number(s.headers["x-ratelimit-limit"]),this.resetTime=1e3*Number(s.headers["x-ratelimit-reset"]),this.remaining=Number(s.headers["x-ratelimit-remaining"]),this.timeDifference=Date.now()-new Date(s.headers.date).getTime()),t)if(429===t.status){if(this.queue.unshift(e),s.headers["x-ratelimit-global"]&&(this.globalLimit=!0),this.resetTimeout)return;this.resetTimeout=this.client.setTimeout(()=>{this.remaining=this.limit,this.globalLimit=!1,this.handle(),this.resetTimeout=null},Number(s.headers["retry-after"])+this.client.options.restTimeOffset)}else t.status>=500&&t.status<600?(this.queue.unshift(e),this.resetTimeout=this.client.setTimeout(()=>{this.handle(),this.resetTimeout=null},1e3+this.client.options.restTimeOffset)):(e.reject(t.status>=400&&t.status<500?new n(s.request.path,s.body):t),this.handle());else{this.globalLimit=!1;const t=s&&s.body?s.body:{};e.resolve(t),this.handle()}})}handle(){super.handle(),this.remaining<=0||0===this.queue.length||this.globalLimit||(this.execute(this.queue.shift()),this.remaining--,this.handle())}}},function(e,t,s){const i=s(24),n=s(0);e.exports=class APIRequest{constructor(e,t,s,i,n,r,o){this.rest=e,this.client=e.client,this.method=t,this.path=s.toString(),this.auth=i,this.data=n,this.files=r,this.route=this.getRoute(this.path),this.reason=o}getRoute(e){let t=e.split("?")[0];if(t.includes("/channels/")||t.includes("/guilds/")){const e=t.includes("/channels/")?t.indexOf("/channels/"):t.indexOf("/guilds/"),s=t.substring(e).split("/")[2];t=t.replace(/(\d{8,})/g,":id").replace(":id",s)}return t}getAuth(){if(this.client.token&&this.client.user&&this.client.user.bot)return`Bot ${this.client.token}`;if(this.client.token)return this.client.token;throw new Error(n.Errors.NO_TOKEN)}gen(){const e=`${this.client.options.http.host}/api/v${this.client.options.http.version}`,t=i[this.method](`${e}${this.path}`);if(this.auth&&t.set("Authorization",this.getAuth()),this.reason&&t.set("X-Audit-Log-Reason",encodeURIComponent(this.reason)),this.rest.client.browser||t.set("User-Agent",this.rest.userAgentManager.userAgent),this.files){for(const e of this.files)e&&e.file&&t.attach(e.name,e.file,e.name);void 0!==this.data&&t.attach("payload_json",JSON.stringify(this.data))}else this.data&&t.send(this.data);return t}}},function(e,t,s){const i=s(0),n=s(4),r=s(22),o=s(9),a=s(49),h=s(51),l=s(16),c=s(52),u=s(53),d=s(18),m=s(32);e.exports=class ClientDataManager{constructor(e){this.client=e}get pastReady(){return this.client.ws.connection.status===i.Status.READY}newGuild(e){const t=this.client.guilds.has(e.id),s=new r(this.client,e);return this.client.guilds.set(s.id,s),this.pastReady&&!t&&(this.client.options.fetchAllMembers?s.fetchMembers().then(()=>{this.client.emit(i.Events.GUILD_CREATE,s)}):this.client.emit(i.Events.GUILD_CREATE,s)),s}newUser(e){if(this.client.users.has(e.id))return this.client.users.get(e.id);const t=new o(this.client,e);return this.client.users.set(t.id,t),t}newChannel(e,t){const s=this.client.channels.has(e.id);let n;return e.type===i.ChannelTypes.DM?n=new h(this.client,e):e.type===i.ChannelTypes.GROUP_DM?n=new m(this.client,e):(t=t||this.client.guilds.get(e.guild_id))&&(e.type===i.ChannelTypes.TEXT?(n=new c(t,e),t.channels.set(n.id,n)):e.type===i.ChannelTypes.VOICE?(n=new u(t,e),t.channels.set(n.id,n)):e.type===i.ChannelTypes.CATEGORY&&(n=new a(t,e),t.channels.set(n.id,n))),n&&!s?(this.pastReady&&this.client.emit(i.Events.CHANNEL_CREATE,n),this.client.channels.set(n.id,n),n):s?n:null}newEmoji(e,t){const s=t.emojis.has(e.id);if(e&&!s){let s=new l(t,e);return this.client.emit(i.Events.GUILD_EMOJI_CREATE,s),t.emojis.set(s.id,s),s}return s?t.emojis.get(e.id):null}killEmoji(e){e instanceof l&&e.guild&&(this.client.emit(i.Events.GUILD_EMOJI_DELETE,e),e.guild.emojis.delete(e.id))}killGuild(e){const t=this.client.guilds.has(e.id);this.client.guilds.delete(e.id),t&&this.pastReady&&this.client.emit(i.Events.GUILD_DELETE,e)}killUser(e){this.client.users.delete(e.id)}killChannel(e){this.client.channels.delete(e.id),e instanceof d&&e.guild.channels.delete(e.id)}updateGuild(e,t){const s=n.cloneObject(e);e.setup(t),this.pastReady&&this.client.emit(i.Events.GUILD_UPDATE,s,e)}updateChannel(e,t){e.setup(t)}updateEmoji(e,t){const s=n.cloneObject(e);return e.setup(t),this.client.emit(i.Events.GUILD_EMOJI_UPDATE,s,e),e}}},function(e,t,s){const i=s(0),n=s(54);e.exports=class ClientManager{constructor(e){this.client=e,this.heartbeatInterval=null}get status(){return this.connection?this.connection.status:i.Status.IDLE}connectToWebSocket(e,t,s){this.client.emit(i.Events.DEBUG,`Authenticated using token ${e}`),this.client.token=e;const r=this.client.setTimeout(()=>s(new Error(i.Errors.TOOK_TOO_LONG)),3e5);this.client.rest.methods.getGateway().then(o=>{const a=i.DefaultOptions.ws.version,h=`${o.url}/?v=${a}&encoding=${n.ENCODING}`;this.client.emit(i.Events.DEBUG,`Using gateway ${h}`),this.client.ws.connect(h),this.client.ws.connection.once("close",e=>{4004===e.code&&s(new Error(i.Errors.BAD_LOGIN)),4010===e.code&&s(new Error(i.Errors.INVALID_SHARD)),4011===e.code&&s(new Error(i.Errors.SHARDING_REQUIRED))}),this.client.once(i.Events.READY,()=>{t(e),this.client.clearTimeout(r)})},s)}destroy(){return this.client.ws.destroy(),this.client.rest.destroy(),this.client.user?this.client.user.bot?(this.client.token=null,Promise.resolve()):this.client.rest.methods.logout().then(()=>{this.client.token=null}):Promise.resolve()}}},function(e,t,s){const i=s(0),n=[i.WSEvents.READY,i.WSEvents.RESUMED,i.WSEvents.GUILD_CREATE,i.WSEvents.GUILD_DELETE,i.WSEvents.GUILD_MEMBERS_CHUNK,i.WSEvents.GUILD_MEMBER_ADD,i.WSEvents.GUILD_MEMBER_REMOVE];e.exports=class WebSocketPacketManager{constructor(e){this.ws=e,this.handlers={},this.queue=[],this.register(i.WSEvents.READY,s(84)),this.register(i.WSEvents.RESUMED,s(86)),this.register(i.WSEvents.GUILD_CREATE,s(87)),this.register(i.WSEvents.GUILD_DELETE,s(88)),this.register(i.WSEvents.GUILD_UPDATE,s(89)),this.register(i.WSEvents.GUILD_BAN_ADD,s(90)),this.register(i.WSEvents.GUILD_BAN_REMOVE,s(91)),this.register(i.WSEvents.GUILD_MEMBER_ADD,s(92)),this.register(i.WSEvents.GUILD_MEMBER_REMOVE,s(93)),this.register(i.WSEvents.GUILD_MEMBER_UPDATE,s(94)),this.register(i.WSEvents.GUILD_ROLE_CREATE,s(95)),this.register(i.WSEvents.GUILD_ROLE_DELETE,s(96)),this.register(i.WSEvents.GUILD_ROLE_UPDATE,s(97)),this.register(i.WSEvents.GUILD_EMOJIS_UPDATE,s(98)),this.register(i.WSEvents.GUILD_MEMBERS_CHUNK,s(99)),this.register(i.WSEvents.CHANNEL_CREATE,s(100)),this.register(i.WSEvents.CHANNEL_DELETE,s(101)),this.register(i.WSEvents.CHANNEL_UPDATE,s(102)),this.register(i.WSEvents.CHANNEL_PINS_UPDATE,s(103)),this.register(i.WSEvents.PRESENCE_UPDATE,s(104)),this.register(i.WSEvents.USER_UPDATE,s(105)),this.register(i.WSEvents.USER_NOTE_UPDATE,s(106)),this.register(i.WSEvents.USER_SETTINGS_UPDATE,s(107)),this.register(i.WSEvents.USER_GUILD_SETTINGS_UPDATE,s(108)),this.register(i.WSEvents.VOICE_STATE_UPDATE,s(109)),this.register(i.WSEvents.TYPING_START,s(110)),this.register(i.WSEvents.MESSAGE_CREATE,s(111)),this.register(i.WSEvents.MESSAGE_DELETE,s(112)),this.register(i.WSEvents.MESSAGE_UPDATE,s(113)),this.register(i.WSEvents.MESSAGE_DELETE_BULK,s(114)),this.register(i.WSEvents.VOICE_SERVER_UPDATE,s(115)),this.register(i.WSEvents.GUILD_SYNC,s(116)),this.register(i.WSEvents.RELATIONSHIP_ADD,s(117)),this.register(i.WSEvents.RELATIONSHIP_REMOVE,s(118)),this.register(i.WSEvents.MESSAGE_REACTION_ADD,s(119)),this.register(i.WSEvents.MESSAGE_REACTION_REMOVE,s(120)),this.register(i.WSEvents.MESSAGE_REACTION_REMOVE_ALL,s(121))}get client(){return this.ws.client}register(e,t){this.handlers[e]=new t(this)}handleQueue(){this.queue.forEach((e,t)=>{this.handle(this.queue[t],!0),this.queue.splice(t,1)})}handle(e,t=!1){return e.op===i.OPCodes.HEARTBEAT_ACK?(this.ws.client._pong(this.ws.client._pingTimestamp),this.ws.lastHeartbeatAck=!0,this.ws.client.emit("debug","Heartbeat acknowledged")):e.op===i.OPCodes.HEARTBEAT&&(this.client.ws.send({op:i.OPCodes.HEARTBEAT,d:this.client.ws.sequence}),this.ws.client.emit("debug","Received gateway heartbeat")),this.ws.status===i.Status.RECONNECTING&&(this.ws.reconnecting=!1,this.ws.checkIfReady()),this.ws.setSequence(e.s),void 0===this.ws.disabledEvents[e.t]&&(this.ws.status!==i.Status.READY&&-1===n.indexOf(e.t)?(this.queue.push(e),!1):(!t&&this.queue.length>0&&this.handleQueue(),!!this.handlers[e.t]&&this.handlers[e.t].handle(e)))}}},function(e,t,s){const i=s(1),n=s(55);e.exports=class ReadyHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.ws.heartbeat(),s.user.user_settings=s.user_settings,s.user.user_guild_settings=s.user_guild_settings;const i=new n(t,s.user);t.user=i,t.readyAt=new Date,t.users.set(i.id,i);for(const e of s.guilds)t.guilds.has(e.id)||t.dataManager.newGuild(e);for(const e of s.private_channels)t.dataManager.newChannel(e);for(const e of s.relationships){const s=t.dataManager.newUser(e.user);1===e.type?t.user.friends.set(s.id,s):2===e.type&&t.user.blocked.set(s.id,s)}s.presences=s.presences||[];for(const e of s.presences)t.dataManager.newUser(e.user),t._setPresence(e.user.id,e);if(s.notes)for(const e in s.notes){let i=s.notes[e];i.length||(i=null),t.user.notes.set(e,i)}!t.user.bot&&t.options.sync&&t.setInterval(t.syncGuilds.bind(t),3e4),t.users.has("1")||t.dataManager.newUser({id:"1",username:"Clyde",discriminator:"0000",avatar:"https://discordapp.com/assets/f78426a064bc9dd24847519259bc42af.png",bot:!0,status:"online",game:null,verified:!0});const r=t.setTimeout(()=>{t.ws.connection.triggerReady()},1200*s.guilds.length);t.setMaxListeners(s.guilds.length+10),t.once("ready",()=>{t.syncGuilds(),t.setMaxListeners(10),t.clearTimeout(r)});const o=this.packetManager.ws;o.sessionID=s.session_id,o._trace=s._trace,t.emit("debug",`READY ${o._trace.join(" -> ")} ${o.sessionID}`),o.checkIfReady()}}},function(e,t,s){const i=s(0);e.exports=class ClientUserChannelOverride{constructor(e){this.patch(e)}patch(e){for(const t of Object.keys(i.UserChannelOverrideMap)){const s=i.UserChannelOverrideMap[t];e.hasOwnProperty(t)&&("function"==typeof s?this[s.name]=s(e[t]):this[s]=e[t])}}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class ResumedHandler extends i{handle(e){const t=this.packetManager.client,s=t.ws.connection;s._trace=e.d._trace,s.status=n.Status.READY,this.packetManager.handleQueue();const i=s.sequence-s.closeSequence;s.debug(`RESUMED ${s._trace.join(" -> ")} | replayed ${i} events.`),t.emit(n.Events.RESUME,i),s.heartbeat()}}},function(e,t,s){const i=s(1);e.exports=class GuildCreateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.guilds.get(s.id);i?i.available||s.unavailable||(i.setup(s),this.packetManager.ws.checkIfReady()):t.dataManager.newGuild(s)}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class GuildDeleteHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.actions.GuildDelete.handle(s);i.guild&&t.emit(n.Events.GUILD_DELETE,i.guild)}}},function(e,t,s){const i=s(1);e.exports=class GuildUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildUpdate.handle(s)}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class GuildBanAddHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.guilds.get(s.guild_id),r=t.users.get(s.user.id);i&&r&&t.emit(n.Events.GUILD_BAN_ADD,i,r)}}},function(e,t,s){const i=s(1);e.exports=class GuildBanRemoveHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildBanRemove.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class GuildMemberAddHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.guilds.get(s.guild_id);i&&(i.memberCount++,i._addMember(s))}}},function(e,t,s){const i=s(1);e.exports=class GuildMemberRemoveHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildMemberRemove.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class GuildMemberUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.guilds.get(s.guild_id);if(i){const e=i.members.get(s.user.id);e&&i._updateMember(e,s)}}}},function(e,t,s){const i=s(1);e.exports=class GuildRoleCreateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildRoleCreate.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class GuildRoleDeleteHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildRoleDelete.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class GuildRoleUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildRoleUpdate.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class GuildEmojisUpdate extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildEmojisUpdate.handle(s)}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class GuildMembersChunkHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.guilds.get(s.guild_id);if(!i)return;const r=s.members.map(e=>i._addMember(e,!1));t.emit(n.Events.GUILD_MEMBERS_CHUNK,r,i),t.ws.lastHeartbeatAck=!0}}},function(e,t,s){const i=s(1);e.exports=class ChannelCreateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.ChannelCreate.handle(s)}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class ChannelDeleteHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.actions.ChannelDelete.handle(s);i.channel&&t.emit(n.Events.CHANNEL_DELETE,i.channel)}}},function(e,t,s){const i=s(1);e.exports=class ChannelUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.ChannelUpdate.handle(s)}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class ChannelPinsUpdate extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.channels.get(s.channel_id),r=new Date(s.last_pin_timestamp);i&&r&&t.emit(n.Events.CHANNEL_PINS_UPDATE,i,r)}}},function(e,t,s){const i=s(1),n=s(0),r=s(4);e.exports=class PresenceUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;let i=t.users.get(s.user.id);const o=t.guilds.get(s.guild_id);if(!i){if(!s.user.username)return;i=t.dataManager.newUser(s.user)}const a=r.cloneObject(i);if(i.patch(s.user),i.equals(a)||t.emit(n.Events.USER_UPDATE,a,i),o){let e=o.members.get(i.id);if(e||"offline"===s.status||(e=o._addMember({user:i,roles:s.roles,deaf:!1,mute:!1},!1),t.emit(n.Events.GUILD_MEMBER_AVAILABLE,e)),e){if(0===t.listenerCount(n.Events.PRESENCE_UPDATE))return void o._setPresence(i.id,s);const a=r.cloneObject(e);e.presence&&(a.frozenPresence=r.cloneObject(e.presence)),o._setPresence(i.id,s),t.emit(n.Events.PRESENCE_UPDATE,a,e)}else o._setPresence(i.id,s)}}}},function(e,t,s){const i=s(1);e.exports=class UserUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.UserUpdate.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class UserNoteUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.UserNoteUpdate.handle(s)}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class UserSettingsUpdateHandler extends i{handle(e){const t=this.packetManager.client;t.user.settings.patch(e.d),t.emit(n.Events.USER_SETTINGS_UPDATE,t.user.settings)}}},function(e,t,s){const i=s(1),n=s(0),r=s(57);e.exports=class UserGuildSettingsUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=t.user.guildSettings.get(e.d.guild_id);s?s.patch(e.d):t.user.guildSettings.set(e.d.guild_id,new r(e.d,t)),t.emit(n.Events.USER_GUILD_SETTINGS_UPDATE,t.user.guildSettings.get(e.d.guild_id))}}},function(e,t,s){const i=s(1),n=s(0),r=s(4);e.exports=class VoiceStateUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.guilds.get(s.guild_id);if(i){const e=i.members.get(s.user_id);if(e){const i=r.cloneObject(e);e.voiceChannel&&e.voiceChannel.id!==s.channel_id&&e.voiceChannel.members.delete(i.id),s.channel_id||(e.speaking=null),e.user.id===t.user.id&&s.channel_id&&t.emit("self.voiceStateUpdate",s);const o=t.channels.get(s.channel_id);o&&(o.members.set(e.id,e),e.guild.channels.set(s.channel_id,o)),e.serverMute=s.mute,e.serverDeaf=s.deaf,e.selfMute=s.self_mute,e.selfDeaf=s.self_deaf,e.voiceSessionID=s.session_id,e.voiceChannelID=s.channel_id,t.emit(n.Events.VOICE_STATE_UPDATE,i,e)}}}}},function(e,t,s){const i=s(1),n=s(0);class TypingData{constructor(e,t,s,i){this.client=e,this.since=t,this.lastTimestamp=s,this._timeout=i}resetTimeout(e){this.client.clearTimeout(this._timeout),this._timeout=e}get elapsedTime(){return Date.now()-this.since}}function r(e,t){return e.client.setTimeout(()=>{e.client.emit(n.Events.TYPING_STOP,e,t,e._typing.get(t.id)),e._typing.delete(t.id)},6e3)}e.exports=class TypingStartHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.channels.get(s.channel_id),o=t.users.get(s.user_id),a=new Date(1e3*s.timestamp);if(i&&o){if("voice"===i.type)return void t.emit(n.Events.WARN,`Discord sent a typing packet to voice channel ${i.id}`);if(i._typing.has(o.id)){const e=i._typing.get(o.id);e.lastTimestamp=a,e.resetTimeout(r(i,o))}else i._typing.set(o.id,new TypingData(t,a,a,r(i,o))),t.emit(n.Events.TYPING_START,i,o)}}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class MessageCreateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.actions.MessageCreate.handle(s);i.message&&t.emit(n.Events.MESSAGE_CREATE,i.message)}}},function(e,t,s){const i=s(1),n=s(0);e.exports=class MessageDeleteHandler extends i{handle(e){const t=this.packetManager.client,s=e.d,i=t.actions.MessageDelete.handle(s);i.message&&t.emit(n.Events.MESSAGE_DELETE,i.message)}}},function(e,t,s){const i=s(1);e.exports=class MessageUpdateHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.MessageUpdate.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class MessageDeleteBulkHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.MessageDeleteBulk.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class VoiceServerUpdate extends i{handle(e){const t=this.packetManager.client,s=e.d;t.emit("self.voiceServer",s)}}},function(e,t,s){const i=s(1);e.exports=class GuildSyncHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.GuildSync.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class RelationshipAddHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;1===s.type?t.fetchUser(s.id).then(e=>{t.user.friends.set(e.id,e)}):2===s.type&&t.fetchUser(s.id).then(e=>{t.user.blocked.set(e.id,e)})}}},function(e,t,s){const i=s(1);e.exports=class RelationshipRemoveHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;2===s.type?t.user.blocked.has(s.id)&&t.user.blocked.delete(s.id):1===s.type&&t.user.friends.has(s.id)&&t.user.friends.delete(s.id)}}},function(e,t,s){const i=s(1);e.exports=class MessageReactionAddHandler extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.MessageReactionAdd.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class MessageReactionRemove extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.MessageReactionRemove.handle(s)}}},function(e,t,s){const i=s(1);e.exports=class MessageReactionRemoveAll extends i{handle(e){const t=this.packetManager.client,s=e.d;t.actions.MessageReactionRemoveAll.handle(s)}}},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t,s){const i=s(19).EventEmitter,n=s(0),r=s(54);e.exports=class WebSocketManager extends i{constructor(e){super(),this.client=e,this.connection=null}heartbeat(){return this.connection?this.connection.heartbeat():this.debug("No connection to heartbeat")}debug(e){return this.client.emit("debug",`[ws] ${e}`)}destroy(){return this.connection?this.connection.destroy():(this.debug("Attempted to destroy WebSocket but no connection exists!"),!1)}send(e){this.connection?this.connection.send(e):this.debug("No connection to websocket")}connect(e){if(!this.connection)return this.connection=new r(this,e),!0;switch(this.connection.status){case n.Status.IDLE:case n.Status.DISCONNECTED:return this.connection.connect(e,5500),!0;default:return this.debug(`Couldn't connect to ${e} as the websocket is at state ${this.connection.status}`),!1}}}},function(e,t,s){e.exports=class ActionsManager{constructor(e){this.client=e,this.register(s(128)),this.register(s(129)),this.register(s(130)),this.register(s(131)),this.register(s(132)),this.register(s(133)),this.register(s(134)),this.register(s(135)),this.register(s(136)),this.register(s(137)),this.register(s(138)),this.register(s(139)),this.register(s(140)),this.register(s(141)),this.register(s(142)),this.register(s(143)),this.register(s(144)),this.register(s(145)),this.register(s(146)),this.register(s(147)),this.register(s(148)),this.register(s(149)),this.register(s(150)),this.register(s(151)),this.register(s(152)),this.register(s(153)),this.register(s(154)),this.register(s(155))}register(e){this[e.name.replace(/Action$/,"")]=new e(this.client)}}},function(e,t,s){const i=s(2),n=s(15);e.exports=class MessageCreateAction extends i{handle(e){const t=this.client,s=t.channels.get((e instanceof Array?e[0]:e).channel_id),i=t.users.get((e instanceof Array?e[0]:e).author.id);if(s){const r=s.guild?s.guild.member(i):null;if(e instanceof Array){const o=new Array(e.length);for(let i=0;ithis.deleted.delete(e+t),this.client.options.restWsBridgeTimeout)}}},function(e,t,s){const i=s(2),n=s(3),r=s(0);e.exports=class MessageDeleteBulkAction extends i{handle(e){const t=new n;if(e.messages)for(const s of e.messages)t.set(s.id,s);else{const s=this.client.channels.get(e.channel_id);for(const i of e.ids){const e=s.messages.get(i);e&&t.set(e.id,e)}}return t.size>0&&this.client.emit(r.Events.MESSAGE_BULK_DELETE,t),{messages:t}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class MessageUpdateAction extends i{handle(e){const t=this.client,s=t.channels.get(e.channel_id);if(s){const i=s.messages.get(e.id);return i?(i.patch(e),t.emit(n.Events.MESSAGE_UPDATE,i._edits[0],i),{old:i._edits[0],updated:i}):{old:i,updated:i}}return{old:null,updated:null}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class MessageReactionAdd extends i{handle(e){const t=this.client.users.get(e.user_id);if(!t)return!1;const s=this.client.channels.get(e.channel_id);if(!s||"voice"===s.type)return!1;const i=s.messages.get(e.message_id);if(!i)return!1;if(!e.emoji)return!1;const r=i._addReaction(e.emoji,t);return r&&this.client.emit(n.Events.MESSAGE_REACTION_ADD,r,t),{message:i,reaction:r,user:t}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class MessageReactionRemove extends i{handle(e){const t=this.client.users.get(e.user_id);if(!t)return!1;const s=this.client.channels.get(e.channel_id);if(!s||"voice"===s.type)return!1;const i=s.messages.get(e.message_id);if(!i)return!1;if(!e.emoji)return!1;const r=i._removeReaction(e.emoji,t);return r&&this.client.emit(n.Events.MESSAGE_REACTION_REMOVE,r,t),{message:i,reaction:r,user:t}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class MessageReactionRemoveAll extends i{handle(e){const t=this.client.channels.get(e.channel_id);if(!t||"voice"===t.type)return!1;const s=t.messages.get(e.message_id);return!!s&&(s._clearReactions(),this.client.emit(n.Events.MESSAGE_REACTION_REMOVE_ALL,s),{message:s})}}},function(e,t,s){const i=s(2);e.exports=class ChannelCreateAction extends i{handle(e){return{channel:this.client.dataManager.newChannel(e)}}}},function(e,t,s){const i=s(2);e.exports=class ChannelDeleteAction extends i{constructor(e){super(e),this.deleted=new Map}handle(e){const t=this.client;let s=t.channels.get(e.id);return s?(t.dataManager.killChannel(s),this.deleted.set(s.id,s),this.scheduleForDeletion(s.id)):s=this.deleted.get(e.id)||null,{channel:s}}scheduleForDeletion(e){this.client.setTimeout(()=>this.deleted.delete(e),this.client.options.restWsBridgeTimeout)}}},function(e,t,s){const i=s(2),n=s(0),r=s(4);e.exports=class ChannelUpdateAction extends i{handle(e){const t=this.client,s=t.channels.get(e.id);if(s){const i=r.cloneObject(s);return s.setup(e),t.emit(n.Events.CHANNEL_UPDATE,i,s),{old:i,updated:s}}return{old:null,updated:null}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class GuildDeleteAction extends i{constructor(e){super(e),this.deleted=new Map}handle(e){const t=this.client;let s=t.guilds.get(e.id);if(s){for(const e of s.channels.values())"text"===e.type&&e.stopTyping(!0);if(s.available&&e.unavailable)return s.available=!1,t.emit(n.Events.GUILD_UNAVAILABLE,s),{guild:null};for(const e of s.channels.values())this.client.channels.delete(e.id);s.voiceConnection&&s.voiceConnection.disconnect(),t.guilds.delete(s.id),this.deleted.set(s.id,s),this.scheduleForDeletion(s.id)}else s=this.deleted.get(e.id)||null;return{guild:s}}scheduleForDeletion(e){this.client.setTimeout(()=>this.deleted.delete(e),this.client.options.restWsBridgeTimeout)}}},function(e,t,s){const i=s(2),n=s(0),r=s(4);e.exports=class GuildUpdateAction extends i{handle(e){const t=this.client,s=t.guilds.get(e.id);if(s){const i=r.cloneObject(s);return s.setup(e),t.emit(n.Events.GUILD_UPDATE,i,s),{old:i,updated:s}}return{old:null,updated:null}}}},function(e,t,s){const i=s(2);e.exports=class GuildMemberGetAction extends i{handle(e,t){return{member:e._addMember(t,!1)}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class GuildMemberRemoveAction extends i{constructor(e){super(e),this.deleted=new Map}handle(e){const t=this.client,s=t.guilds.get(e.guild_id);let i=null;return s&&((i=s.members.get(e.user.id))?(s.memberCount--,s._removeMember(i),this.deleted.set(s.id+e.user.id,i),t.status===n.Status.READY&&t.emit(n.Events.GUILD_MEMBER_REMOVE,i),this.scheduleForDeletion(s.id,e.user.id)):i=this.deleted.get(s.id+e.user.id)||null),{guild:s,member:i}}scheduleForDeletion(e,t){this.client.setTimeout(()=>this.deleted.delete(e+t),this.client.options.restWsBridgeTimeout)}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class GuildBanRemove extends i{handle(e){const t=this.client,s=t.guilds.get(e.guild_id),i=t.dataManager.newUser(e.user);s&&i&&t.emit(n.Events.GUILD_BAN_REMOVE,s,i)}}},function(e,t,s){const i=s(2),n=s(0),r=s(8);e.exports=class GuildRoleCreate extends i{handle(e){const t=this.client,s=t.guilds.get(e.guild_id);let i;if(s){const o=s.roles.has(e.role.id);i=new r(s,e.role),s.roles.set(i.id,i),o||t.emit(n.Events.GUILD_ROLE_CREATE,i)}return{role:i}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class GuildRoleDeleteAction extends i{constructor(e){super(e),this.deleted=new Map}handle(e){const t=this.client,s=t.guilds.get(e.guild_id);let i;return s&&((i=s.roles.get(e.role_id))?(s.roles.delete(e.role_id),this.deleted.set(s.id+e.role_id,i),this.scheduleForDeletion(s.id,e.role_id),t.emit(n.Events.GUILD_ROLE_DELETE,i)):i=this.deleted.get(s.id+e.role_id)||null),{role:i}}scheduleForDeletion(e,t){this.client.setTimeout(()=>this.deleted.delete(e+t),this.client.options.restWsBridgeTimeout)}}},function(e,t,s){const i=s(2),n=s(0),r=s(4);e.exports=class GuildRoleUpdateAction extends i{handle(e){const t=this.client,s=t.guilds.get(e.guild_id);if(s){const i=e.role;let o=null;const a=s.roles.get(i.id);return a&&(o=r.cloneObject(a),a.setup(e.role),t.emit(n.Events.GUILD_ROLE_UPDATE,o,a)),{old:o,updated:a}}return{old:null,updated:null}}}},function(e,t,s){const i=s(2);e.exports=class UserGetAction extends i{handle(e){return{user:this.client.dataManager.newUser(e)}}}},function(e,t,s){const i=s(2),n=s(0),r=s(4);e.exports=class UserUpdateAction extends i{handle(e){const t=this.client;if(t.user){if(t.user.equals(e))return{old:t.user,updated:t.user};const s=r.cloneObject(t.user);return t.user.patch(e),t.emit(n.Events.USER_UPDATE,s,t.user),{old:s,updated:t.user}}return{old:null,updated:null}}}},function(e,t,s){const i=s(2),n=s(0);e.exports=class UserNoteUpdateAction extends i{handle(e){const t=this.client,s=t.user.notes.get(e.id),i=e.note.length?e.note:null;return t.user.notes.set(e.id,i),t.emit(n.Events.USER_NOTE_UPDATE,e.id,s,i),{old:s,updated:i}}}},function(e,t,s){const i=s(2);e.exports=class GuildSync extends i{handle(e){const t=this.client.guilds.get(e.id);if(t){if(e.presences)for(const s of e.presences)t._setPresence(s.user.id,s);if(e.members)for(const s of e.members){const e=t.members.get(s.user.id);e?t._updateMember(e,s):t._addMember(s,!1)}"large"in e&&(t.large=e.large)}}}},function(e,t,s){const i=s(2);e.exports=class GuildEmojiCreateAction extends i{handle(e,t){return{emoji:this.client.dataManager.newEmoji(t,e)}}}},function(e,t,s){const i=s(2);e.exports=class GuildEmojiDeleteAction extends i{handle(e){return this.client.dataManager.killEmoji(e),{emoji:e}}}},function(e,t,s){const i=s(2);e.exports=class GuildEmojiUpdateAction extends i{handle(e,t){return{emoji:this.client.dataManager.updateEmoji(e,t)}}}},function(e,t,s){const i=s(2);e.exports=class GuildEmojisUpdateAction extends i{handle(e){const t=this.client.guilds.get(e.guild_id);if(!t||!t.emojis)return;const s=function(e){const t=new Map;for(const s of e)t.set(...s);return t}(t.emojis.entries());for(const i of e.emojis){const e=t.emojis.get(i.id);e?(s.delete(i.id),e.equals(i,!0)||this.client.actions.GuildEmojiUpdate.handle(e,i)):this.client.actions.GuildEmojiCreate.handle(t,i)}for(const e of s.values())this.client.actions.GuildEmojiDelete.handle(e)}}},function(e,t,s){const i=s(2);e.exports=class GuildRolesPositionUpdate extends i{handle(e){const t=this.client.guilds.get(e.guild_id);if(t)for(const s of e.roles){const e=t.roles.get(s.id);e&&(e.position=s.position)}return{guild:t}}}},function(e,t,s){const i=s(2);e.exports=class GuildChannelsPositionUpdate extends i{handle(e){const t=this.client.guilds.get(e.guild_id);if(t)for(const s of e.channels){const e=t.channels.get(s.id);e&&(e.position=s.position)}return{guild:t}}}},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t,s){const i=s(23),n=s(37),r=s(27),o=s(0),a=s(4);e.exports=class WebhookClient extends i{constructor(e,t,s){super(null,e,t),this.options=a.mergeDefault(o.DefaultOptions,s),this.rest=new n(this),this.resolver=new r(this),this._timeouts=new Set,this._intervals=new Set}setTimeout(e,t,...s){const i=setTimeout(()=>{e(...s),this._timeouts.delete(i)},t);return this._timeouts.add(i),i}clearTimeout(e){clearTimeout(e),this._timeouts.delete(e)}setInterval(e,t,...s){const i=setInterval(e,t,...s);return this._intervals.add(i),i}clearInterval(e){clearInterval(e),this._intervals.delete(e)}destroy(){for(const e of this._timeouts)clearTimeout(e);for(const e of this._intervals)clearInterval(e);this._timeouts.clear(),this._intervals.clear()}}}]); \ No newline at end of file