mirror of
https://gitlab.com/upRootNutrition/zookeeper.git
synced 2025-06-16 02:15:12 -05:00
feat: init
This commit is contained in:
parent
8379d09058
commit
2cfa016090
2929 changed files with 299087 additions and 3 deletions
191
node_modules/discord.js/LICENSE
generated
vendored
Normal file
191
node_modules/discord.js/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,191 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2021 Noel Buechler
|
||||
Copyright 2015 Amish Shah
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
144
node_modules/discord.js/README.md
generated
vendored
Normal file
144
node_modules/discord.js/README.md
generated
vendored
Normal file
|
@ -0,0 +1,144 @@
|
|||
<div align="center">
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/v/discord.js.svg?maxAge=3600" alt="npm version" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/dt/discord.js.svg?maxAge=3600" alt="npm downloads" /></a>
|
||||
<a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Tests status" /></a>
|
||||
<a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2" alt="Code coverage" /></a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a>
|
||||
<a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## About
|
||||
|
||||
discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to easily interact with the
|
||||
[Discord API](https://discord.com/developers/docs/intro).
|
||||
|
||||
- Object-oriented
|
||||
- Predictable abstractions
|
||||
- Performant
|
||||
- 100% coverage of the Discord API
|
||||
|
||||
## Installation
|
||||
|
||||
**Node.js 16.11.0 or newer is required.**
|
||||
|
||||
```sh
|
||||
npm install discord.js
|
||||
yarn add discord.js
|
||||
pnpm add discord.js
|
||||
bun add discord.js
|
||||
```
|
||||
|
||||
### Optional packages
|
||||
|
||||
- [zlib-sync](https://www.npmjs.com/package/zlib-sync) for WebSocket data compression and inflation (`npm install zlib-sync`)
|
||||
- [bufferutil](https://www.npmjs.com/package/bufferutil) for a much faster WebSocket connection (`npm install bufferutil`)
|
||||
- [utf-8-validate](https://www.npmjs.com/package/utf-8-validate) in combination with `bufferutil` for much faster WebSocket processing (`npm install utf-8-validate`)
|
||||
- [@discordjs/voice](https://www.npmjs.com/package/@discordjs/voice) for interacting with the Discord Voice API (`npm install @discordjs/voice`)
|
||||
|
||||
## Example usage
|
||||
|
||||
Install discord.js:
|
||||
|
||||
```sh
|
||||
npm install discord.js
|
||||
yarn add discord.js
|
||||
pnpm add discord.js
|
||||
bun add discord.js
|
||||
```
|
||||
|
||||
Register a slash command against the Discord API:
|
||||
|
||||
```js
|
||||
import { REST, Routes } from 'discord.js';
|
||||
|
||||
const commands = [
|
||||
{
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong!',
|
||||
},
|
||||
];
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(TOKEN);
|
||||
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
```
|
||||
|
||||
Afterwards we can create a quite simple example bot:
|
||||
|
||||
```js
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
if (interaction.commandName === 'ping') {
|
||||
await interaction.reply('Pong!');
|
||||
}
|
||||
});
|
||||
|
||||
client.login(TOKEN);
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
- [Website][website] ([source][website-source])
|
||||
- [Documentation][documentation]
|
||||
- [Guide][guide] ([source][guide-source])
|
||||
Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library.
|
||||
- [discord.js Discord server][discord]
|
||||
- [Discord API Discord server][discord-api]
|
||||
- [GitHub][source]
|
||||
- [npm][npm]
|
||||
- [Related libraries][related-libs]
|
||||
|
||||
### Extensions
|
||||
|
||||
- [RPC][rpc] ([source][rpc-source])
|
||||
|
||||
## Contributing
|
||||
|
||||
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
||||
[documentation][documentation].
|
||||
See [the contribution guide][contributing] if you'd like to submit a PR.
|
||||
|
||||
## Help
|
||||
|
||||
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord].
|
||||
|
||||
[website]: https://discord.js.org
|
||||
[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website
|
||||
[documentation]: https://discord.js.org/docs/packages/discord.js/stable
|
||||
[guide]: https://discordjs.guide/
|
||||
[guide-source]: https://github.com/discordjs/guide
|
||||
[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html
|
||||
[discord]: https://discord.gg/djs
|
||||
[discord-api]: https://discord.gg/discord-api
|
||||
[source]: https://github.com/discordjs/discord.js/tree/main/packages/discord.js
|
||||
[npm]: https://www.npmjs.com/package/discord.js
|
||||
[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries
|
||||
[rpc]: https://www.npmjs.com/package/discord-rpc
|
||||
[rpc-source]: https://github.com/discordjs/RPC
|
||||
[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md
|
105
node_modules/discord.js/package.json
generated
vendored
Normal file
105
node_modules/discord.js/package.json
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "discord.js",
|
||||
"version": "14.15.2",
|
||||
"description": "A powerful library for interacting with the Discord API",
|
||||
"main": "./src/index.js",
|
||||
"types": "./typings/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./typings/index.d.mts",
|
||||
"default": "./src/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./typings/index.d.ts",
|
||||
"default": "./src/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"typings"
|
||||
],
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Aura Román <kyradiscord@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"discord",
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordapp"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git",
|
||||
"directory": "packages/discord.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "1.5.3",
|
||||
"@sapphire/snowflake": "3.5.3",
|
||||
"discord-api-types": "0.37.83",
|
||||
"fast-deep-equal": "3.1.3",
|
||||
"lodash.snakecase": "4.1.1",
|
||||
"tslib": "2.6.2",
|
||||
"undici": "6.13.0",
|
||||
"@discordjs/builders": "^1.8.1",
|
||||
"@discordjs/rest": "^2.3.0",
|
||||
"@discordjs/formatters": "^0.4.0",
|
||||
"@discordjs/util": "^1.1.0",
|
||||
"@discordjs/ws": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@favware/cliff-jumper": "3.0.2",
|
||||
"@types/node": "16.18.60",
|
||||
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
||||
"@typescript-eslint/parser": "^7.7.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"dtslint": "4.2.1",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-formatter-pretty": "5.0.0",
|
||||
"jest": "29.7.0",
|
||||
"prettier": "3.2.5",
|
||||
"tsd": "0.30.7",
|
||||
"tslint": "6.1.3",
|
||||
"turbo": "^1.13.2",
|
||||
"typescript": "5.4.5",
|
||||
"@discordjs/docgen": "^0.12.1",
|
||||
"@discordjs/scripts": "^0.1.0",
|
||||
"@discordjs/api-extractor": "^7.38.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.11.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"provenance": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "pnpm run docs:test && pnpm run test:typescript",
|
||||
"test:typescript": "tsc --noEmit && tsd",
|
||||
"lint": "prettier --check . && tslint typings/index.d.ts && cross-env ESLINT_USE_FLAT_CONFIG=false eslint --format=pretty src typings",
|
||||
"format": "prettier --write . && cross-env ESLINT_USE_FLAT_CONFIG=false eslint --fix --format=pretty src",
|
||||
"fmt": "pnpm run format",
|
||||
"docs": "docgen -i \"./src/*.js\" \"./src/**/*.js\" -c ./docs/index.json -r ../../ -o ./docs/docs.json && pnpm run docs:new",
|
||||
"docs:test": "docgen -i \"./src/*.js\" \"./src/**/*.js\" -c ./docs/index.json -r ../../",
|
||||
"docs:new": "api-extractor run --local --minify && generate-split-documentation",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/discord.js/*'",
|
||||
"release": "cliff-jumper"
|
||||
}
|
||||
}
|
120
node_modules/discord.js/src/client/BaseClient.js
generated
vendored
Normal file
120
node_modules/discord.js/src/client/BaseClient.js
generated
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
'use strict';
|
||||
|
||||
const EventEmitter = require('node:events');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v10');
|
||||
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
||||
const Options = require('../util/Options');
|
||||
const { flatten } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* The base class for all clients.
|
||||
* @extends {EventEmitter}
|
||||
*/
|
||||
class BaseClient extends EventEmitter {
|
||||
constructor(options = {}) {
|
||||
super({ captureRejections: true });
|
||||
|
||||
if (typeof options !== 'object' || options === null) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
|
||||
}
|
||||
|
||||
const defaultOptions = Options.createDefault();
|
||||
/**
|
||||
* The options the client was instantiated with
|
||||
* @type {ClientOptions}
|
||||
*/
|
||||
this.options = {
|
||||
...defaultOptions,
|
||||
...options,
|
||||
presence: {
|
||||
...defaultOptions.presence,
|
||||
...options.presence,
|
||||
},
|
||||
sweepers: {
|
||||
...defaultOptions.sweepers,
|
||||
...options.sweepers,
|
||||
},
|
||||
ws: {
|
||||
...defaultOptions.ws,
|
||||
...options.ws,
|
||||
},
|
||||
rest: {
|
||||
...defaultOptions.rest,
|
||||
...options.rest,
|
||||
userAgentAppendix: options.rest?.userAgentAppendix
|
||||
? `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}`
|
||||
: Options.userAgentAppendix,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* The REST manager of the client
|
||||
* @type {REST}
|
||||
*/
|
||||
this.rest = new REST(this.options.rest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys all assets used by the base client.
|
||||
* @returns {void}
|
||||
*/
|
||||
destroy() {
|
||||
this.rest.clearHashSweeper();
|
||||
this.rest.clearHandlerSweeper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Options used for deleting a webhook.
|
||||
* @typedef {Object} WebhookDeleteOptions
|
||||
* @property {string} [token] Token of the webhook
|
||||
* @property {string} [reason] The reason for deleting the webhook
|
||||
*/
|
||||
|
||||
/**
|
||||
* Deletes a webhook.
|
||||
* @param {Snowflake} id The webhook's id
|
||||
* @param {WebhookDeleteOptions} [options] Options for deleting the webhook
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async deleteWebhook(id, { token, reason } = {}) {
|
||||
await this.rest.delete(Routes.webhook(id, token), { auth: !token, reason });
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments max listeners by one, if they are not zero.
|
||||
* @private
|
||||
*/
|
||||
incrementMaxListeners() {
|
||||
const maxListeners = this.getMaxListeners();
|
||||
if (maxListeners !== 0) {
|
||||
this.setMaxListeners(maxListeners + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements max listeners by one, if they are not zero.
|
||||
* @private
|
||||
*/
|
||||
decrementMaxListeners() {
|
||||
const maxListeners = this.getMaxListeners();
|
||||
if (maxListeners !== 0) {
|
||||
this.setMaxListeners(maxListeners - 1);
|
||||
}
|
||||
}
|
||||
|
||||
toJSON(...props) {
|
||||
return flatten(this, ...props);
|
||||
}
|
||||
|
||||
async [Symbol.asyncDispose]() {
|
||||
await this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseClient;
|
||||
|
||||
/**
|
||||
* @external REST
|
||||
* @see {@link https://discord.js.org/docs/packages/rest/stable/REST:Class}
|
||||
*/
|
611
node_modules/discord.js/src/client/Client.js
generated
vendored
Normal file
611
node_modules/discord.js/src/client/Client.js
generated
vendored
Normal file
|
@ -0,0 +1,611 @@
|
|||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { makeURLSearchParams } = require('@discordjs/rest');
|
||||
const { OAuth2Scopes, Routes } = require('discord-api-types/v10');
|
||||
const BaseClient = require('./BaseClient');
|
||||
const ActionsManager = require('./actions/ActionsManager');
|
||||
const ClientVoiceManager = require('./voice/ClientVoiceManager');
|
||||
const WebSocketManager = require('./websocket/WebSocketManager');
|
||||
const { DiscordjsError, DiscordjsTypeError, DiscordjsRangeError, ErrorCodes } = require('../errors');
|
||||
const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager');
|
||||
const ChannelManager = require('../managers/ChannelManager');
|
||||
const GuildManager = require('../managers/GuildManager');
|
||||
const UserManager = require('../managers/UserManager');
|
||||
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
||||
const ClientPresence = require('../structures/ClientPresence');
|
||||
const GuildPreview = require('../structures/GuildPreview');
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
const Invite = require('../structures/Invite');
|
||||
const { Sticker } = require('../structures/Sticker');
|
||||
const StickerPack = require('../structures/StickerPack');
|
||||
const VoiceRegion = require('../structures/VoiceRegion');
|
||||
const Webhook = require('../structures/Webhook');
|
||||
const Widget = require('../structures/Widget');
|
||||
const { resolveInviteCode, resolveGuildTemplateCode } = require('../util/DataResolver');
|
||||
const Events = require('../util/Events');
|
||||
const IntentsBitField = require('../util/IntentsBitField');
|
||||
const Options = require('../util/Options');
|
||||
const PermissionsBitField = require('../util/PermissionsBitField');
|
||||
const Status = require('../util/Status');
|
||||
const Sweepers = require('../util/Sweepers');
|
||||
|
||||
let deprecationEmittedForPremiumStickerPacks = false;
|
||||
|
||||
/**
|
||||
* The main hub for interacting with the Discord API, and the starting point for any bot.
|
||||
* @extends {BaseClient}
|
||||
*/
|
||||
class Client extends BaseClient {
|
||||
/**
|
||||
* @param {ClientOptions} options Options for the client
|
||||
*/
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
const data = require('node:worker_threads').workerData ?? process.env;
|
||||
const defaults = Options.createDefault();
|
||||
|
||||
if (this.options.shards === defaults.shards) {
|
||||
if ('SHARDS' in data) {
|
||||
this.options.shards = JSON.parse(data.SHARDS);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.options.shardCount === defaults.shardCount) {
|
||||
if ('SHARD_COUNT' in data) {
|
||||
this.options.shardCount = Number(data.SHARD_COUNT);
|
||||
} else if (Array.isArray(this.options.shards)) {
|
||||
this.options.shardCount = this.options.shards.length;
|
||||
}
|
||||
}
|
||||
|
||||
const typeofShards = typeof this.options.shards;
|
||||
|
||||
if (typeofShards === 'undefined' && typeof this.options.shardCount === 'number') {
|
||||
this.options.shards = Array.from({ length: this.options.shardCount }, (_, i) => i);
|
||||
}
|
||||
|
||||
if (typeofShards === 'number') this.options.shards = [this.options.shards];
|
||||
|
||||
if (Array.isArray(this.options.shards)) {
|
||||
this.options.shards = [
|
||||
...new Set(
|
||||
this.options.shards.filter(item => !isNaN(item) && item >= 0 && item < Infinity && item === (item | 0)),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
this._validateOptions();
|
||||
|
||||
/**
|
||||
* The WebSocket manager of the client
|
||||
* @type {WebSocketManager}
|
||||
*/
|
||||
this.ws = new WebSocketManager(this);
|
||||
|
||||
/**
|
||||
* The action manager of the client
|
||||
* @type {ActionsManager}
|
||||
* @private
|
||||
*/
|
||||
this.actions = new ActionsManager(this);
|
||||
|
||||
/**
|
||||
* The voice manager of the client
|
||||
* @type {ClientVoiceManager}
|
||||
*/
|
||||
this.voice = new ClientVoiceManager(this);
|
||||
|
||||
/**
|
||||
* Shard helpers for the client (only if the process was spawned from a {@link ShardingManager})
|
||||
* @type {?ShardClientUtil}
|
||||
*/
|
||||
this.shard = process.env.SHARDING_MANAGER
|
||||
? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE)
|
||||
: null;
|
||||
|
||||
/**
|
||||
* All of the {@link User} objects that have been cached at any point, mapped by their ids
|
||||
* @type {UserManager}
|
||||
*/
|
||||
this.users = new UserManager(this);
|
||||
|
||||
/**
|
||||
* 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 {GuildManager}
|
||||
*/
|
||||
this.guilds = new GuildManager(this);
|
||||
|
||||
/**
|
||||
* All of the {@link BaseChannel}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 the bot
|
||||
* is a member of. Note that DM channels will not be initially cached, and thus not be present
|
||||
* in the Manager without their explicit fetching or use.
|
||||
* @type {ChannelManager}
|
||||
*/
|
||||
this.channels = new ChannelManager(this);
|
||||
|
||||
/**
|
||||
* The sweeping functions and their intervals used to periodically sweep caches
|
||||
* @type {Sweepers}
|
||||
*/
|
||||
this.sweepers = new Sweepers(this, this.options.sweepers);
|
||||
|
||||
/**
|
||||
* The presence of the Client
|
||||
* @private
|
||||
* @type {ClientPresence}
|
||||
*/
|
||||
this.presence = new ClientPresence(this, this.options.presence);
|
||||
|
||||
Object.defineProperty(this, 'token', { writable: true });
|
||||
if (!this.token && 'DISCORD_TOKEN' in process.env) {
|
||||
/**
|
||||
* Authorization token for the logged in bot.
|
||||
* If present, this defaults to `process.env.DISCORD_TOKEN` when instantiating the client
|
||||
* <warn>This should be kept private at all times.</warn>
|
||||
* @type {?string}
|
||||
*/
|
||||
this.token = process.env.DISCORD_TOKEN;
|
||||
} else {
|
||||
this.token = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* User that the client is logged in as
|
||||
* @type {?ClientUser}
|
||||
*/
|
||||
this.user = null;
|
||||
|
||||
/**
|
||||
* The application of this bot
|
||||
* @type {?ClientApplication}
|
||||
*/
|
||||
this.application = null;
|
||||
|
||||
/**
|
||||
* Timestamp of the time the client was last {@link Status.Ready} at
|
||||
* @type {?number}
|
||||
*/
|
||||
this.readyTimestamp = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* All custom emojis that the client has access to, mapped by their ids
|
||||
* @type {BaseGuildEmojiManager}
|
||||
* @readonly
|
||||
*/
|
||||
get emojis() {
|
||||
const emojis = new BaseGuildEmojiManager(this);
|
||||
for (const guild of this.guilds.cache.values()) {
|
||||
if (guild.available) for (const emoji of guild.emojis.cache.values()) emojis.cache.set(emoji.id, emoji);
|
||||
}
|
||||
return emojis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time at which the client was last regarded as being in the {@link Status.Ready} state
|
||||
* (each time the client disconnects and successfully reconnects, this will be overwritten)
|
||||
* @type {?Date}
|
||||
* @readonly
|
||||
*/
|
||||
get readyAt() {
|
||||
return this.readyTimestamp && new Date(this.readyTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it has been since the client last entered the {@link Status.Ready} state in milliseconds
|
||||
* @type {?number}
|
||||
* @readonly
|
||||
*/
|
||||
get uptime() {
|
||||
return this.readyTimestamp && Date.now() - this.readyTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the client in, establishing a WebSocket connection to Discord.
|
||||
* @param {string} [token=this.token] Token of the account to log in with
|
||||
* @returns {Promise<string>} Token of the account used
|
||||
* @example
|
||||
* client.login('my token');
|
||||
*/
|
||||
async login(token = this.token) {
|
||||
if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid);
|
||||
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
|
||||
this.rest.setToken(token);
|
||||
this.emit(Events.Debug, `Provided token: ${this._censoredToken}`);
|
||||
|
||||
if (this.options.presence) {
|
||||
this.options.ws.presence = this.presence._parse(this.options.presence);
|
||||
}
|
||||
|
||||
this.emit(Events.Debug, 'Preparing to connect to the gateway...');
|
||||
|
||||
try {
|
||||
await this.ws.connect();
|
||||
return this.token;
|
||||
} catch (error) {
|
||||
await this.destroy();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the client has logged in, indicative of being able to access
|
||||
* properties such as `user` and `application`.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isReady() {
|
||||
return !this.ws.destroyed && this.ws.status === Status.Ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out, terminates the connection to Discord, and destroys the client.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async destroy() {
|
||||
super.destroy();
|
||||
|
||||
this.sweepers.destroy();
|
||||
await this.ws.destroy();
|
||||
this.token = null;
|
||||
this.rest.setToken(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options used when fetching an invite from Discord.
|
||||
* @typedef {Object} ClientFetchInviteOptions
|
||||
* @property {Snowflake} [guildScheduledEventId] The id of the guild scheduled event to include with
|
||||
* the invite
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtains an invite from Discord.
|
||||
* @param {InviteResolvable} invite Invite code or URL
|
||||
* @param {ClientFetchInviteOptions} [options] Options for fetching the invite
|
||||
* @returns {Promise<Invite>}
|
||||
* @example
|
||||
* client.fetchInvite('https://discord.gg/djs')
|
||||
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchInvite(invite, options) {
|
||||
const code = resolveInviteCode(invite);
|
||||
const query = makeURLSearchParams({
|
||||
with_counts: true,
|
||||
with_expiration: true,
|
||||
guild_scheduled_event_id: options?.guildScheduledEventId,
|
||||
});
|
||||
const data = await this.rest.get(Routes.invite(code), { query });
|
||||
return new Invite(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a template from Discord.
|
||||
* @param {GuildTemplateResolvable} template Template code or URL
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
* @example
|
||||
* client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
|
||||
* .then(template => console.log(`Obtained template with code: ${template.code}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchGuildTemplate(template) {
|
||||
const code = resolveGuildTemplateCode(template);
|
||||
const data = await this.rest.get(Routes.template(code));
|
||||
return new GuildTemplate(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a webhook from Discord.
|
||||
* @param {Snowflake} id The webhook's id
|
||||
* @param {string} [token] Token for the webhook
|
||||
* @returns {Promise<Webhook>}
|
||||
* @example
|
||||
* client.fetchWebhook('id', 'token')
|
||||
* .then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchWebhook(id, token) {
|
||||
const data = await this.rest.get(Routes.webhook(id, token), { auth: token === undefined });
|
||||
return new Webhook(this, { token, ...data });
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the available voice regions from Discord.
|
||||
* @returns {Promise<Collection<string, VoiceRegion>>}
|
||||
* @example
|
||||
* client.fetchVoiceRegions()
|
||||
* .then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchVoiceRegions() {
|
||||
const apiRegions = await this.rest.get(Routes.voiceRegions());
|
||||
const regions = new Collection();
|
||||
for (const region of apiRegions) regions.set(region.id, new VoiceRegion(region));
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a sticker from Discord.
|
||||
* @param {Snowflake} id The sticker's id
|
||||
* @returns {Promise<Sticker>}
|
||||
* @example
|
||||
* client.fetchSticker('id')
|
||||
* .then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchSticker(id) {
|
||||
const data = await this.rest.get(Routes.sticker(id));
|
||||
return new Sticker(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the list of available sticker packs.
|
||||
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
||||
* @example
|
||||
* client.fetchStickerPacks()
|
||||
* .then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchStickerPacks() {
|
||||
const data = await this.rest.get(Routes.stickerPacks());
|
||||
return new Collection(data.sticker_packs.map(stickerPack => [stickerPack.id, new StickerPack(this, stickerPack)]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the list of available sticker packs.
|
||||
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
||||
* @deprecated Use {@link Client#fetchStickerPacks} instead.
|
||||
*/
|
||||
fetchPremiumStickerPacks() {
|
||||
if (!deprecationEmittedForPremiumStickerPacks) {
|
||||
process.emitWarning(
|
||||
'The Client#fetchPremiumStickerPacks() method is deprecated. Use Client#fetchStickerPacks() instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForPremiumStickerPacks = true;
|
||||
}
|
||||
|
||||
return this.fetchStickerPacks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
||||
* @param {GuildResolvable} guild The guild to fetch the preview for
|
||||
* @returns {Promise<GuildPreview>}
|
||||
*/
|
||||
async fetchGuildPreview(guild) {
|
||||
const id = this.guilds.resolveId(guild);
|
||||
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'guild', 'GuildResolvable');
|
||||
const data = await this.rest.get(Routes.guildPreview(id));
|
||||
return new GuildPreview(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
|
||||
* @param {GuildResolvable} guild The guild to fetch the widget data for
|
||||
* @returns {Promise<Widget>}
|
||||
*/
|
||||
async fetchGuildWidget(guild) {
|
||||
const id = this.guilds.resolveId(guild);
|
||||
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'guild', 'GuildResolvable');
|
||||
const data = await this.rest.get(Routes.guildWidgetJSON(id));
|
||||
return new Widget(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for {@link Client#generateInvite}.
|
||||
* @typedef {Object} InviteGenerationOptions
|
||||
* @property {OAuth2Scopes[]} scopes Scopes that should be requested
|
||||
* @property {PermissionResolvable} [permissions] Permissions to request
|
||||
* @property {GuildResolvable} [guild] Guild to preselect
|
||||
* @property {boolean} [disableGuildSelect] Whether to disable the guild selection
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates a link that can be used to invite the bot to a guild.
|
||||
* @param {InviteGenerationOptions} [options={}] Options for the invite
|
||||
* @returns {string}
|
||||
* @example
|
||||
* const link = client.generateInvite({
|
||||
* scopes: [OAuth2Scopes.ApplicationsCommands],
|
||||
* });
|
||||
* console.log(`Generated application invite link: ${link}`);
|
||||
* @example
|
||||
* const link = client.generateInvite({
|
||||
* permissions: [
|
||||
* PermissionFlagsBits.SendMessages,
|
||||
* PermissionFlagsBits.ManageGuild,
|
||||
* PermissionFlagsBits.MentionEveryone,
|
||||
* ],
|
||||
* scopes: [OAuth2Scopes.Bot],
|
||||
* });
|
||||
* console.log(`Generated bot invite link: ${link}`);
|
||||
*/
|
||||
generateInvite(options = {}) {
|
||||
if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
|
||||
if (!this.application) throw new DiscordjsError(ErrorCodes.ClientNotReady, 'generate an invite link');
|
||||
|
||||
const { scopes } = options;
|
||||
if (scopes === undefined) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
|
||||
}
|
||||
if (!Array.isArray(scopes)) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'scopes', 'Array of Invite Scopes', true);
|
||||
}
|
||||
if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
|
||||
}
|
||||
if (!scopes.includes(OAuth2Scopes.Bot) && options.permissions) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.InvalidScopesWithPermissions);
|
||||
}
|
||||
const validScopes = Object.values(OAuth2Scopes);
|
||||
const invalidScope = scopes.find(scope => !validScopes.includes(scope));
|
||||
if (invalidScope) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'scopes', invalidScope);
|
||||
}
|
||||
|
||||
const query = makeURLSearchParams({
|
||||
client_id: this.application.id,
|
||||
scope: scopes.join(' '),
|
||||
disable_guild_select: options.disableGuildSelect,
|
||||
});
|
||||
|
||||
if (options.permissions) {
|
||||
const permissions = PermissionsBitField.resolve(options.permissions);
|
||||
if (permissions) query.set('permissions', permissions.toString());
|
||||
}
|
||||
|
||||
if (options.guild) {
|
||||
const guildId = this.guilds.resolveId(options.guild);
|
||||
if (!guildId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options.guild', 'GuildResolvable');
|
||||
query.set('guild_id', guildId);
|
||||
}
|
||||
|
||||
return `${this.options.rest.api}${Routes.oauth2Authorization()}?${query}`;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return super.toJSON({
|
||||
actions: false,
|
||||
presence: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Partially censored client token for debug logging purposes.
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
* @private
|
||||
*/
|
||||
get _censoredToken() {
|
||||
if (!this.token) return null;
|
||||
|
||||
return this.token
|
||||
.split('.')
|
||||
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
|
||||
.join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (options.intents === undefined) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
|
||||
} else {
|
||||
options.intents = new IntentsBitField(options.intents).freeze();
|
||||
}
|
||||
if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount < 1) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'shardCount', 'a number greater than or equal to 1');
|
||||
}
|
||||
if (options.shards && !(options.shards === 'auto' || Array.isArray(options.shards))) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'shards', "'auto', a number or array of numbers");
|
||||
}
|
||||
if (options.shards && !options.shards.length) throw new DiscordjsRangeError(ErrorCodes.ClientInvalidProvidedShards);
|
||||
if (typeof options.makeCache !== 'function') {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'makeCache', 'a function');
|
||||
}
|
||||
if (typeof options.sweepers !== 'object' || options.sweepers === null) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'sweepers', 'an object');
|
||||
}
|
||||
if (!Array.isArray(options.partials)) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'partials', 'an Array');
|
||||
}
|
||||
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'waitGuildTimeout', 'a number');
|
||||
}
|
||||
if (typeof options.failIfNotExists !== 'boolean') {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a boolean');
|
||||
}
|
||||
if (
|
||||
(typeof options.allowedMentions !== 'object' && options.allowedMentions !== undefined) ||
|
||||
options.allowedMentions === null
|
||||
) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'allowedMentions', 'an object');
|
||||
}
|
||||
if (typeof options.presence !== 'object' || options.presence === null) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'presence', 'an object');
|
||||
}
|
||||
if (typeof options.ws !== 'object' || options.ws === null) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws', 'an object');
|
||||
}
|
||||
if (typeof options.rest !== 'object' || options.rest === null) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'rest', 'an object');
|
||||
}
|
||||
if (typeof options.jsonTransformer !== 'function') {
|
||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'jsonTransformer', 'a function');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
/**
|
||||
* @class SnowflakeUtil
|
||||
* @classdesc This class is an alias for {@link https://www.npmjs.com/package/@sapphire/snowflake @sapphire/snowflake}'s
|
||||
* `DiscordSnowflake` class.
|
||||
*
|
||||
* Check their documentation
|
||||
* {@link https://www.sapphirejs.dev/docs/Documentation/api-utilities/classes/sapphire_snowflake.Snowflake here}
|
||||
* ({@link https://www.sapphirejs.dev/docs/Guide/utilities/snowflake guide})
|
||||
* to see what you can do.
|
||||
* @hideconstructor
|
||||
*/
|
||||
|
||||
/**
|
||||
* A {@link https://developer.twitter.com/en/docs/twitter-ids 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 milliseconds since Discord epoch worker pid increment
|
||||
* ```
|
||||
* @typedef {string} Snowflake
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emitted for general debugging information.
|
||||
* @event Client#debug
|
||||
* @param {string} info The debug information
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emitted for general warnings.
|
||||
* @event Client#warn
|
||||
* @param {string} info The warning
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external Collection
|
||||
* @see {@link https://discord.js.org/docs/packages/collection/stable/Collection:Class}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external ImageURLOptions
|
||||
* @see {@link https://discord.js.org/docs/packages/rest/stable/ImageURLOptions:Interface}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external BaseImageURLOptions
|
||||
* @see {@link https://discord.js.org/docs/packages/rest/stable/BaseImageURLOptions:Interface}
|
||||
*/
|
103
node_modules/discord.js/src/client/WebhookClient.js
generated
vendored
Normal file
103
node_modules/discord.js/src/client/WebhookClient.js
generated
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
'use strict';
|
||||
|
||||
const BaseClient = require('./BaseClient');
|
||||
const { DiscordjsError, ErrorCodes } = require('../errors');
|
||||
const Webhook = require('../structures/Webhook');
|
||||
const { parseWebhookURL } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* The webhook client.
|
||||
* @implements {Webhook}
|
||||
* @extends {BaseClient}
|
||||
*/
|
||||
class WebhookClient extends BaseClient {
|
||||
/**
|
||||
* Represents the credentials used for a webhook in the form of its id and token.
|
||||
* @typedef {Object} WebhookClientDataIdWithToken
|
||||
* @property {Snowflake} id The webhook's id
|
||||
* @property {string} token The webhook's token
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents the credentials used for a webhook in the form of a URL.
|
||||
* @typedef {Object} WebhookClientDataURL
|
||||
* @property {string} url The full URL for the webhook
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents the credentials used for a webhook.
|
||||
* @typedef {WebhookClientDataIdWithToken|WebhookClientDataURL} WebhookClientData
|
||||
*/
|
||||
|
||||
/**
|
||||
* Options for a webhook client.
|
||||
* @typedef {Object} WebhookClientOptions
|
||||
* @property {MessageMentionOptions} [allowedMentions] Default value for {@link BaseMessageOptions#allowedMentions}
|
||||
* @property {RESTOptions} [rest] Options for the REST manager
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {WebhookClientData} data The data of the webhook
|
||||
* @param {WebhookClientOptions} [options] Options for the webhook client
|
||||
*/
|
||||
constructor(data, options) {
|
||||
super(options);
|
||||
Object.defineProperty(this, 'client', { value: this });
|
||||
let { id, token } = data;
|
||||
|
||||
if ('url' in data) {
|
||||
const parsed = parseWebhookURL(data.url);
|
||||
if (!parsed) {
|
||||
throw new DiscordjsError(ErrorCodes.WebhookURLInvalid);
|
||||
}
|
||||
|
||||
({ id, token } = parsed);
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
Object.defineProperty(this, 'token', { value: token, writable: true, configurable: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* The options the webhook client was instantiated with.
|
||||
* @type {WebhookClientOptions}
|
||||
* @name WebhookClient#options
|
||||
*/
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by Webhook
|
||||
/* eslint-disable no-empty-function, valid-jsdoc */
|
||||
/**
|
||||
* Sends a message with this webhook.
|
||||
* @param {string|MessagePayload|WebhookMessageCreateOptions} options The content for the reply
|
||||
* @returns {Promise<APIMessage>}
|
||||
*/
|
||||
send() {}
|
||||
|
||||
/**
|
||||
* Gets a message that was sent by this webhook.
|
||||
* @param {Snowflake} message The id of the message to fetch
|
||||
* @param {WebhookFetchMessageOptions} [options={}] The options to provide to fetch the message.
|
||||
* @returns {Promise<APIMessage>} Returns the message sent by this webhook
|
||||
*/
|
||||
fetchMessage() {}
|
||||
|
||||
/**
|
||||
* Edits a message that was sent by this webhook.
|
||||
* @param {MessageResolvable} message The message to edit
|
||||
* @param {string|MessagePayload|WebhookMessageEditOptions} options The options to provide
|
||||
* @returns {Promise<APIMessage>} Returns the message edited by this webhook
|
||||
*/
|
||||
editMessage() {}
|
||||
|
||||
sendSlackMessage() {}
|
||||
edit() {}
|
||||
delete() {}
|
||||
deleteMessage() {}
|
||||
get createdTimestamp() {}
|
||||
get createdAt() {}
|
||||
get url() {}
|
||||
}
|
||||
|
||||
Webhook.applyToClass(WebhookClient);
|
||||
|
||||
module.exports = WebhookClient;
|
120
node_modules/discord.js/src/client/actions/Action.js
generated
vendored
Normal file
120
node_modules/discord.js/src/client/actions/Action.js
generated
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
'use strict';
|
||||
|
||||
const Partials = require('../../util/Partials');
|
||||
|
||||
/*
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
getPayload(data, manager, id, partialType, cache) {
|
||||
return this.client.options.partials.includes(partialType) ? manager._add(data, cache) : manager.cache.get(id);
|
||||
}
|
||||
|
||||
getChannel(data) {
|
||||
const payloadData = {};
|
||||
const id = data.channel_id ?? data.id;
|
||||
|
||||
if ('recipients' in data) {
|
||||
payloadData.recipients = data.recipients;
|
||||
} else {
|
||||
// Try to resolve the recipient, but do not add the client user.
|
||||
const recipient = data.author ?? data.user ?? { id: data.user_id };
|
||||
if (recipient.id !== this.client.user.id) payloadData.recipients = [recipient];
|
||||
}
|
||||
|
||||
if (id !== undefined) payloadData.id = id;
|
||||
if ('guild_id' in data) payloadData.guild_id = data.guild_id;
|
||||
if ('last_message_id' in data) payloadData.last_message_id = data.last_message_id;
|
||||
|
||||
return (
|
||||
data[this.client.actions.injectedChannel] ??
|
||||
this.getPayload(payloadData, this.client.channels, id, Partials.Channel)
|
||||
);
|
||||
}
|
||||
|
||||
getMessage(data, channel, cache) {
|
||||
const id = data.message_id ?? data.id;
|
||||
return (
|
||||
data[this.client.actions.injectedMessage] ??
|
||||
this.getPayload(
|
||||
{
|
||||
id,
|
||||
channel_id: channel.id,
|
||||
guild_id: data.guild_id ?? channel.guild?.id,
|
||||
},
|
||||
channel.messages,
|
||||
id,
|
||||
Partials.Message,
|
||||
cache,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
getReaction(data, message, user) {
|
||||
const id = data.emoji.id ?? decodeURIComponent(data.emoji.name);
|
||||
return this.getPayload(
|
||||
{
|
||||
emoji: data.emoji,
|
||||
count: message.partial ? null : 0,
|
||||
me: user?.id === this.client.user.id,
|
||||
},
|
||||
message.reactions,
|
||||
id,
|
||||
Partials.Reaction,
|
||||
);
|
||||
}
|
||||
|
||||
getMember(data, guild) {
|
||||
return this.getPayload(data, guild.members, data.user.id, Partials.GuildMember);
|
||||
}
|
||||
|
||||
getUser(data) {
|
||||
const id = data.user_id;
|
||||
return data[this.client.actions.injectedUser] ?? this.getPayload({ id }, this.client.users, id, Partials.User);
|
||||
}
|
||||
|
||||
getUserFromMember(data) {
|
||||
if (data.guild_id && data.member?.user) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
return guild.members._add(data.member).user;
|
||||
} else {
|
||||
return this.client.users._add(data.member.user);
|
||||
}
|
||||
}
|
||||
return this.getUser(data);
|
||||
}
|
||||
|
||||
getScheduledEvent(data, guild) {
|
||||
const id = data.guild_scheduled_event_id ?? data.id;
|
||||
return this.getPayload(
|
||||
{ id, guild_id: data.guild_id ?? guild.id },
|
||||
guild.scheduledEvents,
|
||||
id,
|
||||
Partials.GuildScheduledEvent,
|
||||
);
|
||||
}
|
||||
|
||||
getThreadMember(id, manager) {
|
||||
return this.getPayload({ user_id: id }, manager, id, Partials.ThreadMember, false);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GenericAction;
|
84
node_modules/discord.js/src/client/actions/ActionsManager.js
generated
vendored
Normal file
84
node_modules/discord.js/src/client/actions/ActionsManager.js
generated
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
'use strict';
|
||||
|
||||
class ActionsManager {
|
||||
// These symbols represent fully built data that we inject at times when calling actions manually.
|
||||
// Action#getUser, for example, will return the injected data (which is assumed to be a built structure)
|
||||
// instead of trying to make it from provided data
|
||||
injectedUser = Symbol('djs.actions.injectedUser');
|
||||
injectedChannel = Symbol('djs.actions.injectedChannel');
|
||||
injectedMessage = Symbol('djs.actions.injectedMessage');
|
||||
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
|
||||
this.register(require('./ApplicationCommandPermissionsUpdate'));
|
||||
this.register(require('./AutoModerationActionExecution'));
|
||||
this.register(require('./AutoModerationRuleCreate'));
|
||||
this.register(require('./AutoModerationRuleDelete'));
|
||||
this.register(require('./AutoModerationRuleUpdate'));
|
||||
this.register(require('./ChannelCreate'));
|
||||
this.register(require('./ChannelDelete'));
|
||||
this.register(require('./ChannelUpdate'));
|
||||
this.register(require('./EntitlementCreate'));
|
||||
this.register(require('./EntitlementDelete'));
|
||||
this.register(require('./EntitlementUpdate'));
|
||||
this.register(require('./GuildAuditLogEntryCreate'));
|
||||
this.register(require('./GuildBanAdd'));
|
||||
this.register(require('./GuildBanRemove'));
|
||||
this.register(require('./GuildChannelsPositionUpdate'));
|
||||
this.register(require('./GuildDelete'));
|
||||
this.register(require('./GuildEmojiCreate'));
|
||||
this.register(require('./GuildEmojiDelete'));
|
||||
this.register(require('./GuildEmojiUpdate'));
|
||||
this.register(require('./GuildEmojisUpdate'));
|
||||
this.register(require('./GuildIntegrationsUpdate'));
|
||||
this.register(require('./GuildMemberRemove'));
|
||||
this.register(require('./GuildMemberUpdate'));
|
||||
this.register(require('./GuildRoleCreate'));
|
||||
this.register(require('./GuildRoleDelete'));
|
||||
this.register(require('./GuildRoleUpdate'));
|
||||
this.register(require('./GuildRolesPositionUpdate'));
|
||||
this.register(require('./GuildScheduledEventCreate'));
|
||||
this.register(require('./GuildScheduledEventDelete'));
|
||||
this.register(require('./GuildScheduledEventUpdate'));
|
||||
this.register(require('./GuildScheduledEventUserAdd'));
|
||||
this.register(require('./GuildScheduledEventUserRemove'));
|
||||
this.register(require('./GuildStickerCreate'));
|
||||
this.register(require('./GuildStickerDelete'));
|
||||
this.register(require('./GuildStickerUpdate'));
|
||||
this.register(require('./GuildStickersUpdate'));
|
||||
this.register(require('./GuildUpdate'));
|
||||
this.register(require('./InteractionCreate'));
|
||||
this.register(require('./InviteCreate'));
|
||||
this.register(require('./InviteDelete'));
|
||||
this.register(require('./MessageCreate'));
|
||||
this.register(require('./MessageDelete'));
|
||||
this.register(require('./MessageDeleteBulk'));
|
||||
this.register(require('./MessagePollVoteAdd'));
|
||||
this.register(require('./MessagePollVoteRemove'));
|
||||
this.register(require('./MessageReactionAdd'));
|
||||
this.register(require('./MessageReactionRemove'));
|
||||
this.register(require('./MessageReactionRemoveAll'));
|
||||
this.register(require('./MessageReactionRemoveEmoji'));
|
||||
this.register(require('./MessageUpdate'));
|
||||
this.register(require('./PresenceUpdate'));
|
||||
this.register(require('./StageInstanceCreate'));
|
||||
this.register(require('./StageInstanceDelete'));
|
||||
this.register(require('./StageInstanceUpdate'));
|
||||
this.register(require('./ThreadCreate'));
|
||||
this.register(require('./ThreadDelete'));
|
||||
this.register(require('./ThreadListSync'));
|
||||
this.register(require('./ThreadMemberUpdate'));
|
||||
this.register(require('./ThreadMembersUpdate'));
|
||||
this.register(require('./TypingStart'));
|
||||
this.register(require('./UserUpdate'));
|
||||
this.register(require('./VoiceStateUpdate'));
|
||||
this.register(require('./WebhooksUpdate'));
|
||||
}
|
||||
|
||||
register(Action) {
|
||||
this[Action.name.replace(/Action$/, '')] = new Action(this.client);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ActionsManager;
|
34
node_modules/discord.js/src/client/actions/ApplicationCommandPermissionsUpdate.js
generated
vendored
Normal file
34
node_modules/discord.js/src/client/actions/ApplicationCommandPermissionsUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
/**
|
||||
* The data received in the {@link Client#event:applicationCommandPermissionsUpdate} event
|
||||
* @typedef {Object} ApplicationCommandPermissionsUpdateData
|
||||
* @property {Snowflake} id The id of the command or global entity that was updated
|
||||
* @property {Snowflake} guildId The id of the guild in which permissions were updated
|
||||
* @property {Snowflake} applicationId The id of the application that owns the command or entity being updated
|
||||
* @property {ApplicationCommandPermissions[]} permissions The updated permissions
|
||||
*/
|
||||
|
||||
class ApplicationCommandPermissionsUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
/**
|
||||
* Emitted whenever permissions for an application command in a guild were updated.
|
||||
* <warn>This includes permission updates for other applications in addition to the logged in client,
|
||||
* check `data.applicationId` to verify which application the update is for</warn>
|
||||
* @event Client#applicationCommandPermissionsUpdate
|
||||
* @param {ApplicationCommandPermissionsUpdateData} data The updated permissions
|
||||
*/
|
||||
client.emit(Events.ApplicationCommandPermissionsUpdate, {
|
||||
permissions: data.permissions,
|
||||
id: data.id,
|
||||
guildId: data.guild_id,
|
||||
applicationId: data.application_id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ApplicationCommandPermissionsUpdateAction;
|
26
node_modules/discord.js/src/client/actions/AutoModerationActionExecution.js
generated
vendored
Normal file
26
node_modules/discord.js/src/client/actions/AutoModerationActionExecution.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const AutoModerationActionExecution = require('../../structures/AutoModerationActionExecution');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class AutoModerationActionExecutionAction extends Action {
|
||||
handle(data) {
|
||||
const { client } = this;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
/**
|
||||
* Emitted whenever an auto moderation rule is triggered.
|
||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||
* @event Client#autoModerationActionExecution
|
||||
* @param {AutoModerationActionExecution} autoModerationActionExecution The data of the execution
|
||||
*/
|
||||
client.emit(Events.AutoModerationActionExecution, new AutoModerationActionExecution(data, guild));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AutoModerationActionExecutionAction;
|
27
node_modules/discord.js/src/client/actions/AutoModerationRuleCreate.js
generated
vendored
Normal file
27
node_modules/discord.js/src/client/actions/AutoModerationRuleCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class AutoModerationRuleCreateAction extends Action {
|
||||
handle(data) {
|
||||
const { client } = this;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
const autoModerationRule = guild.autoModerationRules._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever an auto moderation rule is created.
|
||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||
* @event Client#autoModerationRuleCreate
|
||||
* @param {AutoModerationRule} autoModerationRule The created auto moderation rule
|
||||
*/
|
||||
client.emit(Events.AutoModerationRuleCreate, autoModerationRule);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AutoModerationRuleCreateAction;
|
31
node_modules/discord.js/src/client/actions/AutoModerationRuleDelete.js
generated
vendored
Normal file
31
node_modules/discord.js/src/client/actions/AutoModerationRuleDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class AutoModerationRuleDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const { client } = this;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
const autoModerationRule = guild.autoModerationRules.cache.get(data.id);
|
||||
|
||||
if (autoModerationRule) {
|
||||
guild.autoModerationRules.cache.delete(autoModerationRule.id);
|
||||
|
||||
/**
|
||||
* Emitted whenever an auto moderation rule is deleted.
|
||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||
* @event Client#autoModerationRuleDelete
|
||||
* @param {AutoModerationRule} autoModerationRule The deleted auto moderation rule
|
||||
*/
|
||||
client.emit(Events.AutoModerationRuleDelete, autoModerationRule);
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AutoModerationRuleDeleteAction;
|
29
node_modules/discord.js/src/client/actions/AutoModerationRuleUpdate.js
generated
vendored
Normal file
29
node_modules/discord.js/src/client/actions/AutoModerationRuleUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class AutoModerationRuleUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const { client } = this;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
const oldAutoModerationRule = guild.autoModerationRules.cache.get(data.id)?._clone() ?? null;
|
||||
const newAutoModerationRule = guild.autoModerationRules._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever an auto moderation rule gets updated.
|
||||
* <info>This event requires the {@link PermissionFlagsBits.ManageGuild} permission.</info>
|
||||
* @event Client#autoModerationRuleUpdate
|
||||
* @param {?AutoModerationRule} oldAutoModerationRule The auto moderation rule before the update
|
||||
* @param {AutoModerationRule} newAutoModerationRule The auto moderation rule after the update
|
||||
*/
|
||||
client.emit(Events.AutoModerationRuleUpdate, oldAutoModerationRule, newAutoModerationRule);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AutoModerationRuleUpdateAction;
|
23
node_modules/discord.js/src/client/actions/ChannelCreate.js
generated
vendored
Normal file
23
node_modules/discord.js/src/client/actions/ChannelCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class ChannelCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const existing = client.channels.cache.has(data.id);
|
||||
const channel = client.channels._add(data);
|
||||
if (!existing && channel) {
|
||||
/**
|
||||
* Emitted whenever a guild channel is created.
|
||||
* @event Client#channelCreate
|
||||
* @param {GuildChannel} channel The channel that was created
|
||||
*/
|
||||
client.emit(Events.ChannelCreate, channel);
|
||||
}
|
||||
return { channel };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChannelCreateAction;
|
23
node_modules/discord.js/src/client/actions/ChannelDelete.js
generated
vendored
Normal file
23
node_modules/discord.js/src/client/actions/ChannelDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class ChannelDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.id);
|
||||
|
||||
if (channel) {
|
||||
client.channels._remove(channel.id);
|
||||
/**
|
||||
* Emitted whenever a channel is deleted.
|
||||
* @event Client#channelDelete
|
||||
* @param {DMChannel|GuildChannel} channel The channel that was deleted
|
||||
*/
|
||||
client.emit(Events.ChannelDelete, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChannelDeleteAction;
|
42
node_modules/discord.js/src/client/actions/ChannelUpdate.js
generated
vendored
Normal file
42
node_modules/discord.js/src/client/actions/ChannelUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { createChannel } = require('../../util/Channels');
|
||||
|
||||
class ChannelUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
let channel = client.channels.cache.get(data.id);
|
||||
|
||||
if (channel) {
|
||||
const old = channel._update(data);
|
||||
|
||||
if (channel.type !== data.type) {
|
||||
const newChannel = createChannel(this.client, data, channel.guild);
|
||||
|
||||
if (!newChannel) {
|
||||
this.client.channels.cache.delete(channel.id);
|
||||
return {};
|
||||
}
|
||||
|
||||
if (channel.isTextBased() && newChannel.isTextBased()) {
|
||||
for (const [id, message] of channel.messages.cache) newChannel.messages.cache.set(id, message);
|
||||
}
|
||||
|
||||
channel = newChannel;
|
||||
this.client.channels.cache.set(channel.id, channel);
|
||||
}
|
||||
|
||||
return {
|
||||
old,
|
||||
updated: channel,
|
||||
};
|
||||
} else {
|
||||
client.channels._add(data);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChannelUpdateAction;
|
23
node_modules/discord.js/src/client/actions/EntitlementCreate.js
generated
vendored
Normal file
23
node_modules/discord.js/src/client/actions/EntitlementCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class EntitlementCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const entitlement = client.application.entitlements._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever an entitlement is created.
|
||||
* @event Client#entitlementCreate
|
||||
* @param {Entitlement} entitlement The entitlement that was created
|
||||
*/
|
||||
client.emit(Events.EntitlementCreate, entitlement);
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntitlementCreateAction;
|
27
node_modules/discord.js/src/client/actions/EntitlementDelete.js
generated
vendored
Normal file
27
node_modules/discord.js/src/client/actions/EntitlementDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class EntitlementDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const entitlement = client.application.entitlements._add(data, false);
|
||||
|
||||
client.application.entitlements.cache.delete(entitlement.id);
|
||||
|
||||
/**
|
||||
* Emitted whenever an entitlement is deleted.
|
||||
* <warn>Entitlements are not deleted when they expire.
|
||||
* This is only triggered when Discord issues a refund or deletes the entitlement manually.</warn>
|
||||
* @event Client#entitlementDelete
|
||||
* @param {Entitlement} entitlement The entitlement that was deleted
|
||||
*/
|
||||
client.emit(Events.EntitlementDelete, entitlement);
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntitlementDeleteAction;
|
25
node_modules/discord.js/src/client/actions/EntitlementUpdate.js
generated
vendored
Normal file
25
node_modules/discord.js/src/client/actions/EntitlementUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class EntitlementUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const oldEntitlement = client.application.entitlements.cache.get(data.id)?._clone() ?? null;
|
||||
const newEntitlement = client.application.entitlements._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever an entitlement is updated - i.e. when a user's subscription renews.
|
||||
* @event Client#entitlementUpdate
|
||||
* @param {?Entitlement} oldEntitlement The entitlement before the update
|
||||
* @param {Entitlement} newEntitlement The entitlement after the update
|
||||
*/
|
||||
client.emit(Events.EntitlementUpdate, oldEntitlement, newEntitlement);
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntitlementUpdateAction;
|
29
node_modules/discord.js/src/client/actions/GuildAuditLogEntryCreate.js
generated
vendored
Normal file
29
node_modules/discord.js/src/client/actions/GuildAuditLogEntryCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const GuildAuditLogsEntry = require('../../structures/GuildAuditLogsEntry');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildAuditLogEntryCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
let auditLogEntry;
|
||||
|
||||
if (guild) {
|
||||
auditLogEntry = new GuildAuditLogsEntry(guild, data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild audit log entry is created.
|
||||
* @event Client#guildAuditLogEntryCreate
|
||||
* @param {GuildAuditLogsEntry} auditLogEntry The entry that was created
|
||||
* @param {Guild} guild The guild where the entry was created
|
||||
*/
|
||||
client.emit(Events.GuildAuditLogEntryCreate, auditLogEntry, guild);
|
||||
}
|
||||
|
||||
return { auditLogEntry };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildAuditLogEntryCreateAction;
|
20
node_modules/discord.js/src/client/actions/GuildBanAdd.js
generated
vendored
Normal file
20
node_modules/discord.js/src/client/actions/GuildBanAdd.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildBanAdd extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
/**
|
||||
* Emitted whenever a member is banned from a guild.
|
||||
* @event Client#guildBanAdd
|
||||
* @param {GuildBan} ban The ban that occurred
|
||||
*/
|
||||
if (guild) client.emit(Events.GuildBanAdd, guild.bans._add(data));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildBanAdd;
|
25
node_modules/discord.js/src/client/actions/GuildBanRemove.js
generated
vendored
Normal file
25
node_modules/discord.js/src/client/actions/GuildBanRemove.js
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const GuildBan = require('../../structures/GuildBan');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildBanRemove extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
/**
|
||||
* Emitted whenever a member is unbanned from a guild.
|
||||
* @event Client#guildBanRemove
|
||||
* @param {GuildBan} ban The ban that was removed
|
||||
*/
|
||||
if (guild) {
|
||||
const ban = guild.bans.cache.get(data.user.id) ?? new GuildBan(client, data, guild);
|
||||
guild.bans.cache.delete(ban.user.id);
|
||||
client.emit(Events.GuildBanRemove, ban);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildBanRemove;
|
21
node_modules/discord.js/src/client/actions/GuildChannelsPositionUpdate.js
generated
vendored
Normal file
21
node_modules/discord.js/src/client/actions/GuildChannelsPositionUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
|
||||
class GuildChannelsPositionUpdate extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
for (const partialChannel of data.channels) {
|
||||
const channel = guild.channels.cache.get(partialChannel.id);
|
||||
if (channel) channel.rawPosition = partialChannel.position;
|
||||
}
|
||||
}
|
||||
|
||||
return { guild };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildChannelsPositionUpdate;
|
44
node_modules/discord.js/src/client/actions/GuildDelete.js
generated
vendored
Normal file
44
node_modules/discord.js/src/client/actions/GuildDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
let guild = client.guilds.cache.get(data.id);
|
||||
if (guild) {
|
||||
if (data.unavailable) {
|
||||
// Guild is unavailable
|
||||
guild.available = false;
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild becomes unavailable, likely due to a server outage.
|
||||
* @event Client#guildUnavailable
|
||||
* @param {Guild} guild The guild that has become unavailable
|
||||
*/
|
||||
client.emit(Events.GuildUnavailable, guild);
|
||||
|
||||
// Stops the GuildDelete packet thinking a guild was actually deleted,
|
||||
// handles emitting of event itself
|
||||
return;
|
||||
}
|
||||
|
||||
for (const channel of guild.channels.cache.values()) this.client.channels._remove(channel.id);
|
||||
client.voice.adapters.get(data.id)?.destroy();
|
||||
|
||||
// Delete guild
|
||||
client.guilds.cache.delete(guild.id);
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild kicks the client or the guild is deleted/left.
|
||||
* @event Client#guildDelete
|
||||
* @param {Guild} guild The guild that was deleted
|
||||
*/
|
||||
client.emit(Events.GuildDelete, guild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildDeleteAction;
|
20
node_modules/discord.js/src/client/actions/GuildEmojiCreate.js
generated
vendored
Normal file
20
node_modules/discord.js/src/client/actions/GuildEmojiCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildEmojiCreateAction extends Action {
|
||||
handle(guild, createdEmoji) {
|
||||
const already = guild.emojis.cache.has(createdEmoji.id);
|
||||
const emoji = guild.emojis._add(createdEmoji);
|
||||
/**
|
||||
* Emitted whenever a custom emoji is created in a guild.
|
||||
* @event Client#emojiCreate
|
||||
* @param {GuildEmoji} emoji The emoji that was created
|
||||
*/
|
||||
if (!already) this.client.emit(Events.GuildEmojiCreate, emoji);
|
||||
return { emoji };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildEmojiCreateAction;
|
19
node_modules/discord.js/src/client/actions/GuildEmojiDelete.js
generated
vendored
Normal file
19
node_modules/discord.js/src/client/actions/GuildEmojiDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildEmojiDeleteAction extends Action {
|
||||
handle(emoji) {
|
||||
emoji.guild.emojis.cache.delete(emoji.id);
|
||||
/**
|
||||
* Emitted whenever a custom emoji is deleted in a guild.
|
||||
* @event Client#emojiDelete
|
||||
* @param {GuildEmoji} emoji The emoji that was deleted
|
||||
*/
|
||||
this.client.emit(Events.GuildEmojiDelete, emoji);
|
||||
return { emoji };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildEmojiDeleteAction;
|
20
node_modules/discord.js/src/client/actions/GuildEmojiUpdate.js
generated
vendored
Normal file
20
node_modules/discord.js/src/client/actions/GuildEmojiUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildEmojiUpdateAction extends Action {
|
||||
handle(current, data) {
|
||||
const old = current._update(data);
|
||||
/**
|
||||
* Emitted whenever a custom emoji is updated in a guild.
|
||||
* @event Client#emojiUpdate
|
||||
* @param {GuildEmoji} oldEmoji The old emoji
|
||||
* @param {GuildEmoji} newEmoji The new emoji
|
||||
*/
|
||||
this.client.emit(Events.GuildEmojiUpdate, old, current);
|
||||
return { emoji: current };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildEmojiUpdateAction;
|
34
node_modules/discord.js/src/client/actions/GuildEmojisUpdate.js
generated
vendored
Normal file
34
node_modules/discord.js/src/client/actions/GuildEmojisUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
|
||||
class GuildEmojisUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (!guild?.emojis) return;
|
||||
|
||||
const deletions = new Map(guild.emojis.cache);
|
||||
|
||||
for (const emoji of data.emojis) {
|
||||
// Determine type of emoji event
|
||||
const cachedEmoji = guild.emojis.cache.get(emoji.id);
|
||||
if (cachedEmoji) {
|
||||
deletions.delete(emoji.id);
|
||||
if (!cachedEmoji.equals(emoji)) {
|
||||
// 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;
|
19
node_modules/discord.js/src/client/actions/GuildIntegrationsUpdate.js
generated
vendored
Normal file
19
node_modules/discord.js/src/client/actions/GuildIntegrationsUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildIntegrationsUpdate extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
/**
|
||||
* Emitted whenever a guild integration is updated
|
||||
* @event Client#guildIntegrationsUpdate
|
||||
* @param {Guild} guild The guild whose integrations were updated
|
||||
*/
|
||||
if (guild) client.emit(Events.GuildIntegrationsUpdate, guild);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildIntegrationsUpdate;
|
31
node_modules/discord.js/src/client/actions/GuildMemberRemove.js
generated
vendored
Normal file
31
node_modules/discord.js/src/client/actions/GuildMemberRemove.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
const Status = require('../../util/Status');
|
||||
|
||||
class GuildMemberRemoveAction extends Action {
|
||||
handle(data, shard) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
let member = null;
|
||||
if (guild) {
|
||||
member = this.getMember({ user: data.user }, guild);
|
||||
guild.memberCount--;
|
||||
if (member) {
|
||||
guild.members.cache.delete(member.id);
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
if (shard.status === Status.Ready) client.emit(Events.GuildMemberRemove, member);
|
||||
}
|
||||
guild.presences.cache.delete(data.user.id);
|
||||
guild.voiceStates.cache.delete(data.user.id);
|
||||
}
|
||||
return { guild, member };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildMemberRemoveAction;
|
44
node_modules/discord.js/src/client/actions/GuildMemberUpdate.js
generated
vendored
Normal file
44
node_modules/discord.js/src/client/actions/GuildMemberUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
const Status = require('../../util/Status');
|
||||
|
||||
class GuildMemberUpdateAction extends Action {
|
||||
handle(data, shard) {
|
||||
const { client } = this;
|
||||
if (data.user.username) {
|
||||
const user = client.users.cache.get(data.user.id);
|
||||
if (!user) {
|
||||
client.users._add(data.user);
|
||||
} else if (!user._equals(data.user)) {
|
||||
client.actions.UserUpdate.handle(data.user);
|
||||
}
|
||||
}
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
const member = this.getMember({ user: data.user }, guild);
|
||||
if (member) {
|
||||
const old = member._update(data);
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
if (shard.status === Status.Ready && !member.equals(old)) client.emit(Events.GuildMemberUpdate, old, member);
|
||||
} else {
|
||||
const newMember = guild.members._add(data);
|
||||
/**
|
||||
* Emitted whenever a member becomes available.
|
||||
* @event Client#guildMemberAvailable
|
||||
* @param {GuildMember} member The member that became available
|
||||
*/
|
||||
this.client.emit(Events.GuildMemberAvailable, newMember);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildMemberUpdateAction;
|
25
node_modules/discord.js/src/client/actions/GuildRoleCreate.js
generated
vendored
Normal file
25
node_modules/discord.js/src/client/actions/GuildRoleCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildRoleCreate extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
let role;
|
||||
if (guild) {
|
||||
const already = guild.roles.cache.has(data.role.id);
|
||||
role = guild.roles._add(data.role);
|
||||
/**
|
||||
* Emitted whenever a role is created.
|
||||
* @event Client#roleCreate
|
||||
* @param {Role} role The role that was created
|
||||
*/
|
||||
if (!already) client.emit(Events.GuildRoleCreate, role);
|
||||
}
|
||||
return { role };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildRoleCreate;
|
29
node_modules/discord.js/src/client/actions/GuildRoleDelete.js
generated
vendored
Normal file
29
node_modules/discord.js/src/client/actions/GuildRoleDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildRoleDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
let role;
|
||||
|
||||
if (guild) {
|
||||
role = guild.roles.cache.get(data.role_id);
|
||||
if (role) {
|
||||
guild.roles.cache.delete(data.role_id);
|
||||
/**
|
||||
* Emitted whenever a guild role is deleted.
|
||||
* @event Client#roleDelete
|
||||
* @param {Role} role The role that was deleted
|
||||
*/
|
||||
client.emit(Events.GuildRoleDelete, role);
|
||||
}
|
||||
}
|
||||
|
||||
return { role };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildRoleDeleteAction;
|
39
node_modules/discord.js/src/client/actions/GuildRoleUpdate.js
generated
vendored
Normal file
39
node_modules/discord.js/src/client/actions/GuildRoleUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildRoleUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
let old = null;
|
||||
|
||||
const role = guild.roles.cache.get(data.role.id);
|
||||
if (role) {
|
||||
old = role._update(data.role);
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
client.emit(Events.GuildRoleUpdate, old, role);
|
||||
}
|
||||
|
||||
return {
|
||||
old,
|
||||
updated: role,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildRoleUpdateAction;
|
21
node_modules/discord.js/src/client/actions/GuildRolesPositionUpdate.js
generated
vendored
Normal file
21
node_modules/discord.js/src/client/actions/GuildRolesPositionUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
|
||||
class GuildRolesPositionUpdate extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
for (const partialRole of data.roles) {
|
||||
const role = guild.roles.cache.get(partialRole.id);
|
||||
if (role) role.rawPosition = partialRole.position;
|
||||
}
|
||||
}
|
||||
|
||||
return { guild };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildRolesPositionUpdate;
|
27
node_modules/discord.js/src/client/actions/GuildScheduledEventCreate.js
generated
vendored
Normal file
27
node_modules/discord.js/src/client/actions/GuildScheduledEventCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildScheduledEventCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
const guildScheduledEvent = guild.scheduledEvents._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild scheduled event is created.
|
||||
* @event Client#guildScheduledEventCreate
|
||||
* @param {GuildScheduledEvent} guildScheduledEvent The created guild scheduled event
|
||||
*/
|
||||
client.emit(Events.GuildScheduledEventCreate, guildScheduledEvent);
|
||||
|
||||
return { guildScheduledEvent };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildScheduledEventCreateAction;
|
31
node_modules/discord.js/src/client/actions/GuildScheduledEventDelete.js
generated
vendored
Normal file
31
node_modules/discord.js/src/client/actions/GuildScheduledEventDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildScheduledEventDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
const guildScheduledEvent = this.getScheduledEvent(data, guild);
|
||||
if (guildScheduledEvent) {
|
||||
guild.scheduledEvents.cache.delete(guildScheduledEvent.id);
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild scheduled event is deleted.
|
||||
* @event Client#guildScheduledEventDelete
|
||||
* @param {GuildScheduledEvent} guildScheduledEvent The deleted guild scheduled event
|
||||
*/
|
||||
client.emit(Events.GuildScheduledEventDelete, guildScheduledEvent);
|
||||
|
||||
return { guildScheduledEvent };
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildScheduledEventDeleteAction;
|
30
node_modules/discord.js/src/client/actions/GuildScheduledEventUpdate.js
generated
vendored
Normal file
30
node_modules/discord.js/src/client/actions/GuildScheduledEventUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildScheduledEventUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
const oldGuildScheduledEvent = guild.scheduledEvents.cache.get(data.id)?._clone() ?? null;
|
||||
const newGuildScheduledEvent = guild.scheduledEvents._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild scheduled event gets updated.
|
||||
* @event Client#guildScheduledEventUpdate
|
||||
* @param {?GuildScheduledEvent} oldGuildScheduledEvent The guild scheduled event object before the update
|
||||
* @param {GuildScheduledEvent} newGuildScheduledEvent The guild scheduled event object after the update
|
||||
*/
|
||||
client.emit(Events.GuildScheduledEventUpdate, oldGuildScheduledEvent, newGuildScheduledEvent);
|
||||
|
||||
return { oldGuildScheduledEvent, newGuildScheduledEvent };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildScheduledEventUpdateAction;
|
32
node_modules/discord.js/src/client/actions/GuildScheduledEventUserAdd.js
generated
vendored
Normal file
32
node_modules/discord.js/src/client/actions/GuildScheduledEventUserAdd.js
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildScheduledEventUserAddAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
const guildScheduledEvent = this.getScheduledEvent(data, guild);
|
||||
const user = this.getUser(data);
|
||||
|
||||
if (guildScheduledEvent && user) {
|
||||
/**
|
||||
* Emitted whenever a user subscribes to a guild scheduled event
|
||||
* @event Client#guildScheduledEventUserAdd
|
||||
* @param {GuildScheduledEvent} guildScheduledEvent The guild scheduled event
|
||||
* @param {User} user The user who subscribed
|
||||
*/
|
||||
client.emit(Events.GuildScheduledEventUserAdd, guildScheduledEvent, user);
|
||||
|
||||
return { guildScheduledEvent, user };
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildScheduledEventUserAddAction;
|
32
node_modules/discord.js/src/client/actions/GuildScheduledEventUserRemove.js
generated
vendored
Normal file
32
node_modules/discord.js/src/client/actions/GuildScheduledEventUserRemove.js
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildScheduledEventUserRemoveAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
if (guild) {
|
||||
const guildScheduledEvent = this.getScheduledEvent(data, guild);
|
||||
const user = this.getUser(data);
|
||||
|
||||
if (guildScheduledEvent && user) {
|
||||
/**
|
||||
* Emitted whenever a user unsubscribes from a guild scheduled event
|
||||
* @event Client#guildScheduledEventUserRemove
|
||||
* @param {GuildScheduledEvent} guildScheduledEvent The guild scheduled event
|
||||
* @param {User} user The user who unsubscribed
|
||||
*/
|
||||
client.emit(Events.GuildScheduledEventUserRemove, guildScheduledEvent, user);
|
||||
|
||||
return { guildScheduledEvent, user };
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildScheduledEventUserRemoveAction;
|
20
node_modules/discord.js/src/client/actions/GuildStickerCreate.js
generated
vendored
Normal file
20
node_modules/discord.js/src/client/actions/GuildStickerCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildStickerCreateAction extends Action {
|
||||
handle(guild, createdSticker) {
|
||||
const already = guild.stickers.cache.has(createdSticker.id);
|
||||
const sticker = guild.stickers._add(createdSticker);
|
||||
/**
|
||||
* Emitted whenever a custom sticker is created in a guild.
|
||||
* @event Client#stickerCreate
|
||||
* @param {Sticker} sticker The sticker that was created
|
||||
*/
|
||||
if (!already) this.client.emit(Events.GuildStickerCreate, sticker);
|
||||
return { sticker };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickerCreateAction;
|
19
node_modules/discord.js/src/client/actions/GuildStickerDelete.js
generated
vendored
Normal file
19
node_modules/discord.js/src/client/actions/GuildStickerDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildStickerDeleteAction extends Action {
|
||||
handle(sticker) {
|
||||
sticker.guild.stickers.cache.delete(sticker.id);
|
||||
/**
|
||||
* Emitted whenever a custom sticker is deleted in a guild.
|
||||
* @event Client#stickerDelete
|
||||
* @param {Sticker} sticker The sticker that was deleted
|
||||
*/
|
||||
this.client.emit(Events.GuildStickerDelete, sticker);
|
||||
return { sticker };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickerDeleteAction;
|
20
node_modules/discord.js/src/client/actions/GuildStickerUpdate.js
generated
vendored
Normal file
20
node_modules/discord.js/src/client/actions/GuildStickerUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildStickerUpdateAction extends Action {
|
||||
handle(current, data) {
|
||||
const old = current._update(data);
|
||||
/**
|
||||
* Emitted whenever a custom sticker is updated in a guild.
|
||||
* @event Client#stickerUpdate
|
||||
* @param {Sticker} oldSticker The old sticker
|
||||
* @param {Sticker} newSticker The new sticker
|
||||
*/
|
||||
this.client.emit(Events.GuildStickerUpdate, old, current);
|
||||
return { sticker: current };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickerUpdateAction;
|
34
node_modules/discord.js/src/client/actions/GuildStickersUpdate.js
generated
vendored
Normal file
34
node_modules/discord.js/src/client/actions/GuildStickersUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
|
||||
class GuildStickersUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (!guild?.stickers) return;
|
||||
|
||||
const deletions = new Map(guild.stickers.cache);
|
||||
|
||||
for (const sticker of data.stickers) {
|
||||
// Determine type of sticker event
|
||||
const cachedSticker = guild.stickers.cache.get(sticker.id);
|
||||
if (cachedSticker) {
|
||||
deletions.delete(sticker.id);
|
||||
if (!cachedSticker.equals(sticker)) {
|
||||
// Sticker updated
|
||||
this.client.actions.GuildStickerUpdate.handle(cachedSticker, sticker);
|
||||
}
|
||||
} else {
|
||||
// Sticker added
|
||||
this.client.actions.GuildStickerCreate.handle(guild, sticker);
|
||||
}
|
||||
}
|
||||
|
||||
for (const sticker of deletions.values()) {
|
||||
// Sticker deleted
|
||||
this.client.actions.GuildStickerDelete.handle(sticker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickersUpdateAction;
|
33
node_modules/discord.js/src/client/actions/GuildUpdate.js
generated
vendored
Normal file
33
node_modules/discord.js/src/client/actions/GuildUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class GuildUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const guild = client.guilds.cache.get(data.id);
|
||||
if (guild) {
|
||||
const old = guild._update(data);
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
client.emit(Events.GuildUpdate, old, guild);
|
||||
return {
|
||||
old,
|
||||
updated: guild,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildUpdateAction;
|
101
node_modules/discord.js/src/client/actions/InteractionCreate.js
generated
vendored
Normal file
101
node_modules/discord.js/src/client/actions/InteractionCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
'use strict';
|
||||
|
||||
const { InteractionType, ComponentType, ApplicationCommandType } = require('discord-api-types/v10');
|
||||
const Action = require('./Action');
|
||||
const AutocompleteInteraction = require('../../structures/AutocompleteInteraction');
|
||||
const ButtonInteraction = require('../../structures/ButtonInteraction');
|
||||
const ChannelSelectMenuInteraction = require('../../structures/ChannelSelectMenuInteraction');
|
||||
const ChatInputCommandInteraction = require('../../structures/ChatInputCommandInteraction');
|
||||
const MentionableSelectMenuInteraction = require('../../structures/MentionableSelectMenuInteraction');
|
||||
const MessageContextMenuCommandInteraction = require('../../structures/MessageContextMenuCommandInteraction');
|
||||
const ModalSubmitInteraction = require('../../structures/ModalSubmitInteraction');
|
||||
const RoleSelectMenuInteraction = require('../../structures/RoleSelectMenuInteraction');
|
||||
const StringSelectMenuInteraction = require('../../structures/StringSelectMenuInteraction');
|
||||
const UserContextMenuCommandInteraction = require('../../structures/UserContextMenuCommandInteraction');
|
||||
const UserSelectMenuInteraction = require('../../structures/UserSelectMenuInteraction');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class InteractionCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
// Resolve and cache partial channels for Interaction#channel getter
|
||||
const channel = data.channel && this.getChannel(data.channel);
|
||||
|
||||
// Do not emit this for interactions that cache messages that are non-text-based.
|
||||
let InteractionClass;
|
||||
|
||||
switch (data.type) {
|
||||
case InteractionType.ApplicationCommand:
|
||||
switch (data.data.type) {
|
||||
case ApplicationCommandType.ChatInput:
|
||||
InteractionClass = ChatInputCommandInteraction;
|
||||
break;
|
||||
case ApplicationCommandType.User:
|
||||
InteractionClass = UserContextMenuCommandInteraction;
|
||||
break;
|
||||
case ApplicationCommandType.Message:
|
||||
if (channel && !channel.isTextBased()) return;
|
||||
InteractionClass = MessageContextMenuCommandInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
Events.Debug,
|
||||
`[INTERACTION] Received application command interaction with unknown type: ${data.data.type}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case InteractionType.MessageComponent:
|
||||
if (channel && !channel.isTextBased()) return;
|
||||
|
||||
switch (data.data.component_type) {
|
||||
case ComponentType.Button:
|
||||
InteractionClass = ButtonInteraction;
|
||||
break;
|
||||
case ComponentType.StringSelect:
|
||||
InteractionClass = StringSelectMenuInteraction;
|
||||
break;
|
||||
case ComponentType.UserSelect:
|
||||
InteractionClass = UserSelectMenuInteraction;
|
||||
break;
|
||||
case ComponentType.RoleSelect:
|
||||
InteractionClass = RoleSelectMenuInteraction;
|
||||
break;
|
||||
case ComponentType.MentionableSelect:
|
||||
InteractionClass = MentionableSelectMenuInteraction;
|
||||
break;
|
||||
case ComponentType.ChannelSelect:
|
||||
InteractionClass = ChannelSelectMenuInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
Events.Debug,
|
||||
`[INTERACTION] Received component interaction with unknown type: ${data.data.component_type}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case InteractionType.ApplicationCommandAutocomplete:
|
||||
InteractionClass = AutocompleteInteraction;
|
||||
break;
|
||||
case InteractionType.ModalSubmit:
|
||||
InteractionClass = ModalSubmitInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(Events.Debug, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const interaction = new InteractionClass(client, data);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interactionCreate
|
||||
* @param {BaseInteraction} interaction The interaction which was created
|
||||
*/
|
||||
client.emit(Events.InteractionCreate, interaction);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InteractionCreateAction;
|
27
node_modules/discord.js/src/client/actions/InviteCreate.js
generated
vendored
Normal file
27
node_modules/discord.js/src/client/actions/InviteCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class InviteCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!channel) return false;
|
||||
|
||||
const inviteData = Object.assign(data, { channel, guild });
|
||||
const invite = guild.invites._add(inviteData);
|
||||
|
||||
/**
|
||||
* Emitted when an invite is created.
|
||||
* <info>This event requires the {@link PermissionFlagsBits.ManageChannels} permission for the channel.</info>
|
||||
* @event Client#inviteCreate
|
||||
* @param {Invite} invite The invite that was created
|
||||
*/
|
||||
client.emit(Events.InviteCreate, invite);
|
||||
return { invite };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteCreateAction;
|
29
node_modules/discord.js/src/client/actions/InviteDelete.js
generated
vendored
Normal file
29
node_modules/discord.js/src/client/actions/InviteDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Invite = require('../../structures/Invite');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class InviteDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!channel) return false;
|
||||
|
||||
const inviteData = Object.assign(data, { channel, guild });
|
||||
const invite = new Invite(client, inviteData);
|
||||
guild.invites.cache.delete(invite.code);
|
||||
|
||||
/**
|
||||
* Emitted when an invite is deleted.
|
||||
* <info>This event requires the {@link PermissionFlagsBits.ManageChannels} permission for the channel.</info>
|
||||
* @event Client#inviteDelete
|
||||
* @param {Invite} invite The invite that was deleted
|
||||
*/
|
||||
client.emit(Events.InviteDelete, invite);
|
||||
return { invite };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InviteDeleteAction;
|
37
node_modules/discord.js/src/client/actions/MessageCreate.js
generated
vendored
Normal file
37
node_modules/discord.js/src/client/actions/MessageCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class MessageCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
if (channel) {
|
||||
if (!channel.isTextBased()) return {};
|
||||
|
||||
if (channel.isThread()) {
|
||||
channel.messageCount++;
|
||||
channel.totalMessageSent++;
|
||||
}
|
||||
|
||||
const existing = channel.messages.cache.get(data.id);
|
||||
if (existing && existing.author?.id !== this.client.user.id) return { message: existing };
|
||||
const message = existing ?? channel.messages._add(data);
|
||||
channel.lastMessageId = data.id;
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is created.
|
||||
* @event Client#messageCreate
|
||||
* @param {Message} message The created message
|
||||
*/
|
||||
client.emit(Events.MessageCreate, message);
|
||||
|
||||
return { message };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageCreateAction;
|
32
node_modules/discord.js/src/client/actions/MessageDelete.js
generated
vendored
Normal file
32
node_modules/discord.js/src/client/actions/MessageDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class MessageDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
let message;
|
||||
if (channel) {
|
||||
if (!channel.isTextBased()) return {};
|
||||
|
||||
if (channel.isThread()) channel.messageCount--;
|
||||
|
||||
message = this.getMessage(data, channel);
|
||||
if (message) {
|
||||
channel.messages.cache.delete(message.id);
|
||||
/**
|
||||
* Emitted whenever a message is deleted.
|
||||
* @event Client#messageDelete
|
||||
* @param {Message} message The deleted message
|
||||
*/
|
||||
client.emit(Events.MessageDelete, message);
|
||||
}
|
||||
}
|
||||
|
||||
return { message };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageDeleteAction;
|
47
node_modules/discord.js/src/client/actions/MessageDeleteBulk.js
generated
vendored
Normal file
47
node_modules/discord.js/src/client/actions/MessageDeleteBulk.js
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class MessageDeleteBulkAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
|
||||
if (channel) {
|
||||
if (!channel.isTextBased()) return {};
|
||||
|
||||
if (channel.isThread()) channel.messageCount -= data.ids.length;
|
||||
|
||||
const ids = data.ids;
|
||||
const messages = new Collection();
|
||||
for (const id of ids) {
|
||||
const message = this.getMessage(
|
||||
{
|
||||
id,
|
||||
guild_id: data.guild_id,
|
||||
},
|
||||
channel,
|
||||
false,
|
||||
);
|
||||
if (message) {
|
||||
messages.set(message.id, message);
|
||||
channel.messages.cache.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever messages are deleted in bulk.
|
||||
* @event Client#messageDeleteBulk
|
||||
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their id
|
||||
* @param {GuildTextBasedChannel} channel The channel that the messages were deleted in
|
||||
*/
|
||||
if (messages.size > 0) client.emit(Events.MessageBulkDelete, messages, channel);
|
||||
return { messages };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageDeleteBulkAction;
|
33
node_modules/discord.js/src/client/actions/MessagePollVoteAdd.js
generated
vendored
Normal file
33
node_modules/discord.js/src/client/actions/MessagePollVoteAdd.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class MessagePollVoteAddAction extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel?.isTextBased()) return false;
|
||||
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
const { poll } = message;
|
||||
|
||||
const answer = poll.answers.get(data.answer_id);
|
||||
if (!answer) return false;
|
||||
|
||||
answer.voteCount++;
|
||||
|
||||
/**
|
||||
* Emitted whenever a user votes in a poll.
|
||||
* @event Client#messagePollVoteAdd
|
||||
* @param {PollAnswer} pollAnswer The answer that was voted on
|
||||
* @param {Snowflake} userId The id of the user that voted
|
||||
*/
|
||||
this.client.emit(Events.MessagePollVoteAdd, answer, data.user_id);
|
||||
|
||||
return { poll };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessagePollVoteAddAction;
|
33
node_modules/discord.js/src/client/actions/MessagePollVoteRemove.js
generated
vendored
Normal file
33
node_modules/discord.js/src/client/actions/MessagePollVoteRemove.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class MessagePollVoteRemoveAction extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel?.isTextBased()) return false;
|
||||
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
const { poll } = message;
|
||||
|
||||
const answer = poll.answers.get(data.answer_id);
|
||||
if (!answer) return false;
|
||||
|
||||
answer.voteCount--;
|
||||
|
||||
/**
|
||||
* Emitted whenever a user removes their vote in a poll.
|
||||
* @event Client#messagePollVoteRemove
|
||||
* @param {PollAnswer} pollAnswer The answer where the vote was removed
|
||||
* @param {Snowflake} userId The id of the user that removed their vote
|
||||
*/
|
||||
this.client.emit(Events.MessagePollVoteRemove, answer, data.user_id);
|
||||
|
||||
return { poll };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessagePollVoteRemoveAction;
|
55
node_modules/discord.js/src/client/actions/MessageReactionAdd.js
generated
vendored
Normal file
55
node_modules/discord.js/src/client/actions/MessageReactionAdd.js
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
const Partials = require('../../util/Partials');
|
||||
|
||||
/*
|
||||
{ user_id: 'id',
|
||||
message_id: 'id',
|
||||
emoji: { name: '<27>', id: null },
|
||||
channel_id: 'id',
|
||||
// If originating from a guild
|
||||
guild_id: 'id',
|
||||
member: { ..., user: { ... } } }
|
||||
*/
|
||||
|
||||
class MessageReactionAdd extends Action {
|
||||
handle(data, fromStructure = false) {
|
||||
if (!data.emoji) return false;
|
||||
|
||||
const user = this.getUserFromMember(data);
|
||||
if (!user) return false;
|
||||
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel?.isTextBased()) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
// Verify reaction
|
||||
const includePartial = this.client.options.partials.includes(Partials.Reaction);
|
||||
if (message.partial && !includePartial) return false;
|
||||
const reaction = message.reactions._add({
|
||||
emoji: data.emoji,
|
||||
count: message.partial ? null : 0,
|
||||
me: user.id === this.client.user.id,
|
||||
});
|
||||
if (!reaction) return false;
|
||||
reaction._add(user);
|
||||
if (fromStructure) return { message, reaction, user };
|
||||
/**
|
||||
* Emitted whenever a reaction is added to a cached message.
|
||||
* @event Client#messageReactionAdd
|
||||
* @param {MessageReaction} messageReaction The reaction object
|
||||
* @param {User} user The user that applied the guild or reaction emoji
|
||||
*/
|
||||
this.client.emit(Events.MessageReactionAdd, reaction, user);
|
||||
|
||||
return { message, reaction, user };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageReactionAdd;
|
45
node_modules/discord.js/src/client/actions/MessageReactionRemove.js
generated
vendored
Normal file
45
node_modules/discord.js/src/client/actions/MessageReactionRemove.js
generated
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
/*
|
||||
{ user_id: 'id',
|
||||
message_id: 'id',
|
||||
emoji: { name: '<27>', id: null },
|
||||
channel_id: 'id',
|
||||
guild_id: 'id' }
|
||||
*/
|
||||
|
||||
class MessageReactionRemove extends Action {
|
||||
handle(data) {
|
||||
if (!data.emoji) return false;
|
||||
|
||||
const user = this.getUser(data);
|
||||
if (!user) return false;
|
||||
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel?.isTextBased()) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
// Verify reaction
|
||||
const reaction = this.getReaction(data, message, user);
|
||||
if (!reaction) return false;
|
||||
reaction._remove(user);
|
||||
/**
|
||||
* Emitted whenever a reaction is removed from a cached message.
|
||||
* @event Client#messageReactionRemove
|
||||
* @param {MessageReaction} messageReaction The reaction object
|
||||
* @param {User} user The user whose emoji or reaction emoji was removed
|
||||
*/
|
||||
this.client.emit(Events.MessageReactionRemove, reaction, user);
|
||||
|
||||
return { message, reaction, user };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageReactionRemove;
|
33
node_modules/discord.js/src/client/actions/MessageReactionRemoveAll.js
generated
vendored
Normal file
33
node_modules/discord.js/src/client/actions/MessageReactionRemoveAll.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class MessageReactionRemoveAll extends Action {
|
||||
handle(data) {
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel?.isTextBased()) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
// Copy removed reactions to emit for the event.
|
||||
const removed = message.reactions.cache.clone();
|
||||
|
||||
message.reactions.cache.clear();
|
||||
this.client.emit(Events.MessageReactionRemoveAll, message, removed);
|
||||
|
||||
return { message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever all reactions are removed from a cached message.
|
||||
* @event Client#messageReactionRemoveAll
|
||||
* @param {Message} message The message the reactions were removed from
|
||||
* @param {Collection<string|Snowflake, MessageReaction>} reactions The cached message reactions that were removed.
|
||||
*/
|
||||
|
||||
module.exports = MessageReactionRemoveAll;
|
28
node_modules/discord.js/src/client/actions/MessageReactionRemoveEmoji.js
generated
vendored
Normal file
28
node_modules/discord.js/src/client/actions/MessageReactionRemoveEmoji.js
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class MessageReactionRemoveEmoji extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel?.isTextBased()) return false;
|
||||
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
const reaction = this.getReaction(data, message);
|
||||
if (!reaction) return false;
|
||||
if (!message.partial) message.reactions.cache.delete(reaction.emoji.id ?? reaction.emoji.name);
|
||||
|
||||
/**
|
||||
* Emitted when a bot removes an emoji reaction from a cached message.
|
||||
* @event Client#messageReactionRemoveEmoji
|
||||
* @param {MessageReaction} reaction The reaction that was removed
|
||||
*/
|
||||
this.client.emit(Events.MessageReactionRemoveEmoji, reaction);
|
||||
return { reaction };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageReactionRemoveEmoji;
|
26
node_modules/discord.js/src/client/actions/MessageUpdate.js
generated
vendored
Normal file
26
node_modules/discord.js/src/client/actions/MessageUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
|
||||
class MessageUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (channel) {
|
||||
if (!channel.isTextBased()) return {};
|
||||
|
||||
const { id, channel_id, guild_id, author, timestamp, type } = data;
|
||||
const message = this.getMessage({ id, channel_id, guild_id, author, timestamp, type }, channel);
|
||||
if (message) {
|
||||
const old = message._update(data);
|
||||
return {
|
||||
old,
|
||||
updated: message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MessageUpdateAction;
|
42
node_modules/discord.js/src/client/actions/PresenceUpdate.js
generated
vendored
Normal file
42
node_modules/discord.js/src/client/actions/PresenceUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class PresenceUpdateAction extends Action {
|
||||
handle(data) {
|
||||
let user = this.client.users.cache.get(data.user.id);
|
||||
if (!user && data.user.username) user = this.client.users._add(data.user);
|
||||
if (!user) return;
|
||||
|
||||
if (data.user.username) {
|
||||
if (!user._equals(data.user)) this.client.actions.UserUpdate.handle(data.user);
|
||||
}
|
||||
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
|
||||
const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
|
||||
let member = guild.members.cache.get(user.id);
|
||||
if (!member && data.status !== 'offline') {
|
||||
member = guild.members._add({
|
||||
user,
|
||||
deaf: false,
|
||||
mute: false,
|
||||
});
|
||||
this.client.emit(Events.GuildMemberAvailable, member);
|
||||
}
|
||||
const newPresence = guild.presences._add(Object.assign(data, { guild }));
|
||||
if (this.client.listenerCount(Events.PresenceUpdate) && !newPresence.equals(oldPresence)) {
|
||||
/**
|
||||
* Emitted whenever a guild member's presence (e.g. status, activity) is changed.
|
||||
* @event Client#presenceUpdate
|
||||
* @param {?Presence} oldPresence The presence before the update, if one at all
|
||||
* @param {Presence} newPresence The presence after the update
|
||||
*/
|
||||
this.client.emit(Events.PresenceUpdate, oldPresence, newPresence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PresenceUpdateAction;
|
28
node_modules/discord.js/src/client/actions/StageInstanceCreate.js
generated
vendored
Normal file
28
node_modules/discord.js/src/client/actions/StageInstanceCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class StageInstanceCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const stageInstance = channel.guild.stageInstances._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a stage instance is created.
|
||||
* @event Client#stageInstanceCreate
|
||||
* @param {StageInstance} stageInstance The created stage instance
|
||||
*/
|
||||
client.emit(Events.StageInstanceCreate, stageInstance);
|
||||
|
||||
return { stageInstance };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StageInstanceCreateAction;
|
31
node_modules/discord.js/src/client/actions/StageInstanceDelete.js
generated
vendored
Normal file
31
node_modules/discord.js/src/client/actions/StageInstanceDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class StageInstanceDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const stageInstance = channel.guild.stageInstances._add(data);
|
||||
if (stageInstance) {
|
||||
channel.guild.stageInstances.cache.delete(stageInstance.id);
|
||||
|
||||
/**
|
||||
* Emitted whenever a stage instance is deleted.
|
||||
* @event Client#stageInstanceDelete
|
||||
* @param {StageInstance} stageInstance The deleted stage instance
|
||||
*/
|
||||
client.emit(Events.StageInstanceDelete, stageInstance);
|
||||
|
||||
return { stageInstance };
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StageInstanceDeleteAction;
|
30
node_modules/discord.js/src/client/actions/StageInstanceUpdate.js
generated
vendored
Normal file
30
node_modules/discord.js/src/client/actions/StageInstanceUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class StageInstanceUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone() ?? null;
|
||||
const newStageInstance = channel.guild.stageInstances._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level
|
||||
* @event Client#stageInstanceUpdate
|
||||
* @param {?StageInstance} oldStageInstance The stage instance before the update
|
||||
* @param {StageInstance} newStageInstance The stage instance after the update
|
||||
*/
|
||||
client.emit(Events.StageInstanceUpdate, oldStageInstance, newStageInstance);
|
||||
|
||||
return { oldStageInstance, newStageInstance };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StageInstanceUpdateAction;
|
24
node_modules/discord.js/src/client/actions/ThreadCreate.js
generated
vendored
Normal file
24
node_modules/discord.js/src/client/actions/ThreadCreate.js
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class ThreadCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const existing = client.channels.cache.has(data.id);
|
||||
const thread = client.channels._add(data);
|
||||
if (!existing && thread) {
|
||||
/**
|
||||
* Emitted whenever a thread is created or when the client user is added to a thread.
|
||||
* @event Client#threadCreate
|
||||
* @param {ThreadChannel} thread The thread that was created
|
||||
* @param {boolean} newlyCreated Whether the thread was newly created
|
||||
*/
|
||||
client.emit(Events.ThreadCreate, thread, data.newly_created ?? false);
|
||||
}
|
||||
return { thread };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadCreateAction;
|
26
node_modules/discord.js/src/client/actions/ThreadDelete.js
generated
vendored
Normal file
26
node_modules/discord.js/src/client/actions/ThreadDelete.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class ThreadDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const thread = client.channels.cache.get(data.id);
|
||||
|
||||
if (thread) {
|
||||
client.channels._remove(thread.id);
|
||||
|
||||
/**
|
||||
* Emitted whenever a thread is deleted.
|
||||
* @event Client#threadDelete
|
||||
* @param {ThreadChannel} thread The thread that was deleted
|
||||
*/
|
||||
client.emit(Events.ThreadDelete, thread);
|
||||
}
|
||||
|
||||
return { thread };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadDeleteAction;
|
60
node_modules/discord.js/src/client/actions/ThreadListSync.js
generated
vendored
Normal file
60
node_modules/discord.js/src/client/actions/ThreadListSync.js
generated
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class ThreadListSyncAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return {};
|
||||
|
||||
if (data.channel_ids) {
|
||||
for (const id of data.channel_ids) {
|
||||
const channel = client.channels.resolve(id);
|
||||
if (channel) this.removeStale(channel);
|
||||
}
|
||||
} else {
|
||||
for (const channel of guild.channels.cache.values()) {
|
||||
this.removeStale(channel);
|
||||
}
|
||||
}
|
||||
|
||||
const syncedThreads = data.threads.reduce((coll, rawThread) => {
|
||||
const thread = client.channels._add(rawThread);
|
||||
return coll.set(thread.id, thread);
|
||||
}, new Collection());
|
||||
|
||||
for (const rawMember of Object.values(data.members)) {
|
||||
// Discord sends the thread id as id in this object
|
||||
const thread = client.channels.cache.get(rawMember.id);
|
||||
if (thread) {
|
||||
thread.members._add(rawMember);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever the client user gains access to a text or news channel that contains threads
|
||||
* @event Client#threadListSync
|
||||
* @param {Collection<Snowflake, ThreadChannel>} threads The threads that were synced
|
||||
* @param {Guild} guild The guild that the threads were synced in
|
||||
*/
|
||||
client.emit(Events.ThreadListSync, syncedThreads, guild);
|
||||
|
||||
return {
|
||||
syncedThreads,
|
||||
};
|
||||
}
|
||||
|
||||
removeStale(channel) {
|
||||
channel.threads?.cache.forEach(thread => {
|
||||
if (!thread.archived) {
|
||||
this.client.channels._remove(thread.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadListSyncAction;
|
30
node_modules/discord.js/src/client/actions/ThreadMemberUpdate.js
generated
vendored
Normal file
30
node_modules/discord.js/src/client/actions/ThreadMemberUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class ThreadMemberUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
// Discord sends the thread id as id in this object
|
||||
const thread = client.channels.cache.get(data.id);
|
||||
if (thread) {
|
||||
const member = thread.members.cache.get(data.user_id);
|
||||
if (!member) {
|
||||
const newMember = thread.members._add(data);
|
||||
return { newMember };
|
||||
}
|
||||
const old = member._update(data);
|
||||
/**
|
||||
* Emitted whenever the client user's thread member is updated.
|
||||
* @event Client#threadMemberUpdate
|
||||
* @param {ThreadMember} oldMember The member before the update
|
||||
* @param {ThreadMember} newMember The member after the update
|
||||
*/
|
||||
client.emit(Events.ThreadMemberUpdate, old, member);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadMemberUpdateAction;
|
47
node_modules/discord.js/src/client/actions/ThreadMembersUpdate.js
generated
vendored
Normal file
47
node_modules/discord.js/src/client/actions/ThreadMembersUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class ThreadMembersUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const thread = client.channels.cache.get(data.id);
|
||||
if (thread) {
|
||||
thread.memberCount = data.member_count;
|
||||
const addedMembers = new Collection();
|
||||
const removedMembers = new Collection();
|
||||
|
||||
data.added_members?.reduce(
|
||||
(_addedMembers, addedMember) => _addedMembers.set(addedMember.user_id, thread.members._add(addedMember)),
|
||||
addedMembers,
|
||||
);
|
||||
|
||||
data.removed_member_ids?.reduce((removedMembersIds, removedMembersId) => {
|
||||
const threadMember = this.getThreadMember(removedMembersId, thread.members);
|
||||
if (threadMember) removedMembersIds.set(threadMember.id, threadMember);
|
||||
thread.members.cache.delete(removedMembersId);
|
||||
return removedMembersIds;
|
||||
}, removedMembers);
|
||||
|
||||
if (addedMembers.size === 0 && removedMembers.size === 0) {
|
||||
// Uncached thread member(s) left.
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever members are added or removed from a thread.
|
||||
* <info>This event requires the {@link GatewayIntentBits.GuildMembers} privileged gateway intent.</info>
|
||||
* @event Client#threadMembersUpdate
|
||||
* @param {Collection<Snowflake, ThreadMember>} addedMembers The members that were added
|
||||
* @param {Collection<Snowflake, ThreadMember>} removedMembers The members that were removed
|
||||
* @param {ThreadChannel} thread The thread where members got updated
|
||||
*/
|
||||
client.emit(Events.ThreadMembersUpdate, addedMembers, removedMembers, thread);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadMembersUpdateAction;
|
29
node_modules/discord.js/src/client/actions/TypingStart.js
generated
vendored
Normal file
29
node_modules/discord.js/src/client/actions/TypingStart.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Typing = require('../../structures/Typing');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class TypingStart extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel) return;
|
||||
|
||||
if (!channel.isTextBased()) {
|
||||
this.client.emit(Events.Warn, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = this.getUserFromMember(data);
|
||||
if (user) {
|
||||
/**
|
||||
* Emitted whenever a user starts typing in a channel.
|
||||
* @event Client#typingStart
|
||||
* @param {Typing} typing The typing state
|
||||
*/
|
||||
this.client.emit(Events.TypingStart, new Typing(channel, user, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TypingStart;
|
36
node_modules/discord.js/src/client/actions/UserUpdate.js
generated
vendored
Normal file
36
node_modules/discord.js/src/client/actions/UserUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class UserUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const newUser = data.id === client.user.id ? client.user : client.users.cache.get(data.id);
|
||||
const oldUser = newUser._update(data);
|
||||
|
||||
if (!oldUser.equals(newUser)) {
|
||||
/**
|
||||
* Emitted whenever a user's details (e.g. username) are changed.
|
||||
* Triggered by the Discord gateway events {@link Events.UserUpdate},
|
||||
* {@link Events.GuildMemberUpdate}, and {@link Events.PresenceUpdate}.
|
||||
* @event Client#userUpdate
|
||||
* @param {User} oldUser The user before the update
|
||||
* @param {User} newUser The user after the update
|
||||
*/
|
||||
client.emit(Events.UserUpdate, oldUser, newUser);
|
||||
return {
|
||||
old: oldUser,
|
||||
updated: newUser,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
old: null,
|
||||
updated: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserUpdateAction;
|
43
node_modules/discord.js/src/client/actions/VoiceStateUpdate.js
generated
vendored
Normal file
43
node_modules/discord.js/src/client/actions/VoiceStateUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const VoiceState = require('../../structures/VoiceState');
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
class VoiceStateUpdate extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
// Update the state
|
||||
const oldState =
|
||||
guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id });
|
||||
|
||||
const newState = guild.voiceStates._add(data);
|
||||
|
||||
// Get the member
|
||||
let member = guild.members.cache.get(data.user_id);
|
||||
if (member && data.member) {
|
||||
member._patch(data.member);
|
||||
} else if (data.member?.user && data.member.joined_at) {
|
||||
member = guild.members._add(data.member);
|
||||
}
|
||||
|
||||
// Emit event
|
||||
if (member?.user.id === client.user.id) {
|
||||
client.emit('debug', `[VOICE] received voice state update: ${JSON.stringify(data)}`);
|
||||
client.voice.onVoiceStateUpdate(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
|
||||
* @event Client#voiceStateUpdate
|
||||
* @param {VoiceState} oldState The voice state before the update
|
||||
* @param {VoiceState} newState The voice state after the update
|
||||
*/
|
||||
client.emit(Events.VoiceStateUpdate, oldState, newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceStateUpdate;
|
37
node_modules/discord.js/src/client/actions/WebhooksUpdate.js
generated
vendored
Normal file
37
node_modules/discord.js/src/client/actions/WebhooksUpdate.js
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
const process = require('node:process');
|
||||
const Action = require('./Action');
|
||||
|
||||
let deprecationEmitted = false;
|
||||
|
||||
class WebhooksUpdate extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
if (!channel) return;
|
||||
|
||||
// TODO: change to Events.WebhooksUpdate in the next major version
|
||||
/**
|
||||
* Emitted whenever a channel has its webhooks changed.
|
||||
* @event Client#webhooksUpdate
|
||||
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
|
||||
* The channel that had a webhook update
|
||||
*/
|
||||
client.emit('webhooksUpdate', channel);
|
||||
|
||||
/**
|
||||
* Emitted whenever a channel has its webhooks changed.
|
||||
* @event Client#webhookUpdate
|
||||
* @param {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel} channel
|
||||
* The channel that had a webhook update
|
||||
* @deprecated Use {@link Client#event:webhooksUpdate} instead.
|
||||
*/
|
||||
if (client.emit('webhookUpdate', channel) && !deprecationEmitted) {
|
||||
deprecationEmitted = true;
|
||||
process.emitWarning('The webhookUpdate event is deprecated. Use webhooksUpdate instead.', 'DeprecationWarning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebhooksUpdate;
|
44
node_modules/discord.js/src/client/voice/ClientVoiceManager.js
generated
vendored
Normal file
44
node_modules/discord.js/src/client/voice/ClientVoiceManager.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
const Events = require('../../util/Events');
|
||||
|
||||
/**
|
||||
* Manages voice connections for the client
|
||||
*/
|
||||
class ClientVoiceManager {
|
||||
constructor(client) {
|
||||
/**
|
||||
* The client that instantiated this voice manager
|
||||
* @type {Client}
|
||||
* @readonly
|
||||
* @name ClientVoiceManager#client
|
||||
*/
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
/**
|
||||
* Maps guild ids to voice adapters created for use with `@discordjs/voice`.
|
||||
* @type {Map<Snowflake, Object>}
|
||||
*/
|
||||
this.adapters = new Map();
|
||||
|
||||
client.on(Events.ShardDisconnect, (_, shardId) => {
|
||||
for (const [guildId, adapter] of this.adapters.entries()) {
|
||||
if (client.guilds.cache.get(guildId)?.shardId === shardId) {
|
||||
adapter.destroy();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onVoiceServer(payload) {
|
||||
this.adapters.get(payload.guild_id)?.onVoiceServerUpdate(payload);
|
||||
}
|
||||
|
||||
onVoiceStateUpdate(payload) {
|
||||
if (payload.guild_id && payload.session_id && payload.user_id === this.client.user?.id) {
|
||||
this.adapters.get(payload.guild_id)?.onVoiceStateUpdate(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientVoiceManager;
|
394
node_modules/discord.js/src/client/websocket/WebSocketManager.js
generated
vendored
Normal file
394
node_modules/discord.js/src/client/websocket/WebSocketManager.js
generated
vendored
Normal file
|
@ -0,0 +1,394 @@
|
|||
'use strict';
|
||||
|
||||
const EventEmitter = require('node:events');
|
||||
const process = require('node:process');
|
||||
const { setImmediate } = require('node:timers');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const {
|
||||
WebSocketManager: WSWebSocketManager,
|
||||
WebSocketShardEvents: WSWebSocketShardEvents,
|
||||
CompressionMethod,
|
||||
CloseCodes,
|
||||
} = require('@discordjs/ws');
|
||||
const { GatewayCloseCodes, GatewayDispatchEvents } = require('discord-api-types/v10');
|
||||
const WebSocketShard = require('./WebSocketShard');
|
||||
const PacketHandlers = require('./handlers');
|
||||
const { DiscordjsError, ErrorCodes } = require('../../errors');
|
||||
const Events = require('../../util/Events');
|
||||
const Status = require('../../util/Status');
|
||||
const WebSocketShardEvents = require('../../util/WebSocketShardEvents');
|
||||
|
||||
let zlib;
|
||||
|
||||
try {
|
||||
zlib = require('zlib-sync');
|
||||
} catch {} // eslint-disable-line no-empty
|
||||
|
||||
const BeforeReadyWhitelist = [
|
||||
GatewayDispatchEvents.Ready,
|
||||
GatewayDispatchEvents.Resumed,
|
||||
GatewayDispatchEvents.GuildCreate,
|
||||
GatewayDispatchEvents.GuildDelete,
|
||||
GatewayDispatchEvents.GuildMembersChunk,
|
||||
GatewayDispatchEvents.GuildMemberAdd,
|
||||
GatewayDispatchEvents.GuildMemberRemove,
|
||||
];
|
||||
|
||||
const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
|
||||
|
||||
const UNRESUMABLE_CLOSE_CODES = [
|
||||
CloseCodes.Normal,
|
||||
GatewayCloseCodes.AlreadyAuthenticated,
|
||||
GatewayCloseCodes.InvalidSeq,
|
||||
];
|
||||
|
||||
const reasonIsDeprecated = 'the reason property is deprecated, use the code property to determine the reason';
|
||||
let deprecationEmittedForInvalidSessionEvent = false;
|
||||
let deprecationEmittedForDestroyedEvent = false;
|
||||
|
||||
/**
|
||||
* The WebSocket manager for this client.
|
||||
* <info>This class forwards raw dispatch events,
|
||||
* read more about it here {@link https://discord.com/developers/docs/topics/gateway}</info>
|
||||
* @extends {EventEmitter}
|
||||
*/
|
||||
class WebSocketManager extends EventEmitter {
|
||||
constructor(client) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The client that instantiated this WebSocketManager
|
||||
* @type {Client}
|
||||
* @readonly
|
||||
* @name WebSocketManager#client
|
||||
*/
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
/**
|
||||
* The gateway this manager uses
|
||||
* @type {?string}
|
||||
*/
|
||||
this.gateway = null;
|
||||
|
||||
/**
|
||||
* A collection of all shards this manager handles
|
||||
* @type {Collection<number, WebSocketShard>}
|
||||
*/
|
||||
this.shards = new Collection();
|
||||
|
||||
/**
|
||||
* An array of queued events before this WebSocketManager became ready
|
||||
* @type {Object[]}
|
||||
* @private
|
||||
* @name WebSocketManager#packetQueue
|
||||
*/
|
||||
Object.defineProperty(this, 'packetQueue', { value: [] });
|
||||
|
||||
/**
|
||||
* The current status of this WebSocketManager
|
||||
* @type {Status}
|
||||
*/
|
||||
this.status = Status.Idle;
|
||||
|
||||
/**
|
||||
* If this manager was destroyed. It will prevent shards from reconnecting
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.destroyed = false;
|
||||
|
||||
/**
|
||||
* The internal WebSocketManager from `@discordjs/ws`.
|
||||
* @type {WSWebSocketManager}
|
||||
* @private
|
||||
*/
|
||||
this._ws = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The average ping of all WebSocketShards
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get ping() {
|
||||
const sum = this.shards.reduce((a, b) => a + b.ping, 0);
|
||||
return sum / this.shards.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a debug message.
|
||||
* @param {string} message The debug message
|
||||
* @param {?number} [shardId] The id of the shard that emitted this message, if any
|
||||
* @private
|
||||
*/
|
||||
debug(message, shardId) {
|
||||
this.client.emit(
|
||||
Events.Debug,
|
||||
`[WS => ${typeof shardId === 'number' ? `Shard ${shardId}` : 'Manager'}] ${message}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects this manager to the gateway.
|
||||
* @private
|
||||
*/
|
||||
async connect() {
|
||||
const invalidToken = new DiscordjsError(ErrorCodes.TokenInvalid);
|
||||
const { shards, shardCount, intents, ws } = this.client.options;
|
||||
if (this._ws && this._ws.options.token !== this.client.token) {
|
||||
await this._ws.destroy({ code: CloseCodes.Normal, reason: 'Login with differing token requested' });
|
||||
this._ws = null;
|
||||
}
|
||||
if (!this._ws) {
|
||||
const wsOptions = {
|
||||
intents: intents.bitfield,
|
||||
rest: this.client.rest,
|
||||
token: this.client.token,
|
||||
largeThreshold: ws.large_threshold,
|
||||
version: ws.version,
|
||||
shardIds: shards === 'auto' ? null : shards,
|
||||
shardCount: shards === 'auto' ? null : shardCount,
|
||||
initialPresence: ws.presence,
|
||||
retrieveSessionInfo: shardId => this.shards.get(shardId).sessionInfo,
|
||||
updateSessionInfo: (shardId, sessionInfo) => {
|
||||
this.shards.get(shardId).sessionInfo = sessionInfo;
|
||||
},
|
||||
compression: zlib ? CompressionMethod.ZlibStream : null,
|
||||
};
|
||||
if (ws.buildIdentifyThrottler) wsOptions.buildIdentifyThrottler = ws.buildIdentifyThrottler;
|
||||
if (ws.buildStrategy) wsOptions.buildStrategy = ws.buildStrategy;
|
||||
this._ws = new WSWebSocketManager(wsOptions);
|
||||
this.attachEvents();
|
||||
}
|
||||
|
||||
const {
|
||||
url: gatewayURL,
|
||||
shards: recommendedShards,
|
||||
session_start_limit: sessionStartLimit,
|
||||
} = await this._ws.fetchGatewayInformation().catch(error => {
|
||||
throw error.status === 401 ? invalidToken : error;
|
||||
});
|
||||
|
||||
const { total, remaining } = sessionStartLimit;
|
||||
|
||||
this.debug(`Fetched Gateway Information
|
||||
URL: ${gatewayURL}
|
||||
Recommended Shards: ${recommendedShards}`);
|
||||
|
||||
this.debug(`Session Limit Information
|
||||
Total: ${total}
|
||||
Remaining: ${remaining}`);
|
||||
|
||||
this.gateway = `${gatewayURL}/`;
|
||||
|
||||
this.client.options.shardCount = await this._ws.getShardCount();
|
||||
this.client.options.shards = await this._ws.getShardIds();
|
||||
this.totalShards = this.client.options.shards.length;
|
||||
for (const id of this.client.options.shards) {
|
||||
if (!this.shards.has(id)) {
|
||||
const shard = new WebSocketShard(this, id);
|
||||
this.shards.set(id, shard);
|
||||
|
||||
shard.on(WebSocketShardEvents.AllReady, unavailableGuilds => {
|
||||
/**
|
||||
* Emitted when a shard turns ready.
|
||||
* @event Client#shardReady
|
||||
* @param {number} id The shard id that turned ready
|
||||
* @param {?Set<Snowflake>} unavailableGuilds Set of unavailable guild ids, if any
|
||||
*/
|
||||
this.client.emit(Events.ShardReady, shard.id, unavailableGuilds);
|
||||
|
||||
this.checkShardsReady();
|
||||
});
|
||||
shard.status = Status.Connecting;
|
||||
}
|
||||
}
|
||||
|
||||
await this._ws.connect();
|
||||
|
||||
this.shards.forEach(shard => {
|
||||
if (shard.listenerCount(WebSocketShardEvents.InvalidSession) > 0 && !deprecationEmittedForInvalidSessionEvent) {
|
||||
process.emitWarning(
|
||||
'The WebSocketShard#invalidSession event is deprecated and will never emit.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForInvalidSessionEvent = true;
|
||||
}
|
||||
if (shard.listenerCount(WebSocketShardEvents.Destroyed) > 0 && !deprecationEmittedForDestroyedEvent) {
|
||||
process.emitWarning(
|
||||
'The WebSocketShard#destroyed event is deprecated and will never emit.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForDestroyedEvent = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches event handlers to the internal WebSocketShardManager from `@discordjs/ws`.
|
||||
* @private
|
||||
*/
|
||||
attachEvents() {
|
||||
this._ws.on(WSWebSocketShardEvents.Debug, ({ message, shardId }) => this.debug(message, shardId));
|
||||
this._ws.on(WSWebSocketShardEvents.Dispatch, ({ data, shardId }) => {
|
||||
this.client.emit(Events.Raw, data, shardId);
|
||||
this.emit(data.t, data.d, shardId);
|
||||
const shard = this.shards.get(shardId);
|
||||
this.handlePacket(data, shard);
|
||||
if (shard.status === Status.WaitingForGuilds && WaitingForGuildEvents.includes(data.t)) {
|
||||
shard.gotGuild(data.d.id);
|
||||
}
|
||||
});
|
||||
|
||||
this._ws.on(WSWebSocketShardEvents.Ready, ({ data, shardId }) => {
|
||||
this.shards.get(shardId).onReadyPacket(data);
|
||||
});
|
||||
|
||||
this._ws.on(WSWebSocketShardEvents.Closed, ({ code, shardId }) => {
|
||||
const shard = this.shards.get(shardId);
|
||||
shard.emit(WebSocketShardEvents.Close, { code, reason: reasonIsDeprecated, wasClean: true });
|
||||
if (UNRESUMABLE_CLOSE_CODES.includes(code) && this.destroyed) {
|
||||
shard.status = Status.Disconnected;
|
||||
/**
|
||||
* Emitted when a shard's WebSocket disconnects and will no longer reconnect.
|
||||
* @event Client#shardDisconnect
|
||||
* @param {CloseEvent} event The WebSocket close event
|
||||
* @param {number} id The shard id that disconnected
|
||||
*/
|
||||
this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId);
|
||||
this.debug(`Shard not resumable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`, shardId);
|
||||
return;
|
||||
}
|
||||
|
||||
this.shards.get(shardId).status = Status.Connecting;
|
||||
/**
|
||||
* Emitted when a shard is attempting to reconnect or re-identify.
|
||||
* @event Client#shardReconnecting
|
||||
* @param {number} id The shard id that is attempting to reconnect
|
||||
*/
|
||||
this.client.emit(Events.ShardReconnecting, shardId);
|
||||
});
|
||||
this._ws.on(WSWebSocketShardEvents.Hello, ({ shardId }) => {
|
||||
const shard = this.shards.get(shardId);
|
||||
if (shard.sessionInfo) {
|
||||
shard.closeSequence = shard.sessionInfo.sequence;
|
||||
shard.status = Status.Resuming;
|
||||
} else {
|
||||
shard.status = Status.Identifying;
|
||||
}
|
||||
});
|
||||
|
||||
this._ws.on(WSWebSocketShardEvents.Resumed, ({ shardId }) => {
|
||||
const shard = this.shards.get(shardId);
|
||||
shard.status = Status.Ready;
|
||||
/**
|
||||
* Emitted when the shard resumes successfully
|
||||
* @event WebSocketShard#resumed
|
||||
*/
|
||||
shard.emit(WebSocketShardEvents.Resumed);
|
||||
});
|
||||
|
||||
this._ws.on(WSWebSocketShardEvents.HeartbeatComplete, ({ heartbeatAt, latency, shardId }) => {
|
||||
this.debug(`Heartbeat acknowledged, latency of ${latency}ms.`, shardId);
|
||||
const shard = this.shards.get(shardId);
|
||||
shard.lastPingTimestamp = heartbeatAt;
|
||||
shard.ping = latency;
|
||||
});
|
||||
|
||||
this._ws.on(WSWebSocketShardEvents.Error, ({ error, shardId }) => {
|
||||
/**
|
||||
* Emitted whenever a shard's WebSocket encounters a connection error.
|
||||
* @event Client#shardError
|
||||
* @param {Error} error The encountered error
|
||||
* @param {number} shardId The shard that encountered this error
|
||||
*/
|
||||
this.client.emit(Events.ShardError, error, shardId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a packet to every shard this manager handles.
|
||||
* @param {Object} packet The packet to send
|
||||
* @private
|
||||
*/
|
||||
broadcast(packet) {
|
||||
for (const shardId of this.shards.keys()) this._ws.send(shardId, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys this manager and all its shards.
|
||||
* @private
|
||||
*/
|
||||
async destroy() {
|
||||
if (this.destroyed) return;
|
||||
// TODO: Make a util for getting a stack
|
||||
this.debug(Object.assign(new Error(), { name: 'Manager was destroyed:' }).stack);
|
||||
this.destroyed = true;
|
||||
await this._ws?.destroy({ code: CloseCodes.Normal, reason: 'Manager was destroyed' });
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a packet and queues it if this WebSocketManager is not ready.
|
||||
* @param {Object} [packet] The packet to be handled
|
||||
* @param {WebSocketShard} [shard] The shard that will handle this packet
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
*/
|
||||
handlePacket(packet, shard) {
|
||||
if (packet && this.status !== Status.Ready) {
|
||||
if (!BeforeReadyWhitelist.includes(packet.t)) {
|
||||
this.packetQueue.push({ packet, shard });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.packetQueue.length) {
|
||||
const item = this.packetQueue.shift();
|
||||
setImmediate(() => {
|
||||
this.handlePacket(item.packet, item.shard);
|
||||
}).unref();
|
||||
}
|
||||
|
||||
if (packet && PacketHandlers[packet.t]) {
|
||||
PacketHandlers[packet.t](this.client, packet, shard);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the client is ready to be marked as ready.
|
||||
* @private
|
||||
*/
|
||||
checkShardsReady() {
|
||||
if (this.status === Status.Ready) return;
|
||||
if (this.shards.size !== this.totalShards || this.shards.some(shard => shard.status !== Status.Ready)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.triggerClientReady();
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the client to be marked as ready and emits the ready event.
|
||||
* @private
|
||||
*/
|
||||
triggerClientReady() {
|
||||
this.status = Status.Ready;
|
||||
|
||||
this.client.readyTimestamp = Date.now();
|
||||
|
||||
/**
|
||||
* Emitted when the client becomes ready to start working.
|
||||
* @event Client#ready
|
||||
* @param {Client} client The client
|
||||
*/
|
||||
this.client.emit(Events.ClientReady, this.client);
|
||||
|
||||
this.handlePacket();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebSocketManager;
|
231
node_modules/discord.js/src/client/websocket/WebSocketShard.js
generated
vendored
Normal file
231
node_modules/discord.js/src/client/websocket/WebSocketShard.js
generated
vendored
Normal file
|
@ -0,0 +1,231 @@
|
|||
'use strict';
|
||||
|
||||
const EventEmitter = require('node:events');
|
||||
const process = require('node:process');
|
||||
const { setTimeout, clearTimeout } = require('node:timers');
|
||||
const { GatewayIntentBits } = require('discord-api-types/v10');
|
||||
const Status = require('../../util/Status');
|
||||
const WebSocketShardEvents = require('../../util/WebSocketShardEvents');
|
||||
|
||||
let deprecationEmittedForImportant = false;
|
||||
/**
|
||||
* Represents a Shard's WebSocket connection
|
||||
* @extends {EventEmitter}
|
||||
*/
|
||||
class WebSocketShard extends EventEmitter {
|
||||
constructor(manager, id) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The WebSocketManager of the shard
|
||||
* @type {WebSocketManager}
|
||||
*/
|
||||
this.manager = manager;
|
||||
|
||||
/**
|
||||
* The shard's id
|
||||
* @type {number}
|
||||
*/
|
||||
this.id = id;
|
||||
|
||||
/**
|
||||
* The current status of the shard
|
||||
* @type {Status}
|
||||
*/
|
||||
this.status = Status.Idle;
|
||||
|
||||
/**
|
||||
* The sequence of the shard after close
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.closeSequence = 0;
|
||||
|
||||
/**
|
||||
* The previous heartbeat ping of the shard
|
||||
* @type {number}
|
||||
*/
|
||||
this.ping = -1;
|
||||
|
||||
/**
|
||||
* The last time a ping was sent (a timestamp)
|
||||
* @type {number}
|
||||
*/
|
||||
this.lastPingTimestamp = -1;
|
||||
|
||||
/**
|
||||
* A set of guild ids this shard expects to receive
|
||||
* @name WebSocketShard#expectedGuilds
|
||||
* @type {?Set<string>}
|
||||
* @private
|
||||
*/
|
||||
Object.defineProperty(this, 'expectedGuilds', { value: null, writable: true });
|
||||
|
||||
/**
|
||||
* The ready timeout
|
||||
* @name WebSocketShard#readyTimeout
|
||||
* @type {?NodeJS.Timeout}
|
||||
* @private
|
||||
*/
|
||||
Object.defineProperty(this, 'readyTimeout', { value: null, writable: true });
|
||||
|
||||
/**
|
||||
* @external SessionInfo
|
||||
* @see {@link https://discord.js.org/docs/packages/ws/stable/SessionInfo:Interface}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The session info used by `@discordjs/ws` package.
|
||||
* @name WebSocketShard#sessionInfo
|
||||
* @type {?SessionInfo}
|
||||
* @private
|
||||
*/
|
||||
Object.defineProperty(this, 'sessionInfo', { value: null, writable: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a debug event.
|
||||
* @param {string} message The debug message
|
||||
* @private
|
||||
*/
|
||||
debug(message) {
|
||||
this.manager.debug(message, this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @external CloseEvent
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent}
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method is responsible to emit close event for this shard.
|
||||
* This method helps the shard reconnect.
|
||||
* @param {CloseEvent} [event] Close event that was received
|
||||
* @deprecated
|
||||
*/
|
||||
emitClose(
|
||||
event = {
|
||||
code: 1011,
|
||||
reason: 'INTERNAL_ERROR',
|
||||
wasClean: false,
|
||||
},
|
||||
) {
|
||||
this.debug(`[CLOSE]
|
||||
Event Code: ${event.code}
|
||||
Clean : ${event.wasClean}
|
||||
Reason : ${event.reason ?? 'No reason received'}`);
|
||||
/**
|
||||
* Emitted when a shard's WebSocket closes.
|
||||
* @private
|
||||
* @event WebSocketShard#close
|
||||
* @param {CloseEvent} event The received event
|
||||
*/
|
||||
this.emit(WebSocketShardEvents.Close, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the shard receives the READY payload.
|
||||
* @param {Object} packet The received packet
|
||||
* @private
|
||||
*/
|
||||
onReadyPacket(packet) {
|
||||
if (!packet) {
|
||||
this.debug(`Received broken packet: '${packet}'.`);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted when the shard receives the READY payload and is now waiting for guilds
|
||||
* @event WebSocketShard#ready
|
||||
*/
|
||||
this.emit(WebSocketShardEvents.Ready);
|
||||
|
||||
this.expectedGuilds = new Set(packet.guilds.map(guild => guild.id));
|
||||
this.status = Status.WaitingForGuilds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a GuildCreate or GuildDelete for this shard was sent after READY payload was received,
|
||||
* but before we emitted the READY event.
|
||||
* @param {Snowflake} guildId the id of the Guild sent in the payload
|
||||
* @private
|
||||
*/
|
||||
gotGuild(guildId) {
|
||||
this.expectedGuilds.delete(guildId);
|
||||
this.checkReady();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the shard can be marked as ready
|
||||
* @private
|
||||
*/
|
||||
checkReady() {
|
||||
// Step 0. Clear the ready timeout, if it exists
|
||||
if (this.readyTimeout) {
|
||||
clearTimeout(this.readyTimeout);
|
||||
this.readyTimeout = null;
|
||||
}
|
||||
// Step 1. If we don't have any other guilds pending, we are ready
|
||||
if (!this.expectedGuilds.size) {
|
||||
this.debug('Shard received all its guilds. Marking as fully ready.');
|
||||
this.status = Status.Ready;
|
||||
|
||||
/**
|
||||
* Emitted when the shard is fully ready.
|
||||
* This event is emitted if:
|
||||
* * all guilds were received by this shard
|
||||
* * the ready timeout expired, and some guilds are unavailable
|
||||
* @event WebSocketShard#allReady
|
||||
* @param {?Set<string>} unavailableGuilds Set of unavailable guilds, if any
|
||||
*/
|
||||
this.emit(WebSocketShardEvents.AllReady);
|
||||
return;
|
||||
}
|
||||
const hasGuildsIntent = this.manager.client.options.intents.has(GatewayIntentBits.Guilds);
|
||||
// Step 2. Create a timeout that will mark the shard as ready if there are still unavailable guilds
|
||||
// * The timeout is 15 seconds by default
|
||||
// * This can be optionally changed in the client options via the `waitGuildTimeout` option
|
||||
// * a timeout time of zero will skip this timeout, which potentially could cause the Client to miss guilds.
|
||||
|
||||
const { waitGuildTimeout } = this.manager.client.options;
|
||||
|
||||
this.readyTimeout = setTimeout(
|
||||
() => {
|
||||
this.debug(
|
||||
`Shard ${hasGuildsIntent ? 'did' : 'will'} not receive any more guild packets` +
|
||||
`${hasGuildsIntent ? ` in ${waitGuildTimeout} ms` : ''}.\nUnavailable guild count: ${
|
||||
this.expectedGuilds.size
|
||||
}`,
|
||||
);
|
||||
|
||||
this.readyTimeout = null;
|
||||
this.status = Status.Ready;
|
||||
|
||||
this.emit(WebSocketShardEvents.AllReady, this.expectedGuilds);
|
||||
},
|
||||
hasGuildsIntent ? waitGuildTimeout : 0,
|
||||
).unref();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a packet to the queue to be sent to the gateway.
|
||||
* <warn>If you use this method, make sure you understand that you need to provide
|
||||
* a full [Payload](https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-commands).
|
||||
* Do not use this method if you don't know what you're doing.</warn>
|
||||
* @param {Object} data The full packet to send
|
||||
* @param {boolean} [important=false] If this packet should be added first in queue
|
||||
* <warn>This parameter is **deprecated**. Important payloads are determined by their opcode instead.</warn>
|
||||
*/
|
||||
send(data, important = false) {
|
||||
if (important && !deprecationEmittedForImportant) {
|
||||
process.emitWarning(
|
||||
'Sending important payloads explicitly is deprecated. They are determined by their opcode implicitly now.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
deprecationEmittedForImportant = true;
|
||||
}
|
||||
this.manager._ws.send(this.id, data);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebSocketShard;
|
5
node_modules/discord.js/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.ApplicationCommandPermissionsUpdate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.AutoModerationActionExecution.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.AutoModerationRuleCreate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.AutoModerationRuleDelete.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.AutoModerationRuleUpdate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_CREATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_CREATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.ChannelCreate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_DELETE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_DELETE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.ChannelDelete.handle(packet.d);
|
||||
};
|
22
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js
generated
vendored
Normal file
22
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
const Events = require('../../../util/Events');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
const time = data.last_pin_timestamp ? Date.parse(data.last_pin_timestamp) : null;
|
||||
|
||||
if (channel) {
|
||||
// Discord sends null for last_pin_timestamp if the last pinned message was removed
|
||||
channel.lastPinTimestamp = 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 {TextBasedChannels} channel The channel that the pins update occurred in
|
||||
* @param {Date} time The time of the pins update
|
||||
*/
|
||||
client.emit(Events.ChannelPinsUpdate, channel, time);
|
||||
}
|
||||
};
|
16
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_UPDATE.js
generated
vendored
Normal file
16
node_modules/discord.js/src/client/websocket/handlers/CHANNEL_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const Events = require('../../../util/Events');
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d);
|
||||
if (old && updated) {
|
||||
/**
|
||||
* Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
|
||||
* @event Client#channelUpdate
|
||||
* @param {DMChannel|GuildChannel} oldChannel The channel before the update
|
||||
* @param {DMChannel|GuildChannel} newChannel The channel after the update
|
||||
*/
|
||||
client.emit(Events.ChannelUpdate, old, updated);
|
||||
}
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/ENTITLEMENT_CREATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/ENTITLEMENT_CREATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.EntitlementCreate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/ENTITLEMENT_DELETE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/ENTITLEMENT_DELETE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.EntitlementDelete.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.EntitlementUpdate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildAuditLogEntryCreate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_BAN_ADD.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_BAN_ADD.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildBanAdd.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_BAN_REMOVE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_BAN_REMOVE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildBanRemove.handle(packet.d);
|
||||
};
|
33
node_modules/discord.js/src/client/websocket/handlers/GUILD_CREATE.js
generated
vendored
Normal file
33
node_modules/discord.js/src/client/websocket/handlers/GUILD_CREATE.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const Events = require('../../../util/Events');
|
||||
const Status = require('../../../util/Status');
|
||||
|
||||
module.exports = (client, { d: data }, shard) => {
|
||||
let guild = client.guilds.cache.get(data.id);
|
||||
if (guild) {
|
||||
if (!guild.available && !data.unavailable) {
|
||||
// A newly available guild
|
||||
guild._patch(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild becomes available.
|
||||
* @event Client#guildAvailable
|
||||
* @param {Guild} guild The guild that became available
|
||||
*/
|
||||
client.emit(Events.GuildAvailable, guild);
|
||||
}
|
||||
} else {
|
||||
// A new guild
|
||||
data.shardId = shard.id;
|
||||
guild = client.guilds._add(data);
|
||||
if (client.ws.status === Status.Ready) {
|
||||
/**
|
||||
* Emitted whenever the client joins a guild.
|
||||
* @event Client#guildCreate
|
||||
* @param {Guild} guild The created guild
|
||||
*/
|
||||
client.emit(Events.GuildCreate, guild);
|
||||
}
|
||||
}
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_DELETE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_DELETE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildDelete.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildEmojisUpdate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildIntegrationsUpdate.handle(packet.d);
|
||||
};
|
39
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js
generated
vendored
Normal file
39
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Events = require('../../../util/Events');
|
||||
|
||||
module.exports = (client, { d: data }) => {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
const members = new Collection();
|
||||
|
||||
for (const member of data.members) members.set(member.user.id, guild.members._add(member));
|
||||
if (data.presences) {
|
||||
for (const presence of data.presences) guild.presences._add(Object.assign(presence, { guild }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the properties of a guild members chunk
|
||||
* @typedef {Object} GuildMembersChunk
|
||||
* @property {number} index Index of the received chunk
|
||||
* @property {number} count Number of chunks the client should receive
|
||||
* @property {Array<*>} notFound An array of whatever could not be found
|
||||
* when using {@link GatewayOpcodes.RequestGuildMembers}
|
||||
* @property {?string} nonce Nonce for this chunk
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emitted whenever a chunk of guild members is received (all members come from the same guild).
|
||||
* @event Client#guildMembersChunk
|
||||
* @param {Collection<Snowflake, GuildMember>} members The members in the chunk
|
||||
* @param {Guild} guild The guild related to the member chunk
|
||||
* @param {GuildMembersChunk} chunk Properties of the received chunk
|
||||
*/
|
||||
client.emit(Events.GuildMembersChunk, members, guild, {
|
||||
index: data.chunk_index,
|
||||
count: data.chunk_count,
|
||||
notFound: data.not_found,
|
||||
nonce: data.nonce,
|
||||
});
|
||||
};
|
20
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_ADD.js
generated
vendored
Normal file
20
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_ADD.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const Events = require('../../../util/Events');
|
||||
const Status = require('../../../util/Status');
|
||||
|
||||
module.exports = (client, { d: data }, shard) => {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
guild.memberCount++;
|
||||
const member = guild.members._add(data);
|
||||
if (shard.status === Status.Ready) {
|
||||
/**
|
||||
* Emitted whenever a user joins a guild.
|
||||
* @event Client#guildMemberAdd
|
||||
* @param {GuildMember} member The member that has joined a guild
|
||||
*/
|
||||
client.emit(Events.GuildMemberAdd, member);
|
||||
}
|
||||
}
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet, shard) => {
|
||||
client.actions.GuildMemberRemove.handle(packet.d, shard);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet, shard) => {
|
||||
client.actions.GuildMemberUpdate.handle(packet.d, shard);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_ROLE_CREATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_ROLE_CREATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildRoleCreate.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_ROLE_DELETE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_ROLE_DELETE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildRoleDelete.handle(packet.d);
|
||||
};
|
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js
generated
vendored
Normal file
5
node_modules/discord.js/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.GuildRoleUpdate.handle(packet.d);
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue