From 9f9875997fcc93d9ea626187fb408094fa21a909 Mon Sep 17 00:00:00 2001 From: Junior Date: Sat, 3 Jun 2023 13:38:51 +0100 Subject: [PATCH] chore: build artefact --- dist/index.js | 17192 +++++++++++++++++++++++--------------------- dist/index.js.map | 2 +- 2 files changed, 9096 insertions(+), 8098 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1d326f2..464303f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5,21 +5,21 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; - -var _a; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.OPTIONS = exports.MANAGE_ROLES = void 0; -const core_1 = __nccwpck_require__(2186); -const v10_1 = __nccwpck_require__(27); -exports.MANAGE_ROLES = Number(v10_1.PermissionFlagsBits.ManageRoles); -exports.OPTIONS = { - appToken: (0, core_1.getInput)('app-token', { required: true }), - guildID: (0, core_1.getInput)('guild-id', { required: true }), - roleID: (0, core_1.getInput)('role-id', { required: true }), - roleFormat: (_a = (0, core_1.getInput)('role-format', { required: false })) !== null && _a !== void 0 ? _a : 'COTD - %s' - // &s - Color name (e.g. "COTD - Red") - // &h - Color hex (e.g. "COTD - #FF0000") -}; + +var _a; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.OPTIONS = exports.MANAGE_ROLES = void 0; +const core_1 = __nccwpck_require__(2186); +const v10_1 = __nccwpck_require__(27); +exports.MANAGE_ROLES = Number(v10_1.PermissionFlagsBits.ManageRoles); +exports.OPTIONS = { + appToken: (0, core_1.getInput)('app-token', { required: true }), + guildID: (0, core_1.getInput)('guild-id', { required: true }), + roleID: (0, core_1.getInput)('role-id', { required: true }), + roleFormat: (_a = (0, core_1.getInput)('role-format', { required: false })) !== null && _a !== void 0 ? _a : 'COTD - %s' + // &s - Color name (e.g. "COTD - Red") + // &h - Color hex (e.g. "COTD - #FF0000") +}; /***/ }), @@ -28,90 +28,90 @@ exports.OPTIONS = { /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -const core_1 = __nccwpck_require__(2186); -const collection_1 = __nccwpck_require__(4277); -const node_fetch_1 = __importDefault(__nccwpck_require__(4429)); -const constants_1 = __nccwpck_require__(5105); -const util_1 = __nccwpck_require__(4024); -const request_handler_1 = __importDefault(__nccwpck_require__(3734)); -// Check if Token User... -// * has valid access -// * is bot user -// Request: -// * Guild Data (/api/v10/guilds/:guild) -// > Escape null / Error Code 404 = no access -// * Member Data (/api/v10/guilds/:guild/members/:member) -// Check if Token User... -// * has permissions for MANAGE_ROLES for the guild (not a channel overwrite) -// * is higher on the role list than the target role {b.position - a.position} -// > MUST be higher, not below and certainly not the highest role they have -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - const { appToken, guildID, roleID, roleFormat } = constants_1.OPTIONS; - const timer = (0, util_1.wrapDuration)(); - const handler = new request_handler_1.default(appToken); - // Can only throw exceptions, user is guaranteed to exist if token is valid - const user = yield handler.getUser(); - if (!user.bot) - throw new Error('Authenticated user is not a bot'); - const guild = yield handler.getGuild(guildID); - if (!guild.roles.length) - throw new Error('No roles found.'); - const roles = new collection_1.Collection(guild.roles.map(r => [r.id, r])); - const target = roles.get(roleID); - if (!target) - throw new Error('Role not found.'); - const member = yield handler.getMember(guildID, user.id); - // No failover necessary, guild was found and user is authenticated - const userRoles = roles.filter(r => member.roles.includes(r.id)); - const permissions = (0, util_1.resolvePermissionsOf)(userRoles); - if (!(0, util_1.hasPermissionFor)(constants_1.MANAGE_ROLES, permissions)) - throw new Error('User does not have permission to manage roles.'); - const highestRole = userRoles - .sort((a, b) => b.position - a.position) - .first(); - if (guild.owner || (highestRole && highestRole.position <= target.position)) - throw new Error('User does not have permission to manage this role.'); - const colorCode = (0, util_1.randomHexInt)(); - const colorHex = colorCode.toString(16); - const colorDataRes = yield (0, node_fetch_1.default)(`https://www.thecolorapi.com/id?hex=${colorHex}`); - const colorData = (yield colorDataRes.json()); - const newRole = yield handler.modifyRole(guildID, roleID, { - color: colorCode, - name: roleFormat - .replace('&s', colorData.name.value) - .replace('&h', colorData.hex.clean) - }); - const duration = timer(); - (0, core_1.info)(`Role ${newRole.name} has been updated.`); - (0, core_1.info)(`Old data: ${target.name} | ${target.color}`); - (0, core_1.info)(`New data: ${newRole.name} | ${newRole.color}`); - (0, core_1.info)(`Took ${duration} to complete.`); - (0, core_1.setOutput)('color-int', newRole.color); - (0, core_1.setOutput)('color-hex', newRole.color.toString(16)); - } - catch (error) { - if (error instanceof Error) - (0, core_1.setFailed)(error.message); - } - }); -} -run(); + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +const core_1 = __nccwpck_require__(2186); +const collection_1 = __nccwpck_require__(8861); +const node_fetch_1 = __importDefault(__nccwpck_require__(4429)); +const constants_1 = __nccwpck_require__(5105); +const util_1 = __nccwpck_require__(4024); +const request_handler_1 = __importDefault(__nccwpck_require__(3734)); +// Check if Token User... +// * has valid access +// * is bot user +// Request: +// * Guild Data (/api/v10/guilds/:guild) +// > Escape null / Error Code 404 = no access +// * Member Data (/api/v10/guilds/:guild/members/:member) +// Check if Token User... +// * has permissions for MANAGE_ROLES for the guild (not a channel overwrite) +// * is higher on the role list than the target role {b.position - a.position} +// > MUST be higher, not below and certainly not the highest role they have +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + const { appToken, guildID, roleID, roleFormat } = constants_1.OPTIONS; + const timer = (0, util_1.wrapDuration)(); + const handler = new request_handler_1.default(appToken); + // Can only throw exceptions, user is guaranteed to exist if token is valid + const user = yield handler.getUser(); + if (!user.bot) + throw new Error('Authenticated user is not a bot'); + const guild = yield handler.getGuild(guildID); + if (!guild.roles.length) + throw new Error('No roles found.'); + const roles = new collection_1.Collection(guild.roles.map(r => [r.id, r])); + const target = roles.get(roleID); + if (!target) + throw new Error('Role not found.'); + const member = yield handler.getMember(guildID, user.id); + // No failover necessary, guild was found and user is authenticated + const userRoles = roles.filter(r => member.roles.includes(r.id)); + const permissions = (0, util_1.resolvePermissionsOf)(userRoles); + if (!(0, util_1.hasPermissionFor)(constants_1.MANAGE_ROLES, permissions)) + throw new Error('User does not have permission to manage roles.'); + const highestRole = userRoles + .sort((a, b) => b.position - a.position) + .first(); + if (guild.owner || (highestRole && highestRole.position <= target.position)) + throw new Error('User does not have permission to manage this role.'); + const colorCode = (0, util_1.randomHexInt)(); + const colorHex = colorCode.toString(16).padStart(6, '0'); + const colorDataRes = yield (0, node_fetch_1.default)(`https://www.thecolorapi.com/id?hex=${colorHex}`); + const colorData = (yield colorDataRes.json()); + const newRole = yield handler.modifyRole(guildID, roleID, { + color: colorCode, + name: roleFormat + .replace('&s', colorData.name.value) + .replace('&h', colorData.hex.clean) + }); + const duration = timer(); + (0, core_1.info)(`Role ${newRole.name} has been updated.`); + (0, core_1.info)(`Old data: ${target.name} | ${target.color}`); + (0, core_1.info)(`New data: ${newRole.name} | ${newRole.color}`); + (0, core_1.info)(`Took ${duration} to complete.`); + (0, core_1.setOutput)('color-int', newRole.color); + (0, core_1.setOutput)('color-hex', newRole.color.toString(16)); + } + catch (error) { + if (error instanceof Error) + (0, core_1.setFailed)(error.message); + } + }); +} +run(); /***/ }), @@ -120,92 +120,92 @@ run(); /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -const core_1 = __nccwpck_require__(2186); -const v10_1 = __nccwpck_require__(27); -const node_fetch_1 = __importDefault(__nccwpck_require__(4429)); -const util_1 = __nccwpck_require__(4024); -class RequestHandler { - constructor(token) { - this.token = token; - } - request(url, options = {}) { - var _a; - return __awaiter(this, void 0, void 0, function* () { - const path = `${(_a = options.method) !== null && _a !== void 0 ? _a : 'GET'} ${url}`; - (0, core_1.debug)(`Requesting for ${path}`); - const timer = (0, util_1.wrapDuration)(); - const res = yield (0, node_fetch_1.default)(v10_1.RouteBases.api + url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { 'Content-Type': 'application/json', Authorization: `Bot ${this.token}` }) })); - (0, core_1.debug)(`Request for ${path} took ${timer()}`); - const data = (yield res.json()); - if ('message' in data) - throw new Error(data.message); - // Failover is necessary for handler to fallback on for 4** and 5** error codes - return data; - }); - } - /** - * @returns The authenticated user - * @throws {Error} If the user is not found - */ - getUser() { - return __awaiter(this, void 0, void 0, function* () { - return this.request(v10_1.Routes.user()); - }); - } - /** - * - * @param guildID The guild to get the roles from - * @returns The requested guild entity - * @throws {Error} If the guild is not found, within the scope of the authenticated user - */ - getGuild(guildID) { - return __awaiter(this, void 0, void 0, function* () { - return this.request(v10_1.Routes.guild(guildID)); - }); - } - /** - * - * @param guildID The guild to get the member from - * @param memberID The member to get - * @returns The requested member entity - * @throws {Error} If the member is not found, within the scope of the requested guild - */ - getMember(guildID, memberID) { - return __awaiter(this, void 0, void 0, function* () { - return this.request(v10_1.Routes.guildMember(guildID, memberID)); - }); - } - /** - * - * @param guildID The guild to get the roles from - * @param roleID The role to modify - * @param options The options to modify the role with - * @returns - */ - modifyRole(guildID, roleID, options) { - return __awaiter(this, void 0, void 0, function* () { - return this.request(v10_1.Routes.guildRole(guildID, roleID), { - method: 'PATCH', - body: JSON.stringify(options) - }); - }); - } -} -exports["default"] = RequestHandler; + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +const core_1 = __nccwpck_require__(2186); +const v10_1 = __nccwpck_require__(27); +const node_fetch_1 = __importDefault(__nccwpck_require__(4429)); +const util_1 = __nccwpck_require__(4024); +class RequestHandler { + constructor(token) { + this.token = token; + } + request(url, options = {}) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + const path = `${(_a = options.method) !== null && _a !== void 0 ? _a : 'GET'} ${url}`; + (0, core_1.debug)(`Requesting for ${path}`); + const timer = (0, util_1.wrapDuration)(); + const res = yield (0, node_fetch_1.default)(v10_1.RouteBases.api + url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { 'Content-Type': 'application/json', Authorization: `Bot ${this.token}` }) })); + (0, core_1.debug)(`Request for ${path} took ${timer()}`); + const data = (yield res.json()); + if ('message' in data) + throw new Error(data.message); + // Failover is necessary for handler to fallback on for 4** and 5** error codes + return data; + }); + } + /** + * @returns The authenticated user + * @throws {Error} If the user is not found + */ + getUser() { + return __awaiter(this, void 0, void 0, function* () { + return this.request(v10_1.Routes.user()); + }); + } + /** + * + * @param guildID The guild to get the roles from + * @returns The requested guild entity + * @throws {Error} If the guild is not found, within the scope of the authenticated user + */ + getGuild(guildID) { + return __awaiter(this, void 0, void 0, function* () { + return this.request(v10_1.Routes.guild(guildID)); + }); + } + /** + * + * @param guildID The guild to get the member from + * @param memberID The member to get + * @returns The requested member entity + * @throws {Error} If the member is not found, within the scope of the requested guild + */ + getMember(guildID, memberID) { + return __awaiter(this, void 0, void 0, function* () { + return this.request(v10_1.Routes.guildMember(guildID, memberID)); + }); + } + /** + * + * @param guildID The guild to get the roles from + * @param roleID The role to modify + * @param options The options to modify the role with + * @returns + */ + modifyRole(guildID, roleID, options) { + return __awaiter(this, void 0, void 0, function* () { + return this.request(v10_1.Routes.guildRole(guildID, roleID), { + method: 'PATCH', + body: JSON.stringify(options) + }); + }); + } +} +exports["default"] = RequestHandler; /***/ }), @@ -214,32 +214,32 @@ exports["default"] = RequestHandler; /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; - -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.randomHexInt = exports.wrapDuration = exports.getDuration = exports.hasPermissionFor = exports.resolvePermissionsOf = void 0; -const ms_1 = __importDefault(__nccwpck_require__(7026)); -const resolvePermissionsOf = (roles) => roles.reduce((acc, role) => acc | Number(role.permissions), 0); -exports.resolvePermissionsOf = resolvePermissionsOf; -const hasPermissionFor = (flag, permissions) => (permissions & flag) === flag; -exports.hasPermissionFor = hasPermissionFor; -function getDuration(start) { - const duration = performance.now() - start; - return `${duration.toFixed(2)}ms`; -} -exports.getDuration = getDuration; -function wrapDuration() { - const start = performance.now(); - return () => { - const end = performance.now(); - return (0, ms_1.default)(end - start); - }; -} -exports.wrapDuration = wrapDuration; -const randomHexInt = () => Math.floor(Math.random() * 0xffffff); -exports.randomHexInt = randomHexInt; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.randomHexInt = exports.wrapDuration = exports.getDuration = exports.hasPermissionFor = exports.resolvePermissionsOf = void 0; +const ms_1 = __importDefault(__nccwpck_require__(7026)); +const resolvePermissionsOf = (roles) => roles.reduce((acc, role) => acc | Number(role.permissions), 0); +exports.resolvePermissionsOf = resolvePermissionsOf; +const hasPermissionFor = (flag, permissions) => (permissions & flag) === flag; +exports.hasPermissionFor = hasPermissionFor; +function getDuration(start) { + const duration = performance.now() - start; + return `${duration.toFixed(2)}ms`; +} +exports.getDuration = getDuration; +function wrapDuration() { + const start = performance.now(); + return () => { + const end = performance.now(); + return (0, ms_1.default)(end - start); + }; +} +exports.wrapDuration = wrapDuration; +const randomHexInt = () => Math.floor(Math.random() * 0xffffff); +exports.randomHexInt = randomHexInt; /***/ }), @@ -383,7 +383,6 @@ const file_command_1 = __nccwpck_require__(717); const utils_1 = __nccwpck_require__(5278); const os = __importStar(__nccwpck_require__(2037)); const path = __importStar(__nccwpck_require__(1017)); -const uuid_1 = __nccwpck_require__(5840); const oidc_utils_1 = __nccwpck_require__(8041); /** * The code to exit an action @@ -413,20 +412,9 @@ function exportVariable(name, val) { process.env[name] = convertedVal; const filePath = process.env['GITHUB_ENV'] || ''; if (filePath) { - const delimiter = `ghadelimiter_${uuid_1.v4()}`; - // These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter. - if (name.includes(delimiter)) { - throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`); - } - if (convertedVal.includes(delimiter)) { - throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); - } - const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`; - file_command_1.issueCommand('ENV', commandValue); - } - else { - command_1.issueCommand('set-env', { name }, convertedVal); + return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val)); } + command_1.issueCommand('set-env', { name }, convertedVal); } exports.exportVariable = exportVariable; /** @@ -444,7 +432,7 @@ exports.setSecret = setSecret; function addPath(inputPath) { const filePath = process.env['GITHUB_PATH'] || ''; if (filePath) { - file_command_1.issueCommand('PATH', inputPath); + file_command_1.issueFileCommand('PATH', inputPath); } else { command_1.issueCommand('add-path', {}, inputPath); @@ -484,7 +472,10 @@ function getMultilineInput(name, options) { const inputs = getInput(name, options) .split('\n') .filter(x => x !== ''); - return inputs; + if (options && options.trimWhitespace === false) { + return inputs; + } + return inputs.map(input => input.trim()); } exports.getMultilineInput = getMultilineInput; /** @@ -517,8 +508,12 @@ exports.getBooleanInput = getBooleanInput; */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function setOutput(name, value) { + const filePath = process.env['GITHUB_OUTPUT'] || ''; + if (filePath) { + return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value)); + } process.stdout.write(os.EOL); - command_1.issueCommand('set-output', { name }, value); + command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value)); } exports.setOutput = setOutput; /** @@ -647,7 +642,11 @@ exports.group = group; */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function saveState(name, value) { - command_1.issueCommand('save-state', { name }, value); + const filePath = process.env['GITHUB_STATE'] || ''; + if (filePath) { + return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value)); + } + command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value)); } exports.saveState = saveState; /** @@ -713,13 +712,14 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.issueCommand = void 0; +exports.prepareKeyValueMessage = exports.issueFileCommand = void 0; // We use any as a valid input type /* eslint-disable @typescript-eslint/no-explicit-any */ const fs = __importStar(__nccwpck_require__(7147)); const os = __importStar(__nccwpck_require__(2037)); +const uuid_1 = __nccwpck_require__(5840); const utils_1 = __nccwpck_require__(5278); -function issueCommand(command, message) { +function issueFileCommand(command, message) { const filePath = process.env[`GITHUB_${command}`]; if (!filePath) { throw new Error(`Unable to find environment variable for file command ${command}`); @@ -731,7 +731,22 @@ function issueCommand(command, message) { encoding: 'utf8' }); } -exports.issueCommand = issueCommand; +exports.issueFileCommand = issueFileCommand; +function prepareKeyValueMessage(key, value) { + const delimiter = `ghadelimiter_${uuid_1.v4()}`; + const convertedValue = utils_1.toCommandValue(value); + // These should realistically never happen, but just in case someone finds a + // way to exploit uuid generation let's not allow keys or values that contain + // the delimiter. + if (key.includes(delimiter)) { + throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`); + } + if (convertedValue.includes(delimiter)) { + throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); + } + return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`; +} +exports.prepareKeyValueMessage = prepareKeyValueMessage; //# sourceMappingURL=file-command.js.map /***/ }), @@ -1990,4448 +2005,5366 @@ exports.checkBypass = checkBypass; /***/ }), -/***/ 5429: -/***/ ((__unused_webpack_module, exports) => { +/***/ 8861: +/***/ ((module) => { "use strict"; -Object.defineProperty(exports, "__esModule", ({ value: true })); -//# sourceMappingURL=common.js.map - -/***/ }), - -/***/ 1820: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); -"use strict"; +// src/index.ts +var src_exports = {}; +__export(src_exports, { + Collection: () => Collection, + version: () => version +}); +module.exports = __toCommonJS(src_exports); -/** - * Types extracted from https://discord.com/developers/docs/topics/gateway - */ -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; +// src/collection.ts +var Collection = class extends Map { + /** + * Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator. + * + * @param key - The key to get if it exists, or set otherwise + * @param defaultValueGenerator - A function that generates the default value + * @example + * ```ts + * collection.ensure(guildId, () => defaultGuildConfig); + * ``` + */ + ensure(key, defaultValueGenerator) { + if (this.has(key)) + return this.get(key); + if (typeof defaultValueGenerator !== "function") + throw new TypeError(`${defaultValueGenerator} is not a function`); + const defaultValue = defaultValueGenerator(key, this); + this.set(key, defaultValue); + return defaultValue; + } + /** + * Checks if all of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if all of the elements exist, `false` if at least one does not exist. + */ + hasAll(...keys) { + return keys.every((key) => super.has(key)); + } + /** + * Checks if any of the elements exist in the collection. + * + * @param keys - The keys of the elements to check for + * @returns `true` if any of the elements exist, `false` if none exist. + */ + hasAny(...keys) { + return keys.some((key) => super.has(key)); + } + first(amount) { + if (amount === void 0) + return this.values().next().value; + if (amount < 0) + return this.last(amount * -1); + amount = Math.min(this.size, amount); + const iter = this.values(); + return Array.from({ length: amount }, () => iter.next().value); + } + firstKey(amount) { + if (amount === void 0) + return this.keys().next().value; + if (amount < 0) + return this.lastKey(amount * -1); + amount = Math.min(this.size, amount); + const iter = this.keys(); + return Array.from({ length: amount }, () => iter.next().value); + } + last(amount) { + const arr = [...this.values()]; + if (amount === void 0) + return arr[arr.length - 1]; + if (amount < 0) + return this.first(amount * -1); + if (!amount) + return []; + return arr.slice(-amount); + } + lastKey(amount) { + const arr = [...this.keys()]; + if (amount === void 0) + return arr[arr.length - 1]; + if (amount < 0) + return this.firstKey(amount * -1); + if (!amount) + return []; + return arr.slice(-amount); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the item at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the element to obtain + */ + at(index) { + index = Math.floor(index); + const arr = [...this.values()]; + return arr.at(index); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at | Array.at()}. + * Returns the key at a given index, allowing for positive and negative integers. + * Negative integers count back from the last item in the collection. + * + * @param index - The index of the key to obtain + */ + keyAt(index) { + index = Math.floor(index); + const arr = [...this.keys()]; + return arr.at(index); + } + random(amount) { + const arr = [...this.values()]; + if (amount === void 0) + return arr[Math.floor(Math.random() * arr.length)]; + if (!arr.length || !amount) + return []; + return Array.from( + { length: Math.min(amount, arr.length) }, + () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0] + ); + } + randomKey(amount) { + const arr = [...this.keys()]; + if (amount === void 0) + return arr[Math.floor(Math.random() * arr.length)]; + if (!arr.length || !amount) + return []; + return Array.from( + { length: Math.min(amount, arr.length) }, + () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0] + ); + } + /** + * Identical to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse | Array.reverse()} + * but returns a Collection instead of an Array. + */ + reverse() { + const entries = [...this.entries()].reverse(); + this.clear(); + for (const [key, value] of entries) + this.set(key, value); + return this; + } + find(fn, thisArg) { + if (typeof fn !== "function") + throw new TypeError(`${fn} is not a function`); + if (thisArg !== void 0) + fn = fn.bind(thisArg); + for (const [key, val] of this) { + if (fn(val, key, this)) + return val; } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.GatewayDispatchEvents = exports.GatewayIntentBits = exports.GatewayCloseCodes = exports.GatewayOpcodes = exports.GatewayVersion = void 0; -__exportStar(__nccwpck_require__(5429), exports); -exports.GatewayVersion = '10'; -/** - * https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes - */ -var GatewayOpcodes; -(function (GatewayOpcodes) { - /** - * An event was dispatched - */ - GatewayOpcodes[GatewayOpcodes["Dispatch"] = 0] = "Dispatch"; - /** - * A bidirectional opcode to maintain an active gateway connection. - * Fired periodically by the client, or fired by the gateway to request an immediate heartbeat from the client. - */ - GatewayOpcodes[GatewayOpcodes["Heartbeat"] = 1] = "Heartbeat"; - /** - * Starts a new session during the initial handshake - */ - GatewayOpcodes[GatewayOpcodes["Identify"] = 2] = "Identify"; - /** - * Update the client's presence - */ - GatewayOpcodes[GatewayOpcodes["PresenceUpdate"] = 3] = "PresenceUpdate"; - /** - * Used to join/leave or move between voice channels - */ - GatewayOpcodes[GatewayOpcodes["VoiceStateUpdate"] = 4] = "VoiceStateUpdate"; - /** - * Resume a previous session that was disconnected - */ - GatewayOpcodes[GatewayOpcodes["Resume"] = 6] = "Resume"; - /** - * You should attempt to reconnect and resume immediately - */ - GatewayOpcodes[GatewayOpcodes["Reconnect"] = 7] = "Reconnect"; - /** - * Request information about offline guild members in a large guild - */ - GatewayOpcodes[GatewayOpcodes["RequestGuildMembers"] = 8] = "RequestGuildMembers"; - /** - * The session has been invalidated. You should reconnect and identify/resume accordingly - */ - GatewayOpcodes[GatewayOpcodes["InvalidSession"] = 9] = "InvalidSession"; - /** - * Sent immediately after connecting, contains the `heartbeat_interval` to use - */ - GatewayOpcodes[GatewayOpcodes["Hello"] = 10] = "Hello"; - /** - * Sent in response to receiving a heartbeat to acknowledge that it has been received - */ - GatewayOpcodes[GatewayOpcodes["HeartbeatAck"] = 11] = "HeartbeatAck"; -})(GatewayOpcodes = exports.GatewayOpcodes || (exports.GatewayOpcodes = {})); -/** - * https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes - */ -var GatewayCloseCodes; -(function (GatewayCloseCodes) { - /** - * We're not sure what went wrong. Try reconnecting? - */ - GatewayCloseCodes[GatewayCloseCodes["UnknownError"] = 4000] = "UnknownError"; - /** - * You sent an invalid Gateway opcode or an invalid payload for an opcode. Don't do that! - * - * See https://discord.com/developers/docs/topics/gateway#payloads-and-opcodes - */ - GatewayCloseCodes[GatewayCloseCodes["UnknownOpcode"] = 4001] = "UnknownOpcode"; - /** - * You sent an invalid payload to us. Don't do that! - * - * See https://discord.com/developers/docs/topics/gateway#sending-payloads - */ - GatewayCloseCodes[GatewayCloseCodes["DecodeError"] = 4002] = "DecodeError"; - /** - * You sent us a payload prior to identifying - * - * See https://discord.com/developers/docs/topics/gateway#identify - */ - GatewayCloseCodes[GatewayCloseCodes["NotAuthenticated"] = 4003] = "NotAuthenticated"; - /** - * The account token sent with your identify payload is incorrect - * - * See https://discord.com/developers/docs/topics/gateway#identify - */ - GatewayCloseCodes[GatewayCloseCodes["AuthenticationFailed"] = 4004] = "AuthenticationFailed"; - /** - * You sent more than one identify payload. Don't do that! - */ - GatewayCloseCodes[GatewayCloseCodes["AlreadyAuthenticated"] = 4005] = "AlreadyAuthenticated"; - /** - * The sequence sent when resuming the session was invalid. Reconnect and start a new session - * - * See https://discord.com/developers/docs/topics/gateway#resume - */ - GatewayCloseCodes[GatewayCloseCodes["InvalidSeq"] = 4007] = "InvalidSeq"; - /** - * Woah nelly! You're sending payloads to us too quickly. Slow it down! You will be disconnected on receiving this - */ - GatewayCloseCodes[GatewayCloseCodes["RateLimited"] = 4008] = "RateLimited"; - /** - * Your session timed out. Reconnect and start a new one - */ - GatewayCloseCodes[GatewayCloseCodes["SessionTimedOut"] = 4009] = "SessionTimedOut"; - /** - * You sent us an invalid shard when identifying - * - * See https://discord.com/developers/docs/topics/gateway#sharding - */ - GatewayCloseCodes[GatewayCloseCodes["InvalidShard"] = 4010] = "InvalidShard"; - /** - * The session would have handled too many guilds - you are required to shard your connection in order to connect - * - * See https://discord.com/developers/docs/topics/gateway#sharding - */ - GatewayCloseCodes[GatewayCloseCodes["ShardingRequired"] = 4011] = "ShardingRequired"; - /** - * You sent an invalid version for the gateway - */ - GatewayCloseCodes[GatewayCloseCodes["InvalidAPIVersion"] = 4012] = "InvalidAPIVersion"; - /** - * You sent an invalid intent for a Gateway Intent. You may have incorrectly calculated the bitwise value - * - * See https://discord.com/developers/docs/topics/gateway#gateway-intents - */ - GatewayCloseCodes[GatewayCloseCodes["InvalidIntents"] = 4013] = "InvalidIntents"; - /** - * You sent a disallowed intent for a Gateway Intent. You may have tried to specify an intent that you have not - * enabled or are not whitelisted for - * - * See https://discord.com/developers/docs/topics/gateway#gateway-intents - * - * See https://discord.com/developers/docs/topics/gateway#privileged-intents - */ - GatewayCloseCodes[GatewayCloseCodes["DisallowedIntents"] = 4014] = "DisallowedIntents"; -})(GatewayCloseCodes = exports.GatewayCloseCodes || (exports.GatewayCloseCodes = {})); -/** - * https://discord.com/developers/docs/topics/gateway#list-of-intents - */ -var GatewayIntentBits; -(function (GatewayIntentBits) { - GatewayIntentBits[GatewayIntentBits["Guilds"] = 1] = "Guilds"; - GatewayIntentBits[GatewayIntentBits["GuildMembers"] = 2] = "GuildMembers"; - GatewayIntentBits[GatewayIntentBits["GuildBans"] = 4] = "GuildBans"; - GatewayIntentBits[GatewayIntentBits["GuildEmojisAndStickers"] = 8] = "GuildEmojisAndStickers"; - GatewayIntentBits[GatewayIntentBits["GuildIntegrations"] = 16] = "GuildIntegrations"; - GatewayIntentBits[GatewayIntentBits["GuildWebhooks"] = 32] = "GuildWebhooks"; - GatewayIntentBits[GatewayIntentBits["GuildInvites"] = 64] = "GuildInvites"; - GatewayIntentBits[GatewayIntentBits["GuildVoiceStates"] = 128] = "GuildVoiceStates"; - GatewayIntentBits[GatewayIntentBits["GuildPresences"] = 256] = "GuildPresences"; - GatewayIntentBits[GatewayIntentBits["GuildMessages"] = 512] = "GuildMessages"; - GatewayIntentBits[GatewayIntentBits["GuildMessageReactions"] = 1024] = "GuildMessageReactions"; - GatewayIntentBits[GatewayIntentBits["GuildMessageTyping"] = 2048] = "GuildMessageTyping"; - GatewayIntentBits[GatewayIntentBits["DirectMessages"] = 4096] = "DirectMessages"; - GatewayIntentBits[GatewayIntentBits["DirectMessageReactions"] = 8192] = "DirectMessageReactions"; - GatewayIntentBits[GatewayIntentBits["DirectMessageTyping"] = 16384] = "DirectMessageTyping"; - GatewayIntentBits[GatewayIntentBits["MessageContent"] = 32768] = "MessageContent"; - GatewayIntentBits[GatewayIntentBits["GuildScheduledEvents"] = 65536] = "GuildScheduledEvents"; -})(GatewayIntentBits = exports.GatewayIntentBits || (exports.GatewayIntentBits = {})); -/** - * https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events - */ -var GatewayDispatchEvents; -(function (GatewayDispatchEvents) { - GatewayDispatchEvents["ApplicationCommandPermissionsUpdate"] = "APPLICATION_COMMAND_PERMISSIONS_UPDATE"; - GatewayDispatchEvents["ChannelCreate"] = "CHANNEL_CREATE"; - GatewayDispatchEvents["ChannelDelete"] = "CHANNEL_DELETE"; - GatewayDispatchEvents["ChannelPinsUpdate"] = "CHANNEL_PINS_UPDATE"; - GatewayDispatchEvents["ChannelUpdate"] = "CHANNEL_UPDATE"; - GatewayDispatchEvents["GuildBanAdd"] = "GUILD_BAN_ADD"; - GatewayDispatchEvents["GuildBanRemove"] = "GUILD_BAN_REMOVE"; - GatewayDispatchEvents["GuildCreate"] = "GUILD_CREATE"; - GatewayDispatchEvents["GuildDelete"] = "GUILD_DELETE"; - GatewayDispatchEvents["GuildEmojisUpdate"] = "GUILD_EMOJIS_UPDATE"; - GatewayDispatchEvents["GuildIntegrationsUpdate"] = "GUILD_INTEGRATIONS_UPDATE"; - GatewayDispatchEvents["GuildMemberAdd"] = "GUILD_MEMBER_ADD"; - GatewayDispatchEvents["GuildMemberRemove"] = "GUILD_MEMBER_REMOVE"; - GatewayDispatchEvents["GuildMembersChunk"] = "GUILD_MEMBERS_CHUNK"; - GatewayDispatchEvents["GuildMemberUpdate"] = "GUILD_MEMBER_UPDATE"; - GatewayDispatchEvents["GuildRoleCreate"] = "GUILD_ROLE_CREATE"; - GatewayDispatchEvents["GuildRoleDelete"] = "GUILD_ROLE_DELETE"; - GatewayDispatchEvents["GuildRoleUpdate"] = "GUILD_ROLE_UPDATE"; - GatewayDispatchEvents["GuildStickersUpdate"] = "GUILD_STICKERS_UPDATE"; - GatewayDispatchEvents["GuildUpdate"] = "GUILD_UPDATE"; - GatewayDispatchEvents["IntegrationCreate"] = "INTEGRATION_CREATE"; - GatewayDispatchEvents["IntegrationDelete"] = "INTEGRATION_DELETE"; - GatewayDispatchEvents["IntegrationUpdate"] = "INTEGRATION_UPDATE"; - GatewayDispatchEvents["InteractionCreate"] = "INTERACTION_CREATE"; - GatewayDispatchEvents["InviteCreate"] = "INVITE_CREATE"; - GatewayDispatchEvents["InviteDelete"] = "INVITE_DELETE"; - GatewayDispatchEvents["MessageCreate"] = "MESSAGE_CREATE"; - GatewayDispatchEvents["MessageDelete"] = "MESSAGE_DELETE"; - GatewayDispatchEvents["MessageDeleteBulk"] = "MESSAGE_DELETE_BULK"; - GatewayDispatchEvents["MessageReactionAdd"] = "MESSAGE_REACTION_ADD"; - GatewayDispatchEvents["MessageReactionRemove"] = "MESSAGE_REACTION_REMOVE"; - GatewayDispatchEvents["MessageReactionRemoveAll"] = "MESSAGE_REACTION_REMOVE_ALL"; - GatewayDispatchEvents["MessageReactionRemoveEmoji"] = "MESSAGE_REACTION_REMOVE_EMOJI"; - GatewayDispatchEvents["MessageUpdate"] = "MESSAGE_UPDATE"; - GatewayDispatchEvents["PresenceUpdate"] = "PRESENCE_UPDATE"; - GatewayDispatchEvents["StageInstanceCreate"] = "STAGE_INSTANCE_CREATE"; - GatewayDispatchEvents["StageInstanceDelete"] = "STAGE_INSTANCE_DELETE"; - GatewayDispatchEvents["StageInstanceUpdate"] = "STAGE_INSTANCE_UPDATE"; - GatewayDispatchEvents["Ready"] = "READY"; - GatewayDispatchEvents["Resumed"] = "RESUMED"; - GatewayDispatchEvents["ThreadCreate"] = "THREAD_CREATE"; - GatewayDispatchEvents["ThreadDelete"] = "THREAD_DELETE"; - GatewayDispatchEvents["ThreadListSync"] = "THREAD_LIST_SYNC"; - GatewayDispatchEvents["ThreadMembersUpdate"] = "THREAD_MEMBERS_UPDATE"; - GatewayDispatchEvents["ThreadMemberUpdate"] = "THREAD_MEMBER_UPDATE"; - GatewayDispatchEvents["ThreadUpdate"] = "THREAD_UPDATE"; - GatewayDispatchEvents["TypingStart"] = "TYPING_START"; - GatewayDispatchEvents["UserUpdate"] = "USER_UPDATE"; - GatewayDispatchEvents["VoiceServerUpdate"] = "VOICE_SERVER_UPDATE"; - GatewayDispatchEvents["VoiceStateUpdate"] = "VOICE_STATE_UPDATE"; - GatewayDispatchEvents["WebhooksUpdate"] = "WEBHOOKS_UPDATE"; - GatewayDispatchEvents["GuildScheduledEventCreate"] = "GUILD_SCHEDULED_EVENT_CREATE"; - GatewayDispatchEvents["GuildScheduledEventUpdate"] = "GUILD_SCHEDULED_EVENT_UPDATE"; - GatewayDispatchEvents["GuildScheduledEventDelete"] = "GUILD_SCHEDULED_EVENT_DELETE"; - GatewayDispatchEvents["GuildScheduledEventUserAdd"] = "GUILD_SCHEDULED_EVENT_USER_ADD"; - GatewayDispatchEvents["GuildScheduledEventUserRemove"] = "GUILD_SCHEDULED_EVENT_USER_REMOVE"; -})(GatewayDispatchEvents = exports.GatewayDispatchEvents || (exports.GatewayDispatchEvents = {})); -// #endregion Shared -//# sourceMappingURL=v10.js.map - -/***/ }), - -/***/ 279: -/***/ ((__unused_webpack_module, exports) => { - -"use strict"; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.FormattingPatterns = void 0; -/** - * https://discord.com/developers/docs/reference#message-formatting-formats - */ -exports.FormattingPatterns = { - /** - * Regular expression for matching a user mention, strictly without a nickname - * - * The `id` group property is present on the `exec` result of this expression - */ - User: /<@(?\d{17,20})>/, - /** - * Regular expression for matching a user mention, strictly with a nickname - * - * The `id` group property is present on the `exec` result of this expression - * @deprecated Passing `!` in user mentions is no longer necessary / supported, and future message contents won't have it - */ - UserWithNickname: /<@!(?\d{17,20})>/, - /** - * Regular expression for matching a user mention, with or without a nickname - * - * The `id` group property is present on the `exec` result of this expression - * @deprecated Passing `!` in user mentions is no longer necessary / supported, and future message contents won't have it - */ - UserWithOptionalNickname: /<@!?(?\d{17,20})>/, - /** - * Regular expression for matching a channel mention - * - * The `id` group property is present on the `exec` result of this expression - */ - Channel: /<#(?\d{17,20})>/, - /** - * Regular expression for matching a role mention - * - * The `id` group property is present on the `exec` result of this expression - */ - Role: /<@&(?\d{17,20})>/, - /** - * Regular expression for matching a application command mention - * - * The `fullName` (possibly including `name`, `subcommandOrGroup` and `subcommand`) and `id` group properties are present on the `exec` result of this expression - */ - SlashCommand: /<\/(?(?[\w-]{1,32})(?: (?[\w-]{1,32}))?(?: (?[\w-]{1,32}))?):(?\d{17,20})>/, - /** - * Regular expression for matching a custom emoji, either static or animated - * - * The `animated`, `name` and `id` group properties are present on the `exec` result of this expression - */ - Emoji: /<(?a)?:(?\w{2,32}):(?\d{17,20})>/, - /** - * Regular expression for matching strictly an animated custom emoji - * - * The `animated`, `name` and `id` group properties are present on the `exec` result of this expression - */ - AnimatedEmoji: /<(?a):(?\w{2,32}):(?\d{17,20})>/, - /** - * Regular expression for matching strictly a static custom emoji - * - * The `name` and `id` group properties are present on the `exec` result of this expression - */ - StaticEmoji: /<:(?\w{2,32}):(?\d{17,20})>/, - /** - * Regular expression for matching a timestamp, either default or custom styled - * - * The `timestamp` and `style` group properties are present on the `exec` result of this expression - */ - Timestamp: /-?\d{1,13})(:(?