mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
reset indev
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"ecmaFeatures": {
|
||||
"modules": true
|
||||
}
|
||||
}
|
||||
40
.gitignore
vendored
40
.gitignore
vendored
@@ -1,40 +0,0 @@
|
||||
# Created by https://www.gitignore.io
|
||||
|
||||
hydrabot/config.json
|
||||
hydrabot/authority.json
|
||||
hydrabot/tokencache.json
|
||||
esdoc/
|
||||
|
||||
.tmp/
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||
node_modules
|
||||
test/auth.json
|
||||
examples/auth.json
|
||||
docs/_build
|
||||
@@ -1,7 +0,0 @@
|
||||
.vscode/
|
||||
docs/
|
||||
examples/
|
||||
web-dist/
|
||||
src/
|
||||
.travis.yml
|
||||
TODO.md
|
||||
13
.travis.yml
13
.travis.yml
@@ -1,13 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- stable
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- indev
|
||||
before_install: npm install -g grunt-cli eslint
|
||||
install: npm install
|
||||
before_script: grunt --dev
|
||||
30
.vscode/launch.json
vendored
30
.vscode/launch.json
vendored
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"program": "./entrypoint.js",
|
||||
"stopOnEntry": false,
|
||||
"args": [],
|
||||
"cwd": ".",
|
||||
"runtimeExecutable": null,
|
||||
"runtimeArgs": [
|
||||
"--nolazy"
|
||||
],
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"externalConsole": false,
|
||||
"sourceMaps": false,
|
||||
"outDir": null
|
||||
},
|
||||
{
|
||||
"name": "Attach",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"port": 5858
|
||||
}
|
||||
]
|
||||
}
|
||||
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -1,6 +0,0 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"editor.wrappingColumn": 0,
|
||||
"editor.formatOnType": true,
|
||||
"files.trimTrailingWhitespace": true
|
||||
}
|
||||
220
.vscode/tasks.json
vendored
220
.vscode/tasks.json
vendored
@@ -1,220 +0,0 @@
|
||||
// Available variables which can be used inside of strings.
|
||||
// ${workspaceRoot}: the root folder of the team
|
||||
// ${file}: the current opened file
|
||||
// ${fileBasename}: the current opened file's basename
|
||||
// ${fileDirname}: the current opened file's dirname
|
||||
// ${fileExtname}: the current opened file's extension
|
||||
// ${cwd}: the current working directory of the spawned process
|
||||
|
||||
// A task runner that calls the Typescript compiler (tsc) and
|
||||
// Compiles a HelloWorld.ts program
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command" : "babel",
|
||||
"isShellCommand": true,
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "watch",
|
||||
"suppressTaskName": true,
|
||||
"isBuildCommand": true,
|
||||
"isWatching": true,
|
||||
"args": [
|
||||
"src", "--out-dir", "lib", "-w", "--loose=all"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// A task runner that calls the Typescript compiler (tsc) and
|
||||
// compiles based on a tsconfig.json file that is present in
|
||||
// the root of the folder open in VSCode
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
|
||||
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
|
||||
"command": "tsc",
|
||||
|
||||
// The command is a shell script
|
||||
"isShellCommand": true,
|
||||
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
|
||||
// Tell the tsc compiler to use the tsconfig.json from the open folder.
|
||||
"args": ["-p", "."],
|
||||
|
||||
// use the standard tsc problem matcher to find compile problems
|
||||
// in the output.
|
||||
"problemMatcher": "$tsc"
|
||||
}
|
||||
*/
|
||||
|
||||
// A task runner configuration for gulp. Gulp provides a less task
|
||||
// which compiles less to css.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "gulp",
|
||||
"isShellCommand": true,
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "less",
|
||||
// Make this the default build command.
|
||||
"isBuildCommand": true,
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the standard less compilation problem matcher.
|
||||
"problemMatcher": "$lessCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the following section to use gulp in a watching mode that compiles a
|
||||
// less file. The gulp task prints "[hh:mm:ss] Starting 'clean-styles'" to the console
|
||||
// when existing css files get deleted and "[hh:mm:ss] Finished 'styles'" when the
|
||||
// overall less compilation has finished. When the clean pattern is detect internal less
|
||||
// problems are cleaned. When the finshed pattern is detected in the output less
|
||||
// problems are published.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "gulp",
|
||||
"isShellCommand": true,
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "watch-less",
|
||||
// Make this the default build command.
|
||||
"isBuildCommand": true,
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Task is running in watching mode.
|
||||
"isWatching": true,
|
||||
"problemMatcher": {
|
||||
// Use the standard less compilation problem matcher as the base.
|
||||
"base": "$lessCompile",
|
||||
// A regular expression signalling that a watched task begins executing (usually triggered through file watching).
|
||||
"watchedTaskBeginsRegExp": "^\\[\\d+:\\d+:\\d+\\] Starting 'clean-styles'\\.\\.\\.$",
|
||||
// A regular expression signalling that a watched tasks ends executing.
|
||||
"watchedTaskEndsRegExp": "^\\[\\d+:\\d+:\\d+\\] Finished 'styles' after \\d+"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the following section to use jake to build a workspace
|
||||
// cloned from https://github.com/Microsoft/TypeScript.git
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
// Task runner is jake
|
||||
"command": "jake",
|
||||
// Need to be executed in shell / cmd
|
||||
"isShellCommand": true,
|
||||
"showOutput": "silent",
|
||||
"tasks": [
|
||||
{
|
||||
// TS build command is local.
|
||||
"taskName": "local",
|
||||
// Make this the default build command.
|
||||
"isBuildCommand": true,
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the redefined Typescript output problem matcher.
|
||||
"problemMatcher": [
|
||||
"$tsc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the section below to use msbuild and generate problems
|
||||
// for csc, cpp, tsc and vb. The configuration assumes that msbuild
|
||||
// is available on the path and a solution file exists in the
|
||||
// workspace folder root.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "msbuild",
|
||||
"args": [
|
||||
// Ask msbuild to generate full paths for file names.
|
||||
"/property:GenerateFullPaths=true"
|
||||
],
|
||||
"taskSelector": "/t:",
|
||||
"showOutput": "silent",
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the standard MS compiler pattern to detect errors, warnings
|
||||
// and infos in the output.
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
// Uncomment the following section to use msbuild which compiles Typescript
|
||||
// and less files.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "msbuild",
|
||||
"args": [
|
||||
// Ask msbuild to generate full paths for file names.
|
||||
"/property:GenerateFullPaths=true"
|
||||
],
|
||||
"taskSelector": "/t:",
|
||||
"showOutput": "silent",
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build",
|
||||
// Show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
// Use the standard MS compiler pattern to detect errors, warnings
|
||||
// and infos in the output.
|
||||
"problemMatcher": [
|
||||
"$msCompile",
|
||||
"$lessCompile"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
// A task runner example that defines a problemMatcher inline instead of using
|
||||
// a predfined one.
|
||||
/*
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "tsc",
|
||||
"isShellCommand": true,
|
||||
"args": ["HelloWorld.ts"],
|
||||
"showOutput": "silent",
|
||||
"problemMatcher": {
|
||||
// The problem is owned by the typescript language service. Ensure that the problems
|
||||
// are merged with problems produced by Visual Studio's language service.
|
||||
"owner": "typescript",
|
||||
// The file name for reported problems is relative to the current working directory.
|
||||
"fileLocation": ["relative", "${cwd}"],
|
||||
// The actual pattern to match problems in the output.
|
||||
"pattern": {
|
||||
// The regular expression. Matches HelloWorld.ts(2,10): error TS2339: Property 'logg' does not exist on type 'Console'.
|
||||
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
|
||||
// The match group that denotes the file containing the problem.
|
||||
"file": 1,
|
||||
// The match group that denotes the problem location.
|
||||
"location": 2,
|
||||
// The match group that denotes the problem's severity. Can be omitted.
|
||||
"severity": 3,
|
||||
// The match group that denotes the problem code. Can be omitted.
|
||||
"code": 4,
|
||||
// The match group that denotes the problem's message.
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,7 +0,0 @@
|
||||
### Contributing
|
||||
|
||||
We welcome contributions, but we ask that you follow a few simple guidelines
|
||||
|
||||
1. Please check the indev branch to make sure the issue hasn't already been patched.
|
||||
2. If the issue hasn't been patched, edit the files in the **src folder**
|
||||
3. Prior to making the PR, build the lib files by running `grunt --dev`
|
||||
202
LICENSE
202
LICENSE
@@ -1,202 +0,0 @@
|
||||
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
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
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.
|
||||
|
||||
77
README.md
77
README.md
@@ -1,77 +0,0 @@
|
||||
<p align="center">
|
||||
<a href="https://hydrabolt.github.io/discord.js">
|
||||
<img alt="discord.js" src="http://hydrabolt.github.io/discord.js/res/logo.png" width="546">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
[](https://travis-ci.org/hydrabolt/discord.js) [](http://discordjs.readthedocs.org/en/latest/?badge=latest)
|
||||
|
||||
[](https://nodei.co/npm/discord.js/)
|
||||
|
||||
|
||||
discord.js is a node module used as a way of interfacing with [Discord](https://discordapp.com/). It is a very useful module for creating bots.
|
||||
|
||||
### Installation
|
||||
|
||||
**Requires node 0.12+**
|
||||
|
||||
`npm install --save discord.js`
|
||||
|
||||
If you don't need voice support:
|
||||
|
||||
`npm install --save --no-optional discord.js`
|
||||
|
||||
---
|
||||
|
||||
### Example: ping-pong
|
||||
```js
|
||||
var Discord = require("discord.js");
|
||||
|
||||
var mybot = new Discord.Client();
|
||||
|
||||
mybot.on("message", function(message) {
|
||||
if(message.content === "ping") {
|
||||
mybot.reply(message, "pong");
|
||||
}
|
||||
});
|
||||
|
||||
mybot.loginWithToken("token");
|
||||
// If you still need to login with email and password, use mybot.login("email", "password");
|
||||
```
|
||||
---
|
||||
|
||||
### Contributing
|
||||
|
||||
Feel free to contribute! Just clone the repo and edit the files in the **src folder, not the lib folder.**
|
||||
|
||||
Whenever you come to making a pull request, make sure it's to the *indev* branch and that you have built the lib files by running `grunt --dev`
|
||||
|
||||
---
|
||||
|
||||
### Related Projects
|
||||
|
||||
A list of other Discord API libraries [can be found here](https://discordapi.com/unofficial/libs.html)
|
||||
|
||||
---
|
||||
|
||||
### Links
|
||||
**[Documentation](http://discordjs.readthedocs.org/en/latest/)**
|
||||
|
||||
**[GitHub](https://github.com/discord-js/discord.js)**
|
||||
|
||||
**[Wiki](https://github.com/discord-js/discord.js/wiki)**
|
||||
|
||||
**[Website](http://hydrabolt.github.io/discord.js/)**
|
||||
|
||||
**[NPM](http://npmjs.com/package/discord.js)**
|
||||
|
||||
---
|
||||
|
||||
### Contact
|
||||
|
||||
If you have an issue or want to know if a feature exists, [read the documentation](http://discordjs.readthedocs.org/en/latest/) before contacting me about any issues! If it's badly/wrongly implemented, let me know!
|
||||
|
||||
|
||||
If you would like to contact me, you can create an issue on the GitHub repo, e-mail me via the one available on my NPM profile.
|
||||
|
||||
Alternatively, you could just send a DM to **hydrabolt** in [**Discord API**](https://discord.gg/0SBTUU1wZTYd2XyW).
|
||||
8
TODO.md
8
TODO.md
@@ -1,8 +0,0 @@
|
||||
# Things yet to be implemented:
|
||||
|
||||
* Unbanning
|
||||
* Re-ordering of roles (no effect, just aesthetics)
|
||||
* Normalising attachments and embeds of messages
|
||||
* Normalising parameter types
|
||||
* More Documentation
|
||||
* Voice Chat
|
||||
192
docs/Makefile
192
docs/Makefile
@@ -1,192 +0,0 @@
|
||||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# User-friendly check for sphinx-build
|
||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
||||
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
|
||||
endif
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " applehelp to make an Apple Help Book"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " xml to make Docutils-native XML files"
|
||||
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
@echo " coverage to run coverage check of the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/discordjs.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/discordjs.qhc"
|
||||
|
||||
applehelp:
|
||||
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
|
||||
@echo
|
||||
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
|
||||
@echo "N.B. You won't be able to view it unless you put it in" \
|
||||
"~/Library/Documentation/Help or install it in your application" \
|
||||
"bundle."
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/discordjs"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/discordjs"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
latexpdfja:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through platex and dvipdfmx..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
|
||||
coverage:
|
||||
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
|
||||
@echo "Testing of coverage in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/coverage/python.txt."
|
||||
|
||||
xml:
|
||||
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
|
||||
@echo
|
||||
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
|
||||
|
||||
pseudoxml:
|
||||
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
|
||||
@echo
|
||||
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
|
||||
292
docs/conf.py
292
docs/conf.py
@@ -1,292 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# discord.js documentation build configuration file, created by
|
||||
# sphinx-quickstart on Fri Sep 25 17:25:49 2015.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import shlex
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = []
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
# source_suffix = ['.rst', '.md']
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'discord.js'
|
||||
copyright = u'2015-2016, hydrabolt'
|
||||
author = u'hydrabolt'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '8.0.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '8.0.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
#keep_warnings = False
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = False
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'default'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
#html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
#html_static_path = ['_static']
|
||||
|
||||
# Add any extra paths that contain custom files (such as robots.txt or
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
# directly to the root of the documentation.
|
||||
#html_extra_path = []
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
#html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Language to be used for generating the HTML full-text search index.
|
||||
# Sphinx supports the following languages:
|
||||
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
|
||||
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
|
||||
#html_search_language = 'en'
|
||||
|
||||
# A dictionary with options for the search language support, empty by default.
|
||||
# Now only 'ja' uses this config value
|
||||
#html_search_options = {'type': 'default'}
|
||||
|
||||
# The name of a javascript file (relative to the configuration directory) that
|
||||
# implements a search results scorer. If empty, the default will be used.
|
||||
#html_search_scorer = 'scorer.js'
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'discordjsdoc'
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'discordjs.tex', u'discord.js Documentation',
|
||||
u'hydrabolt', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'discordjs', u'discord.js Documentation',
|
||||
[author], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'discordjs', u'discord.js Documentation',
|
||||
author, 'discordjs', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
#texinfo_no_detailmenu = False
|
||||
|
||||
if not os.environ.get('READTHEDOCS', None) == 'True':
|
||||
try:
|
||||
import sphinx_rtd_theme
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
|
||||
except ImportError:
|
||||
print("sphinx_rtd_theme not found! Do 'pip install sphinx_rtd_theme' to make local builds use the RTD theme.")
|
||||
@@ -1,61 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Cache
|
||||
=====
|
||||
|
||||
**extends Array**
|
||||
|
||||
A Cache object extends an Array (so it can be used like a regular array) but introduces helper functions to make it more useful when developing with discord.js. Unlike a regular array, it doesn't care about the instance or prototype of an object, it works purely on properties.
|
||||
|
||||
**Examples:**
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
client.users.get("id", 11238414);
|
||||
|
||||
client.channels.getAll("name", "general");
|
||||
|
||||
--------
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
get(key, value)
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Returns a contained object where ``object[key] == value``. Also works if value is a regex or a function. Returns the first object found that matches the criteria.
|
||||
|
||||
get(value)
|
||||
~~~~~~~~~~
|
||||
|
||||
Returns a contained object where ``object["id"] == value``. Shorthand for ``get("id", value)``. Returns ``null`` if ID is not found.
|
||||
|
||||
getAll(key, value)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Similar to ``cache.get(key, value)``, but returns a Cache of any objects that meet the criteria.
|
||||
|
||||
has(key, value)
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Returns `true` if there is an object that meets the condition ``object[key] == value`` in the cache
|
||||
|
||||
add(data)
|
||||
~~~~~~~~~
|
||||
|
||||
Adds an object to the Cache as long as all the other objects in the cache don't have the same ID as it.
|
||||
|
||||
update(old, data)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
Updates an old object in the Cache (if it exists) with the new one.
|
||||
|
||||
remove(data)
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Removes an object from the cache if it exists.
|
||||
|
||||
random()
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Get a random object from the cache.
|
||||
@@ -1,43 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Channel
|
||||
=======
|
||||
|
||||
**extends** Equality_
|
||||
|
||||
The Channel class is the base class for all types of channel.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
id
|
||||
~~
|
||||
|
||||
The ID of the channel, a `String`.
|
||||
|
||||
client
|
||||
~~~~~~
|
||||
|
||||
The Client_ that cached the channel.
|
||||
|
||||
isPrivate
|
||||
~~~~~~~~~
|
||||
|
||||
Indicates whether the channel is PM channel, is `Boolean`.
|
||||
|
||||
createdAt
|
||||
~~~~~~~~~
|
||||
|
||||
A `Date` referring to when the channel was created.
|
||||
|
||||
--------
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
delete()
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Deletes the channel.
|
||||
@@ -1,42 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
ChannelPermissions
|
||||
==================
|
||||
|
||||
ChannelPermissions is used to represent the final permissions of a user in a channel, to see exactly what they are and aren't allowed to do.
|
||||
|
||||
**Examples:**
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
var user_permissions = channel.permissionsOf(user);
|
||||
|
||||
var can_mention_everyone = user_permissions.hasPermission("mentionEveryone");
|
||||
|
||||
--------
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
serialize()
|
||||
~~~~~~~~~~~
|
||||
|
||||
**Aliases:** `serialise`
|
||||
|
||||
Returns an object containing permission names and values. E.g:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
{
|
||||
createInstantInvite : true,
|
||||
kickMembers : false
|
||||
}
|
||||
|
||||
For more on valid permission names, see `Permission Constants`_.
|
||||
|
||||
hasPermission(permission)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Sees whether the user has the permission given.
|
||||
|
||||
- **permission** - See `Permission Constants`_ for valid permission names.
|
||||
1042
docs/docs_client.rst
1042
docs/docs_client.rst
File diff suppressed because it is too large
Load Diff
@@ -1,26 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Equality
|
||||
========
|
||||
|
||||
The Equality class is used to see if two objects are equal, based on ``object_1.id === object_2.id``.
|
||||
|
||||
If any class in Discord extends equality, it means you should never the default equality operands (``==`` & ``===``) as they could potentially be different instances and therefore appear not to be equal. Instead, use ``equalityObject.equals()`` as shown below.
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
object1.equals(object2); // GOOD ✓
|
||||
|
||||
object1 == object2; // BAD ✖
|
||||
|
||||
--------
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
equals(object)
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Returns true if the specified object is the same as this one.
|
||||
|
||||
- **object** - Any `object` with an ``id`` property.
|
||||
@@ -1,91 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Invite
|
||||
======
|
||||
|
||||
Used to represent data of an invite.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
maxAge
|
||||
~~~~~~
|
||||
|
||||
`Number`, how long (in seconds) the invite has since creation before expiring.
|
||||
|
||||
code
|
||||
~~~~
|
||||
|
||||
`String`, the invite code.
|
||||
|
||||
server
|
||||
~~~~~~
|
||||
|
||||
The Server_ the invite is for.
|
||||
|
||||
channel
|
||||
~~~~~~~
|
||||
|
||||
The ServerChannel_ the invite is for.
|
||||
|
||||
revoked
|
||||
~~~~~~~
|
||||
|
||||
`Boolean`, whether the invite has been revoked or not.
|
||||
|
||||
createdAt
|
||||
~~~~~~~~~
|
||||
|
||||
`Number`, timestamp of when the invite was created.
|
||||
|
||||
temporary
|
||||
~~~~~~~~~
|
||||
|
||||
`Boolean`, whether the invite is temporary or not.
|
||||
|
||||
uses
|
||||
~~~~
|
||||
|
||||
`Number`, uses of the invite remaining.
|
||||
|
||||
maxUses
|
||||
~~~~~~~
|
||||
|
||||
`Number`, maximum uses of the invite.
|
||||
|
||||
inviter
|
||||
~~~~~~~
|
||||
|
||||
User_ who sent/created the invite.
|
||||
|
||||
xkcd
|
||||
~~~~
|
||||
|
||||
`Boolean`, whether the invite is intended to be easy to read and remember by a human.
|
||||
|
||||
--------
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
toString()
|
||||
~~~~~~~~~~
|
||||
|
||||
Returns the invite URL.
|
||||
|
||||
delete(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.deleteInvite(invite, callback)``
|
||||
| **See** client.deleteInvite_
|
||||
|
||||
join(`callback`)
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.joinServer(invite, callback)``
|
||||
| **See** client.joinServer_
|
||||
|
||||
.. _client.deleteInvite : ./docs_client.html#deleteinvite-invite-callback
|
||||
.. _client.joinServer : ./docs_client.html#joinserver-invite-callback
|
||||
@@ -1,149 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Message
|
||||
=======
|
||||
|
||||
**extends** Equality_
|
||||
|
||||
A Message object is used to represent the data of a message.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
channel
|
||||
~~~~~~~
|
||||
|
||||
The channel the message was sent in, either a TextChannel_ or PMChannel_.
|
||||
|
||||
server
|
||||
~~~~~~~
|
||||
|
||||
The Server_ the message was sent in. Will be undefined if the message was sent in a PMChannel_.
|
||||
|
||||
client
|
||||
~~~~~~
|
||||
|
||||
The Client_ that cached the message.
|
||||
|
||||
attachments
|
||||
~~~~~~~~~~~
|
||||
|
||||
A raw array of attachment objects.
|
||||
|
||||
tts
|
||||
~~~
|
||||
|
||||
`Boolean`, true if the message was text-to-speech.
|
||||
|
||||
embeds
|
||||
~~~~~~
|
||||
|
||||
A raw array of embed objects.
|
||||
|
||||
timestamp
|
||||
~~~~~~~~~
|
||||
|
||||
`Number`, timestamp of when the message was sent.
|
||||
|
||||
everyoneMentioned
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
`Boolean`, true if ``@everyone`` was mentioned.
|
||||
|
||||
id
|
||||
~~
|
||||
|
||||
`String`, ID of the message.
|
||||
|
||||
editedTimestamp
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Timestamp on when the message was last edited, `Number`. Potentially null.
|
||||
|
||||
author
|
||||
~~~~~~
|
||||
|
||||
**Alias:** `sender`
|
||||
|
||||
The User_ that sent the message.
|
||||
|
||||
content
|
||||
~~~~~~~
|
||||
|
||||
`String`, content of the message.
|
||||
|
||||
cleanContent
|
||||
~~~~~~~
|
||||
|
||||
`String`, content of the message with valid user mentions (<@123>) replaced with "@username".
|
||||
|
||||
mentions
|
||||
~~~~~~~~
|
||||
|
||||
A array of User_ objects that were mentioned in the message.
|
||||
|
||||
pinned
|
||||
~~~~~~
|
||||
|
||||
`Boolean`, true if the message is pinned to its channel.
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
isMentioned(user)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
Returns true if the given user was mentioned in the message.
|
||||
|
||||
- **user** - A `User Resolvable`_
|
||||
|
||||
toString()
|
||||
~~~~~~~~~~
|
||||
|
||||
Returns the content of the Message.
|
||||
|
||||
delete(`options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.deleteMessage(message, options, callback)``
|
||||
| **See** client.deleteMessage_
|
||||
|
||||
update(content, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.updateMessage(message, content, options, callback)``
|
||||
| **Aliases** `edit`
|
||||
| **See** client.updateMessage_
|
||||
|
||||
reply(content, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.reply(message, content, options, callback)``
|
||||
| **See** client.reply_
|
||||
|
||||
replyTTS(content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.replyTTS(message, content, callback)``
|
||||
| **See** client.replyTTS_
|
||||
|
||||
pin(`callback`)
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.pinMessage(message, callback)``
|
||||
| **See** client.pinMessage_
|
||||
|
||||
unpin(`callback`)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.unpinMessage(message, callback)``
|
||||
| **See** client.unpinMessage_
|
||||
|
||||
.. _client.deleteMessage : ./docs_client.html#deletemessage-message-options-callback
|
||||
.. _client.updateMessage : ./docs_client.html#updatemessage-message-content-options-callback
|
||||
.. _client.reply : ./docs_client.html#reply-message-content-options-callback
|
||||
.. _client.replyTTS : ./docs_client.html#replytts-message-content-callback
|
||||
.. _client.pinMessage : ./docs_client.html#pinmessage-message-callback
|
||||
.. _client.unpinMessage : ./docs_client.html#unpinmessage-message-callback
|
||||
@@ -1,58 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Permission Constants
|
||||
====================
|
||||
|
||||
In discord.js, you can handle permissions in two ways. The preferred way is to just use the string name of the permission, alternatively you can use ``Discord.Constants.Permissions["permission name"]``.
|
||||
|
||||
--------
|
||||
|
||||
Valid Permission Names
|
||||
----------------------
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
{
|
||||
// general
|
||||
administrator,
|
||||
createInstantInvite,
|
||||
kickMembers,
|
||||
banMembers,
|
||||
manageRoles,
|
||||
managePermissions,
|
||||
manageChannels,
|
||||
manageChannel,
|
||||
manageServer,
|
||||
changeNickname,
|
||||
manageNicknames,
|
||||
// text
|
||||
readMessages,
|
||||
sendMessages,
|
||||
sendTTSMessages,
|
||||
manageMessages,
|
||||
embedLinks,
|
||||
attachFiles,
|
||||
readMessageHistory,
|
||||
mentionEveryone,
|
||||
// voice
|
||||
voiceConnect,
|
||||
voiceSpeak,
|
||||
voiceMuteMembers,
|
||||
voiceDeafenMembers,
|
||||
voiceMoveMembers,
|
||||
voiceUseVAD
|
||||
};
|
||||
|
||||
Preferred Way
|
||||
-------------
|
||||
|
||||
The preferred way of using permissions in discord.js is to just use the name. E.g:
|
||||
|
||||
``role.hasPermission("voiceUseVAD")``
|
||||
|
||||
Alternative
|
||||
-----------
|
||||
|
||||
You can also go the long way round and use the numerical permission like so:
|
||||
|
||||
``role.hasPermission( Discord.Constants.Permissions.voiceUseVAD )``
|
||||
@@ -1,31 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
PermissionOverwrite
|
||||
===================
|
||||
|
||||
PermissionOverwrite is used to represent data about permission overwrites for roles or users in channels.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
id
|
||||
~~
|
||||
|
||||
`String`, the ID of the PermissionOverwrite. If ``overwrite.type`` is ``role``, this is the role's ID. Otherwise, it is a User_ overwrite.
|
||||
|
||||
type
|
||||
~~~~
|
||||
|
||||
`String`, type of the overwrite. Either ``member`` or ``role``.
|
||||
|
||||
allowed
|
||||
~~~~~~~
|
||||
|
||||
Returns the permissions explicitly allowed by the overwrite. An `Array` of Strings, which are names of permissions. More can be found at `Permission Constants`_
|
||||
|
||||
denied
|
||||
~~~~~~
|
||||
|
||||
Returns the permissions explicitly denied by the overwrite. An `Array` of Strings, which are names of permissions. More can be found at `Permission Constants`_
|
||||
@@ -1,90 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
PMChannel
|
||||
=========
|
||||
|
||||
**extends** Channel_
|
||||
|
||||
A PMChannel is a Private/Direct channel between the Client and another user.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
messages
|
||||
~~~~~~~~
|
||||
|
||||
A Cache_ of Message_ objects.
|
||||
|
||||
recipient
|
||||
~~~~~~~~~
|
||||
|
||||
The User_ that is the recipient of the Channel.
|
||||
|
||||
lastMessage
|
||||
~~~~~~~~~~~
|
||||
|
||||
The last Message_ sent in the channel, may be null if no messages have been sent during the time the bound Client_ has been online.
|
||||
|
||||
--------
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
toString()
|
||||
~~~~~~~~~~
|
||||
|
||||
Returns a mention of the recipient.
|
||||
|
||||
sendMessage(content, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendMessage(channel, content, options, callback)``
|
||||
| **Aliases** `send`
|
||||
| **See** client.sendMessage_
|
||||
|
||||
sendTTSMessage(content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendTTSMessage(channel, content, callback)``
|
||||
| **Aliases** `sendTTS`
|
||||
| **See** client.sendTTSMessage_
|
||||
|
||||
sendFile(attachment, name, content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendFile(channel, attachment, name, content, callbasck)``
|
||||
| **See** client.sendFile_
|
||||
|
||||
startTyping(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.startTyping(channel, callback)``
|
||||
| **See** client.startTyping_
|
||||
|
||||
stopTyping(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.stopTyping(channel, callback)``
|
||||
| **See** client.stopTyping_
|
||||
|
||||
getLogs(`limit`, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.getChannelLogs(channel, limit, options, callback)``
|
||||
| **See** client.getChannelLogs_
|
||||
|
||||
getMessage(messageID, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.getMessage(channel, messageID, callback)``
|
||||
| **See** client.getMessage_
|
||||
|
||||
.. _client.sendMessage : ./docs_client.html#sendmessage-channel-content-options-callback
|
||||
.. _client.sendTTSMessage : ./docs_client.html#sendttsmessage-channel-content-callback
|
||||
.. _client.sendFile : ./docs_client.html#sendfile-channel-attachment-name-content-callback
|
||||
.. _client.startTyping : ./docs_client.html#starttyping-channel-callback
|
||||
.. _client.stopTyping : ./docs_client.html#stoptyping-channel-callback
|
||||
.. _client.getChannelLogs : ./docs_client.html#getchannellogs-channel-limit-options-callback
|
||||
.. _client.getMessage : ./docs_client.html#getmessage-channel-messageid-callback
|
||||
@@ -1,100 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Resolvables
|
||||
===========
|
||||
|
||||
In discord.js, the aim is to allow the end developer to have freedom in what sort of data types they supply. References to any sort of resolvable basically mean what types of data you can provide. The different resolvables are shown before:
|
||||
|
||||
--------
|
||||
|
||||
Channel Resolvable
|
||||
------------------
|
||||
|
||||
A Channel Resolvable allows:
|
||||
|
||||
- Channel_
|
||||
- Server_
|
||||
- Message_
|
||||
- User_ (in some instances)
|
||||
- String of Channel ID
|
||||
- String of User ID
|
||||
|
||||
File Resolvable
|
||||
---------------
|
||||
|
||||
A File Resolvable allows:
|
||||
|
||||
- URL
|
||||
- Local file path
|
||||
- Readable stream
|
||||
|
||||
Role Resolvable
|
||||
---------------
|
||||
|
||||
A Role Resolvable allows:
|
||||
|
||||
- Role ID
|
||||
- Role_
|
||||
|
||||
Voice Channel Resolvable
|
||||
------------------------
|
||||
|
||||
A Voice Channel Resolvable allows:
|
||||
|
||||
- VoiceChannel_
|
||||
- Voice Channel ID
|
||||
|
||||
Message Resolvable
|
||||
------------------
|
||||
|
||||
A Message Resolvable allows:
|
||||
|
||||
- Message_
|
||||
- TextChannel_
|
||||
- PMChannel_
|
||||
|
||||
User Resolvable
|
||||
---------------
|
||||
|
||||
A User Resolvable allows:
|
||||
|
||||
- User_
|
||||
- Message_
|
||||
- TextChannel_
|
||||
- PMChannel_
|
||||
- Server_
|
||||
- String of User ID
|
||||
|
||||
String Resolvable
|
||||
-----------------
|
||||
|
||||
A String Resolvable allows:
|
||||
|
||||
- Array
|
||||
- String
|
||||
|
||||
Server Resolvable
|
||||
-----------------
|
||||
|
||||
A Server Resolvable allows:
|
||||
|
||||
- Server_
|
||||
- ServerChannel_
|
||||
- Message_ (only for messages from server channels)
|
||||
- String of Server ID
|
||||
|
||||
Invite ID Resolvable
|
||||
--------------------
|
||||
|
||||
An Invite ID Resolvable allows:
|
||||
|
||||
- Invite_
|
||||
- String containing either a http link to the invite or the invite code on its own.
|
||||
|
||||
Base64 Resolvable
|
||||
-----------------
|
||||
|
||||
A Base64 Resolvable allows:
|
||||
|
||||
- Buffer
|
||||
- String
|
||||
@@ -1,115 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Role
|
||||
====
|
||||
|
||||
Represents data for a Server Role.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
position
|
||||
~~~~~~~~
|
||||
|
||||
`Number`, position of the role when viewing the roles of a server.
|
||||
|
||||
name
|
||||
~~~~
|
||||
|
||||
`String`, name of the role.
|
||||
|
||||
managed
|
||||
~~~~~~~
|
||||
|
||||
`Boolean`, whether Discord has created the role itself. Currently only used for Twitch integration.
|
||||
|
||||
id
|
||||
~~
|
||||
|
||||
`String`, ID of the role.
|
||||
|
||||
hoist
|
||||
~~~~~
|
||||
|
||||
`Boolean`, whether the role should be displayed as a separate category in the users section.
|
||||
|
||||
color
|
||||
~~~~~
|
||||
|
||||
`Number`, a base 10 colour. Use ``role.colorAsHex()`` to get a hex colour instead.
|
||||
|
||||
server
|
||||
~~~~~~
|
||||
|
||||
The Server_ the role belongs to.
|
||||
|
||||
client
|
||||
~~~~~~
|
||||
|
||||
The Client_ that cached the role.
|
||||
|
||||
createdAt
|
||||
~~~~~~~~~
|
||||
|
||||
A `Date` referring to when the role was created.
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
serialise()
|
||||
~~~~~~~~~~~
|
||||
|
||||
**Aliases:** `serialize`
|
||||
|
||||
Makes an object with the permission names found in `Permission Constants`_ and a boolean value for them.
|
||||
|
||||
hasPermission(permission)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Sees whether the role has the permission given.
|
||||
|
||||
- **permission** - See `Permission Constants`_ for valid permission names.
|
||||
|
||||
colorAsHex()
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Returns the role's colour as hex, e.g. ``#FF0000``.
|
||||
|
||||
mention()
|
||||
~~~~~~~~~
|
||||
|
||||
Returns a valid string that can be sent in a message to mention the role. By default, ``role.toString()`` does this so by adding a role object to a string, e.g. ``role + ""``, their mention code will be retrieved. If the role isn't mentionable, its name gets returned.
|
||||
|
||||
delete()
|
||||
~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.deleteRole(role)``
|
||||
| **See** client.deleteRole_
|
||||
|
||||
update(data)
|
||||
~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.updateRole(role, data)``
|
||||
| **Aliases** `edit`
|
||||
| **See** client.updateRole_
|
||||
|
||||
addMember(member, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.addMemberToRole(member, roles, callback)``
|
||||
| **Aliases** `addUser`
|
||||
| **See** client.addMemberToRole_
|
||||
|
||||
removeMember(member, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.removeMemberFromRole(member, roles, callback)``
|
||||
| **Aliases** `removeUser`
|
||||
| **See** client.removeMemberFromRole_
|
||||
|
||||
.. _client.deleteRole : ./docs_client.html#deleterole-role-callback
|
||||
.. _client.updateRole : ./docs_client.html#updaterole-role-data-callback
|
||||
.. _client.addMemberToRole : ./docs_client.html#addmembertorole-member-role-callback
|
||||
.. _client.removeMemberFromRole : ./docs_client.html#removememberfromrole-member-role-callback
|
||||
@@ -1,189 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Server
|
||||
======
|
||||
|
||||
**extends** Equality_
|
||||
|
||||
Stores information about a Discord Server.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
client
|
||||
~~~~~~
|
||||
|
||||
The Client_ that cached the Server.
|
||||
|
||||
region
|
||||
~~~~~~
|
||||
|
||||
`String`, region of the server.
|
||||
|
||||
name
|
||||
~~~~
|
||||
|
||||
`String`, name of the server.
|
||||
|
||||
id
|
||||
~~
|
||||
|
||||
`String`, ID of the server - never changes.
|
||||
|
||||
members
|
||||
~~~~~~~
|
||||
|
||||
Members of the server, a Cache_ of User_ objects.
|
||||
|
||||
channels
|
||||
~~~~~~~~
|
||||
|
||||
Channels in the server, a Cache_ of ServerChannel_ objects.
|
||||
|
||||
roles
|
||||
~~~~~
|
||||
|
||||
Roles of the server, a Cache_ of Role_ objects.
|
||||
|
||||
icon
|
||||
~~~~
|
||||
|
||||
ID/Hash of server icon, use ``server.iconURL`` for an URL to the icon.
|
||||
|
||||
afkTimeout
|
||||
~~~~~~~~~~
|
||||
|
||||
`Number`, the AFK timeout in seconds before a user is classed as AFK. If there isn't an AFK timeout, this will be null.
|
||||
|
||||
afkChannel
|
||||
~~~~~~~~~~
|
||||
|
||||
The channel where AFK users are moved to, ServerChannel_ object. If one isn't set, this will be null.
|
||||
|
||||
defaultChannel
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
**Aliases** `generalChannel, general`
|
||||
|
||||
The ``#general`` ServerChannel_ of the server.
|
||||
|
||||
owner
|
||||
~~~~~
|
||||
|
||||
The founder of the server, a User_ object.
|
||||
|
||||
iconURL
|
||||
~~~~~~~
|
||||
|
||||
The URL of the Server's icon. If the server doesn't have an icon, this will be null.
|
||||
|
||||
createdAt
|
||||
~~~~~~~~~
|
||||
|
||||
A `Date` referring to when the server was created.
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
rolesOfUser(user)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Aliases**: `rolesOf`, `rolesOfMember`
|
||||
|
||||
Returns an array of the roles affecting a user server-wide.
|
||||
|
||||
usersWithRole(role)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Aliases**: `membersWithRole`
|
||||
|
||||
Returns an array of users that have the specified role.
|
||||
|
||||
detailsOfUser(user)
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Aliases** `detailsOf`, `detailsOfMember`
|
||||
|
||||
Returns an object containing metadata of a user within the server, containing a structure similar to the following:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
{
|
||||
joinedAt: 1449339323747,
|
||||
roles: [],
|
||||
mute: false,
|
||||
selfMute: false,
|
||||
deaf: false,
|
||||
selfDeaf: false,
|
||||
nick: 'Nickname'
|
||||
}
|
||||
|
||||
leave()
|
||||
~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.leaveServer(server)``
|
||||
| **Aliases** `delete`
|
||||
| **See** client.leaveServer_
|
||||
|
||||
createInvite(`options`, `callback`)
|
||||
~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.createInvite(server, options, callback)``
|
||||
| **See** client.createInvite_
|
||||
|
||||
createRole(`data`, `callback`)
|
||||
~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.createRole(server, data, callback)``
|
||||
| **See** client.createRole_
|
||||
|
||||
createChannel(name, `type`, `callback`)
|
||||
~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.createChannel(server, name, type, callback)``
|
||||
| **See** client.createChannel_
|
||||
|
||||
getBans(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.getBans(server, callback)``
|
||||
| **See** client.getBans_
|
||||
|
||||
banMember(user, `length`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.banMember(member, server, length, callback)``
|
||||
| **Aliases** `banUser, ban`
|
||||
| **See** client.banMember_
|
||||
|
||||
unbanMember(user, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.unbanMember(member, server, callback)``
|
||||
| **Aliases** `unbanUser, unban`
|
||||
| **See** client.unbanMember_
|
||||
|
||||
kickMember(user, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.kickMember(member, server, callback)``
|
||||
| **Aliases** `kickUser, kick`
|
||||
| **See** client.kickMember_
|
||||
|
||||
setNickname(nickname, user, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.setNickname(server, nickname, user, callback)``
|
||||
| **See** client.setNickname_
|
||||
|
||||
.. _client.leaveServer : ./docs_client.html#leaveserver-server-callback
|
||||
.. _client.createInvite : ./docs_client.html#createinvite-channel-options-callback
|
||||
.. _client.createRole : ./docs_client.html#createrole-server-data-callback
|
||||
.. _client.createChannel : ./docs_client.html#createchannel-server-name-type-callback
|
||||
.. _client.banMember : ./docs_client.html#banmember-user-server-length-callback
|
||||
.. _client.unbanMember : ./docs_client.html#unbanmember-user-server-callback
|
||||
.. _client.kickMember : ./docs_client.html#kickmember-user-server-callback
|
||||
.. _client.setNickname : ./docs_client.html#setNickname-server-nickname-user-callback
|
||||
.. _client.getBans : ./docs_client.html#getbans-server-callback
|
||||
@@ -1,59 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
ServerChannel
|
||||
=============
|
||||
|
||||
**extends** Channel_
|
||||
|
||||
A ServerChannel is a Channel_ that belongs to a Server_.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
name
|
||||
~~~~
|
||||
|
||||
`String`, name of the channel.
|
||||
|
||||
type
|
||||
~~~~
|
||||
|
||||
`String`, either ``voice`` or ``text``.
|
||||
|
||||
position
|
||||
~~~~~~~~
|
||||
|
||||
`Number`, position in the channel list.
|
||||
|
||||
permissionOverwrites
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Cache_ of all the PermissionOverwrite_ objects affecting the channel.
|
||||
|
||||
server
|
||||
~~~~~~
|
||||
|
||||
Server_ the channel belongs to.
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
permissionsOf(userOrRole)
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Aliases:** permsOf
|
||||
|
||||
Returns a ChannelPermissions_ object of a user or role's permissions in that channel.
|
||||
|
||||
mention()
|
||||
~~~~~~~~~
|
||||
|
||||
Returns a `string` that can be used in discord messages to mention a channel. `serverChannel.toString()` defaults to this.
|
||||
|
||||
update(data, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.updateChannel(channel, data, callback)``
|
||||
| **See** client.updateChannel_
|
||||
@@ -1,99 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
TextChannel
|
||||
===========
|
||||
|
||||
**extends** ServerChannel_
|
||||
|
||||
A text channel of a server.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
topic
|
||||
~~~~~
|
||||
|
||||
The topic of the channel, a `String`.
|
||||
|
||||
lastMessage
|
||||
~~~~~~~~~~~
|
||||
|
||||
Last Message_ sent in the channel. May be null if no messages sent whilst the Client was online.
|
||||
|
||||
messages
|
||||
~~~~~~~~
|
||||
|
||||
A Cache_ of Message_ objects.
|
||||
|
||||
--------
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
setTopic(topic, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.setChannelTopic(channel, topic, callback)``
|
||||
| **See** client.setChannelTopic_
|
||||
|
||||
setNameAndTopic(name, topic, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.setChannelNameAndTopic(channel, name, topic, callback)``
|
||||
| **See** client.setChannelNameAndTopic_
|
||||
|
||||
sendMessage(content, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendMessage(channel, content, options, callback)``
|
||||
| **Aliases** `send`
|
||||
| **See** client.sendMessage_
|
||||
|
||||
sendTTSMessage(content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendTTSMessage(channel, content, callback)``
|
||||
| **Aliases** `sendTTS`
|
||||
| **See** client.sendTTSMessage_
|
||||
|
||||
sendFile(attachment, name, content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendFile(channel, attachment, name, content, callbasck)``
|
||||
| **See** client.sendFile_
|
||||
|
||||
startTyping(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.startTyping(channel, callback)``
|
||||
| **See** client.startTyping_
|
||||
|
||||
stopTyping(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.stopTyping(channel, callback)``
|
||||
| **See** client.stopTyping
|
||||
|
||||
getLogs(`limit`, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.getChannelLogs(channel, limit, options, callback)
|
||||
| **See** client.getChannelLogs_
|
||||
|
||||
getMessage(messageID, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.getMessage(channel, messageID, callback)``
|
||||
| **See** client.getMessage_
|
||||
|
||||
.. _client.sendMessage : ./docs_client.html#sendmessage-channel-content-options-callback
|
||||
.. _client.sendTTSMessage : ./docs_client.html#sendttsmessage-channel-content-callback
|
||||
.. _client.sendFile : ./docs_client.html#sendfile-channel-attachment-name-content-callback
|
||||
.. _client.startTyping : ./docs_client.html#starttyping-channel-callback
|
||||
.. _client.stopTyping : ./docs_client.html#stoptyping-channel-callback
|
||||
.. _client.getChannelLogs : ./docs_client.html#getchannellogs-channel-limit-options-callback
|
||||
.. _client.getMessage : ./docs_client.html#getmessage-channel-messageid-callback
|
||||
.. _client.setChannelTopic : ./docs_client.html#setchanneltopic-channel-topic-callback
|
||||
.. _client.setChannelNameAndTopic : ./docs_client.html#setchannelnameandtopic-channel-name-topic-callback
|
||||
@@ -1,180 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
User
|
||||
====
|
||||
|
||||
**extends** Equality_
|
||||
|
||||
Stores information about users.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
client
|
||||
~~~~~~
|
||||
|
||||
The Client_ that created the user.
|
||||
|
||||
username
|
||||
~~~~~~~~
|
||||
|
||||
_Alias_ : ``name``
|
||||
|
||||
`String`, username of the User.
|
||||
|
||||
discriminator
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
`Integer` from 0-9999, don't use this to identify users. Used to separate the user from the 9998 others that may have the same username. Made redundant by ``user.id``.
|
||||
|
||||
id
|
||||
~~
|
||||
|
||||
`String` (do not parse to an Integer, will become inaccurate). The ID of a user, never changes.
|
||||
|
||||
avatar
|
||||
~~~~~~
|
||||
|
||||
`String`, the ID/hash of a user's avatar. To get a path to their avatar, see ``user.avatarURL``.
|
||||
|
||||
status
|
||||
~~~~~~
|
||||
|
||||
The status of a user, `String`. Either ``online``, ``offline`` or ``idle``.
|
||||
|
||||
game
|
||||
~~~~
|
||||
|
||||
The game object of a user. `null` if not playing a game, otherwise `Object` containing the following values:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
{
|
||||
name : 'Game Name' //Name of game user is playing
|
||||
}
|
||||
|
||||
typing
|
||||
~~~~~~
|
||||
|
||||
`Object` containing the following values:
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
{
|
||||
since : 1448038288519, //timestamp of when
|
||||
channel : <Channel Object> // channel they are typing in.
|
||||
}
|
||||
|
||||
avatarURL
|
||||
~~~~~~~~~
|
||||
|
||||
A valid URL to the user's avatar if they have one, otherwise null.
|
||||
|
||||
bot
|
||||
~~~
|
||||
|
||||
A boolean that represents if the user is an official OAuth bot account or not.
|
||||
|
||||
voiceChannel
|
||||
~~~~~~~~~~~~
|
||||
|
||||
The VoiceChannel_ the user is connected to. If they aren't in any voice channels, this will be ``null``.
|
||||
|
||||
createdAt
|
||||
~~~~~~~~~
|
||||
|
||||
A `Date` referring to when the user was created.
|
||||
|
||||
note
|
||||
~~~~
|
||||
|
||||
The note of the user, `String`.
|
||||
|
||||
speaking
|
||||
~~~~~~~~
|
||||
|
||||
A boolean that represents whether or not the user is speaking in a voice channel, default is `false`.
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
mention()
|
||||
~~~~~~~~~
|
||||
|
||||
Returns a valid string that can be sent in a message to mention the user. By default, ``user.toString()`` does this so by adding a user object to a string, e.g. ``user + ""``, their mention code will be retrieved.
|
||||
|
||||
sendMessage(content, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendMessage(channel, content, options, callback)``
|
||||
| **Aliases** `send`
|
||||
| **See** client.sendMessage_
|
||||
|
||||
sendTTSMessage(content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendTTSMessage(channel, content, callback)``
|
||||
| **Aliases** `sendTTS`
|
||||
| **See** client.sendTTSMessage_
|
||||
|
||||
sendFile(attachment, name, content, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.sendFile(channel, attachment, name, content, callbasck)``
|
||||
| **See** client.sendFile_
|
||||
|
||||
startTyping(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.startTyping(channel, callback)``
|
||||
| **See** client.startTyping_
|
||||
|
||||
stopTyping(`callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.stopTyping(channel, callback)``
|
||||
| **See** client.stopTyping_
|
||||
|
||||
addTo(role, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.addMemberToRole(member, role, callback)``
|
||||
| **See** client.addMemberToRole_
|
||||
|
||||
removeFrom(role, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.removeMemberFromRole(member, role, callback)``
|
||||
| **See** client.removeMemberFromRole_
|
||||
|
||||
getLogs(`limit`, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.getChannelLogs(channel, limit, options, callback)``
|
||||
| **See** client.getChannelLogs_
|
||||
|
||||
getMessage(messageID, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.getMessage(channel, messageID, callback)``
|
||||
| **See** client.getMessage_
|
||||
|
||||
hasRole(role)
|
||||
~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.memberHasRole(member, role)``
|
||||
| **See** client.memberHasRole_
|
||||
|
||||
|
||||
.. _client.addMemberToRole : ./docs_client.html#addmembertorole-member-role-callback
|
||||
.. _client.removeMemberFromRole : ./docs_client.html#removememberfromrole-member-role-callback
|
||||
.. _client.memberHasRole : ./docs_client.html#memberhasrole-member-role
|
||||
.. _client.sendMessage : ./docs_client.html#sendmessage-channel-content-options-callback
|
||||
.. _client.sendTTSMessage : ./docs_client.html#sendttsmessage-channel-content-callback
|
||||
.. _client.sendFile : ./docs_client.html#sendfile-channel-attachment-name-content-callback
|
||||
.. _client.startTyping : ./docs_client.html#starttyping-channel-callback
|
||||
.. _client.stopTyping : ./docs_client.html#stoptyping-channel-callback
|
||||
.. _client.getChannelLogs : ./docs_client.html#getchannellogs-channel-limit-options-callback
|
||||
.. _client.getMessage : ./docs_client.html#getmessage-channel-messageid-callback
|
||||
@@ -1,54 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
VoiceChannel
|
||||
============
|
||||
|
||||
**extends** ServerChannel_
|
||||
|
||||
A voice channel of a server. Currently, the voice channel class has no differences to the ServerChannel class.
|
||||
|
||||
--------
|
||||
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
members
|
||||
~~~~~~~~
|
||||
|
||||
A Cache_ of Users_ that are connected to the voice channel
|
||||
|
||||
userLimit
|
||||
~~~~~~~~
|
||||
|
||||
The maximum amount of users that can connect to the voice channel. If it's 0, there is no limit
|
||||
|
||||
bitrate
|
||||
~~~~~~~~
|
||||
|
||||
The bitrate of the voice channel (in kb/s).
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
setUserLimit(limit, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.setChannelUserLimit(channel, limit, callback)``
|
||||
| **See** client.setChannelUserLimit_
|
||||
|
||||
setBitrate(kbitrate, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.setChannelBitrate(channel, kbitrate, callback)``
|
||||
| **See** client.setChannelBitrate_
|
||||
|
||||
join(`callback`)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
| **Shortcut of** ``client.joinVoiceChannel(channel, callback)``
|
||||
| **See** client.joinVoiceChannel_
|
||||
|
||||
.. _client.setChannelUserLimit : ./docs_client.html#setchanneluserlimit-channel-limit-callback
|
||||
.. _client.setChannelBitrate : ./docs_client.html#setchannelbitrate-channel-bitrate-callback
|
||||
.. _client.getBans : ./docs_client.html#joinvoicechannel-channel-callback
|
||||
@@ -1,151 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
VoiceConnection
|
||||
===============
|
||||
|
||||
discord.js currently supports sending audio data over Discord voice chat. A voice connection can be initiated using
|
||||
client.joinVoiceChannel_ and then later accessed again using the `client.voiceConnection` property. You can play something
|
||||
using the `playXYZ` methods and then later stop the playback and listen for events that tell you about the playback status.
|
||||
|
||||
Note that discord.js does not support receiving data from voice yet, only sending.
|
||||
|
||||
--------
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
||||
voiceChannel
|
||||
~~~~~~~~~~~~
|
||||
|
||||
VoiceChannel_ that the connection is for
|
||||
|
||||
client
|
||||
~~~~~~
|
||||
|
||||
Client_ the connection belongs to
|
||||
|
||||
token
|
||||
~~~~~
|
||||
|
||||
The token used to authenticate with Discord
|
||||
|
||||
server
|
||||
~~~~~~
|
||||
|
||||
The Server_ on which the voice connection takes place
|
||||
|
||||
encoder
|
||||
~~~~~~~
|
||||
|
||||
The AudioEncoder_ used to encode data in this particular session
|
||||
|
||||
playingIntent
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
A stream intent used to bind events to the voice connection
|
||||
|
||||
playing
|
||||
~~~~~~~
|
||||
|
||||
Whether or not the bot is currently playing something
|
||||
|
||||
paused
|
||||
~~~~~~
|
||||
|
||||
Whether or not the playback is currently paused
|
||||
|
||||
streamTime
|
||||
~~~~~~~~~~
|
||||
|
||||
The amount of time the current track has been playing for, in milliseconds
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
playFile(path, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Plays a file to the voice channel. The file can be in practically any format; if you're looking for a list, look here: `Format list`_.
|
||||
In addition to a file path local to your computer, it can also accept a URL, however this is not recommended as the entire content of the URL will be read before any playback starts.
|
||||
This can cause delays from seconds to minutes - you can use `playRawStream` with a Stream obtained from the URL instead.
|
||||
|
||||
The `options` object can be used to control playback properties, currently, it allows setting the seek (in seconds) using the `seek` property, and the volume using the `volume` property, which can be in any of the following formats:
|
||||
|
||||
- A number representing the linear change in volume; 1 is equal to no change, 0 is completely silent, 0.5 is half the regular volume and 2 is double the regular volume.
|
||||
- A string representing the linear change in volume, if this is more convenient for you.
|
||||
- A string representing decibel gain, where `"0dB"` is no change, `"-3dB"` is half the volume (in linear units), `"+6dB"` is four times the volume (in linear units) and so on.
|
||||
|
||||
It is recommended to change the volume, because the default of 1 is usually too loud. (A reasonable setting is `0.25` or `"-6dB"`).
|
||||
|
||||
The callback will be called immediately after playback has *started*, it will have an error object and the stream intent as its parameters. The callback will only receive
|
||||
an error if the encoding fails, for playback errors, you can bind a function to the `error` event of the intent. The intent supports the following events:
|
||||
|
||||
- The `time` event is emitted every packet (20 milliseconds) and has the current playback time in milliseconds as its only parameter. The playback time can also be checked at any time using the `streamTime` attribute.
|
||||
- The `end` event is emitted once playback ends. Depending on various factors, it may be emitted a couple seconds earlier than the actual stream ending, you may have to add an offset if necessary.
|
||||
- The `error` event is emitted if an error happens during playback, such as failing to send a packet.
|
||||
|
||||
The intent can later be accessed again using the `playingIntent` property. If you prefer _Promises over callbacks, this method will return a promise you can use in the same way as the callback.
|
||||
|
||||
playRawStream(stream, `options`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This method is used in much the same way as `playFile`, except it plays data back from a stream containing audio data instead of a file or URL.
|
||||
|
||||
| See voiceConnection.playFile_ for usage information.
|
||||
|
||||
playArbitraryFFmpeg(ffmpegOptions, `volume`, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This method can be used to play data obtained from an arbitrary call to ffmpeg. Note that the array of options given as the parameter will
|
||||
still be concatenated with the following options so it can be used with Discord:
|
||||
|
||||
.. code::
|
||||
|
||||
-loglevel 0
|
||||
-f s16le
|
||||
-ar 48000
|
||||
-ac 2
|
||||
pipe:1
|
||||
|
||||
setSpeaking(value)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Sets whether or not the user is speaking (green circle around user on the official client). discord.js does this automatically when playing something,
|
||||
but you may want to spoof it or manually disable it.
|
||||
|
||||
- **value** - `true` or `false`: whether or not you want the bot to show as speaking
|
||||
|
||||
setVolume(volume)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Sets the current volume of the connecion. 1.0 is normal, 0.5 is half as loud, 2.0 is twice as loud.
|
||||
|
||||
getVolume()
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Returns the current volume. 1.0 is normal, 0.5 is half as loud, 2.0 is twice as loud.
|
||||
|
||||
pause()
|
||||
~~~~~~~
|
||||
|
||||
Pauses the current connection's audio.
|
||||
|
||||
resume()
|
||||
~~~~~~~~
|
||||
|
||||
Resumes the current connection's audio.
|
||||
|
||||
stopPlaying()
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Stops the current playback immediately. After this method has finished, it is safe to play something else.
|
||||
|
||||
destroy()
|
||||
~~~~~~~~~
|
||||
|
||||
Disconnects from the voice server and destroys all network connection. It's impossible to play anything on this connection afterwards, you will have to re-initiate
|
||||
a connection using client.joinVoiceChannel_. This method also calls `stopPlaying` internally, you don't have to do that yourself.
|
||||
|
||||
.. _Format list: https://ffmpeg.org/general.html#File-Formats
|
||||
.. _voiceConnection.playFile: ./docs_voiceconnection.html#playfile-path-options-callback
|
||||
.. _client.joinVoiceChannel: ./docs_client.html#joinvoicechannel-channel-callback
|
||||
@@ -1,323 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Usage Examples
|
||||
==============
|
||||
|
||||
Not all of these are standalone examples, many of them are usage examples. If you're a beginner to Discord.js, we encourage you to look through these examples to get a hang of the way things work using the library.
|
||||
|
||||
.. warning :: Please do not copy/paste code directly from these examples. Try to learn from and adapt these pieces of code to your specific situation.
|
||||
|
||||
.. note :: We use `Template Literals`_ in these examples. These are an ES6 feature and may not be fully supported in your environment. In this case, it is safe to use other methods of concatenating strings.
|
||||
|
||||
-----
|
||||
|
||||
Logging In
|
||||
----------
|
||||
|
||||
Logs the Client_ in, allowing you to begin working with the Discord API.
|
||||
|
||||
Logging in with a username and password
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
**Do not use a normal user account for large or public bots. This is considered abuse of the API and can land you in trouble.**
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const Discord = require('discord.js');
|
||||
var client = new Discord.Client();
|
||||
|
||||
client.login('mybot@example.com', 'password', output);
|
||||
|
||||
function output(error, token) {
|
||||
if (error) {
|
||||
console.log(`There was an error logging in: ${error}`);
|
||||
return;
|
||||
} else
|
||||
console.log(`Logged in. Token: ${token}`);
|
||||
}
|
||||
|
||||
Logging in with a token
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
You can get your bot's token using the `My Applications`_ page on the Discord Developers site.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const Discord = require('discord.js');
|
||||
var client = new Discord.Client();
|
||||
|
||||
client.loginWithToken('token', output);
|
||||
|
||||
function output(error, token) {
|
||||
if (error) {
|
||||
console.log(`There was an error logging in: ${error}`);
|
||||
return;
|
||||
} else
|
||||
console.log(`Logged in. Token: ${token}`);
|
||||
}
|
||||
|
||||
-----
|
||||
|
||||
Logging Out
|
||||
----------
|
||||
|
||||
The logOut function should be used if you intend to reconnect with the same process. The function takes one parameter, which is a callback.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.logOut((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
|
||||
However, if you want to completely shut down your application, use destroy.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.destroy((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
-----
|
||||
|
||||
Receiving Messages
|
||||
------------------
|
||||
|
||||
Here we will demonstrate receiving messages and logging them to the console.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
if (message.channel.isPrivate) {
|
||||
console.log(`(Private) ${message.author.name}: ${message.content}`);
|
||||
} else {
|
||||
console.log(`(${message.server.name} / ${message.channel.name}) ${message.author.name}: ${message.content}`);
|
||||
}
|
||||
});
|
||||
|
||||
-----
|
||||
|
||||
Sending messages
|
||||
-----------------
|
||||
|
||||
In the same channel
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This is by far the most common way people will send a message in the Discord API. Here we will send a message to the same Channel_ we received a message from in the above example.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
// Don't forget to log the message!
|
||||
client.sendMessage(message.channel, "Hello!");
|
||||
});
|
||||
|
||||
You can also use a `Message`_ resolvable as a parameter. This example does the same thing as above.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
client.sendMessage(message, "Hello!");
|
||||
});
|
||||
|
||||
You can also directly reply to messages. This does the same as adding an @mention in front of your text.
|
||||
|
||||
Sends "@author Hello!"
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
client.reply(message, "Hello!");
|
||||
});
|
||||
|
||||
To a specific server and channel
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Sends "Hello" to the default Channel_ in the Server_ "My Server". Note that this does not require any sort of received message to be activated, however if there are multiple servers with the name "My Server", a random one will be chosen.
|
||||
|
||||
See Cache_ for more details on getting specific objects and resolvables.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
var channel = client.servers.get("name", "My Server").defaultChannel;
|
||||
client.sendMessage(channel, "Hello");
|
||||
|
||||
Private Messages
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
You can also send private messages to a user with a User_ object. This will send "Hello!" as a private message to the original author of the received message.
|
||||
|
||||
Do note however, that a PMChannel_ is not the same as a ServerChannel_ and therefore does not have the same properties such as ``server`` and ``name``.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
client.sendMessage(message.author, "Hello!");
|
||||
});
|
||||
|
||||
|
||||
-----
|
||||
|
||||
Sending files
|
||||
-----------------
|
||||
|
||||
The process of sending files is similar to how you send messages.
|
||||
|
||||
The first parameter takes an `Channel Resolvable`_ or `User Resolvable`_. The User Resolvable will send the file as a DM, and the Channel Resolvable will send the file to a text channel.
|
||||
|
||||
The next parameter is a `File Resolvable`_.
|
||||
|
||||
The third parameter lets you name your file. This is optional.
|
||||
|
||||
The fourth parameter lets you add a message. This is optional.
|
||||
|
||||
The last parameter is a callback. It takes an error and a `Message`_ object.
|
||||
|
||||
URL
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
client.sendFile(message, 'http://i.imgur.com/6CbxaPc.jpg', 'kappa.jpg', 'Check out this cool file!', (err, m) => {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
});
|
||||
|
||||
Local file
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
client.sendFile(message, '/assets/dank_meme.jpg', 'dank_meme.jpg', 'Check out this cool file!', (err, m) => {
|
||||
if (err) console.log(err);
|
||||
});
|
||||
});
|
||||
|
||||
Buffer
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Send data from streams.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
client.on('message', function(message) {
|
||||
var stream = fs.createReadStream('/assets/dank_meme.jpg');
|
||||
var chunks = [];
|
||||
stream.on('data', (dataChunk) => {
|
||||
chunks.push(dataChunk);
|
||||
});
|
||||
|
||||
stream.on('end' () => {
|
||||
client.sendFile(message, Buffer.concat(chunks), 'dank_meme.jpg', 'Check out this cool file!');
|
||||
});
|
||||
});
|
||||
|
||||
-----
|
||||
|
||||
Deleting messages
|
||||
-----------------
|
||||
|
||||
The deleteMessage function takes an `Message Resolvable`_ as the first parameter. The second parameter is a callback.
|
||||
|
||||
This snippet will delete the received message.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('message', function(message) {
|
||||
client.deleteMessage(message);
|
||||
});
|
||||
|
||||
|
||||
You can also delete multiple messages with the deleteMessages function. It takes an array of `Message Resolvable`_ s.
|
||||
|
||||
This code deletes all the messages recieved every 10 seconds.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
var messages = [];
|
||||
|
||||
client.on('message', function(message) {
|
||||
messages.push(message);
|
||||
});
|
||||
|
||||
function clear() {
|
||||
client.deleteMessages(messages);
|
||||
messages = [];
|
||||
}
|
||||
|
||||
setInterval(clear, 10000);
|
||||
|
||||
|
||||
-----
|
||||
|
||||
Status updates
|
||||
-----------------
|
||||
|
||||
Updating your status is very simple.
|
||||
|
||||
The ready event needs to be emitted before you can use these functions.
|
||||
|
||||
You can either use the setStatus function or you can use helpers.
|
||||
|
||||
This will set the status to online and playing Call of Duty: Black Ops 10.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('ready', () => {
|
||||
client.setStatus('online', 'Call of Duty: Black Ops 10');
|
||||
});
|
||||
|
||||
You can also use the setPlayingGame function, if you just want to set your game...
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('ready', () => {
|
||||
client.setPlayingGame('Call of Duty: Black Ops 10');
|
||||
});
|
||||
|
||||
|
||||
...and setStatusIdle/setStatusOnline, if you just want to change your status.
|
||||
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('ready', () => {
|
||||
client.setStatusIdle(); // Now idle
|
||||
setTimeout(() => { client.setStatusOnline(); }, 10000); // Set the status back to online after 10 seconds.
|
||||
});
|
||||
|
||||
Set streaming
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
You can even set the streaming status.
|
||||
|
||||
The setStreaming function takes 3 parameters, and one callback.
|
||||
|
||||
The first defines the name of the game, the second the URL to a twitch.tv channel and the third a type where 1 = streamnig.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('ready', () => {
|
||||
client.setStreaming('Call of Duty: Black Ops 10', 'https://www.twitch.tv/lirik', 1);
|
||||
});
|
||||
|
||||
You can also use the setStatus function to do this.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
client.on('ready', () => {
|
||||
var opts = {
|
||||
name: 'Call of Duty: Black Ops 10',
|
||||
url: 'https://www.twitch.tv/lirik',
|
||||
type: 1
|
||||
};
|
||||
|
||||
client.setStatus(null, opts);
|
||||
});
|
||||
|
||||
|
||||
-----
|
||||
@@ -1,66 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Welcome to discord.js's documentation!
|
||||
======================================
|
||||
|
||||
discord.js is an easy-to-use and intuitive JavaScript API for Discord_. It's fairly high level, so if you're
|
||||
looking for something low level, check out `discord.io`_.
|
||||
|
||||
if you're having problems, check out the `troubleshooting guide`_.
|
||||
|
||||
Feel free to make any contributions you want, whether it be through creating an issue, giving a suggestion or making a pull request!
|
||||
|
||||
.. note:: This documentation is still a work-in-progress, apologies if something isn't yet documented!
|
||||
|
||||
.. _docs:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: General
|
||||
|
||||
installing
|
||||
migrating
|
||||
troubleshooting
|
||||
examples
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Documentation
|
||||
|
||||
docs_client
|
||||
docs_server
|
||||
docs_user
|
||||
docs_message
|
||||
docs_invite
|
||||
docs_voiceconnection
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Channel Documentation
|
||||
|
||||
docs_channel
|
||||
docs_pmchannel
|
||||
docs_serverchannel
|
||||
docs_textchannel
|
||||
docs_voicechannel
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Permission Documentation
|
||||
|
||||
docs_permissionconstants
|
||||
docs_role
|
||||
docs_permissionoverwrite
|
||||
docs_channelpermissions
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Utility Documentation
|
||||
|
||||
docs_cache
|
||||
docs_equality
|
||||
docs_resolvables
|
||||
|
||||
.. _Discord : https://discordapp.com/
|
||||
.. _troubleshooting guide : troubleshooting.html
|
||||
.. _discord.io : https://github.com/izy521/discord.io
|
||||
@@ -1,62 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Installing discord.js
|
||||
=====================
|
||||
|
||||
To install discord.js, you need a few dependencies.
|
||||
|
||||
.. warning:: **When installing with any of these methods, you'll encounter some errors.** This is because an optional dependency isn't working properly, but discord.js should still work fine.
|
||||
|
||||
-----------
|
||||
|
||||
Windows
|
||||
-------
|
||||
|
||||
------------
|
||||
|
||||
- You need `Visual Studio`_ and `Python 2.7`_.
|
||||
|
||||
Your Visual Studio installation ideally has to be recent, but you can try installing without it first. You can use **Express, Community, Enteprise** or any others apart from ``VS Code``.
|
||||
|
||||
- You (obviously) need `NodeJS`_. Node 4 or higher is recommended.
|
||||
|
||||
After you have installed these things, to install just run: ``npm install --save --msvs_version=2015 discord.js`` to install the latest version of discord.js for your project.
|
||||
|
||||
Additional Audio Support
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
- Install `ffmpeg`_ and add it to your PATH.
|
||||
|
||||
-----------
|
||||
|
||||
Linux (Debian-based)
|
||||
-----
|
||||
|
||||
-----------
|
||||
|
||||
- You (obviously) need `NodeJS Linux`_. Node 4 or higher is recommended.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo apt-get install build-essential
|
||||
$ npm install --save discord.js
|
||||
|
||||
|
||||
Additional Audio Support
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo apt-get install ffmpeg
|
||||
|
||||
Note: Ubuntu 14.04 needs to do:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ sudo add-apt-repository ppa:mc3man/trusty-media && sudo apt-get update && sudo apt-get install ffmpeg
|
||||
|
||||
.. _Visual Studio : https://www.visualstudio.com/downloads/download-visual-studio-vs
|
||||
.. _Python 2.7 : https://www.python.org/download/releases/2.7.8/
|
||||
.. _ffmpeg : https://www.ffmpeg.org/download.html
|
||||
.. _NodeJS : https://nodejs.org/en/download/
|
||||
.. _NodeJS Linux : https://nodejs.org/en/download/package-manager/
|
||||
263
docs/make.bat
263
docs/make.bat
@@ -1,263 +0,0 @@
|
||||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=_build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
|
||||
set I18NSPHINXOPTS=%SPHINXOPTS% .
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. texinfo to make Texinfo files
|
||||
echo. gettext to make PO message catalogs
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. xml to make Docutils-native XML files
|
||||
echo. pseudoxml to make pseudoxml-XML files for display purposes
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
echo. coverage to run coverage check of the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
|
||||
REM Check if sphinx-build is available and fallback to Python version if any
|
||||
%SPHINXBUILD% 2> nul
|
||||
if errorlevel 9009 goto sphinx_python
|
||||
goto sphinx_ok
|
||||
|
||||
:sphinx_python
|
||||
|
||||
set SPHINXBUILD=python -m sphinx.__init__
|
||||
%SPHINXBUILD% 2> nul
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:sphinx_ok
|
||||
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\discordjs.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\discordjs.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latexpdf" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
cd %BUILDDIR%/latex
|
||||
make all-pdf
|
||||
cd %~dp0
|
||||
echo.
|
||||
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latexpdfja" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
cd %BUILDDIR%/latex
|
||||
make all-pdf-ja
|
||||
cd %~dp0
|
||||
echo.
|
||||
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "texinfo" (
|
||||
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "gettext" (
|
||||
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "coverage" (
|
||||
%SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of coverage in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/coverage/python.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "xml" (
|
||||
%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The XML files are in %BUILDDIR%/xml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pseudoxml" (
|
||||
%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
||||
@@ -1,45 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Updating to v5.0.0
|
||||
==================
|
||||
|
||||
If you're coming from versions below v5, you might find some changes. Here are the major changes:
|
||||
|
||||
Change 1
|
||||
--------
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
// OLD:
|
||||
|
||||
client.getUser();
|
||||
client.getServer();
|
||||
server.getMember(); // etc etc
|
||||
|
||||
// NEW:
|
||||
|
||||
client.users.get();
|
||||
client.servers.get();
|
||||
client.members.get();
|
||||
|
||||
Change 2
|
||||
--------
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
// OLD:
|
||||
|
||||
client.on("serverNewMember", (member, server) => {
|
||||
|
||||
});
|
||||
|
||||
// NEW:
|
||||
|
||||
client.on("serverNewMember", (server, user) => {
|
||||
|
||||
});
|
||||
|
||||
Change 3
|
||||
---------
|
||||
|
||||
The Member Class has been removed, meaning you can't use ``member.permissionsIn(channel)``. To get permissions, use ``channel.permissionsOf(user)``.
|
||||
@@ -1,51 +0,0 @@
|
||||
.. include:: ./vars.rst
|
||||
|
||||
Troubleshooting
|
||||
===============
|
||||
|
||||
General
|
||||
-------
|
||||
|
||||
Occasionally, the API can stop working for whatever reason. If it was working previously and it stopped working on the same version, it means that either we screwed code up or there's been a change to the Discord API. You can try asking around in the `discord.js channel in the API server`_. You could also `make an issue`_ if one relating to a similar issue doesn't exist. Please post a stacktrace if there is one, and be as detailed as possible - *"the API isn't working"* doesn't help at all.
|
||||
|
||||
If there is already an issue, feel free to comment that you're also experiencing the same thing. This helps to see how widespread the bug is.
|
||||
|
||||
You can try reconnecting before submitting an issue, as sometimes some of the servers may be slightly different.
|
||||
|
||||
If you're your bot or client is exiting unexpectedly with no error, this is likely caused by websocket disconnects. Make sure you have ``autoReconnect`` enabled. See `Client`_.
|
||||
|
||||
Voice
|
||||
------
|
||||
|
||||
Often, especially if you're on Windows, voice will not work out of the box.
|
||||
Follow the steps below, one by one.
|
||||
|
||||
|
||||
- Is your system supported? The following are:
|
||||
- Linux x64 & ia32
|
||||
- Linux ARM (Raspberry Pi 1 & 2)
|
||||
- Mac OS X x64
|
||||
- Windows x64
|
||||
- Did you install Python 2.7.x correctly? Is it in your PATH? ``python -V``. If not, install it correctly or try reinstalling.
|
||||
- **Windows** - See https://python.org/downloads/
|
||||
- **Linux / Mac OS** - Unix systems should already have it installed, but if not, use the OS's package manager
|
||||
- Did you install FFMPEG correctly? Is it in your PATH? ``ffmpeg -version``. If not, install it correctly or try reinstalling.
|
||||
- **Windows** - `Follow this guide`_
|
||||
- **Linux / Mac OS** - Use your OS's package manager
|
||||
- Did you install the required C++ compiler tool for your OS? If not, install the corresponding program, **then** try reinstalling discord.js ``npm i -S discord.js``
|
||||
- **Windows** - `Visual Studio 2015`_ with `C++ Support enabled`_
|
||||
- **Linux** - build-essential
|
||||
- **Mac OS** - Xcode CLI tools
|
||||
|
||||
If you're still having problems try
|
||||
- ``npm cache clean``
|
||||
- ``npm config set msvs_version 2015``
|
||||
- ``npm i -S discord.js``
|
||||
|
||||
If nothing of the above helped, feel free to jump on the `discord.js channel in the API server`_
|
||||
|
||||
.. _discord.js channel in the API server : https://discord.gg/0SBTUU1wZTYcFtmP
|
||||
.. _make an issue : https://github.com/hydrabolt/discord.js/issues
|
||||
.. _Follow this guide : http://adaptivesamples.com/how-to-install-ffmpeg-on-windows/
|
||||
.. _Visual Studio 2015 : https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx
|
||||
.. _C++ Support enabled : https://social.msdn.microsoft.com/Forums/getfile/740020
|
||||
@@ -1,35 +0,0 @@
|
||||
.. _Client : ./docs_client.html
|
||||
.. _Cache : ./docs_cache.html
|
||||
.. _User : ./docs_user.html
|
||||
.. _Users : ./docs_user.html
|
||||
.. _Server : ./docs_server.html
|
||||
.. _Channel : ./docs_channel.html
|
||||
.. _ServerChannel : ./docs_serverchannel.html
|
||||
.. _TextChannel : ./docs_textchannel.html
|
||||
.. _VoiceChannel : ./docs_voicechannel.html
|
||||
.. _PMChannel : ./docs_pmchannel.html
|
||||
.. _Message : ./docs_message.html
|
||||
.. _Invite : ./docs_invite.html
|
||||
.. _Equality : ./docs_equality.html
|
||||
.. _Role : ./docs_role.html
|
||||
.. _ChannelPermissions : ./docs_channelpermissions.html
|
||||
.. _PermissionOverwrite : ./docs_permissionoverwrite.html
|
||||
.. _Permission Constants : ./docs_permissionconstants.html
|
||||
.. _Resolvables : ./docs_resolvables.html
|
||||
.. _VoiceConnection : ./docs_voiceconnection.html
|
||||
.. _Promises : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||
.. _Template Literals : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
|
||||
.. _EventEmitter : https://nodejs.org/api/events.html#events_class_events_eventemitter
|
||||
.. _Channel Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#channel-resolvable
|
||||
.. _String Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#string-resolvable
|
||||
.. _Message Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#message-resolvable
|
||||
.. _Server Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#server-resolvable
|
||||
.. _Invite Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#invite-id-resolvable
|
||||
.. _User Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#user-resolvable
|
||||
.. _Base64 Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#base64-resolvable
|
||||
|
||||
.. _VoiceChannel Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#voice-channel-resolvable
|
||||
.. _File Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#file-resolvable
|
||||
.. _Role Resolvable : http://discordjs.readthedocs.org/en/indev/docs_resolvables.html#role-resolvable
|
||||
|
||||
.. _My Applications : https://discordapp.com/developers/applications/me
|
||||
@@ -1,39 +0,0 @@
|
||||
/* global process */
|
||||
/*
|
||||
this is the entrypoint file, when node finally catches
|
||||
up with all ES6 drafts etc, the entrypoint file will stop
|
||||
using the transpiled ES5 and switch straight to the ES6
|
||||
code. This allows for easier debugging and potentially
|
||||
faster execution!
|
||||
*/
|
||||
var v = process.version;
|
||||
if(v.charAt(0) === "v"){
|
||||
v = v.substring(1);
|
||||
}
|
||||
|
||||
v = v.split(".");
|
||||
|
||||
var major = parseInt(v[0]),
|
||||
minor = parseInt(v[1]),
|
||||
patch = parseInt(v[2]);
|
||||
|
||||
if((major == 0 && minor < 12) || (major == 0 && minor == 12 && patch < 7)) {
|
||||
if(!process.env.OVERRIDE_DISCORD_MIN_VERSION) {
|
||||
throw new Error(
|
||||
"discord.js doesn't support node versions less than 0.12.7.\n"+
|
||||
"If you /really/ want to run it on this node " + process.version + ", then set OVERRIDE_DISCORD_MIN_VERSION as an environment variable.\n"+
|
||||
"This is unsupported and WILL cause problems."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// at the moment no node version has full ES6 support
|
||||
use5();
|
||||
|
||||
function use6(){
|
||||
module.exports = require("./src/index.js");
|
||||
}
|
||||
|
||||
function use5(){
|
||||
module.exports = require("./lib/index.js");
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"source": "./src",
|
||||
"destination": "./esdoc"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
# Analysis Bot
|
||||
|
||||
Analysis Bot provides Analysis and Utility to Discord Users!
|
||||
@@ -1,161 +0,0 @@
|
||||
/* global process */
|
||||
|
||||
var Discord = require("../../");
|
||||
var bot = new Discord.Client();
|
||||
var auth = require("../auth.json");
|
||||
var request = require("superagent");
|
||||
|
||||
var loose = false;
|
||||
|
||||
bot.on("message", msg => {
|
||||
|
||||
if (!msg.content.startsWith("$")) return;
|
||||
|
||||
msg.content = msg.content.substr(1);
|
||||
|
||||
if (msg.content === "stats") {
|
||||
msg.reply([
|
||||
"I am connected/have access to:",
|
||||
`${bot.servers.length} servers`,
|
||||
`${bot.channels.length} channels`,
|
||||
`${bot.users.length} users`,
|
||||
]);
|
||||
}
|
||||
|
||||
else if (msg.content.startsWith("startplaying")) {
|
||||
var game = msg.content.split(" ").slice(1).join(" ");
|
||||
bot.setPlayingGame(game);
|
||||
}
|
||||
|
||||
else if (msg.content.startsWith("setname") && loose) {
|
||||
bot.setUsername(msg.content.split(" ").slice(1).join(" ")).then(() => {
|
||||
msg.reply("Done!");
|
||||
});
|
||||
}
|
||||
|
||||
else if (msg.content === "updateav") {
|
||||
request
|
||||
.get("https://api.github.com/search/repositories?q=discord.js")
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = res.body.items[0].stargazers_count
|
||||
|
||||
bot.updateDetails({
|
||||
username : "d.js star bot - " + text,
|
||||
avatar: getStars(text)
|
||||
}).then(() => {
|
||||
msg.reply("Success!");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
else if (msg.content.startsWith("setavatar") && loose) {
|
||||
request
|
||||
.get(msg.content.split(" ")[1])
|
||||
.end((err, res) => {
|
||||
bot.updateDetails({
|
||||
avatar: getStars(text)
|
||||
}).then(() => {
|
||||
|
||||
msg.reply("done!");
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
else if (msg.content === "away") {
|
||||
bot.setStatusIdle();
|
||||
}
|
||||
|
||||
else if (msg.content === "here") {
|
||||
bot.setStatusOnline();
|
||||
}
|
||||
|
||||
else if (msg.content === "randomUser") {
|
||||
var random = bot.users.random();
|
||||
msg.reply([
|
||||
random.username,
|
||||
"avatar: ", random.avatarURL
|
||||
]);
|
||||
}
|
||||
|
||||
else if (msg.content.startsWith("mimic") && loose) {
|
||||
var toMimic = msg.mentions[0];
|
||||
|
||||
if (!toMimic) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!toMimic.avatar) {
|
||||
bot.updateDetails({
|
||||
username: toMimic.username,
|
||||
avatar: null
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
request
|
||||
.get(toMimic.avatarURL)
|
||||
.end((err, res) => {
|
||||
bot.updateDetails({
|
||||
username: toMimic.username,
|
||||
avatar: res.body
|
||||
}).then(() => {
|
||||
|
||||
msg.reply("Done!");
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
|
||||
request
|
||||
.get("https://api.github.com/search/repositories?q=discord.js")
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = res.body.items[0].stargazers_count
|
||||
|
||||
bot.updateDetails({
|
||||
username : "d.js star bot - " + text,
|
||||
avatar: getStars(text)
|
||||
}).then(() => {
|
||||
console.log("many successes");
|
||||
});
|
||||
});
|
||||
|
||||
}, 60000);
|
||||
|
||||
bot.on("disconnected", () => {
|
||||
console.log("Disconnected, exiting!");
|
||||
process.exit();
|
||||
})
|
||||
|
||||
bot.loginWithToken(auth.token);
|
||||
|
||||
function getStars(text) {
|
||||
var Canvas = require('canvas')
|
||||
, Image = Canvas.Image
|
||||
, canvas = new Canvas(90, 90)
|
||||
, ctx = canvas.getContext('2d');
|
||||
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillRect(0, 0, 90, 90);
|
||||
|
||||
ctx.font = '45px Arial';
|
||||
ctx.fillStyle = "white";
|
||||
ctx.fillText(text, (ctx.measureText(text).width / 2) - 5, 60);
|
||||
|
||||
ctx.strokeStyle = 'rgb(255,255,255)';
|
||||
|
||||
return canvas.toDataURL();
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"token": "Your bot token here"
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
this bot is an avatar bot, and will give a user their avatar's URL
|
||||
*/
|
||||
|
||||
var Discord = require("../");
|
||||
|
||||
var AuthDetails = require("./auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
|
||||
bot.on("ready", () => {
|
||||
console.log(`Ready to begin! Serving in ${bot.channels.length} channels`);
|
||||
});
|
||||
|
||||
bot.on("disconnected", () => {
|
||||
|
||||
console.log("Disconnected!");
|
||||
process.exit(1); //exit node.js with an error
|
||||
|
||||
});
|
||||
|
||||
bot.on("message", (msg) => {
|
||||
|
||||
// if the message is avatar
|
||||
if (msg.content === "avatar") {
|
||||
bot.reply(msg, "Here is the URL for your avatar: " + msg.author.avatarURL);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6"
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
var Discord = require("../../");
|
||||
|
||||
// Get the token
|
||||
var AuthDetails = require("../auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
|
||||
bot.on("ready", function () {
|
||||
console.log(`Ready to begin! Serving in ${bot.channels.length} channels`);
|
||||
});
|
||||
|
||||
bot.on("disconnected", function () {
|
||||
console.log("Disconnected!");
|
||||
process.exit(1); //exit node.js with an error
|
||||
});
|
||||
|
||||
bot.on("message", function (msg) {
|
||||
if (msg.content === "skype") {
|
||||
|
||||
//stop the user from speaking in the channel:
|
||||
bot.overwritePermissions(msg.channel, msg.author, {
|
||||
sendMessages: false
|
||||
});
|
||||
|
||||
// send a barely funny message ;)
|
||||
bot.reply(msg, "How dare you mention that!");
|
||||
|
||||
}
|
||||
|
||||
if (msg.content === "discord") {
|
||||
|
||||
var role = msg.server.roles.get("name", "good people");
|
||||
|
||||
// if the role doesn't exist, make it
|
||||
if (!role) {
|
||||
bot.createRole(msg.server, {
|
||||
name: "good people",
|
||||
color: "0000FF", // blue
|
||||
hoist: true // make a seperate category in the users list
|
||||
}).then(createdRole => {
|
||||
role = createdRole;
|
||||
}).catch(console.log);
|
||||
}
|
||||
|
||||
bot.addMemberToRole(msg.author, role);
|
||||
bot.reply(msg, "Welcome to the good people!");
|
||||
}
|
||||
|
||||
if (msg.content === "remove me") {
|
||||
// remove the user from the good people list, if it exists
|
||||
var role = msg.server.roles.get("name", "good people");
|
||||
|
||||
if (role) { // if the role exists
|
||||
|
||||
if (msg.author.hasRole(role)) {
|
||||
// remove the member from the role
|
||||
bot.removeMemberFromRole(msg.author, role);
|
||||
bot.reply(msg, "Removed!")
|
||||
} else {
|
||||
bot.reply(msg, "You're not in the role!");
|
||||
}
|
||||
|
||||
} else {
|
||||
// role doesn't exist
|
||||
bot.reply(msg, "The role doesn't even exist!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
this bot will demonstrate the different ways you
|
||||
can create colors in Discord.
|
||||
*/
|
||||
|
||||
var Discord = require("../../");
|
||||
|
||||
// Get the email and password
|
||||
var AuthDetails = require("../auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
|
||||
bot.on("ready", function () {
|
||||
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
|
||||
});
|
||||
|
||||
bot.on("disconnected", function () {
|
||||
|
||||
console.log("Disconnected!");
|
||||
process.exit(1); //exit node.js with an error
|
||||
|
||||
});
|
||||
|
||||
bot.on("message", function (msg) {
|
||||
|
||||
// to use this example, you first have to send 'create role'
|
||||
// you can then change colors afterwards.
|
||||
|
||||
if (msg.content === "create role") {
|
||||
// create the role and add the user to it
|
||||
|
||||
bot.createRole(msg.server, {
|
||||
name: "Custom Colors",
|
||||
hoist: true, // so it is visible in the members list
|
||||
}).then(createdRole => { // this is executed when the role has been created
|
||||
|
||||
// adds the sernder to the role
|
||||
bot.addMemberToRole(msg.author, createdRole).then(() => {
|
||||
bot.reply(msg, "Added you to the role!");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
else if (msg.content.startsWith("custom color")) {
|
||||
|
||||
// valid custom colors must follow the format of any of the following:
|
||||
/*
|
||||
#ff0000 <- valid 7 digit hex (including #)
|
||||
ff0000 <- valid 6 digit hex
|
||||
16711680 <- valid decimal number (this if #ff0000 as a decimal)
|
||||
*/
|
||||
|
||||
var colorName = msg.content.split(" ")[2];
|
||||
|
||||
// get the role by its name
|
||||
var role = msg.server.roles.get("name", "Custom Colors");
|
||||
|
||||
// updates the role with the given color
|
||||
bot.updateRole(role, {
|
||||
color: colorName
|
||||
}).then(function (role) {
|
||||
|
||||
// this executes if the change was successful
|
||||
bot.reply(msg, "Done! Using the color " + colorName);
|
||||
}).catch(function (e) {
|
||||
|
||||
// this executes if it wasn't successful
|
||||
bot.reply(msg, "An error occurred. Was that a valid hex/dec color?");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -1,46 +0,0 @@
|
||||
/* this bot will see if a user can send TTS messages */
|
||||
|
||||
var Discord = require("../../");
|
||||
|
||||
var AuthDetails = require("../auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
|
||||
bot.on("ready", () => {
|
||||
console.log("Ready to begin!");
|
||||
});
|
||||
|
||||
bot.on("message", (msg) => {
|
||||
var user = msg.author;
|
||||
|
||||
if(msg.content === "can I tts?"){
|
||||
|
||||
// get the evaluated permissions for a user in the channel they asked
|
||||
var permissions = msg.channel.permissionsOf(user);
|
||||
|
||||
if(permissions.sendTTSMessages)
|
||||
bot.reply(msg, "You ***can*** send TTS messages.");
|
||||
|
||||
else
|
||||
bot.reply(msg, "You ***can't*** send TTS messages.");
|
||||
|
||||
|
||||
} else if(msg.content === "what are my full permissions?") {
|
||||
|
||||
// get the serialised permissions of the user
|
||||
var permissions = msg.channel.permissionsOf(user).serialise();
|
||||
|
||||
// if you want to stringify permissions, they need to be serialised first.
|
||||
|
||||
bot.reply(msg, JSON.stringify(permissions, null, 4).replace(/true/g, "**true**"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
for a list of more permissions, go to
|
||||
http://discordjs.readthedocs.io/en/indev/docs_permissionconstants.html
|
||||
*/
|
||||
|
||||
})
|
||||
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
This bot is a ping pong bot, and every time a message
|
||||
beginning with "ping" is sent, it will reply with
|
||||
"pong!".
|
||||
*/
|
||||
|
||||
var Discord = require("../");
|
||||
|
||||
// Get the email and password
|
||||
var AuthDetails = require("./auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
|
||||
//when the bot is ready
|
||||
bot.on("ready", () => {
|
||||
console.log(`Ready to begin! Serving in ${bot.channels.length} channels`);
|
||||
});
|
||||
|
||||
//when the bot disconnects
|
||||
bot.on("disconnected", () => {
|
||||
//alert the console
|
||||
console.log("Disconnected!");
|
||||
|
||||
//exit node.js with an error
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
//when the bot receives a message
|
||||
bot.on("message", msg => {
|
||||
//if message begins with "ping"
|
||||
if (msg.content.startsWith("ping")) {
|
||||
//send a message to the channel the ping message was sent in.
|
||||
bot.sendMessage(msg, "pong!");
|
||||
|
||||
//alert the console
|
||||
console.log("pong-ed " + msg.author.username);
|
||||
}
|
||||
});
|
||||
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -1,30 +0,0 @@
|
||||
/* this bot will send an image to a channel */
|
||||
|
||||
var Discord = require("../");
|
||||
|
||||
var AuthDetails = require("./auth.json");
|
||||
|
||||
var bot = new Discord.Client();
|
||||
|
||||
bot.on("ready", () => {
|
||||
console.log("Ready to begin!");
|
||||
});
|
||||
|
||||
bot.on("message", (msg) => {
|
||||
|
||||
if (msg.content === "photos") {
|
||||
bot.sendFile(msg, "./test/image.png", "photo.png", (err, sentMessage) => {
|
||||
if (err)
|
||||
console.log("Couldn't send image: ", err);
|
||||
});
|
||||
}
|
||||
|
||||
else if (msg.content === "file") {
|
||||
bot.sendFile(msg.channel, new Buffer("Text in a file!"), "file.txt", (err, sentMessage) => {
|
||||
if (err)
|
||||
console.log("Couldn't send file: ", err)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
bot.loginWithToken(AuthDetails.token);
|
||||
@@ -1,31 +0,0 @@
|
||||
var Discord = require('discord.js');
|
||||
|
||||
const token = ''; // token for bot login
|
||||
|
||||
//when the bot is ready
|
||||
bot.on("ready", () => {
|
||||
console.log(`Ready to begin! Serving in ${bot.channels.length} channels`);
|
||||
});
|
||||
|
||||
//when the bot disconnects
|
||||
bot.on("disconnected", () => {
|
||||
//alert the console
|
||||
console.log("Disconnected!");
|
||||
|
||||
//exit node.js with an error
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
//when the bot receives a message
|
||||
bot.on("message", msg => {
|
||||
//if message begins with "ping"
|
||||
if (msg.content.startsWith("ping")) {
|
||||
//send a message to the channel the ping message was sent in.
|
||||
bot.sendMessage(msg, "pong!");
|
||||
|
||||
//alert the console
|
||||
console.log("pong-ed " + msg.author.username);
|
||||
}
|
||||
});
|
||||
|
||||
bot.loginWithToken(token);
|
||||
53
gruntfile.js
53
gruntfile.js
@@ -1,53 +0,0 @@
|
||||
module.exports = function (grunt) {
|
||||
|
||||
require('load-grunt-tasks')(grunt);
|
||||
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON("package.json"),
|
||||
// define source files and their destinations
|
||||
babel: {
|
||||
options: {
|
||||
loose: "all",
|
||||
compact: !grunt.option('dev')
|
||||
},
|
||||
dist: {
|
||||
files: [{
|
||||
expand: true,
|
||||
cwd: "src/",
|
||||
src: ["**/**.*"],
|
||||
dest: "lib/",
|
||||
ext: ".js"
|
||||
}]
|
||||
}
|
||||
},
|
||||
browserify: {
|
||||
dist: {
|
||||
files: {
|
||||
'web-dist/discord.<%= pkg.version %>.js': ["lib/index.js"],
|
||||
},
|
||||
options: {
|
||||
browserifyOptions: {
|
||||
standalone: "Discord"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
uglify: {
|
||||
min: {
|
||||
files: {
|
||||
"./web-dist/discord.min.<%= pkg.version %>.js": "./web-dist/discord.<%= pkg.version %>.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// load plugins
|
||||
grunt.loadNpmTasks('grunt-browserify');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
|
||||
// register at least this one task
|
||||
grunt.registerTask('default', ['babel']);
|
||||
grunt.registerTask('web', ['browserify', "uglify"]);
|
||||
grunt.registerTask("dist", ["babel", "browserify", "uglify"])
|
||||
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "commonjs"
|
||||
}
|
||||
}
|
||||
1486
lib/Client/Client.js
1486
lib/Client/Client.js
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports["default"] = {
|
||||
IDLE: 0,
|
||||
LOGGING_IN: 1,
|
||||
LOGGED_IN: 2,
|
||||
READY: 3,
|
||||
DISCONNECTED: 4
|
||||
};
|
||||
module.exports = exports["default"];
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,382 +0,0 @@
|
||||
"use strict";
|
||||
/* global Buffer */
|
||||
|
||||
/**
|
||||
* Resolves supplied data type to a Channel. If a String, it should be a Channel ID.
|
||||
* @typedef {(Channel|Server|Message|User|String)} ChannelResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to a TextChannel or PMChannel. If a String, it should be a Channel ID.
|
||||
* @typedef {(TextChannel|PMChannel|Server|Message|User|String)} TextChannelResolvable
|
||||
*/
|
||||
/**
|
||||
* If given an array, turns it into a newline-separated string.
|
||||
* @typedef {(String|Array)} StringResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to a Message. If a channel, it is the latest message from that channel.
|
||||
* @typedef {(Message|TextChannel|PMChannel)} MessageResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to a Server. If a String, it should be the server's ID.
|
||||
* @typedef {(Server|ServerChannel|Message|String)} ServerResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to something that can be attached to a message. If a String, it can be an URL or a path to a local file.
|
||||
* @typedef {(String|ReadableStream|Buffer)} FileResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to an invite ID. If a String, it should be an ID or a direct URL to the invite.
|
||||
* @typedef {(Invite|String)} InviteIDResolvable
|
||||
*/
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var _fs = require("fs");
|
||||
|
||||
var _fs2 = _interopRequireDefault(_fs);
|
||||
|
||||
var _superagent = require("superagent");
|
||||
|
||||
var _superagent2 = _interopRequireDefault(_superagent);
|
||||
|
||||
var _StructuresUser = require("../../Structures/User");
|
||||
|
||||
var _StructuresUser2 = _interopRequireDefault(_StructuresUser);
|
||||
|
||||
var _StructuresChannel = require("../../Structures/Channel");
|
||||
|
||||
var _StructuresChannel2 = _interopRequireDefault(_StructuresChannel);
|
||||
|
||||
var _StructuresTextChannel = require("../../Structures/TextChannel");
|
||||
|
||||
var _StructuresTextChannel2 = _interopRequireDefault(_StructuresTextChannel);
|
||||
|
||||
var _StructuresVoiceChannel = require("../../Structures/VoiceChannel");
|
||||
|
||||
var _StructuresVoiceChannel2 = _interopRequireDefault(_StructuresVoiceChannel);
|
||||
|
||||
var _StructuresServerChannel = require("../../Structures/ServerChannel");
|
||||
|
||||
var _StructuresServerChannel2 = _interopRequireDefault(_StructuresServerChannel);
|
||||
|
||||
var _StructuresPMChannel = require("../../Structures/PMChannel");
|
||||
|
||||
var _StructuresPMChannel2 = _interopRequireDefault(_StructuresPMChannel);
|
||||
|
||||
var _StructuresRole = require("../../Structures/Role");
|
||||
|
||||
var _StructuresRole2 = _interopRequireDefault(_StructuresRole);
|
||||
|
||||
var _StructuresServer = require("../../Structures/Server");
|
||||
|
||||
var _StructuresServer2 = _interopRequireDefault(_StructuresServer);
|
||||
|
||||
var _StructuresMessage = require("../../Structures/Message");
|
||||
|
||||
var _StructuresMessage2 = _interopRequireDefault(_StructuresMessage);
|
||||
|
||||
var _StructuresInvite = require("../../Structures/Invite");
|
||||
|
||||
var _StructuresInvite2 = _interopRequireDefault(_StructuresInvite);
|
||||
|
||||
var _VoiceVoiceConnection = require("../../Voice/VoiceConnection");
|
||||
|
||||
var _VoiceVoiceConnection2 = _interopRequireDefault(_VoiceVoiceConnection);
|
||||
|
||||
var Resolver = (function () {
|
||||
function Resolver(internal) {
|
||||
_classCallCheck(this, Resolver);
|
||||
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
Resolver.prototype.resolveToBase64 = function resolveToBase64(resource) {
|
||||
if (resource instanceof Buffer) {
|
||||
resource = resource.toString("base64");
|
||||
resource = "data:image/jpg;base64," + resource;
|
||||
}
|
||||
return resource;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveInviteID = function resolveInviteID(resource) {
|
||||
if (resource instanceof _StructuresInvite2["default"]) {
|
||||
return resource.id;
|
||||
}
|
||||
if (typeof resource === "string" || resource instanceof String) {
|
||||
if (resource.indexOf("http") === 0) {
|
||||
var split = resource.split("/");
|
||||
return split.pop();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveServer = function resolveServer(resource) {
|
||||
if (resource instanceof _StructuresServer2["default"]) {
|
||||
return resource;
|
||||
}
|
||||
if (resource instanceof _StructuresServerChannel2["default"]) {
|
||||
return resource.server;
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
return this.internal.servers.get("id", resource);
|
||||
}
|
||||
if (resource instanceof _StructuresMessage2["default"]) {
|
||||
if (resource.channel instanceof _StructuresTextChannel2["default"]) {
|
||||
return resource.channel.server;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveRole = function resolveRole(resource) {
|
||||
if (resource instanceof _StructuresRole2["default"]) {
|
||||
return resource;
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
var role = null;
|
||||
for (var _iterator = this.internal.servers, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var server = _ref;
|
||||
|
||||
if (role = server.roles.get("id", resource)) {
|
||||
return role;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveFile = function resolveFile(resource) {
|
||||
if (typeof resource === "string" || resource instanceof String) {
|
||||
if (/^https?:\/\//.test(resource)) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
_superagent2["default"].get(resource).buffer().parse(function (res, cb) {
|
||||
res.setEncoding("binary");
|
||||
res.data = "";
|
||||
res.on("data", function (chunk) {
|
||||
res.data += chunk;
|
||||
});
|
||||
res.on("end", function () {
|
||||
cb(null, new Buffer(res.data, "binary"));
|
||||
});
|
||||
}).end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(res.body);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve(resource);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(resource);
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveMentions = function resolveMentions(resource, channel) {
|
||||
var _mentions = [];
|
||||
var changed = resource;
|
||||
for (var _iterator2 = resource.match(/<@\!?[0-9]+>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var mention = _ref2;
|
||||
// username mention
|
||||
if (mention[2] === '!') {
|
||||
var user = this.internal.users.get("id", mention.substring(3, mention.length - 1));
|
||||
if (user) {
|
||||
_mentions.push(user);
|
||||
var details = channel.server && channel.server.detailsOf(user);
|
||||
if (details) {
|
||||
changed = changed.replace(new RegExp(mention, "g"), "@" + (details.nick || user.username + "#" + user.discriminator));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var user = this.internal.users.get("id", mention.substring(2, mention.length - 1));
|
||||
if (user) {
|
||||
_mentions.push(user);
|
||||
changed = changed.replace(new RegExp(mention, "g"), "@" + (user.username + "#" + user.discriminator));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (channel && channel.server && channel.server.roles) {
|
||||
for (var _iterator3 = resource.match(/<@&[0-9]+>/g) || [], _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var mention = _ref3;
|
||||
// role mention
|
||||
var role = channel.server.roles.get("id", mention.substring(3, mention.length - 1));
|
||||
if (role) {
|
||||
changed = changed.replace(new RegExp(mention, "g"), "@" + role.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var _iterator4 = resource.match(/<#[0-9]+>/g) || [], _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||||
var _ref4;
|
||||
|
||||
if (_isArray4) {
|
||||
if (_i4 >= _iterator4.length) break;
|
||||
_ref4 = _iterator4[_i4++];
|
||||
} else {
|
||||
_i4 = _iterator4.next();
|
||||
if (_i4.done) break;
|
||||
_ref4 = _i4.value;
|
||||
}
|
||||
|
||||
var mention = _ref4;
|
||||
// channel mention
|
||||
var channel = this.internal.channels.get("id", mention.substring(2, mention.length - 1));
|
||||
if (channel) {
|
||||
changed = changed.replace(new RegExp(mention, "g"), "#" + channel.name);
|
||||
}
|
||||
}
|
||||
return [_mentions, changed];
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveString = function resolveString(resource) {
|
||||
|
||||
// accepts Array, Channel, Server, User, Message, String and anything
|
||||
// toString()-able
|
||||
|
||||
if (resource instanceof Array) {
|
||||
resource = resource.join("\n");
|
||||
}
|
||||
|
||||
return resource.toString();
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveUser = function resolveUser(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, Server, String ID, User, PMChannel
|
||||
*/
|
||||
if (resource instanceof _StructuresUser2["default"]) {
|
||||
return resource;
|
||||
}
|
||||
if (resource instanceof _StructuresMessage2["default"]) {
|
||||
return resource.author;
|
||||
}
|
||||
if (resource instanceof _StructuresTextChannel2["default"]) {
|
||||
var lmsg = resource.lastMessage;
|
||||
if (lmsg) {
|
||||
return lmsg.author;
|
||||
}
|
||||
}
|
||||
if (resource instanceof _StructuresServer2["default"]) {
|
||||
return resource.owner;
|
||||
}
|
||||
if (resource instanceof _StructuresPMChannel2["default"]) {
|
||||
return resource.recipient;
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
return this.internal.users.get("id", resource);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveMessage = function resolveMessage(resource) {
|
||||
// accepts a Message, PMChannel & TextChannel
|
||||
|
||||
if (resource instanceof _StructuresTextChannel2["default"] || resource instanceof _StructuresPMChannel2["default"]) {
|
||||
return resource.lastMessage;
|
||||
}
|
||||
if (resource instanceof _StructuresMessage2["default"]) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Resolver.prototype.resolveChannel = function resolveChannel(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, VoiceConnection, Server, String ID, User
|
||||
*/
|
||||
|
||||
if (resource instanceof _StructuresMessage2["default"]) {
|
||||
return Promise.resolve(resource.channel);
|
||||
}
|
||||
if (resource instanceof _StructuresChannel2["default"]) {
|
||||
return Promise.resolve(resource);
|
||||
}
|
||||
if (resource instanceof _VoiceVoiceConnection2["default"]) {
|
||||
return Promise.resolve(resource.voiceChannel);
|
||||
}
|
||||
if (resource instanceof _StructuresServer2["default"]) {
|
||||
return Promise.resolve(resource.defaultChannel);
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
var user = this.internal.users.get("id", resource);
|
||||
if (user) {
|
||||
resource = user;
|
||||
} else {
|
||||
return Promise.resolve(this.internal.channels.get("id", resource) || this.internal.private_channels.get("id", resource));
|
||||
}
|
||||
}
|
||||
if (resource instanceof _StructuresUser2["default"]) {
|
||||
// see if a PM exists
|
||||
for (var _iterator5 = this.internal.private_channels, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
||||
var _ref5;
|
||||
|
||||
if (_isArray5) {
|
||||
if (_i5 >= _iterator5.length) break;
|
||||
_ref5 = _iterator5[_i5++];
|
||||
} else {
|
||||
_i5 = _iterator5.next();
|
||||
if (_i5.done) break;
|
||||
_ref5 = _i5.value;
|
||||
}
|
||||
|
||||
var pmchat = _ref5;
|
||||
|
||||
if (pmchat.recipient.equals(resource)) {
|
||||
return Promise.resolve(pmchat);
|
||||
}
|
||||
}
|
||||
|
||||
// PM does not exist :\
|
||||
return this.internal.startPM(resource);
|
||||
}
|
||||
var error = new Error("Could not resolve channel");
|
||||
error.resource = resource;
|
||||
return Promise.reject(error);
|
||||
};
|
||||
|
||||
return Resolver;
|
||||
})();
|
||||
|
||||
exports["default"] = Resolver;
|
||||
module.exports = exports["default"];
|
||||
161
lib/Constants.js
161
lib/Constants.js
@@ -1,161 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
var Constants = {};
|
||||
|
||||
var API = Constants.API = "https://discordapp.com/api";
|
||||
var CDN = Constants.CDN = "https://cdn.discordapp.com";
|
||||
|
||||
var Endpoints = Constants.Endpoints = {
|
||||
// general endpoints
|
||||
LOGIN: API + "/auth/login",
|
||||
LOGOUT: API + "/auth/logout",
|
||||
ME: API + "/users/@me",
|
||||
ME_CHANNELS: API + "/users/@me/channels",
|
||||
ME_SERVER: function ME_SERVER(serverID) {
|
||||
return Endpoints.ME + "/guilds/" + serverID;
|
||||
},
|
||||
OAUTH2_APPLICATION: function OAUTH2_APPLICATION(appID) {
|
||||
return API + "/oauth2/applications/" + appID;
|
||||
},
|
||||
ME_NOTES: API + "/users/@me/notes",
|
||||
GATEWAY: API + "/gateway",
|
||||
AVATAR: function AVATAR(userID, avatar) {
|
||||
return API + "/users/" + userID + "/avatars/" + avatar + ".jpg";
|
||||
},
|
||||
INVITE: function INVITE(id) {
|
||||
return API + "/invite/" + id;
|
||||
},
|
||||
|
||||
// emojis
|
||||
EMOJI: function EMOJI(emojiID) {
|
||||
return CDN + "/emojis/" + emojiID + ".png";
|
||||
},
|
||||
|
||||
// servers
|
||||
SERVERS: API + "/guilds",
|
||||
SERVER: function SERVER(serverID) {
|
||||
return Endpoints.SERVERS + "/" + serverID;
|
||||
},
|
||||
SERVER_ICON: function SERVER_ICON(serverID, hash) {
|
||||
return Endpoints.SERVER(serverID) + "/icons/" + hash + ".jpg";
|
||||
},
|
||||
SERVER_PRUNE: function SERVER_PRUNE(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/prune";
|
||||
},
|
||||
SERVER_EMBED: function SERVER_EMBED(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/embed";
|
||||
},
|
||||
SERVER_INVITES: function SERVER_INVITES(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/invites";
|
||||
},
|
||||
SERVER_ROLES: function SERVER_ROLES(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/roles";
|
||||
},
|
||||
SERVER_BANS: function SERVER_BANS(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/bans";
|
||||
},
|
||||
SERVER_INTEGRATIONS: function SERVER_INTEGRATIONS(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/integrations";
|
||||
},
|
||||
SERVER_MEMBERS: function SERVER_MEMBERS(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/members";
|
||||
},
|
||||
SERVER_CHANNELS: function SERVER_CHANNELS(serverID) {
|
||||
return Endpoints.SERVER(serverID) + "/channels";
|
||||
},
|
||||
|
||||
// channels
|
||||
CHANNELS: API + "/channels",
|
||||
CHANNEL: function CHANNEL(channelID) {
|
||||
return Endpoints.CHANNELS + "/" + channelID;
|
||||
},
|
||||
CHANNEL_MESSAGES: function CHANNEL_MESSAGES(channelID) {
|
||||
return Endpoints.CHANNEL(channelID) + "/messages";
|
||||
},
|
||||
CHANNEL_INVITES: function CHANNEL_INVITES(channelID) {
|
||||
return Endpoints.CHANNEL(channelID) + "/invites";
|
||||
},
|
||||
CHANNEL_TYPING: function CHANNEL_TYPING(channelID) {
|
||||
return Endpoints.CHANNEL(channelID) + "/typing";
|
||||
},
|
||||
CHANNEL_PERMISSIONS: function CHANNEL_PERMISSIONS(channelID) {
|
||||
return Endpoints.CHANNEL(channelID) + "/permissions";
|
||||
},
|
||||
CHANNEL_MESSAGE: function CHANNEL_MESSAGE(channelID, messageID) {
|
||||
return Endpoints.CHANNEL_MESSAGES(channelID) + "/" + messageID;
|
||||
},
|
||||
CHANNEL_PINS: function CHANNEL_PINS(channelID) {
|
||||
return Endpoints.CHANNEL(channelID) + "/pins";
|
||||
},
|
||||
CHANNEL_PIN: function CHANNEL_PIN(channelID, messageID) {
|
||||
return Endpoints.CHANNEL_PINS(channelID) + "/" + messageID;
|
||||
},
|
||||
|
||||
// friends
|
||||
FRIENDS: API + "/users/@me/relationships"
|
||||
};
|
||||
|
||||
Constants.Permissions = {
|
||||
// general
|
||||
createInstantInvite: 1 << 0,
|
||||
kickMembers: 1 << 1,
|
||||
banMembers: 1 << 2,
|
||||
administrator: 1 << 3,
|
||||
manageChannels: 1 << 4,
|
||||
manageChannel: 1 << 4,
|
||||
manageServer: 1 << 5,
|
||||
changeNickname: 1 << 26,
|
||||
manageNicknames: 1 << 27,
|
||||
manageRoles: 1 << 28,
|
||||
managePermissions: 1 << 28,
|
||||
// text
|
||||
readMessages: 1 << 10,
|
||||
sendMessages: 1 << 11,
|
||||
sendTTSMessages: 1 << 12,
|
||||
manageMessages: 1 << 13,
|
||||
embedLinks: 1 << 14,
|
||||
attachFiles: 1 << 15,
|
||||
readMessageHistory: 1 << 16,
|
||||
mentionEveryone: 1 << 17,
|
||||
// voice
|
||||
voiceConnect: 1 << 20,
|
||||
voiceSpeak: 1 << 21,
|
||||
voiceMuteMembers: 1 << 22,
|
||||
voiceDeafenMembers: 1 << 23,
|
||||
voiceMoveMembers: 1 << 24,
|
||||
voiceUseVAD: 1 << 25
|
||||
|
||||
};
|
||||
|
||||
Constants.PacketType = {
|
||||
CHANNEL_CREATE: "CHANNEL_CREATE",
|
||||
CHANNEL_DELETE: "CHANNEL_DELETE",
|
||||
CHANNEL_UPDATE: "CHANNEL_UPDATE",
|
||||
MESSAGE_CREATE: "MESSAGE_CREATE",
|
||||
MESSAGE_DELETE: "MESSAGE_DELETE",
|
||||
MESSAGE_UPDATE: "MESSAGE_UPDATE",
|
||||
PRESENCE_UPDATE: "PRESENCE_UPDATE",
|
||||
READY: "READY",
|
||||
SERVER_BAN_ADD: "GUILD_BAN_ADD",
|
||||
SERVER_BAN_REMOVE: "GUILD_BAN_REMOVE",
|
||||
SERVER_CREATE: "GUILD_CREATE",
|
||||
SERVER_DELETE: "GUILD_DELETE",
|
||||
SERVER_MEMBER_ADD: "GUILD_MEMBER_ADD",
|
||||
SERVER_MEMBER_REMOVE: "GUILD_MEMBER_REMOVE",
|
||||
SERVER_MEMBER_UPDATE: "GUILD_MEMBER_UPDATE",
|
||||
SERVER_MEMBERS_CHUNK: "GUILD_MEMBERS_CHUNK",
|
||||
SERVER_ROLE_CREATE: "GUILD_ROLE_CREATE",
|
||||
SERVER_ROLE_DELETE: "GUILD_ROLE_DELETE",
|
||||
SERVER_ROLE_UPDATE: "GUILD_ROLE_UPDATE",
|
||||
SERVER_UPDATE: "GUILD_UPDATE",
|
||||
TYPING: "TYPING_START",
|
||||
USER_UPDATE: "USER_UPDATE",
|
||||
USER_NOTE_UPDATE: "USER_NOTE_UPDATE",
|
||||
VOICE_STATE_UPDATE: "VOICE_STATE_UPDATE",
|
||||
FRIEND_ADD: "RELATIONSHIP_ADD",
|
||||
FRIEND_REMOVE: "RELATIONSHIP_REMOVE"
|
||||
};
|
||||
|
||||
exports["default"] = Constants;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,50 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _UtilEquality = require("../Util/Equality");
|
||||
|
||||
var _UtilEquality2 = _interopRequireDefault(_UtilEquality);
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var Channel = (function (_Equality) {
|
||||
_inherits(Channel, _Equality);
|
||||
|
||||
function Channel(data, client) {
|
||||
_classCallCheck(this, Channel);
|
||||
|
||||
_Equality.call(this);
|
||||
this.id = data.id;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
Channel.prototype["delete"] = function _delete() {
|
||||
return this.client.deleteChannel.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
_createClass(Channel, [{
|
||||
key: "createdAt",
|
||||
get: function get() {
|
||||
return new Date(+this.id / 4194304 + 1420070400000);
|
||||
}
|
||||
}, {
|
||||
key: "isPrivate",
|
||||
get: function get() {
|
||||
return !this.server;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Channel;
|
||||
})(_UtilEquality2["default"]);
|
||||
|
||||
exports["default"] = Channel;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,60 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var _Constants = require("../Constants");
|
||||
|
||||
var ChannelPermissions = (function () {
|
||||
function ChannelPermissions(permissions) {
|
||||
_classCallCheck(this, ChannelPermissions);
|
||||
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
ChannelPermissions.prototype.serialise = function serialise(explicit) {
|
||||
var _this = this;
|
||||
|
||||
var hp = function hp(perm) {
|
||||
return _this.hasPermission(perm, explicit);
|
||||
};
|
||||
|
||||
var json = {};
|
||||
|
||||
for (var permission in _Constants.Permissions) {
|
||||
json[permission] = hp(_Constants.Permissions[permission]);
|
||||
}
|
||||
|
||||
return json;
|
||||
};
|
||||
|
||||
ChannelPermissions.prototype.serialize = function serialize() {
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
};
|
||||
|
||||
ChannelPermissions.prototype.hasPermission = function hasPermission(perm) {
|
||||
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
|
||||
if (perm instanceof String || typeof perm === "string") {
|
||||
perm = _Constants.Permissions[perm];
|
||||
}
|
||||
if (!perm) {
|
||||
return false;
|
||||
}
|
||||
if (!explicit) {
|
||||
// implicit permissions allowed
|
||||
if (!!(this.permissions & _Constants.Permissions.administrator)) {
|
||||
// administrator allowed, they have all permissions
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !!(this.permissions & perm);
|
||||
};
|
||||
|
||||
return ChannelPermissions;
|
||||
})();
|
||||
|
||||
exports["default"] = ChannelPermissions;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,82 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var _Constants = require("../Constants");
|
||||
|
||||
/* example data
|
||||
{
|
||||
id: '164585980739846145'
|
||||
name: 'wlfSS',
|
||||
roles: [ '135829612780322816' ],
|
||||
require_colons: false,
|
||||
managed: true,
|
||||
}
|
||||
*/
|
||||
|
||||
var Emoji = (function () {
|
||||
function Emoji(data, server) {
|
||||
_classCallCheck(this, Emoji);
|
||||
|
||||
this.server = server;
|
||||
this.id = data.id;
|
||||
this.name = data.name;
|
||||
this.roleList = data.roles;
|
||||
this.colons = data.require_colons;
|
||||
this.managed = data.managed;
|
||||
}
|
||||
|
||||
Emoji.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'name', 'roleList', 'colons', 'managed'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
_createClass(Emoji, [{
|
||||
key: "roles",
|
||||
get: function get() {
|
||||
var roleGroup = [];
|
||||
|
||||
if (this.managed) {
|
||||
for (var i = 0; i < this.roleList.length; i++) {
|
||||
var roleID = this.roleList[i].toString();
|
||||
var role = this.server.roles.get("id", roleID);
|
||||
roleGroup.push(role);
|
||||
}
|
||||
}
|
||||
return roleGroup;
|
||||
}
|
||||
}, {
|
||||
key: "getURL",
|
||||
get: function get() {
|
||||
return _Constants.Endpoints.EMOJI(this.id);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Emoji;
|
||||
})();
|
||||
|
||||
exports["default"] = Emoji;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,47 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var Invite = (function () {
|
||||
function Invite(data, chan, client) {
|
||||
_classCallCheck(this, Invite);
|
||||
|
||||
this.maxAge = data.max_age;
|
||||
this.code = data.code;
|
||||
if (chan) {
|
||||
this.channel = chan;
|
||||
this.server = chan.server;
|
||||
} else {
|
||||
this.channel = data.channel;
|
||||
this.server = data.guild;
|
||||
}
|
||||
this.revoked = data.revoked;
|
||||
this.createdAt = Date.parse(data.created_at);
|
||||
this.temporary = data.temporary;
|
||||
this.uses = data.uses;
|
||||
this.maxUses = data.max_uses;
|
||||
if (data.inviter) {
|
||||
this.inviter = client.internal.users.get("id", data.inviter.id);
|
||||
}
|
||||
this.xkcd = data.xkcdpass;
|
||||
}
|
||||
|
||||
Invite.prototype.toString = function toString() {
|
||||
return "https://discord.gg/" + this.code;
|
||||
};
|
||||
|
||||
Invite.prototype["delete"] = function _delete() {
|
||||
return this.client.deleteInvite.apply(this.client, reg(this, arguments));
|
||||
};
|
||||
|
||||
Invite.prototype.join = function join() {
|
||||
return this.client.joinServer.apply(this.client, reg(this, arguments));
|
||||
};
|
||||
|
||||
return Invite;
|
||||
})();
|
||||
|
||||
exports["default"] = Invite;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,182 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Options that can be applied to a message before sending it.
|
||||
* @typedef {(object)} MessageOptions
|
||||
* @property {boolean} [tts=false] Whether or not the message should be sent as text-to-speech.
|
||||
*/
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _UtilCache = require("../Util/Cache");
|
||||
|
||||
var _UtilCache2 = _interopRequireDefault(_UtilCache);
|
||||
|
||||
var _User = require("./User");
|
||||
|
||||
var _User2 = _interopRequireDefault(_User);
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var _UtilEquality = require("../Util/Equality");
|
||||
|
||||
var _UtilEquality2 = _interopRequireDefault(_UtilEquality);
|
||||
|
||||
var Message = (function (_Equality) {
|
||||
_inherits(Message, _Equality);
|
||||
|
||||
function Message(data, channel, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, Message);
|
||||
|
||||
_Equality.call(this);
|
||||
this.channel = channel;
|
||||
this.server = channel.server;
|
||||
this.client = client;
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone !== undefined ? data.mention_everyone : data.everyoneMentioned;
|
||||
this.pinned = data.pinned;
|
||||
this.id = data.id;
|
||||
|
||||
if (data.edited_timestamp) {
|
||||
this.editedTimestamp = Date.parse(data.edited_timestamp);
|
||||
}
|
||||
|
||||
if (data.author instanceof _User2["default"]) {
|
||||
this.author = data.author;
|
||||
} else if (data.author) {
|
||||
this.author = client.internal.users.add(new _User2["default"](data.author, client));
|
||||
}
|
||||
|
||||
this.content = data.content;
|
||||
|
||||
var mentionData = client.internal.resolver.resolveMentions(data.content, channel);
|
||||
this.cleanContent = mentionData[1];
|
||||
this.mentions = [];
|
||||
|
||||
mentionData[0].forEach(function (mention) {
|
||||
// this is .add and not .get because it allows the bot to cache
|
||||
// users from messages from logs who may have left the server and were
|
||||
// not previously cached.
|
||||
if (mention instanceof _User2["default"]) {
|
||||
_this.mentions.push(mention);
|
||||
} else {
|
||||
_this.mentions.push(client.internal.users.add(new _User2["default"](mention, client)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Message.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'timestamp', 'everyoneMentioned', 'pinned', 'editedTimestamp', 'content', 'cleanContent', 'tts', 'attachments', 'embeds'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
obj.channelID = this.channel ? this.channel.id : null;
|
||||
obj.serverID = this.server ? this.server.id : null;
|
||||
obj.author = this.author.toObject();
|
||||
obj.mentions = this.mentions.map(function (m) {
|
||||
return m.toObject();
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
Message.prototype.isMentioned = function isMentioned(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (!user) {
|
||||
return false;
|
||||
}
|
||||
for (var _iterator2 = this.mentions, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var mention = _ref2;
|
||||
|
||||
if (mention.id == user.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Message.prototype.toString = function toString() {
|
||||
return this.content;
|
||||
};
|
||||
|
||||
Message.prototype["delete"] = function _delete() {
|
||||
return this.client.deleteMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Message.prototype.update = function update() {
|
||||
return this.client.updateMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Message.prototype.edit = function edit() {
|
||||
return this.client.updateMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Message.prototype.reply = function reply() {
|
||||
return this.client.reply.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Message.prototype.replyTTS = function replyTTS() {
|
||||
return this.client.replyTTS.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Message.prototype.pin = function pin() {
|
||||
return this.client.pinMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Message.prototype.unpin = function unpin() {
|
||||
return this.client.unpinMessage.apply(this.client, req(this, arguments));
|
||||
};
|
||||
|
||||
_createClass(Message, [{
|
||||
key: "sender",
|
||||
get: function get() {
|
||||
return this.author;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Message;
|
||||
})(_UtilEquality2["default"]);
|
||||
|
||||
exports["default"] = Message;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,118 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _Channel2 = require("./Channel");
|
||||
|
||||
var _Channel3 = _interopRequireDefault(_Channel2);
|
||||
|
||||
var _User = require("./User");
|
||||
|
||||
var _User2 = _interopRequireDefault(_User);
|
||||
|
||||
var _UtilCache = require("../Util/Cache");
|
||||
|
||||
var _UtilCache2 = _interopRequireDefault(_UtilCache);
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var PMChannel = (function (_Channel) {
|
||||
_inherits(PMChannel, _Channel);
|
||||
|
||||
function PMChannel(data, client) {
|
||||
_classCallCheck(this, PMChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.messages = new _UtilCache2["default"]("id", client.options.maxCachedMessages);
|
||||
this.recipient = this.client.internal.users.add(new _User2["default"](data.recipient, this.client));
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
|
||||
PMChannel.prototype.toString = function toString() {
|
||||
return this.recipient.toString();
|
||||
};
|
||||
|
||||
PMChannel.prototype.toObject = function toObject() {
|
||||
var keys = ['type', 'lastMessageID', 'recipient'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
PMChannel.prototype.sendMessage = function sendMessage() {
|
||||
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.send = function send() {
|
||||
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.sendTTSMessage = function sendTTSMessage() {
|
||||
return this.client.sendTTSMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.sendTTS = function sendTTS() {
|
||||
return this.client.sendTTSMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.sendFile = function sendFile() {
|
||||
return this.client.sendFile.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.startTyping = function startTyping() {
|
||||
return this.client.startTyping.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.stopTyping = function stopTyping() {
|
||||
return this.client.stopTyping.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.getLogs = function getLogs() {
|
||||
return this.client.getChannelLogs.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
PMChannel.prototype.getMessage = function getMessage() {
|
||||
return this.client.getMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
_createClass(PMChannel, [{
|
||||
key: "lastMessage",
|
||||
get: function get() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return PMChannel;
|
||||
})(_Channel3["default"]);
|
||||
|
||||
exports["default"] = PMChannel;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,113 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var _Constants = require("../Constants");
|
||||
|
||||
var PermissionOverwrite = (function () {
|
||||
function PermissionOverwrite(data) {
|
||||
_classCallCheck(this, PermissionOverwrite);
|
||||
|
||||
this.id = data.id;
|
||||
this.type = data.type; // member or role
|
||||
this.deny = data.deny;
|
||||
this.allow = data.allow;
|
||||
}
|
||||
|
||||
// returns an array of allowed permissions
|
||||
|
||||
PermissionOverwrite.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'type', 'allow', 'deny'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
PermissionOverwrite.prototype.setAllowed = function setAllowed(allowedArray) {
|
||||
var _this = this;
|
||||
|
||||
allowedArray.forEach(function (permission) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = _Constants.Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
_this.allow |= 1 << permission;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
PermissionOverwrite.prototype.setDenied = function setDenied(deniedArray) {
|
||||
var _this2 = this;
|
||||
|
||||
deniedArray.forEach(function (permission) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = _Constants.Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
_this2.deny |= 1 << permission;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
_createClass(PermissionOverwrite, [{
|
||||
key: "allowed",
|
||||
get: function get() {
|
||||
var allowed = [];
|
||||
for (var permName in _Constants.Permissions) {
|
||||
if (permName === "manageRoles" || permName === "manageChannels") {
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!!(this.allow & _Constants.Permissions[permName])) {
|
||||
allowed.push(permName);
|
||||
}
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
|
||||
// returns an array of denied permissions
|
||||
}, {
|
||||
key: "denied",
|
||||
get: function get() {
|
||||
var denied = [];
|
||||
for (var permName in _Constants.Permissions) {
|
||||
if (permName === "manageRoles" || permName === "manageChannels") {
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!!(this.deny & _Constants.Permissions[permName])) {
|
||||
denied.push(permName);
|
||||
}
|
||||
}
|
||||
return denied;
|
||||
}
|
||||
}]);
|
||||
|
||||
return PermissionOverwrite;
|
||||
})();
|
||||
|
||||
exports["default"] = PermissionOverwrite;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,216 +0,0 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var _Constants = require("../Constants");
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
/*
|
||||
|
||||
example data
|
||||
|
||||
{ position: -1,
|
||||
permissions: 36953089,
|
||||
name: '@everyone',
|
||||
managed: false,
|
||||
id: '110007368451915776',
|
||||
hoist: false,
|
||||
color: 0 }
|
||||
*/
|
||||
|
||||
var DefaultRole = [_Constants.Permissions.createInstantInvite, _Constants.Permissions.readMessages, _Constants.Permissions.readMessageHistory, _Constants.Permissions.sendMessages, _Constants.Permissions.sendTTSMessages, _Constants.Permissions.embedLinks, _Constants.Permissions.attachFiles, _Constants.Permissions.readMessageHistory, _Constants.Permissions.mentionEveryone, _Constants.Permissions.voiceConnect, _Constants.Permissions.voiceSpeak, _Constants.Permissions.voiceUseVAD].reduce(function (previous, current) {
|
||||
return previous | current;
|
||||
}, 0);
|
||||
|
||||
var Role = (function () {
|
||||
function Role(data, server, client) {
|
||||
_classCallCheck(this, Role);
|
||||
|
||||
this.position = data.position || -1;
|
||||
this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0);
|
||||
this.name = data.name || "@everyone";
|
||||
this.managed = data.managed || false;
|
||||
this.id = data.id;
|
||||
this.hoist = data.hoist || false;
|
||||
this.color = data.color || 0;
|
||||
this.server = server;
|
||||
this.client = client;
|
||||
this.mentionable = data.mentionable || false;
|
||||
}
|
||||
|
||||
Role.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'position', 'permissions', 'name', 'managed', 'hoist', 'color', 'mentionable'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
Role.prototype.serialise = function serialise(explicit) {
|
||||
var _this = this;
|
||||
|
||||
var hp = function hp(perm) {
|
||||
return _this.hasPermission(perm, explicit);
|
||||
};
|
||||
|
||||
return {
|
||||
// general
|
||||
createInstantInvite: hp(_Constants.Permissions.createInstantInvite),
|
||||
kickMembers: hp(_Constants.Permissions.kickMembers),
|
||||
banMembers: hp(_Constants.Permissions.banMembers),
|
||||
manageRoles: hp(_Constants.Permissions.manageRoles),
|
||||
manageChannels: hp(_Constants.Permissions.manageChannels),
|
||||
manageServer: hp(_Constants.Permissions.manageServer),
|
||||
administrator: hp(_Constants.Permissions.administrator),
|
||||
// text
|
||||
readMessages: hp(_Constants.Permissions.readMessages),
|
||||
sendMessages: hp(_Constants.Permissions.sendMessages),
|
||||
sendTTSMessages: hp(_Constants.Permissions.sendTTSMessages),
|
||||
manageMessages: hp(_Constants.Permissions.manageMessages),
|
||||
embedLinks: hp(_Constants.Permissions.embedLinks),
|
||||
attachFiles: hp(_Constants.Permissions.attachFiles),
|
||||
readMessageHistory: hp(_Constants.Permissions.readMessageHistory),
|
||||
mentionEveryone: hp(_Constants.Permissions.mentionEveryone),
|
||||
// voice
|
||||
voiceConnect: hp(_Constants.Permissions.voiceConnect),
|
||||
voiceSpeak: hp(_Constants.Permissions.voiceSpeak),
|
||||
voiceMuteMembers: hp(_Constants.Permissions.voiceMuteMembers),
|
||||
voiceDeafenMembers: hp(_Constants.Permissions.voiceDeafenMembers),
|
||||
voiceMoveMembers: hp(_Constants.Permissions.voiceMoveMembers),
|
||||
voiceUseVAD: hp(_Constants.Permissions.voiceUseVAD)
|
||||
};
|
||||
};
|
||||
|
||||
Role.prototype.serialize = function serialize() {
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
};
|
||||
|
||||
Role.prototype.hasPermission = function hasPermission(perm) {
|
||||
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
|
||||
if (perm instanceof String || typeof perm === "string") {
|
||||
perm = _Constants.Permissions[perm];
|
||||
}
|
||||
if (!perm) {
|
||||
return false;
|
||||
}
|
||||
if (!explicit) {
|
||||
// implicit permissions allowed
|
||||
if (!!(this.permissions & _Constants.Permissions.administrator)) {
|
||||
// administrator allowed, they have all permissions
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// e.g.
|
||||
// !!(36953089 & Permissions.manageRoles) = not allowed to manage roles
|
||||
// !!(36953089 & (1 << 21)) = voice speak allowed
|
||||
|
||||
return !!(this.permissions & perm);
|
||||
};
|
||||
|
||||
Role.prototype.setPermission = function setPermission(permission, value) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = _Constants.Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
// valid permission
|
||||
if (value) {
|
||||
this.permissions |= permission;
|
||||
} else {
|
||||
this.permissions &= ~permission;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Role.prototype.setPermissions = function setPermissions(obj) {
|
||||
var _this2 = this;
|
||||
|
||||
obj.forEach(function (value, permission) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = _Constants.Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
// valid permission
|
||||
_this2.setPermission(permission, value);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Role.prototype.colorAsHex = function colorAsHex() {
|
||||
var val = this.color.toString(16);
|
||||
while (val.length < 6) {
|
||||
val = "0" + val;
|
||||
}
|
||||
return "#" + val;
|
||||
};
|
||||
|
||||
Role.prototype["delete"] = function _delete() {
|
||||
return this.client.deleteRole.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Role.prototype.edit = function edit() {
|
||||
return this.client.updateRole.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Role.prototype.update = function update() {
|
||||
return this.client.updateRole.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Role.prototype.addMember = function addMember(member, callback) {
|
||||
return this.client.addMemberToRole.apply(this.client, [member, this, callback]);
|
||||
};
|
||||
|
||||
Role.prototype.addUser = function addUser(member, callback) {
|
||||
return this.client.addUserToRole.apply(this.client, [member, this, callback]);
|
||||
};
|
||||
|
||||
Role.prototype.removeMember = function removeMember(member, callback) {
|
||||
return this.client.removeMemberFromRole.apply(this.client, [member, this, callback]);
|
||||
};
|
||||
|
||||
Role.prototype.removeUser = function removeUser(member, callback) {
|
||||
return this.client.removeUserFromRole.apply(this.client, [member, this, callback]);
|
||||
};
|
||||
|
||||
Role.prototype.mention = function mention() {
|
||||
if (this.mentionable) return "<@&" + this.id + ">";
|
||||
return this.name;
|
||||
};
|
||||
|
||||
Role.prototype.toString = function toString() {
|
||||
return this.mention();
|
||||
};
|
||||
|
||||
_createClass(Role, [{
|
||||
key: "createdAt",
|
||||
get: function get() {
|
||||
return new Date(+this.id / 4194304 + 1420070400000);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Role;
|
||||
})();
|
||||
|
||||
exports["default"] = Role;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,493 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Types of region for a server, include: `us-west`, `us-east`, `us-south`, `us-central`, `singapore`, `london`, `sydney`, `amsterdam` and `frankfurt`
|
||||
* @typedef {(string)} region
|
||||
*/
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _UtilBucket = require("../Util/Bucket");
|
||||
|
||||
var _UtilBucket2 = _interopRequireDefault(_UtilBucket);
|
||||
|
||||
var _UtilEquality = require("../Util/Equality");
|
||||
|
||||
var _UtilEquality2 = _interopRequireDefault(_UtilEquality);
|
||||
|
||||
var _Constants = require("../Constants");
|
||||
|
||||
var _UtilCache = require("../Util/Cache");
|
||||
|
||||
var _UtilCache2 = _interopRequireDefault(_UtilCache);
|
||||
|
||||
var _User = require("./User");
|
||||
|
||||
var _User2 = _interopRequireDefault(_User);
|
||||
|
||||
var _TextChannel = require("./TextChannel");
|
||||
|
||||
var _TextChannel2 = _interopRequireDefault(_TextChannel);
|
||||
|
||||
var _VoiceChannel = require("./VoiceChannel");
|
||||
|
||||
var _VoiceChannel2 = _interopRequireDefault(_VoiceChannel);
|
||||
|
||||
var _Role = require("./Role");
|
||||
|
||||
var _Role2 = _interopRequireDefault(_Role);
|
||||
|
||||
var _Emoji = require("./Emoji");
|
||||
|
||||
var _Emoji2 = _interopRequireDefault(_Emoji);
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var strictKeys = ["region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"];
|
||||
|
||||
var Server = (function (_Equality) {
|
||||
_inherits(Server, _Equality);
|
||||
|
||||
function Server(data, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, Server);
|
||||
|
||||
_Equality.call(this);
|
||||
|
||||
this.client = client;
|
||||
this.id = data.id;
|
||||
|
||||
if (data.owner_id) {
|
||||
// new server data
|
||||
client.internal.buckets["bot:msg:guild:" + this.id] = new _UtilBucket2["default"](5, 5000);
|
||||
client.internal.buckets["dmsg:" + this.id] = new _UtilBucket2["default"](5, 1000);
|
||||
client.internal.buckets["bdmsg:" + this.id] = new _UtilBucket2["default"](1, 1000);
|
||||
client.internal.buckets["guild_member:" + this.id] = new _UtilBucket2["default"](10, 10000);
|
||||
client.internal.buckets["guild_member_nick:" + this.id] = new _UtilBucket2["default"](1, 1000);
|
||||
}
|
||||
|
||||
this.region = data.region;
|
||||
this.ownerID = data.owner_id || data.ownerID;
|
||||
this.name = data.name;
|
||||
this.members = new _UtilCache2["default"]();
|
||||
this.channels = new _UtilCache2["default"]();
|
||||
this.roles = new _UtilCache2["default"]();
|
||||
this.emojis = new _UtilCache2["default"]();
|
||||
this.icon = data.icon;
|
||||
this.afkTimeout = data.afk_timeout;
|
||||
this.afkChannelID = data.afk_channel_id || data.afkChannelID;
|
||||
this.memberMap = data.memberMap || {};
|
||||
this.memberCount = data.member_count || data.memberCount;
|
||||
this.large = data.large || this.memberCount > 250;
|
||||
|
||||
if (data.roles instanceof _UtilCache2["default"]) {
|
||||
data.roles.forEach(function (role) {
|
||||
return _this.roles.add(role);
|
||||
});
|
||||
} else {
|
||||
data.roles.forEach(function (dataRole) {
|
||||
_this.roles.add(new _Role2["default"](dataRole, _this, client));
|
||||
});
|
||||
}
|
||||
|
||||
if (data.emojis instanceof _UtilCache2["default"]) {
|
||||
data.emojis.forEach(function (emoji) {
|
||||
return _this.emojis.add(emoji);
|
||||
});
|
||||
} else {
|
||||
data.emojis.forEach(function (dataEmoji) {
|
||||
_this.emojis.add(new _Emoji2["default"](dataEmoji, _this));
|
||||
});
|
||||
}
|
||||
|
||||
if (data.members instanceof _UtilCache2["default"]) {
|
||||
data.members.forEach(function (member) {
|
||||
return _this.members.add(member);
|
||||
});
|
||||
} else {
|
||||
data.members.forEach(function (dataUser) {
|
||||
_this.memberMap[dataUser.user.id] = {
|
||||
roles: dataUser.roles,
|
||||
mute: dataUser.mute,
|
||||
selfMute: dataUser.self_mute,
|
||||
deaf: dataUser.deaf,
|
||||
selfDeaf: dataUser.self_deaf,
|
||||
joinedAt: Date.parse(dataUser.joined_at),
|
||||
nick: dataUser.nick || null
|
||||
};
|
||||
_this.members.add(client.internal.users.add(new _User2["default"](dataUser.user, client)));
|
||||
});
|
||||
}
|
||||
|
||||
if (data.channels instanceof _UtilCache2["default"]) {
|
||||
data.channels.forEach(function (channel) {
|
||||
return _this.channels.add(channel);
|
||||
});
|
||||
} else {
|
||||
data.channels.forEach(function (dataChannel) {
|
||||
if (dataChannel.type === "text") {
|
||||
_this.channels.add(client.internal.channels.add(new _TextChannel2["default"](dataChannel, client, _this)));
|
||||
} else {
|
||||
_this.channels.add(client.internal.channels.add(new _VoiceChannel2["default"](dataChannel, client, _this)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (data.presences) {
|
||||
for (var _iterator = data.presences, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var presence = _ref;
|
||||
|
||||
var user = client.internal.users.get("id", presence.user.id);
|
||||
if (user) {
|
||||
user.status = presence.status;
|
||||
user.game = presence.game;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
for (var _iterator2 = data.voice_states, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var voiceState = _ref2;
|
||||
|
||||
var _user = this.members.get("id", voiceState.user_id);
|
||||
if (_user) {
|
||||
this.memberMap[_user.id] = this.memberMap[_user.id] || {};
|
||||
this.memberMap[_user.id].mute = voiceState.mute || this.memberMap[_user.id].mute;
|
||||
this.memberMap[_user.id].selfMute = voiceState.self_mute === undefined ? this.memberMap[_user.id].selfMute : voiceState.self_mute;
|
||||
this.memberMap[_user.id].deaf = voiceState.deaf || this.memberMap[_user.id].deaf;
|
||||
this.memberMap[_user.id].selfDeaf = voiceState.self_deaf === undefined ? this.memberMap[_user.id].selfDeaf : voiceState.self_deaf;
|
||||
var channel = this.channels.get("id", voiceState.channel_id);
|
||||
if (channel) {
|
||||
this.eventVoiceJoin(_user, channel);
|
||||
} else {
|
||||
this.client.emit("warn", "channel doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Server.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'name', 'region', 'ownerID', 'icon', 'afkTimeout', 'afkChannelID', 'large', 'memberCount'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator3 = keys, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var k = _ref3;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
obj.members = this.members.map(function (member) {
|
||||
return member.toObject();
|
||||
});
|
||||
obj.channels = this.channels.map(function (channel) {
|
||||
return channel.toObject();
|
||||
});
|
||||
obj.roles = this.roles.map(function (role) {
|
||||
return role.toObject();
|
||||
});
|
||||
obj.emojis = this.emojis.map(function (emoji) {
|
||||
return emoji.toObject();
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
Server.prototype.detailsOf = function detailsOf(user) {
|
||||
var _this2 = this;
|
||||
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
var result = this.memberMap[user.id] || {};
|
||||
if (result && result.roles) {
|
||||
result.roles = result.roles.map(function (pid) {
|
||||
return _this2.roles.get("id", pid) || pid;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
Server.prototype.detailsOfUser = function detailsOfUser(user) {
|
||||
return this.detailsOf(user);
|
||||
};
|
||||
|
||||
Server.prototype.detailsOfMember = function detailsOfMember(user) {
|
||||
return this.detailsOf(user);
|
||||
};
|
||||
|
||||
Server.prototype.details = function details(user) {
|
||||
return this.detailsOf(user);
|
||||
};
|
||||
|
||||
Server.prototype.rolesOfUser = function rolesOfUser(user) {
|
||||
return this.detailsOf(user).roles || [];
|
||||
};
|
||||
|
||||
Server.prototype.rolesOfMember = function rolesOfMember(member) {
|
||||
return this.rolesOfUser(member);
|
||||
};
|
||||
|
||||
Server.prototype.rolesOf = function rolesOf(user) {
|
||||
return this.rolesOfUser(user);
|
||||
};
|
||||
|
||||
Server.prototype.toString = function toString() {
|
||||
return this.name;
|
||||
};
|
||||
|
||||
Server.prototype.eventVoiceJoin = function eventVoiceJoin(user, channel) {
|
||||
// removes from other speaking channels first
|
||||
var oldChannel = this.eventVoiceLeave(user);
|
||||
|
||||
channel.members.add(user);
|
||||
user.voiceChannel = channel;
|
||||
|
||||
if (oldChannel.id && channel.id !== oldChannel.id) {
|
||||
this.client.emit("voiceLeave", oldChannel, user);
|
||||
this.client.emit("voiceSwitch", oldChannel, channel, user);
|
||||
}
|
||||
|
||||
this.client.emit("voiceJoin", channel, user);
|
||||
};
|
||||
|
||||
Server.prototype.eventVoiceStateUpdate = function eventVoiceStateUpdate(channel, user, data) {
|
||||
if (!user.voiceChannel || user.voiceChannel.id !== channel.id) {
|
||||
return this.eventVoiceJoin(user, channel);
|
||||
}
|
||||
if (!this.memberMap[user.id]) {
|
||||
this.memberMap[user.id] = {};
|
||||
}
|
||||
var oldState = {
|
||||
mute: this.memberMap[user.id].mute,
|
||||
selfMute: this.memberMap[user.id].self_mute,
|
||||
deaf: this.memberMap[user.id].deaf,
|
||||
selfDeaf: this.memberMap[user.id].self_deaf
|
||||
};
|
||||
this.memberMap[user.id].mute = data.mute;
|
||||
this.memberMap[user.id].selfMute = data.self_mute;
|
||||
this.memberMap[user.id].deaf = data.deaf;
|
||||
this.memberMap[user.id].selfDeaf = data.self_deaf;
|
||||
if (oldState.mute !== undefined && (oldState.mute != data.mute || oldState.self_mute != data.self_mute || oldState.deaf != data.deaf || oldState.self_deaf != data.self_deaf)) {
|
||||
this.client.emit("voiceStateUpdate", channel, user, oldState, this.memberMap[user.id]);
|
||||
} else {
|
||||
this.eventVoiceJoin(user, channel);
|
||||
}
|
||||
};
|
||||
|
||||
Server.prototype.eventVoiceLeave = function eventVoiceLeave(user) {
|
||||
for (var _iterator4 = this.channels.getAll("type", "voice"), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||||
var _ref4;
|
||||
|
||||
if (_isArray4) {
|
||||
if (_i4 >= _iterator4.length) break;
|
||||
_ref4 = _iterator4[_i4++];
|
||||
} else {
|
||||
_i4 = _iterator4.next();
|
||||
if (_i4.done) break;
|
||||
_ref4 = _i4.value;
|
||||
}
|
||||
|
||||
var chan = _ref4;
|
||||
|
||||
if (chan.members.has("id", user.id)) {
|
||||
chan.members.remove(user);
|
||||
user.voiceChannel = null;
|
||||
return chan;
|
||||
}
|
||||
}
|
||||
return { server: this };
|
||||
};
|
||||
|
||||
Server.prototype.equalsStrict = function equalsStrict(obj) {
|
||||
if (obj instanceof Server) {
|
||||
for (var _iterator5 = strictKeys, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
||||
var _ref5;
|
||||
|
||||
if (_isArray5) {
|
||||
if (_i5 >= _iterator5.length) break;
|
||||
_ref5 = _iterator5[_i5++];
|
||||
} else {
|
||||
_i5 = _iterator5.next();
|
||||
if (_i5.done) break;
|
||||
_ref5 = _i5.value;
|
||||
}
|
||||
|
||||
var key = _ref5;
|
||||
|
||||
if (obj[key] !== this[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Server.prototype.leave = function leave() {
|
||||
return this.client.leaveServer.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Server.prototype["delete"] = function _delete() {
|
||||
return this.client.leaveServer.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Server.prototype.createInvite = function createInvite() {
|
||||
return this.client.createInvite.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Server.prototype.createRole = function createRole() {
|
||||
return this.client.createRole.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Server.prototype.banMember = function banMember(user, tlength, callback) {
|
||||
return this.client.banMember.apply(this.client, [user, this, tlength, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.banUser = function banUser(user, tlength, callback) {
|
||||
return this.client.banMember.apply(this.client, [user, this, tlength, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.ban = function ban(user, tlength, callback) {
|
||||
return this.client.banMember.apply(this.client, [user, this, tlength, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.unbanMember = function unbanMember(user, callback) {
|
||||
return this.client.unbanMember.apply(this.client, [user, this, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.unbanUser = function unbanUser(user, callback) {
|
||||
return this.client.unbanMember.apply(this.client, [user, this, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.unban = function unban(user, callback) {
|
||||
return this.client.unbanMember.apply(this.client, [user, this, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.kickMember = function kickMember(user, callback) {
|
||||
return this.client.kickMember.apply(this.client, [user, this, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.kickUser = function kickUser(user, callback) {
|
||||
return this.client.kickMember.apply(this.client, [user, this, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.kick = function kick(user, callback) {
|
||||
return this.client.kickMember.apply(this.client, [user, this, callback]);
|
||||
};
|
||||
|
||||
Server.prototype.getBans = function getBans() {
|
||||
return this.client.getBans.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Server.prototype.createChannel = function createChannel() {
|
||||
return this.client.createChannel.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Server.prototype.setNickname = function setNickname() {
|
||||
return this.client.setNickname.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
Server.prototype.membersWithRole = function membersWithRole(role) {
|
||||
return this.members.filter(function (m) {
|
||||
return m.hasRole(role);
|
||||
});
|
||||
};
|
||||
|
||||
Server.prototype.usersWithRole = function usersWithRole(role) {
|
||||
return this.membersWithRole(role);
|
||||
};
|
||||
|
||||
_createClass(Server, [{
|
||||
key: "createdAt",
|
||||
get: function get() {
|
||||
return new Date(+this.id / 4194304 + 1420070400000);
|
||||
}
|
||||
}, {
|
||||
key: "iconURL",
|
||||
get: function get() {
|
||||
if (!this.icon) {
|
||||
return null;
|
||||
} else {
|
||||
return _Constants.Endpoints.SERVER_ICON(this.id, this.icon);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "afkChannel",
|
||||
get: function get() {
|
||||
return this.channels.get("id", this.afkChannelID);
|
||||
}
|
||||
}, {
|
||||
key: "defaultChannel",
|
||||
get: function get() {
|
||||
return this.channels.get("id", this.id);
|
||||
}
|
||||
}, {
|
||||
key: "generalChannel",
|
||||
get: function get() {
|
||||
return this.defaultChannel;
|
||||
}
|
||||
}, {
|
||||
key: "general",
|
||||
get: function get() {
|
||||
return this.defaultChannel;
|
||||
}
|
||||
}, {
|
||||
key: "owner",
|
||||
get: function get() {
|
||||
return this.members.get("id", this.ownerID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Server;
|
||||
})(_UtilEquality2["default"]);
|
||||
|
||||
exports["default"] = Server;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,190 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _Channel2 = require("./Channel");
|
||||
|
||||
var _Channel3 = _interopRequireDefault(_Channel2);
|
||||
|
||||
var _UtilCache = require("../Util/Cache");
|
||||
|
||||
var _UtilCache2 = _interopRequireDefault(_UtilCache);
|
||||
|
||||
var _PermissionOverwrite = require("./PermissionOverwrite");
|
||||
|
||||
var _PermissionOverwrite2 = _interopRequireDefault(_PermissionOverwrite);
|
||||
|
||||
var _ChannelPermissions = require("./ChannelPermissions");
|
||||
|
||||
var _ChannelPermissions2 = _interopRequireDefault(_ChannelPermissions);
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var ServerChannel = (function (_Channel) {
|
||||
_inherits(ServerChannel, _Channel);
|
||||
|
||||
function ServerChannel(data, client, server) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, ServerChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
this.name = data.name;
|
||||
this.type = data.type;
|
||||
this.position = data.position;
|
||||
this.permissionOverwrites = data.permissionOverwrites || new _UtilCache2["default"]();
|
||||
this.server = server;
|
||||
if (!data.permissionOverwrites) {
|
||||
data.permission_overwrites.forEach(function (permission) {
|
||||
_this.permissionOverwrites.add(new _PermissionOverwrite2["default"](permission));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ServerChannel.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'name', 'type', 'position'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
obj.permissionOverwrites = this.permissionOverwrites.map(function (p) {
|
||||
return p.toObject();
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
ServerChannel.prototype.permissionsOf = function permissionsOf(userOrRole) {
|
||||
userOrRole = this.client.internal.resolver.resolveUser(userOrRole);
|
||||
if (userOrRole) {
|
||||
if (this.server.ownerID === userOrRole.id) {
|
||||
return new _ChannelPermissions2["default"](4294967295);
|
||||
}
|
||||
var everyoneRole = this.server.roles.get("id", this.server.id);
|
||||
|
||||
var userRoles = [everyoneRole].concat(this.server.rolesOf(userOrRole) || []);
|
||||
var userRolesID = userRoles.filter(function (v) {
|
||||
return !!v;
|
||||
}).map(function (v) {
|
||||
return v.id;
|
||||
});
|
||||
var roleOverwrites = [],
|
||||
memberOverwrites = [];
|
||||
|
||||
this.permissionOverwrites.forEach(function (overwrite) {
|
||||
if (overwrite.type === "member" && overwrite.id === userOrRole.id) {
|
||||
memberOverwrites.push(overwrite);
|
||||
} else if (overwrite.type === "role" && ~userRolesID.indexOf(overwrite.id)) {
|
||||
roleOverwrites.push(overwrite);
|
||||
}
|
||||
});
|
||||
|
||||
var permissions = 0;
|
||||
|
||||
for (var _iterator2 = userRoles, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var serverRole = _ref2;
|
||||
|
||||
if (serverRole) {
|
||||
permissions |= serverRole.permissions;
|
||||
}
|
||||
}
|
||||
|
||||
for (var _iterator3 = roleOverwrites.concat(memberOverwrites), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var overwrite = _ref3;
|
||||
|
||||
if (overwrite) {
|
||||
permissions = permissions & ~overwrite.deny;
|
||||
permissions = permissions | overwrite.allow;
|
||||
}
|
||||
}
|
||||
|
||||
return new _ChannelPermissions2["default"](permissions);
|
||||
} else {
|
||||
userOrRole = this.client.internal.resolver.resolveRole(userOrRole);
|
||||
if (userOrRole) {
|
||||
var permissions = this.server.roles.get("id", this.server.id).permissions | userOrRole.permissions;
|
||||
var overwrite = this.permissionOverwrites.get("id", this.server.id);
|
||||
permissions = permissions & ~overwrite.deny | overwrite.allow;
|
||||
overwrite = this.permissionOverwrites.get("id", userOrRole.id);
|
||||
if (overwrite) {
|
||||
permissions = permissions & ~overwrite.deny | overwrite.allow;
|
||||
}
|
||||
return new _ChannelPermissions2["default"](permissions);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ServerChannel.prototype.permsOf = function permsOf(user) {
|
||||
return this.permissionsOf(user);
|
||||
};
|
||||
|
||||
ServerChannel.prototype.mention = function mention() {
|
||||
return "<#" + this.id + ">";
|
||||
};
|
||||
|
||||
ServerChannel.prototype.toString = function toString() {
|
||||
return this.mention();
|
||||
};
|
||||
|
||||
ServerChannel.prototype.setName = function setName() {
|
||||
return this.client.setChannelName.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
ServerChannel.prototype.setPosition = function setPosition() {
|
||||
return this.client.setChannelPosition.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
ServerChannel.prototype.update = function update() {
|
||||
return this.client.updateChannel.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
return ServerChannel;
|
||||
})(_Channel3["default"]);
|
||||
|
||||
exports["default"] = ServerChannel;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,98 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _ServerChannel2 = require("./ServerChannel");
|
||||
|
||||
var _ServerChannel3 = _interopRequireDefault(_ServerChannel2);
|
||||
|
||||
var _UtilCache = require("../Util/Cache");
|
||||
|
||||
var _UtilCache2 = _interopRequireDefault(_UtilCache);
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var TextChannel = (function (_ServerChannel) {
|
||||
_inherits(TextChannel, _ServerChannel);
|
||||
|
||||
function TextChannel(data, client, server) {
|
||||
_classCallCheck(this, TextChannel);
|
||||
|
||||
_ServerChannel.call(this, data, client, server);
|
||||
|
||||
this.topic = data.topic;
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.messages = new _UtilCache2["default"]("id", client.options.maxCachedMessages);
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
|
||||
TextChannel.prototype.toObject = function toObject() {
|
||||
var obj = _ServerChannel.prototype.toObject.call(this);
|
||||
|
||||
obj.topic = this.topic;
|
||||
obj.lastMessageID = this.lastMessageID;
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
TextChannel.prototype.setTopic = function setTopic() {
|
||||
return this.client.setChannelTopic.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.sendMessage = function sendMessage() {
|
||||
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.send = function send() {
|
||||
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.sendTTSMessage = function sendTTSMessage() {
|
||||
return this.client.sendTTSMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.sendTTS = function sendTTS() {
|
||||
return this.client.sendTTSMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.sendFile = function sendFile() {
|
||||
return this.client.sendFile.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.getLogs = function getLogs() {
|
||||
return this.client.getChannelLogs.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.getMessage = function getMessage() {
|
||||
return this.client.getMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.startTyping = function startTyping() {
|
||||
return this.client.startTyping.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
TextChannel.prototype.stopTyping = function stopTyping() {
|
||||
return this.client.stopTyping.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
_createClass(TextChannel, [{
|
||||
key: "lastMessage",
|
||||
get: function get() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return TextChannel;
|
||||
})(_ServerChannel3["default"]);
|
||||
|
||||
exports["default"] = TextChannel;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,165 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _UtilEquality = require("../Util/Equality");
|
||||
|
||||
var _UtilEquality2 = _interopRequireDefault(_UtilEquality);
|
||||
|
||||
var _Constants = require("../Constants");
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var User = (function (_Equality) {
|
||||
_inherits(User, _Equality);
|
||||
|
||||
function User(data, client) {
|
||||
_classCallCheck(this, User);
|
||||
|
||||
_Equality.call(this);
|
||||
this.client = client;
|
||||
this.username = data.username;
|
||||
this.discriminator = data.discriminator;
|
||||
this.id = data.id;
|
||||
this.avatar = data.avatar;
|
||||
this.bot = !!data.bot;
|
||||
this.status = data.status || "offline";
|
||||
this.game = data.game || null;
|
||||
this.typing = {
|
||||
since: null,
|
||||
channel: null
|
||||
};
|
||||
this.note = data.note || null;
|
||||
this.voiceChannel = null;
|
||||
this.voiceState = {};
|
||||
this.speaking = false;
|
||||
}
|
||||
|
||||
User.prototype.mention = function mention() {
|
||||
return "<@" + this.id + ">";
|
||||
};
|
||||
|
||||
User.prototype.toString = function toString() {
|
||||
return this.mention();
|
||||
};
|
||||
|
||||
User.prototype.toObject = function toObject() {
|
||||
var keys = ['id', 'username', 'discriminator', 'avatar', 'bot', 'status', 'game', 'note', 'voiceState', 'speaking'],
|
||||
obj = {};
|
||||
|
||||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var k = _ref;
|
||||
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
obj.typing = {
|
||||
since: this.typing.since,
|
||||
channelID: this.typing.channel ? this.typing.channel.id : null
|
||||
};
|
||||
obj.voiceChannelID = this.voiceChannel ? this.voiceChannel.id : null;
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
User.prototype.equalsStrict = function equalsStrict(obj) {
|
||||
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && (this.game === obj.game || this.game && obj.game && this.game.name === obj.game.name);else return false;
|
||||
};
|
||||
|
||||
User.prototype.equals = function equals(obj) {
|
||||
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar;else return false;
|
||||
};
|
||||
|
||||
User.prototype.sendMessage = function sendMessage() {
|
||||
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.send = function send() {
|
||||
return this.client.sendMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.sendTTSMessage = function sendTTSMessage() {
|
||||
return this.client.sendTTSMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.sendTTS = function sendTTS() {
|
||||
return this.client.sendTTSMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.sendFile = function sendFile() {
|
||||
return this.client.sendFile.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.startTyping = function startTyping() {
|
||||
return this.client.startTyping.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.stopTyping = function stopTyping() {
|
||||
return this.client.stopTyping.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.addTo = function addTo(role, callback) {
|
||||
return this.client.addMemberToRole.apply(this.client, [this, role, callback]);
|
||||
};
|
||||
|
||||
User.prototype.removeFrom = function removeFrom(role, callback) {
|
||||
return this.client.removeMemberFromRole.apply(this.client, [this, role, callback]);
|
||||
};
|
||||
|
||||
User.prototype.getLogs = function getLogs() {
|
||||
return this.client.getChannelLogs.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.getMessage = function getMessage() {
|
||||
return this.client.getMessage.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
User.prototype.hasRole = function hasRole(role) {
|
||||
return this.client.memberHasRole.apply(this.client, [this, role]);
|
||||
};
|
||||
|
||||
_createClass(User, [{
|
||||
key: "createdAt",
|
||||
get: function get() {
|
||||
return new Date(+this.id / 4194304 + 1420070400000);
|
||||
}
|
||||
}, {
|
||||
key: "avatarURL",
|
||||
get: function get() {
|
||||
if (!this.avatar) {
|
||||
return null;
|
||||
} else {
|
||||
return _Constants.Endpoints.AVATAR(this.id, this.avatar);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "name",
|
||||
get: function get() {
|
||||
return this.username;
|
||||
}
|
||||
}]);
|
||||
|
||||
return User;
|
||||
})(_UtilEquality2["default"]);
|
||||
|
||||
exports["default"] = User;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,64 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _ServerChannel2 = require("./ServerChannel");
|
||||
|
||||
var _ServerChannel3 = _interopRequireDefault(_ServerChannel2);
|
||||
|
||||
var _UtilCache = require("../Util/Cache");
|
||||
|
||||
var _UtilCache2 = _interopRequireDefault(_UtilCache);
|
||||
|
||||
var _UtilArgumentRegulariser = require("../Util/ArgumentRegulariser");
|
||||
|
||||
var VoiceChannel = (function (_ServerChannel) {
|
||||
_inherits(VoiceChannel, _ServerChannel);
|
||||
|
||||
function VoiceChannel(data, client, server) {
|
||||
_classCallCheck(this, VoiceChannel);
|
||||
|
||||
_ServerChannel.call(this, data, client, server);
|
||||
this.members = data.members || new _UtilCache2["default"]();
|
||||
this.userLimit = data.user_limit || 0;
|
||||
this._bitrate = data.bitrate || 64000; // incase somebody wants to access the bps value???
|
||||
this.bitrate = Math.round(this._bitrate / 1000); // store as kbps
|
||||
}
|
||||
|
||||
VoiceChannel.prototype.toObject = function toObject() {
|
||||
var obj = _ServerChannel.prototype.toObject.call(this);
|
||||
|
||||
obj.userLimit = this.userLimit;
|
||||
obj.bitrate = this.bitrate;
|
||||
obj.members = this.members.map(function (member) {
|
||||
return member.toObject();
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
VoiceChannel.prototype.join = function join() {
|
||||
var callback = arguments.length <= 0 || arguments[0] === undefined ? function () {} : arguments[0];
|
||||
|
||||
return this.client.joinVoiceChannel.apply(this.client, [this, callback]);
|
||||
};
|
||||
|
||||
VoiceChannel.prototype.setUserLimit = function setUserLimit() {
|
||||
return this.client.setChannelUserLimit.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
VoiceChannel.prototype.setBitrate = function setBitrate() {
|
||||
return this.client.setChannelBitrate.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
return VoiceChannel;
|
||||
})(_ServerChannel3["default"]);
|
||||
|
||||
exports["default"] = VoiceChannel;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.reg = reg;
|
||||
|
||||
function reg(c, a) {
|
||||
return [c].concat(Array.prototype.slice.call(a));
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var Bucket = (function () {
|
||||
// Adapted from Eris
|
||||
|
||||
function Bucket(tokenLimit, interval) {
|
||||
_classCallCheck(this, Bucket);
|
||||
|
||||
this.tokenLimit = tokenLimit;
|
||||
this.interval = interval;
|
||||
this.extraTime = 500;
|
||||
this.lastReset = this.tokens = this.lastSend = 0;
|
||||
this._queue = [];
|
||||
}
|
||||
|
||||
Bucket.prototype.queue = function queue(func) {
|
||||
this._queue.push(func);
|
||||
this.check();
|
||||
};
|
||||
|
||||
Bucket.prototype.check = function check() {
|
||||
var _this = this;
|
||||
|
||||
if (this.timeout || this._queue.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (this.lastReset + this.interval + this.extraTime < Date.now()) {
|
||||
this.lastReset = Date.now();
|
||||
this.tokens = Math.max(0, this.tokens - this.tokenLimit);
|
||||
}
|
||||
|
||||
var val;
|
||||
while (this._queue.length > 0 && this.tokens < this.tokenLimit) {
|
||||
this.tokens++;
|
||||
this._queue.shift()();
|
||||
this.lastSend = Date.now();
|
||||
}
|
||||
|
||||
if (this._queue.length > 0 && !this.timeout) {
|
||||
this.timeout = setTimeout(function () {
|
||||
_this.timeout = null;
|
||||
_this.check();
|
||||
}, this.tokens < this.tokenLimit ? 1 : Math.max(0, this.lastReset + this.interval + this.extraTime - Date.now()));
|
||||
}
|
||||
};
|
||||
|
||||
return Bucket;
|
||||
})();
|
||||
|
||||
exports["default"] = Bucket;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,153 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var discrimS = Symbol();
|
||||
var discrimCacheS = Symbol();
|
||||
|
||||
var Cache = (function (_Array) {
|
||||
_inherits(Cache, _Array);
|
||||
|
||||
function Cache(discrim, limit) {
|
||||
_classCallCheck(this, Cache);
|
||||
|
||||
_Array.call(this);
|
||||
this[discrimS] = discrim || "id";
|
||||
this[discrimCacheS] = {};
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
Cache.prototype.get = function get(key, value) {
|
||||
if (typeof key === 'function') {
|
||||
var valid = key;
|
||||
key = null;
|
||||
} else if (key && !value) {
|
||||
return this[discrimCacheS][key] || null;
|
||||
} else if (key === this[discrimS] && typeof value === "string") {
|
||||
return this[discrimCacheS][value] || null;
|
||||
} else if (value && value.constructor.name === 'RegExp') {
|
||||
var valid = function valid(item) {
|
||||
return value.test(item);
|
||||
};
|
||||
} else if (typeof value !== 'function') {
|
||||
var valid = function valid(item) {
|
||||
return item == value;
|
||||
};
|
||||
}
|
||||
|
||||
for (var _iterator = this, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var item = _ref;
|
||||
|
||||
if (valid(key == null ? item : item[key])) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Cache.prototype.has = function has(key, value) {
|
||||
return !!this.get(key, value);
|
||||
};
|
||||
|
||||
Cache.prototype.getAll = function getAll(key, value) {
|
||||
var found = new Cache(this[discrimS]);
|
||||
|
||||
if (typeof key === 'function') {
|
||||
var valid = key;
|
||||
key = null;
|
||||
} else if (value && value.constructor.name === 'RegExp') {
|
||||
var valid = function valid(item) {
|
||||
return value.test(item);
|
||||
};
|
||||
} else if (typeof value !== 'function') {
|
||||
var valid = function valid(item) {
|
||||
return item == value;
|
||||
};
|
||||
}
|
||||
|
||||
for (var _iterator2 = this, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var item = _ref2;
|
||||
|
||||
if (valid(key == null ? item : item[key])) {
|
||||
found.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
};
|
||||
|
||||
Cache.prototype.add = function add(data) {
|
||||
var cacheKey = data[this[discrimS]];
|
||||
if (this[discrimCacheS][cacheKey]) {
|
||||
return this[discrimCacheS][cacheKey];
|
||||
}
|
||||
if (this.limit && this.length >= this.limit) {
|
||||
this.splice(0, 1);
|
||||
}
|
||||
this.push(data);
|
||||
this[discrimCacheS][cacheKey] = data;
|
||||
return data;
|
||||
};
|
||||
|
||||
Cache.prototype.update = function update(old, data) {
|
||||
var obj = this[discrimCacheS][old[this[discrimS]]];
|
||||
if (obj) {
|
||||
for (var key in data) {
|
||||
if (data.hasOwnProperty(key)) {
|
||||
obj[key] = data[key];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Cache.prototype.random = function random() {
|
||||
return this[Math.floor(Math.random() * this.length)];
|
||||
};
|
||||
|
||||
Cache.prototype.remove = function remove(data) {
|
||||
if (!this[discrimCacheS][data[this[discrimS]]]) return false;
|
||||
|
||||
delete this[discrimCacheS][data[this[discrimS]]];
|
||||
for (var i in this) {
|
||||
if (this[i] && this[i][this[discrimS]] === data[this[discrimS]]) {
|
||||
this.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return Cache;
|
||||
})(Array);
|
||||
|
||||
exports["default"] = Cache;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
The Equality Class is just used to show
|
||||
that a Class has an ID that can be used to
|
||||
check for equality.
|
||||
|
||||
Never use == or === when comparing
|
||||
objects in discord.js, they will be different
|
||||
instances sometimes.
|
||||
|
||||
Instead, use objectThatExtendsEquality.equals()
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var Equality = (function () {
|
||||
function Equality() {
|
||||
_classCallCheck(this, Equality);
|
||||
}
|
||||
|
||||
Equality.prototype.equals = function equals(object) {
|
||||
return object && object[this.eqDiscriminator] === this[this.eqDiscriminator];
|
||||
};
|
||||
|
||||
Equality.prototype.equalsStrict = function equalsStrict(object) {
|
||||
// override per class type
|
||||
return;
|
||||
};
|
||||
|
||||
_createClass(Equality, [{
|
||||
key: "eqDiscriminator",
|
||||
get: function get() {
|
||||
return "id";
|
||||
}
|
||||
}]);
|
||||
|
||||
return Equality;
|
||||
})();
|
||||
|
||||
exports["default"] = Equality;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,29 +0,0 @@
|
||||
// Shim for the token cacher in the browser.
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var TokenCacher = (function () {
|
||||
function TokenCacher() {
|
||||
_classCallCheck(this, TokenCacher);
|
||||
}
|
||||
|
||||
TokenCacher.prototype.setToken = function setToken() {};
|
||||
|
||||
TokenCacher.prototype.save = function save() {};
|
||||
|
||||
TokenCacher.prototype.getToken = function getToken() {
|
||||
return null;
|
||||
};
|
||||
|
||||
TokenCacher.prototype.init = function init(ind) {
|
||||
this.done = true;
|
||||
};
|
||||
|
||||
return TokenCacher;
|
||||
})();
|
||||
|
||||
exports["default"] = TokenCacher;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,157 +0,0 @@
|
||||
"use strict";
|
||||
/* global process */
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _fs = require("fs");
|
||||
|
||||
var _fs2 = _interopRequireDefault(_fs);
|
||||
|
||||
var _events = require("events");
|
||||
|
||||
var _events2 = _interopRequireDefault(_events);
|
||||
|
||||
var _crypto = require("crypto");
|
||||
|
||||
var _crypto2 = _interopRequireDefault(_crypto);
|
||||
|
||||
var savePaths = [process.env.APPDATA || (process.platform == "darwin" ? process.env.HOME + "Library/Preferences" : "/var/local"), process.env[process.platform == "win32" ? "USERPROFILE" : "HOME"], process.cwd(), "/tmp"];
|
||||
|
||||
var algo = "aes-256-ctr";
|
||||
|
||||
function secureEmail(email, password) {
|
||||
return new Buffer(_crypto2["default"].createHash("sha256").update(email + password, "utf8").digest()).toString("hex");
|
||||
}
|
||||
|
||||
function exists(path) {
|
||||
// Node deprecated the `fs.exists` method apparently...
|
||||
try {
|
||||
_fs2["default"].accessSync(path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var TokenCacher = (function (_EventEmitter) {
|
||||
_inherits(TokenCacher, _EventEmitter);
|
||||
|
||||
function TokenCacher(client, options) {
|
||||
_classCallCheck(this, TokenCacher);
|
||||
|
||||
_EventEmitter.call(this);
|
||||
this.client = client;
|
||||
this.savePath = null;
|
||||
this.error = false;
|
||||
this.done = false;
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
TokenCacher.prototype.setToken = function setToken() {
|
||||
var email = arguments.length <= 0 || arguments[0] === undefined ? "" : arguments[0];
|
||||
var password = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
||||
var token = arguments.length <= 2 || arguments[2] === undefined ? "" : arguments[2];
|
||||
|
||||
email = secureEmail(email, password);
|
||||
var cipher = _crypto2["default"].createCipher(algo, password);
|
||||
var crypted = cipher.update("valid" + token, "utf8", "hex");
|
||||
crypted += cipher.final("hex");
|
||||
this.data[email] = crypted;
|
||||
this.save();
|
||||
};
|
||||
|
||||
TokenCacher.prototype.save = function save() {
|
||||
_fs2["default"].writeFile(this.savePath, JSON.stringify(this.data));
|
||||
};
|
||||
|
||||
TokenCacher.prototype.getToken = function getToken() {
|
||||
var email = arguments.length <= 0 || arguments[0] === undefined ? "" : arguments[0];
|
||||
var password = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
||||
|
||||
email = secureEmail(email, password);
|
||||
|
||||
if (this.data[email]) {
|
||||
|
||||
try {
|
||||
var decipher = _crypto2["default"].createDecipher(algo, password);
|
||||
var dec = decipher.update(this.data[email], "hex", "utf8");
|
||||
dec += decipher.final("utf8");
|
||||
return dec.indexOf("valid") === 0 ? dec.substr(5) : false;
|
||||
} catch (e) {
|
||||
// not a valid token
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
TokenCacher.prototype.init = function init(ind) {
|
||||
var _this = this;
|
||||
|
||||
var self = this;
|
||||
var savePath = savePaths[ind];
|
||||
|
||||
// Use one async function at the beginning, so the entire function is async,
|
||||
// then later use only sync functions to increase readability
|
||||
_fs2["default"].stat(savePath, function (err, dirStats) {
|
||||
// Directory does not exist.
|
||||
if (err) error(err);else {
|
||||
try {
|
||||
var storeDirPath = savePath + "/.discordjs";
|
||||
var filePath = storeDirPath + "/tokens.json";
|
||||
|
||||
if (!exists(storeDirPath)) {
|
||||
// First, make sure the directory exists, otherwise the next
|
||||
// call will fail.
|
||||
_fs2["default"].mkdirSync(storeDirPath);
|
||||
}
|
||||
if (!exists(filePath)) {
|
||||
// This will create an empty file if the file doesn't exist, and error
|
||||
// if it does exist. We previously checked that it doesn't exist so we
|
||||
// can do this safely.
|
||||
_fs2["default"].closeSync(_fs2["default"].openSync(filePath, 'wx'));
|
||||
}
|
||||
|
||||
var data = _fs2["default"].readFileSync(filePath);
|
||||
try {
|
||||
_this.data = JSON.parse(data);
|
||||
_this.savePath = filePath;
|
||||
_this.emit('ready');
|
||||
_this.done = true;
|
||||
} catch (e) {
|
||||
// not valid JSON, make it valid and then write
|
||||
_fs2["default"].writeFileSync(filePath, '{}');
|
||||
_this.savePath = filePath;
|
||||
_this.emit("ready");
|
||||
_this.done = true;
|
||||
}
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function error(e) {
|
||||
ind++;
|
||||
if (!savePaths[ind]) {
|
||||
self.emit("error");
|
||||
self.error = e;
|
||||
self.done = true;
|
||||
} else {
|
||||
self.init(ind);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return TokenCacher;
|
||||
})(_events2["default"]);
|
||||
|
||||
exports["default"] = TokenCacher;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,219 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var _child_process = require("child_process");
|
||||
|
||||
var _child_process2 = _interopRequireDefault(_child_process);
|
||||
|
||||
// no opus!
|
||||
|
||||
var _VolumeTransformer = require("./VolumeTransformer");
|
||||
|
||||
var _VolumeTransformer2 = _interopRequireDefault(_VolumeTransformer);
|
||||
|
||||
var opus;
|
||||
try {
|
||||
opus = require("node-opus");
|
||||
} catch (e) {}
|
||||
|
||||
var AudioEncoder = (function () {
|
||||
function AudioEncoder() {
|
||||
_classCallCheck(this, AudioEncoder);
|
||||
|
||||
if (opus) {
|
||||
this.opus = new opus.OpusEncoder(48000, 2);
|
||||
}
|
||||
this.choice = false;
|
||||
this.sanityCheckPassed = undefined;
|
||||
}
|
||||
|
||||
AudioEncoder.prototype.sanityCheck = function sanityCheck() {
|
||||
var _opus = this.opus;
|
||||
var encodeZeroes = function encodeZeroes() {
|
||||
try {
|
||||
var zeroes = new Buffer(1920);
|
||||
zeroes.fill(0);
|
||||
return _opus.encode(zeroes, 1920).readUIntBE(0, 3);
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (this.sanityCheckPassed === undefined) this.sanityCheckPassed = encodeZeroes() === 16056318;
|
||||
return this.sanityCheckPassed;
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.opusBuffer = function opusBuffer(buffer) {
|
||||
|
||||
return this.opus.encode(buffer, 1920);
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.getCommand = function getCommand(force) {
|
||||
if (this.choice && force) return choice;
|
||||
|
||||
var choices = ["avconv", "ffmpeg"];
|
||||
|
||||
for (var _iterator = choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var choice = _ref;
|
||||
|
||||
var p = _child_process2["default"].spawnSync(choice);
|
||||
if (!p.error) {
|
||||
this.choice = choice;
|
||||
return choice;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.encodeStream = function encodeStream(stream, options) {
|
||||
var _this = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this.volume = new _VolumeTransformer2["default"](options.volume);
|
||||
|
||||
var command = _this.getCommand();
|
||||
|
||||
// check if avconv or ffmpeg were found.
|
||||
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
||||
|
||||
var enc = _child_process2["default"].spawn(command, ['-i', '-', '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']);
|
||||
|
||||
var dest = stream.pipe(enc.stdin);
|
||||
|
||||
dest.on('unpipe', function () {
|
||||
return dest.destroy();
|
||||
});
|
||||
dest.on('error', function (err) {
|
||||
return dest.destroy();
|
||||
});
|
||||
|
||||
_this.hookEncodingProcess(resolve, reject, enc, stream);
|
||||
});
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.encodeFile = function encodeFile(file, options) {
|
||||
var _this2 = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this2.volume = new _VolumeTransformer2["default"](options.volume);
|
||||
|
||||
var command = _this2.getCommand();
|
||||
|
||||
// check if avconv or ffmpeg were found.
|
||||
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
||||
|
||||
var enc = _child_process2["default"].spawn(command, ['-i', file, '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']);
|
||||
|
||||
_this2.hookEncodingProcess(resolve, reject, enc);
|
||||
});
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.encodeArbitraryFFmpeg = function encodeArbitraryFFmpeg(ffmpegOptions, volume) {
|
||||
var _this3 = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this3.volume = new _VolumeTransformer2["default"](volume);
|
||||
|
||||
var command = _this3.getCommand();
|
||||
|
||||
// check if avconv or ffmpeg were found.
|
||||
if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.'));
|
||||
|
||||
// add options discord.js needs
|
||||
var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
|
||||
var enc = _child_process2["default"].spawn(command, options);
|
||||
|
||||
_this3.hookEncodingProcess(resolve, reject, enc);
|
||||
});
|
||||
};
|
||||
|
||||
AudioEncoder.prototype.hookEncodingProcess = function hookEncodingProcess(resolve, reject, enc, stream) {
|
||||
var _this4 = this;
|
||||
|
||||
var processKilled = false;
|
||||
|
||||
function killProcess(cause) {
|
||||
if (processKilled) return;
|
||||
|
||||
enc.stdin.pause();
|
||||
enc.kill("SIGKILL");
|
||||
|
||||
processKilled = true;
|
||||
|
||||
reject(cause);
|
||||
}
|
||||
|
||||
var ffmpegErrors = "";
|
||||
|
||||
enc.stdout.pipe(this.volume);
|
||||
|
||||
enc.stderr.on("data", function (data) {
|
||||
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
||||
});
|
||||
|
||||
enc.stdout.once("end", function () {
|
||||
killProcess("end");
|
||||
});
|
||||
|
||||
enc.stdout.once("error", function () {
|
||||
enc.stdout.emit("end");
|
||||
});
|
||||
|
||||
enc.once("exit", function (code, signal) {
|
||||
if (code) {
|
||||
reject(new Error("FFMPEG: " + ffmpegErrors));
|
||||
}
|
||||
});
|
||||
|
||||
this.volume.once("readable", function () {
|
||||
var data = {
|
||||
proc: enc,
|
||||
stream: _this4.volume,
|
||||
channels: 2
|
||||
};
|
||||
|
||||
if (stream) {
|
||||
data.instream = stream;
|
||||
}
|
||||
|
||||
resolve(data);
|
||||
});
|
||||
|
||||
this.volume.once("end", function () {
|
||||
killProcess("end");
|
||||
});
|
||||
|
||||
this.volume.once("error", function () {
|
||||
killProcess("end");
|
||||
});
|
||||
|
||||
this.volume.on("end", function () {
|
||||
killProcess("end");
|
||||
});
|
||||
|
||||
this.volume.on("close", function () {
|
||||
killProcess("close");
|
||||
});
|
||||
};
|
||||
|
||||
return AudioEncoder;
|
||||
})();
|
||||
|
||||
exports["default"] = AudioEncoder;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
// represents an intent of streaming music
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _events = require("events");
|
||||
|
||||
var _events2 = _interopRequireDefault(_events);
|
||||
|
||||
var StreamIntent = (function (_EventEmitter) {
|
||||
_inherits(StreamIntent, _EventEmitter);
|
||||
|
||||
function StreamIntent() {
|
||||
_classCallCheck(this, StreamIntent);
|
||||
|
||||
_EventEmitter.call(this);
|
||||
}
|
||||
|
||||
return StreamIntent;
|
||||
})(_events2["default"]);
|
||||
|
||||
exports["default"] = StreamIntent;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,522 +0,0 @@
|
||||
"use strict";
|
||||
/*
|
||||
Major credit to izy521 who is the creator of
|
||||
https://github.com/izy521/discord.io,
|
||||
|
||||
without his help voice chat in discord.js would not have
|
||||
been possible!
|
||||
*/
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var _ws = require("ws");
|
||||
|
||||
var _ws2 = _interopRequireDefault(_ws);
|
||||
|
||||
var _dns = require("dns");
|
||||
|
||||
var _dns2 = _interopRequireDefault(_dns);
|
||||
|
||||
var _dgram = require("dgram");
|
||||
|
||||
var _dgram2 = _interopRequireDefault(_dgram);
|
||||
|
||||
var _AudioEncoder = require("./AudioEncoder");
|
||||
|
||||
var _AudioEncoder2 = _interopRequireDefault(_AudioEncoder);
|
||||
|
||||
var _VoicePacket = require("./VoicePacket");
|
||||
|
||||
var _VoicePacket2 = _interopRequireDefault(_VoicePacket);
|
||||
|
||||
var _VolumeTransformer = require("./VolumeTransformer");
|
||||
|
||||
var _VolumeTransformer2 = _interopRequireDefault(_VolumeTransformer);
|
||||
|
||||
var _StreamIntent = require("./StreamIntent");
|
||||
|
||||
var _StreamIntent2 = _interopRequireDefault(_StreamIntent);
|
||||
|
||||
var _events = require("events");
|
||||
|
||||
var _events2 = _interopRequireDefault(_events);
|
||||
|
||||
var _unpipe = require("unpipe");
|
||||
|
||||
var _unpipe2 = _interopRequireDefault(_unpipe);
|
||||
|
||||
var MODE_xsalsa20_poly1305 = "xsalsa20_poly1305";
|
||||
var MODE_plain = "plain";
|
||||
|
||||
var VoiceConnection = (function (_EventEmitter) {
|
||||
_inherits(VoiceConnection, _EventEmitter);
|
||||
|
||||
function VoiceConnection(channel, client, session, token, server, endpoint) {
|
||||
_classCallCheck(this, VoiceConnection);
|
||||
|
||||
_EventEmitter.call(this);
|
||||
this.id = channel.id;
|
||||
this.voiceChannel = channel;
|
||||
this.client = client;
|
||||
this.session = session;
|
||||
this.token = token;
|
||||
this.server = server;
|
||||
this.endpoint = endpoint.split(":")[0];
|
||||
this.vWS = null; // vWS means voice websocket
|
||||
this.ready = false;
|
||||
this.vWSData = {};
|
||||
this.encoder = new _AudioEncoder2["default"]();
|
||||
this.udp = null;
|
||||
this.playingIntent = null;
|
||||
this.playing = false;
|
||||
this.streamTime = 0;
|
||||
this.streamProc = null;
|
||||
this.KAI = null;
|
||||
this.timestamp = 0;
|
||||
this.sequence = 0;
|
||||
|
||||
this.mode = null;
|
||||
this.secret = null;
|
||||
|
||||
this.volume = new _VolumeTransformer2["default"]();
|
||||
this.paused = false;
|
||||
this.init();
|
||||
}
|
||||
|
||||
VoiceConnection.prototype.destroy = function destroy() {
|
||||
this.stopPlaying();
|
||||
if (this.KAI) {
|
||||
clearInterval(this.KAI);
|
||||
}
|
||||
this.client.internal.sendWS({
|
||||
op: 4,
|
||||
d: {
|
||||
guild_id: this.server.id,
|
||||
channel_id: null,
|
||||
self_mute: true,
|
||||
self_deaf: false
|
||||
}
|
||||
});
|
||||
this.client.internal.voiceConnections.remove(this);
|
||||
try {
|
||||
this.vWS.close();
|
||||
} catch (e) {}
|
||||
try {
|
||||
this.udp.close();
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
|
||||
this.playing = false;
|
||||
this.playingIntent = null;
|
||||
if (this.instream) {
|
||||
//not all streams implement these...
|
||||
//and even file stream don't seem to implement them properly...
|
||||
_unpipe2["default"](this.instream);
|
||||
if (this.instream.end) {
|
||||
this.instream.end();
|
||||
}
|
||||
if (this.instream.destroy) {
|
||||
this.instream.destroy();
|
||||
}
|
||||
this.instream = null;
|
||||
}
|
||||
if (this.streamProc) {
|
||||
this.streamProc.stdin.pause();
|
||||
this.streamProc.kill("SIGKILL");
|
||||
this.streamProc = null;
|
||||
}
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.playStream = function playStream(stream) {
|
||||
var channels = arguments.length <= 1 || arguments[1] === undefined ? 2 : arguments[1];
|
||||
|
||||
var self = this,
|
||||
startTime = Date.now(),
|
||||
count = 0,
|
||||
length = 20,
|
||||
retStream = new _StreamIntent2["default"](),
|
||||
onWarning = false;
|
||||
|
||||
this.volume = stream;
|
||||
this.playing = true;
|
||||
this.playingIntent = retStream;
|
||||
|
||||
function send() {
|
||||
if (self.paused) {
|
||||
startTime += Date.now() - (startTime + count * length);
|
||||
setTimeout(send, length);
|
||||
return;
|
||||
}
|
||||
if (!self.playingIntent || !self.playing) {
|
||||
self.setSpeaking(false);
|
||||
self.stopPlaying();
|
||||
retStream.emit("end");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
var buffer = stream.read(1920 * channels);
|
||||
|
||||
if (!buffer) {
|
||||
if (onWarning) {
|
||||
self.setSpeaking(false);
|
||||
self.stopPlaying();
|
||||
retStream.emit("end");
|
||||
return;
|
||||
} else {
|
||||
onWarning = true;
|
||||
setTimeout(send, length * 10); // give chance for some data in 200ms to appear
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer.length !== 1920 * channels) {
|
||||
var newBuffer = new Buffer(1920 * channels).fill(0);
|
||||
buffer.copy(newBuffer);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
|
||||
count++;
|
||||
self.sequence + 1 < 65535 ? self.sequence += 1 : self.sequence = 0;
|
||||
self.timestamp + 960 < 4294967295 ? self.timestamp += 960 : self.timestamp = 0;
|
||||
|
||||
self.sendBuffer(buffer, self.sequence, self.timestamp, function (e) {});
|
||||
|
||||
var nextTime = startTime + count * length;
|
||||
|
||||
self.streamTime = count * length;
|
||||
|
||||
setTimeout(send, length + (nextTime - Date.now()));
|
||||
|
||||
if (!self.playing) self.setSpeaking(true);
|
||||
|
||||
retStream.emit("time", self.streamTime);
|
||||
} catch (e) {
|
||||
retStream.emit("error", e);
|
||||
}
|
||||
}
|
||||
self.setSpeaking(true);
|
||||
send();
|
||||
|
||||
return retStream;
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.setSpeaking = function setSpeaking(value) {
|
||||
this.playing = value;
|
||||
if (this.vWS.readyState === _ws2["default"].OPEN) this.vWS.send(JSON.stringify({
|
||||
op: 5,
|
||||
d: {
|
||||
speaking: value,
|
||||
delay: 0
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.sendPacket = function sendPacket(packet) {
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
||||
|
||||
var self = this;
|
||||
self.playing = true;
|
||||
try {
|
||||
if (self.vWS.readyState === _ws2["default"].OPEN) self.udp.send(packet, 0, packet.length, self.vWSData.port, self.endpoint, callback);
|
||||
} catch (e) {
|
||||
self.playing = false;
|
||||
callback(e);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.sendBuffer = function sendBuffer(rawbuffer, sequence, timestamp, callback) {
|
||||
var self = this;
|
||||
self.playing = true;
|
||||
try {
|
||||
if (!self.encoder.opus) {
|
||||
self.playing = false;
|
||||
throw new Error("node-opus not found! Perhaps you didn't install it.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self.encoder.sanityCheck()) {
|
||||
self.playing = false;
|
||||
throw new Error("node-opus sanity check failed! Try re-installing node-opus.");
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer = self.encoder.opusBuffer(rawbuffer);
|
||||
var packet = new _VoicePacket2["default"](buffer, sequence, timestamp, self.vWSData.ssrc, self.secret);
|
||||
return self.sendPacket(packet, callback);
|
||||
} catch (e) {
|
||||
self.playing = false;
|
||||
self.emit("error", e);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.playFile = function playFile(stream) {
|
||||
var _this = this;
|
||||
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
self.stopPlaying();
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
}
|
||||
if (typeof options !== "object") {
|
||||
options = {};
|
||||
}
|
||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this.encoder.encodeFile(stream, options)["catch"](error).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
var intent = self.playStream(data.stream, 2);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
});
|
||||
function error() {
|
||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||
|
||||
reject(e);
|
||||
callback(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
|
||||
var _this2 = this;
|
||||
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
self.stopPlaying();
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
}
|
||||
if (typeof options !== "object") {
|
||||
options = {};
|
||||
}
|
||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this2.encoder.encodeStream(stream, options)["catch"](error).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
});
|
||||
function error() {
|
||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||
|
||||
reject(e);
|
||||
callback(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.playArbitraryFFmpeg = function playArbitraryFFmpeg(ffmpegOptions, volume) {
|
||||
var _this3 = this;
|
||||
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
self.stopPlaying();
|
||||
if (typeof volume === "function") {
|
||||
// volume is the callback
|
||||
callback = volume;
|
||||
}
|
||||
if (!ffmpegOptions instanceof Array) {
|
||||
ffmpegOptions = [];
|
||||
}
|
||||
var volume = volume !== undefined ? volume : this.getVolume();
|
||||
return new Promise(function (resolve, reject) {
|
||||
_this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions, volume)["catch"](error).then(function (data) {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
});
|
||||
function error() {
|
||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||
|
||||
reject(e);
|
||||
callback(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.init = function init() {
|
||||
var _this4 = this;
|
||||
|
||||
var self = this;
|
||||
_dns2["default"].lookup(this.endpoint, function (err, address, family) {
|
||||
var vWS = self.vWS = new _ws2["default"]("wss://" + _this4.endpoint, null, { rejectUnauthorized: false });
|
||||
_this4.endpoint = address;
|
||||
var udpClient = self.udp = _dgram2["default"].createSocket("udp4");
|
||||
|
||||
var firstPacket = true;
|
||||
|
||||
var discordIP = "",
|
||||
discordPort = "";
|
||||
|
||||
udpClient.bind({ exclusive: true });
|
||||
udpClient.on('message', function (msg, rinfo) {
|
||||
var buffArr = JSON.parse(JSON.stringify(msg)).data;
|
||||
if (firstPacket === true) {
|
||||
for (var i = 4; i < buffArr.indexOf(0, i); i++) {
|
||||
discordIP += String.fromCharCode(buffArr[i]);
|
||||
}
|
||||
discordPort = msg.readUIntLE(msg.length - 2, 2).toString(10);
|
||||
|
||||
var modes = self.vWSData.modes;
|
||||
var mode = MODE_xsalsa20_poly1305;
|
||||
if (modes.indexOf(MODE_xsalsa20_poly1305) < 0) {
|
||||
mode = MODE_plain;
|
||||
self.client.emit("debug", "Encrypted mode not reported as supported by the server, using 'plain'");
|
||||
}
|
||||
|
||||
vWS.send(JSON.stringify({
|
||||
"op": 1,
|
||||
"d": {
|
||||
"protocol": "udp",
|
||||
"data": {
|
||||
"address": discordIP,
|
||||
"port": Number(discordPort),
|
||||
"mode": mode
|
||||
}
|
||||
}
|
||||
}));
|
||||
firstPacket = false;
|
||||
}
|
||||
});
|
||||
|
||||
vWS.on("open", function () {
|
||||
vWS.send(JSON.stringify({
|
||||
op: 0,
|
||||
d: {
|
||||
server_id: self.server.id,
|
||||
user_id: self.client.internal.user.id,
|
||||
session_id: self.session,
|
||||
token: self.token
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
var KAI;
|
||||
|
||||
vWS.on("message", function (msg) {
|
||||
var data = JSON.parse(msg);
|
||||
switch (data.op) {
|
||||
case 2:
|
||||
self.vWSData = data.d;
|
||||
|
||||
self.KAI = KAI = self.client.internal.intervals.misc["voiceKAI"] = setInterval(function () {
|
||||
if (vWS && vWS.readyState === _ws2["default"].OPEN) vWS.send(JSON.stringify({
|
||||
op: 3,
|
||||
d: null
|
||||
}));
|
||||
}, data.d.heartbeat_interval);
|
||||
|
||||
var udpPacket = new Buffer(70);
|
||||
udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
|
||||
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) {
|
||||
if (err) self.emit("error", err);
|
||||
});
|
||||
break;
|
||||
case 4:
|
||||
if (data.d.secret_key && data.d.secret_key.length > 0) {
|
||||
var buffer = new ArrayBuffer(data.d.secret_key.length);
|
||||
self.secret = new Uint8Array(buffer);
|
||||
for (var i = 0; i < _this4.secret.length; i++) {
|
||||
self.secret[i] = data.d.secret_key[i];
|
||||
}
|
||||
}
|
||||
|
||||
self.ready = true;
|
||||
self.mode = data.d.mode;
|
||||
self.emit("ready", self);
|
||||
|
||||
break;
|
||||
case 5:
|
||||
var user = self.server.members.get("id", data.d.user_id);
|
||||
|
||||
if (user) {
|
||||
var speaking = data.d.speaking;
|
||||
var channel = user.voiceChannel;
|
||||
|
||||
if (channel) {
|
||||
user.speaking = speaking;
|
||||
self.client.emit("voiceSpeaking", channel, user);
|
||||
} else {
|
||||
self.client.emit("warn", "channel doesn't exist even though SPEAKING expects them to");
|
||||
}
|
||||
} else {
|
||||
self.client.emit("warn", "user doesn't exist even though SPEAKING expects them to");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
vWS.on("error", function (err, msg) {
|
||||
self.emit("error", err, msg);
|
||||
});
|
||||
|
||||
vWS.on("close", function (code) {
|
||||
self.emit("close", code);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.wrapVolume = function wrapVolume(stream) {
|
||||
stream.pipe(this.volume);
|
||||
|
||||
return this.volume;
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.setVolume = function setVolume(volume) {
|
||||
this.volume.set(volume);
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.getVolume = function getVolume() {
|
||||
return this.volume.get();
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.mute = function mute() {
|
||||
this.lastVolume = this.volume.get();
|
||||
this.setVolume(0);
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.unmute = function unmute() {
|
||||
this.setVolume(this.lastVolume);
|
||||
this.lastVolume = undefined;
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.pause = function pause() {
|
||||
this.paused = true;
|
||||
this.setSpeaking(false);
|
||||
this.playingIntent.emit("pause");
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.resume = function resume() {
|
||||
this.paused = false;
|
||||
this.setSpeaking(true);
|
||||
this.playingIntent.emit("resume");
|
||||
};
|
||||
|
||||
return VoiceConnection;
|
||||
})(_events2["default"]);
|
||||
|
||||
exports["default"] = VoiceConnection;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,51 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var nacl;
|
||||
try {
|
||||
nacl = require("tweetnacl");
|
||||
} catch (e) {
|
||||
// no tweetnacl!
|
||||
}
|
||||
|
||||
var nonce = new Buffer(24);
|
||||
nonce.fill(0);
|
||||
|
||||
var VoicePacket = function VoicePacket(data, sequence, time, ssrc, secret) {
|
||||
_classCallCheck(this, VoicePacket);
|
||||
|
||||
if (!nacl) {
|
||||
throw new Error("tweetnacl not found! Perhaps you didn't install it.");
|
||||
}
|
||||
var mac = secret ? 16 : 0;
|
||||
var packetLength = data.length + 12 + mac;
|
||||
|
||||
var audioBuffer = data;
|
||||
var returnBuffer = new Buffer(packetLength);
|
||||
|
||||
returnBuffer.fill(0);
|
||||
returnBuffer[0] = 0x80;
|
||||
returnBuffer[1] = 0x78;
|
||||
|
||||
returnBuffer.writeUIntBE(sequence, 2, 2);
|
||||
returnBuffer.writeUIntBE(time, 4, 4);
|
||||
returnBuffer.writeUIntBE(ssrc, 8, 4);
|
||||
|
||||
if (secret) {
|
||||
// copy first 12 bytes
|
||||
returnBuffer.copy(nonce, 0, 0, 12);
|
||||
audioBuffer = nacl.secretbox(data, nonce, secret);
|
||||
}
|
||||
|
||||
for (var i = 0; i < audioBuffer.length; i++) {
|
||||
returnBuffer[i + 12] = audioBuffer[i];
|
||||
}
|
||||
|
||||
return returnBuffer;
|
||||
};
|
||||
|
||||
exports["default"] = VoicePacket;
|
||||
module.exports = exports["default"];
|
||||
@@ -1,91 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var Transform = require('stream').Transform;
|
||||
|
||||
/**
|
||||
* @see https://github.com/reneraab/pcm-volume/blob/master/index.js Inspired by this script
|
||||
*/
|
||||
|
||||
var Volume = (function (_Transform) {
|
||||
_inherits(Volume, _Transform);
|
||||
|
||||
function Volume(volume) {
|
||||
_classCallCheck(this, Volume);
|
||||
|
||||
_Transform.call(this);
|
||||
this.set(volume);
|
||||
}
|
||||
|
||||
// Set the volume so that a value of 0.5 is half the perceived volume and
|
||||
// 2.0 is double the perceived volume.
|
||||
|
||||
Volume.prototype.setVolumeLogarithmic = function setVolumeLogarithmic(value) {
|
||||
this.volume = Math.pow(value, 1.660964);
|
||||
};
|
||||
|
||||
// Set the volume to a value specified as decibels.
|
||||
|
||||
Volume.prototype.setVolumeDecibels = function setVolumeDecibels(db) {
|
||||
this.volume = Math.pow(10, db / 20);
|
||||
};
|
||||
|
||||
Volume.prototype.get = function get() {
|
||||
return this.volume;
|
||||
};
|
||||
|
||||
Volume.prototype.set = function set(volume) {
|
||||
this.volume = volume === undefined ? 1 : volume;
|
||||
};
|
||||
|
||||
Volume.prototype._transform = function _transform(buffer, encoding, callback) {
|
||||
var out = new Buffer(buffer.length);
|
||||
|
||||
for (var i = 0; i < buffer.length; i += 2) {
|
||||
// Check whether the index is actually in range - sometimes it's possible
|
||||
// that it skips ahead too far before the end condition of the for can
|
||||
// kick in.
|
||||
if (i >= buffer.length - 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Read Int16, multiple with multiplier and round down
|
||||
//console.log(this.volume, this.multiplier, buffer.readInt16LE(i));
|
||||
var uint = Math.floor(this.multiplier * buffer.readInt16LE(i));
|
||||
|
||||
// Ensure value stays within 16bit
|
||||
uint = Math.min(32767, uint);
|
||||
uint = Math.max(-32767, uint);
|
||||
|
||||
// Write 2 new bytes into other buffer;
|
||||
out.writeInt16LE(uint, i);
|
||||
}
|
||||
|
||||
this.push(out);
|
||||
callback();
|
||||
};
|
||||
|
||||
_createClass(Volume, [{
|
||||
key: 'volume',
|
||||
get: function get() {
|
||||
return this._volume === undefined ? 1 : this._volume;
|
||||
},
|
||||
set: function set(value) {
|
||||
this._volume = value;
|
||||
}
|
||||
}, {
|
||||
key: 'multiplier',
|
||||
get: function get() {
|
||||
return this.volume;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Volume;
|
||||
})(Transform);
|
||||
|
||||
module.exports = Volume;
|
||||
114
lib/index.js
114
lib/index.js
@@ -1,114 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Object containing user agent data required for API requests.
|
||||
* @typedef {(object)} UserAgent
|
||||
* @property {string} [url=https://github.com/hydrabolt/discord.js] URL to the repository/homepage of the creator.
|
||||
* @property {string} [version=6.0.0] version of your bot.
|
||||
* @property {string} full stringified user-agent that is generate automatically upon changes. Read-only.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object containing properties that can be used to alter the client's functionality.
|
||||
* @typedef {(object)} ClientOptions
|
||||
* @property {boolean} [compress=true] whether or not large packets that are sent over WebSockets should be compressed.
|
||||
* @property {boolean} [autoReconnect=false] whether the Client should attempt to automatically reconnect if it is disconnected.
|
||||
* @property {boolean} [rateLimitAsError=false] whether rejections to API requests due to rate-limiting should be treated as errors.
|
||||
* @property {Number} [largeThreshold=250] an integer between 0 and 250. When a server has more users than `options.largeThreshold`, only the online/active users are cached.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object containing properties that will be applied when deleting messages
|
||||
* @typedef {(object)} MessageDeletionOptions
|
||||
* @property {Number} [wait] If set, the message will be deleted after `options.wait` milliseconds.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object containing properties that will be used when fetching channel logs. You cannot specify _both_ `options.before` and `options.after`
|
||||
* @typedef {(object)} ChannelLogsOptions
|
||||
* @property {MessageResolvable} [before] When fetching logs, it will fetch from messages before `options.before` but not including it.
|
||||
* @property {MessageResolvable} [after] When fetching logs, it will fetch from messages after `options.after` but not including it.
|
||||
*/
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
var _ClientClient = require("./Client/Client");
|
||||
|
||||
var _ClientClient2 = _interopRequireDefault(_ClientClient);
|
||||
|
||||
var _StructuresChannel = require("./Structures/Channel");
|
||||
|
||||
var _StructuresChannel2 = _interopRequireDefault(_StructuresChannel);
|
||||
|
||||
var _StructuresChannelPermissions = require("./Structures/ChannelPermissions");
|
||||
|
||||
var _StructuresChannelPermissions2 = _interopRequireDefault(_StructuresChannelPermissions);
|
||||
|
||||
var _StructuresInvite = require("./Structures/Invite");
|
||||
|
||||
var _StructuresInvite2 = _interopRequireDefault(_StructuresInvite);
|
||||
|
||||
var _StructuresMessage = require("./Structures/Message");
|
||||
|
||||
var _StructuresMessage2 = _interopRequireDefault(_StructuresMessage);
|
||||
|
||||
var _StructuresPermissionOverwrite = require("./Structures/PermissionOverwrite");
|
||||
|
||||
var _StructuresPermissionOverwrite2 = _interopRequireDefault(_StructuresPermissionOverwrite);
|
||||
|
||||
var _StructuresPMChannel = require("./Structures/PMChannel");
|
||||
|
||||
var _StructuresPMChannel2 = _interopRequireDefault(_StructuresPMChannel);
|
||||
|
||||
var _StructuresRole = require("./Structures/Role");
|
||||
|
||||
var _StructuresRole2 = _interopRequireDefault(_StructuresRole);
|
||||
|
||||
var _StructuresServer = require("./Structures/Server");
|
||||
|
||||
var _StructuresServer2 = _interopRequireDefault(_StructuresServer);
|
||||
|
||||
var _StructuresServerChannel = require("./Structures/ServerChannel");
|
||||
|
||||
var _StructuresServerChannel2 = _interopRequireDefault(_StructuresServerChannel);
|
||||
|
||||
var _StructuresTextChannel = require("./Structures/TextChannel");
|
||||
|
||||
var _StructuresTextChannel2 = _interopRequireDefault(_StructuresTextChannel);
|
||||
|
||||
var _StructuresUser = require("./Structures/User");
|
||||
|
||||
var _StructuresUser2 = _interopRequireDefault(_StructuresUser);
|
||||
|
||||
var _StructuresVoiceChannel = require("./Structures/VoiceChannel");
|
||||
|
||||
var _StructuresVoiceChannel2 = _interopRequireDefault(_StructuresVoiceChannel);
|
||||
|
||||
var _Constants = require("./Constants");
|
||||
|
||||
var _Constants2 = _interopRequireDefault(_Constants);
|
||||
|
||||
var _UtilCacheJs = require("./Util/Cache.js");
|
||||
|
||||
var _UtilCacheJs2 = _interopRequireDefault(_UtilCacheJs);
|
||||
|
||||
exports["default"] = {
|
||||
Client: _ClientClient2["default"],
|
||||
Channel: _StructuresChannel2["default"],
|
||||
ChannelPermissions: _StructuresChannelPermissions2["default"],
|
||||
Invite: _StructuresInvite2["default"],
|
||||
Message: _StructuresMessage2["default"],
|
||||
PermissionOverwrite: _StructuresPermissionOverwrite2["default"],
|
||||
PMChannel: _StructuresPMChannel2["default"],
|
||||
Role: _StructuresRole2["default"],
|
||||
Server: _StructuresServer2["default"],
|
||||
ServerChannel: _StructuresServerChannel2["default"],
|
||||
TextChannel: _StructuresTextChannel2["default"],
|
||||
User: _StructuresUser2["default"],
|
||||
VoiceChannel: _StructuresVoiceChannel2["default"],
|
||||
Constants: _Constants2["default"],
|
||||
Cache: _UtilCacheJs2["default"]
|
||||
};
|
||||
module.exports = exports["default"];
|
||||
54
package.json
54
package.json
@@ -1,54 +0,0 @@
|
||||
{
|
||||
"name": "discord.js",
|
||||
"version": "8.1.0",
|
||||
"description": "A way to interface with the Discord API",
|
||||
"main": "./entrypoint.js",
|
||||
"scripts": {
|
||||
"test": "eslint *.js src test && node test/lib-test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hydrabolt/discord.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"discord",
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordapp"
|
||||
],
|
||||
"author": "Amish Shah <amishshah.2k@gmail.com>",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hydrabolt/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/hydrabolt/discord.js#readme",
|
||||
"dependencies": {
|
||||
"superagent": "^2.1.0",
|
||||
"unpipe": "^1.0.0",
|
||||
"ws": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"colors": "^1.1.2",
|
||||
"eslint": "^1.10.3",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-babel": "<6.0.0",
|
||||
"grunt-browserify": "^4.0.1",
|
||||
"grunt-contrib-uglify": "^0.11.0",
|
||||
"load-grunt-tasks": "^3.4.0",
|
||||
"mocha": "^2.4.5"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"node-opus": "^0.2.1",
|
||||
"tweetnacl": "^0.14.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.12.7"
|
||||
},
|
||||
"browser": {
|
||||
"./src/Util/TokenCacher.js": "./src/Util/TokenCacher-shim.js",
|
||||
"./lib/Util/TokenCacher.js": "./lib/Util/TokenCacher-shim.js"
|
||||
},
|
||||
"tonicExampleFilename": "./examples/tonicdev.js"
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
credits to izy521 for the colour list
|
||||
https://github.com/izy521/discord.io/blob/master/docs/colors.md
|
||||
*/
|
||||
exports.DEFAULT = 0;
|
||||
exports.AQUA = 1752220;
|
||||
exports.GREEN= 3066993;
|
||||
exports.BLUE= 3447003;
|
||||
exports.PURPLE= 10181046;
|
||||
exports.GOLD= 15844367;
|
||||
exports.ORANGE= 15105570;
|
||||
exports.RED= 15158332;
|
||||
exports.GREY= 9807270;
|
||||
exports.DARKER_GREY= 8359053;
|
||||
exports.NAVY= 3426654;
|
||||
exports.DARK_AQUA= 1146986;
|
||||
exports.DARK_GREEN= 2067276;
|
||||
exports.DARK_BLUE= 2123412;
|
||||
exports.DARK_PURPLE= 7419530;
|
||||
exports.DARK_GOLD= 12745742;
|
||||
exports.DARK_ORANGE= 11027200;
|
||||
exports.DARK_RED= 10038562;
|
||||
exports.DARK_GREY= 9936031;
|
||||
exports.LIGHT_GREY= 12370112;
|
||||
exports.DARK_NAVY= 2899536;
|
||||
|
||||
exports.toDec = function (data) {
|
||||
var hextest = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i;
|
||||
|
||||
var num;
|
||||
|
||||
if(!data)
|
||||
return 0;
|
||||
|
||||
if (hextest.test(data)) {
|
||||
// it's a hex number with a # in front
|
||||
|
||||
// there's a bug in discord as of 28/10/15, where any
|
||||
// hex colors beginning with a 0 do not render properly.
|
||||
// this is a temporary fix, and it does mean that you won't
|
||||
// get correct colors all the time, although it is barely noticeable.
|
||||
if(data.charAt(1) === "0"){
|
||||
var tdata = data.split("");
|
||||
tdata[1] = 1;
|
||||
data = tdata.join("");
|
||||
}
|
||||
|
||||
num = parseInt(data.substr(1), 16).toString(10);
|
||||
} else if (hextest.test("#" + data)) {
|
||||
// it's a hex number with no # in front
|
||||
if(data.charAt(0) === "0"){
|
||||
var tdata = data.split("");
|
||||
tdata[0] = 1;
|
||||
data = tdata.join("");
|
||||
}
|
||||
num = parseInt(data, 16);
|
||||
} else {
|
||||
num = data.toString(10);
|
||||
}
|
||||
|
||||
return parseInt(num);
|
||||
}
|
||||
|
||||
exports.toHex = function (data) {
|
||||
|
||||
var text = data.toString(16);
|
||||
|
||||
while(text.length < 6){
|
||||
text = "0" + text;
|
||||
}
|
||||
|
||||
return "#" + text;
|
||||
|
||||
}
|
||||
1266
src/Client/Client.js
1266
src/Client/Client.js
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
export default {
|
||||
IDLE: 0,
|
||||
LOGGING_IN: 1,
|
||||
LOGGED_IN: 2,
|
||||
READY: 3,
|
||||
DISCONNECTED: 4
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,267 +0,0 @@
|
||||
"use strict";
|
||||
/* global Buffer */
|
||||
|
||||
/**
|
||||
* Resolves supplied data type to a Channel. If a String, it should be a Channel ID.
|
||||
* @typedef {(Channel|Server|Message|User|String)} ChannelResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to a TextChannel or PMChannel. If a String, it should be a Channel ID.
|
||||
* @typedef {(TextChannel|PMChannel|Server|Message|User|String)} TextChannelResolvable
|
||||
*/
|
||||
/**
|
||||
* If given an array, turns it into a newline-separated string.
|
||||
* @typedef {(String|Array)} StringResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to a Message. If a channel, it is the latest message from that channel.
|
||||
* @typedef {(Message|TextChannel|PMChannel)} MessageResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to a Server. If a String, it should be the server's ID.
|
||||
* @typedef {(Server|ServerChannel|Message|String)} ServerResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to something that can be attached to a message. If a String, it can be an URL or a path to a local file.
|
||||
* @typedef {(String|ReadableStream|Buffer)} FileResolvable
|
||||
*/
|
||||
/**
|
||||
* Resolves supplied data type to an invite ID. If a String, it should be an ID or a direct URL to the invite.
|
||||
* @typedef {(Invite|String)} InviteIDResolvable
|
||||
*/
|
||||
|
||||
import fs from "fs";
|
||||
import request from "superagent";
|
||||
|
||||
import User from "../../Structures/User";
|
||||
import Channel from "../../Structures/Channel";
|
||||
import TextChannel from "../../Structures/TextChannel";
|
||||
import VoiceChannel from "../../Structures/VoiceChannel";
|
||||
import ServerChannel from "../../Structures/ServerChannel";
|
||||
import PMChannel from "../../Structures/PMChannel";
|
||||
import Role from "../../Structures/Role";
|
||||
import Server from "../../Structures/Server";
|
||||
import Message from "../../Structures/Message";
|
||||
import Invite from "../../Structures/Invite";
|
||||
import VoiceConnection from "../../Voice/VoiceConnection";
|
||||
|
||||
export default class Resolver {
|
||||
constructor(internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
resolveToBase64(resource) {
|
||||
if (resource instanceof Buffer) {
|
||||
resource = resource.toString("base64");
|
||||
resource = "data:image/jpg;base64," + resource;
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
resolveInviteID(resource) {
|
||||
if (resource instanceof Invite) {
|
||||
return resource.id;
|
||||
}
|
||||
if (typeof resource === "string" || resource instanceof String) {
|
||||
if (resource.indexOf("http") === 0) {
|
||||
var split = resource.split("/");
|
||||
return split.pop();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveServer(resource) {
|
||||
if (resource instanceof Server) {
|
||||
return resource;
|
||||
}
|
||||
if (resource instanceof ServerChannel) {
|
||||
return resource.server;
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
return this.internal.servers.get("id", resource);
|
||||
}
|
||||
if (resource instanceof Message) {
|
||||
if (resource.channel instanceof TextChannel) {
|
||||
return resource.channel.server;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveRole(resource) {
|
||||
if (resource instanceof Role) {
|
||||
return resource;
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
var role = null;
|
||||
for (var server of this.internal.servers) {
|
||||
if (role = server.roles.get("id", resource)) {
|
||||
return role;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveFile(resource) {
|
||||
if (typeof resource === "string" || resource instanceof String) {
|
||||
if (/^https?:\/\//.test(resource)) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.get(resource).buffer().parse((res, cb) => {
|
||||
res.setEncoding("binary");
|
||||
res.data = "";
|
||||
res.on("data", (chunk) => {
|
||||
res.data += chunk;
|
||||
});
|
||||
res.on("end", () => {
|
||||
cb(null, new Buffer(res.data, "binary"));
|
||||
});
|
||||
}).end((err, res) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(res.body);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve(resource);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(resource);
|
||||
}
|
||||
|
||||
resolveMentions(resource, channel) {
|
||||
var _mentions = [];
|
||||
var changed = resource;
|
||||
for (var mention of (resource.match(/<@\!?[0-9]+>/g) || [])) { // username mention
|
||||
if (mention[2] === '!') {
|
||||
var user = this.internal.users.get("id", mention.substring(3, mention.length - 1));
|
||||
if (user) {
|
||||
_mentions.push(user);
|
||||
var details = channel.server && channel.server.detailsOf(user);
|
||||
if (details) {
|
||||
changed = changed.replace(new RegExp(mention, "g"), `@${details.nick || (user.username + "#" + user.discriminator)}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var user = this.internal.users.get("id", mention.substring(2, mention.length - 1));
|
||||
if (user) {
|
||||
_mentions.push(user);
|
||||
changed = changed.replace(new RegExp(mention, "g"), `@${user.username + "#" + user.discriminator}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(channel && channel.server && channel.server.roles) {
|
||||
for (var mention of (resource.match(/<@&[0-9]+>/g) || [])) { // role mention
|
||||
var role = channel.server.roles.get("id", mention.substring(3, mention.length - 1));
|
||||
if (role) {
|
||||
changed = changed.replace(new RegExp(mention, "g"), `@${role.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var mention of (resource.match(/<#[0-9]+>/g) || [])) { // channel mention
|
||||
var channel = this.internal.channels.get("id", mention.substring(2, mention.length - 1));
|
||||
if (channel) {
|
||||
changed = changed.replace(new RegExp(mention, "g"), `#${channel.name}`);
|
||||
}
|
||||
}
|
||||
return [_mentions, changed];
|
||||
}
|
||||
|
||||
resolveString(resource) {
|
||||
|
||||
// accepts Array, Channel, Server, User, Message, String and anything
|
||||
// toString()-able
|
||||
|
||||
if (resource instanceof Array) {
|
||||
resource = resource.join("\n");
|
||||
}
|
||||
|
||||
return resource.toString();
|
||||
}
|
||||
|
||||
resolveUser(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, Server, String ID, User, PMChannel
|
||||
*/
|
||||
if (resource instanceof User) {
|
||||
return resource;
|
||||
}
|
||||
if (resource instanceof Message) {
|
||||
return resource.author;
|
||||
}
|
||||
if (resource instanceof TextChannel) {
|
||||
var lmsg = resource.lastMessage;
|
||||
if (lmsg) {
|
||||
return lmsg.author;
|
||||
}
|
||||
}
|
||||
if (resource instanceof Server) {
|
||||
return resource.owner;
|
||||
}
|
||||
if (resource instanceof PMChannel) {
|
||||
return resource.recipient;
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
return this.internal.users.get("id", resource);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveMessage(resource) {
|
||||
// accepts a Message, PMChannel & TextChannel
|
||||
|
||||
if (resource instanceof TextChannel || resource instanceof PMChannel) {
|
||||
return resource.lastMessage;
|
||||
}
|
||||
if (resource instanceof Message) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
resolveChannel(resource) {
|
||||
/*
|
||||
accepts a Message, Channel, VoiceConnection, Server, String ID, User
|
||||
*/
|
||||
|
||||
if (resource instanceof Message) {
|
||||
return Promise.resolve(resource.channel);
|
||||
}
|
||||
if (resource instanceof Channel) {
|
||||
return Promise.resolve(resource);
|
||||
}
|
||||
if (resource instanceof VoiceConnection) {
|
||||
return Promise.resolve(resource.voiceChannel);
|
||||
}
|
||||
if (resource instanceof Server) {
|
||||
return Promise.resolve(resource.defaultChannel);
|
||||
}
|
||||
if (resource instanceof String || typeof resource === "string") {
|
||||
var user = this.internal.users.get("id", resource);
|
||||
if (user) {
|
||||
resource = user;
|
||||
} else {
|
||||
return Promise.resolve(this.internal.channels.get("id", resource) || this.internal.private_channels.get("id", resource));
|
||||
}
|
||||
}
|
||||
if (resource instanceof User) {
|
||||
// see if a PM exists
|
||||
for (var pmchat of this.internal.private_channels) {
|
||||
if (pmchat.recipient.equals(resource)) {
|
||||
return Promise.resolve(pmchat);
|
||||
}
|
||||
}
|
||||
|
||||
// PM does not exist :\
|
||||
return this.internal.startPM(resource);
|
||||
}
|
||||
var error = new Error("Could not resolve channel");
|
||||
error.resource = resource;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
113
src/Constants.js
113
src/Constants.js
@@ -1,113 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const Constants = {};
|
||||
|
||||
const API = Constants.API = "https://discordapp.com/api";
|
||||
const CDN = Constants.CDN = "https://cdn.discordapp.com";
|
||||
|
||||
const Endpoints = Constants.Endpoints = {
|
||||
// general endpoints
|
||||
LOGIN: `${API}/auth/login`,
|
||||
LOGOUT: `${API}/auth/logout`,
|
||||
ME: `${API}/users/@me`,
|
||||
ME_CHANNELS: `${API}/users/@me/channels`,
|
||||
ME_SERVER: (serverID) => `${Endpoints.ME}/guilds/${serverID}`,
|
||||
OAUTH2_APPLICATION: (appID) => `${API}/oauth2/applications/${appID}`,
|
||||
ME_NOTES: `${API}/users/@me/notes`,
|
||||
GATEWAY: `${API}/gateway`,
|
||||
AVATAR : (userID, avatar) => `${API}/users/${userID}/avatars/${avatar}.jpg`,
|
||||
INVITE: (id) => `${API}/invite/${id}`,
|
||||
|
||||
// emojis
|
||||
EMOJI: (emojiID) => `${CDN}/emojis/${emojiID}.png`,
|
||||
|
||||
// servers
|
||||
SERVERS: `${API}/guilds`,
|
||||
SERVER: (serverID) => `${Endpoints.SERVERS}/${serverID}`,
|
||||
SERVER_ICON: (serverID, hash) => `${Endpoints.SERVER(serverID) }/icons/${hash}.jpg`,
|
||||
SERVER_PRUNE: (serverID) => `${Endpoints.SERVER(serverID) }/prune`,
|
||||
SERVER_EMBED: (serverID) => `${Endpoints.SERVER(serverID) }/embed`,
|
||||
SERVER_INVITES: (serverID) => `${Endpoints.SERVER(serverID) }/invites`,
|
||||
SERVER_ROLES: (serverID) => `${Endpoints.SERVER(serverID) }/roles`,
|
||||
SERVER_BANS: (serverID) => `${Endpoints.SERVER(serverID) }/bans`,
|
||||
SERVER_INTEGRATIONS: (serverID) => `${Endpoints.SERVER(serverID) }/integrations`,
|
||||
SERVER_MEMBERS: (serverID) => `${Endpoints.SERVER(serverID) }/members`,
|
||||
SERVER_CHANNELS: (serverID) => `${Endpoints.SERVER(serverID) }/channels`,
|
||||
|
||||
// channels
|
||||
CHANNELS: `${API}/channels`,
|
||||
CHANNEL: (channelID) => `${Endpoints.CHANNELS}/${channelID}`,
|
||||
CHANNEL_MESSAGES: (channelID) => `${Endpoints.CHANNEL(channelID) }/messages`,
|
||||
CHANNEL_INVITES: (channelID) => `${Endpoints.CHANNEL(channelID) }/invites`,
|
||||
CHANNEL_TYPING: (channelID) => `${Endpoints.CHANNEL(channelID) }/typing`,
|
||||
CHANNEL_PERMISSIONS: (channelID) => `${Endpoints.CHANNEL(channelID) }/permissions`,
|
||||
CHANNEL_MESSAGE: (channelID, messageID) => `${Endpoints.CHANNEL_MESSAGES(channelID)}/${messageID}`,
|
||||
CHANNEL_PINS: (channelID) => `${Endpoints.CHANNEL(channelID) }/pins`,
|
||||
CHANNEL_PIN: (channelID, messageID) => `${Endpoints.CHANNEL_PINS(channelID) }/${messageID}`,
|
||||
|
||||
// friends
|
||||
FRIENDS: `${API}/users/@me/relationships`
|
||||
};
|
||||
|
||||
Constants.Permissions = {
|
||||
// general
|
||||
createInstantInvite: 1 << 0,
|
||||
kickMembers: 1 << 1,
|
||||
banMembers: 1 << 2,
|
||||
administrator: 1 << 3,
|
||||
manageChannels: 1 << 4,
|
||||
manageChannel: 1 << 4,
|
||||
manageServer: 1 << 5,
|
||||
changeNickname: 1 << 26,
|
||||
manageNicknames: 1 << 27,
|
||||
manageRoles: 1 << 28,
|
||||
managePermissions: 1 << 28,
|
||||
// text
|
||||
readMessages: 1 << 10,
|
||||
sendMessages: 1 << 11,
|
||||
sendTTSMessages: 1 << 12,
|
||||
manageMessages: 1 << 13,
|
||||
embedLinks: 1 << 14,
|
||||
attachFiles: 1 << 15,
|
||||
readMessageHistory: 1 << 16,
|
||||
mentionEveryone: 1 << 17,
|
||||
// voice
|
||||
voiceConnect: 1 << 20,
|
||||
voiceSpeak: 1 << 21,
|
||||
voiceMuteMembers: 1 << 22,
|
||||
voiceDeafenMembers: 1 << 23,
|
||||
voiceMoveMembers: 1 << 24,
|
||||
voiceUseVAD: 1 << 25
|
||||
|
||||
};
|
||||
|
||||
Constants.PacketType = {
|
||||
CHANNEL_CREATE : "CHANNEL_CREATE",
|
||||
CHANNEL_DELETE : "CHANNEL_DELETE",
|
||||
CHANNEL_UPDATE : "CHANNEL_UPDATE",
|
||||
MESSAGE_CREATE : "MESSAGE_CREATE",
|
||||
MESSAGE_DELETE : "MESSAGE_DELETE",
|
||||
MESSAGE_UPDATE : "MESSAGE_UPDATE",
|
||||
PRESENCE_UPDATE : "PRESENCE_UPDATE",
|
||||
READY : "READY",
|
||||
SERVER_BAN_ADD : "GUILD_BAN_ADD",
|
||||
SERVER_BAN_REMOVE: "GUILD_BAN_REMOVE",
|
||||
SERVER_CREATE : "GUILD_CREATE",
|
||||
SERVER_DELETE : "GUILD_DELETE",
|
||||
SERVER_MEMBER_ADD : "GUILD_MEMBER_ADD",
|
||||
SERVER_MEMBER_REMOVE : "GUILD_MEMBER_REMOVE",
|
||||
SERVER_MEMBER_UPDATE : "GUILD_MEMBER_UPDATE",
|
||||
SERVER_MEMBERS_CHUNK : "GUILD_MEMBERS_CHUNK",
|
||||
SERVER_ROLE_CREATE : "GUILD_ROLE_CREATE",
|
||||
SERVER_ROLE_DELETE : "GUILD_ROLE_DELETE",
|
||||
SERVER_ROLE_UPDATE : "GUILD_ROLE_UPDATE",
|
||||
SERVER_UPDATE : "GUILD_UPDATE",
|
||||
TYPING : "TYPING_START",
|
||||
USER_UPDATE : "USER_UPDATE",
|
||||
USER_NOTE_UPDATE: "USER_NOTE_UPDATE",
|
||||
VOICE_STATE_UPDATE : "VOICE_STATE_UPDATE",
|
||||
FRIEND_ADD : "RELATIONSHIP_ADD",
|
||||
FRIEND_REMOVE : "RELATIONSHIP_REMOVE"
|
||||
};
|
||||
|
||||
export default Constants;
|
||||
@@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import Equality from "../Util/Equality";
|
||||
import {reg} from "../Util/ArgumentRegulariser";
|
||||
|
||||
export default class Channel extends Equality {
|
||||
constructor(data, client){
|
||||
super();
|
||||
this.id = data.id;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
get createdAt() {
|
||||
return new Date((+this.id / 4194304) + 1420070400000);
|
||||
}
|
||||
|
||||
get isPrivate() {
|
||||
return !this.server;
|
||||
}
|
||||
|
||||
delete(){
|
||||
return this.client.deleteChannel.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import {Permissions} from "../Constants";
|
||||
|
||||
export default class ChannelPermissions {
|
||||
constructor(permissions){
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
serialise(explicit){
|
||||
|
||||
var hp = (perm) => this.hasPermission(perm, explicit);
|
||||
|
||||
var json = {};
|
||||
|
||||
for(var permission in Permissions) {
|
||||
json[permission] = hp( Permissions[permission] );
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
serialize(){
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
}
|
||||
|
||||
hasPermission(perm, explicit=false){
|
||||
if( perm instanceof String || typeof perm === "string" ){
|
||||
perm = Permissions[perm];
|
||||
}
|
||||
if(!perm){
|
||||
return false;
|
||||
}
|
||||
if(!explicit){ // implicit permissions allowed
|
||||
if( !!(this.permissions & Permissions.administrator) ){
|
||||
// administrator allowed, they have all permissions
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !!(this.permissions & perm);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import {Endpoints} from "../Constants";
|
||||
/* example data
|
||||
{
|
||||
id: '164585980739846145'
|
||||
name: 'wlfSS',
|
||||
roles: [ '135829612780322816' ],
|
||||
require_colons: false,
|
||||
managed: true,
|
||||
}
|
||||
*/
|
||||
|
||||
export default class Emoji {
|
||||
constructor(data, server) {
|
||||
this.server = server;
|
||||
this.id = data.id;
|
||||
this.name = data.name;
|
||||
this.roleList = data.roles;
|
||||
this.colons = data.require_colons;
|
||||
this.managed = data.managed;
|
||||
}
|
||||
|
||||
get roles() {
|
||||
var roleGroup = [];
|
||||
|
||||
if (this.managed) {
|
||||
for (var i = 0; i < this.roleList.length; i++) {
|
||||
var roleID = this.roleList[i].toString();
|
||||
var role = this.server.roles.get("id", roleID);
|
||||
roleGroup.push(role);
|
||||
}
|
||||
}
|
||||
return roleGroup
|
||||
}
|
||||
|
||||
get getURL() {
|
||||
return Endpoints.EMOJI(this.id);
|
||||
}
|
||||
|
||||
toObject() {
|
||||
let keys = ['id', 'name', 'roleList', 'colons', 'managed'],
|
||||
obj = {};
|
||||
|
||||
for (let k of keys) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
export default class Invite {
|
||||
constructor(data, chan, client){
|
||||
this.maxAge = data.max_age;
|
||||
this.code = data.code;
|
||||
if (chan) {
|
||||
this.channel = chan;
|
||||
this.server = chan.server;
|
||||
} else {
|
||||
this.channel = data.channel;
|
||||
this.server = data.guild;
|
||||
}
|
||||
this.revoked = data.revoked;
|
||||
this.createdAt = Date.parse(data.created_at);
|
||||
this.temporary = data.temporary;
|
||||
this.uses = data.uses;
|
||||
this.maxUses = data.max_uses;
|
||||
if (data.inviter) {
|
||||
this.inviter = client.internal.users.get("id", data.inviter.id);
|
||||
}
|
||||
this.xkcd = data.xkcdpass;
|
||||
}
|
||||
|
||||
toString(){
|
||||
return `https://discord.gg/${this.code}`;
|
||||
}
|
||||
|
||||
delete(){
|
||||
return this.client.deleteInvite.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
join(){
|
||||
return this.client.joinServer.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Options that can be applied to a message before sending it.
|
||||
* @typedef {(object)} MessageOptions
|
||||
* @property {boolean} [tts=false] Whether or not the message should be sent as text-to-speech.
|
||||
*/
|
||||
|
||||
import Cache from "../Util/Cache";
|
||||
import User from "./User";
|
||||
import {reg} from "../Util/ArgumentRegulariser";
|
||||
import Equality from "../Util/Equality";
|
||||
|
||||
export default class Message extends Equality{
|
||||
constructor(data, channel, client) {
|
||||
super();
|
||||
this.channel = channel;
|
||||
this.server = channel.server;
|
||||
this.client = client;
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone !== undefined ? data.mention_everyone : data.everyoneMentioned;
|
||||
this.pinned = data.pinned;
|
||||
this.id = data.id;
|
||||
|
||||
if(data.edited_timestamp) {
|
||||
this.editedTimestamp = Date.parse(data.edited_timestamp);
|
||||
}
|
||||
|
||||
if(data.author instanceof User) {
|
||||
this.author = data.author;
|
||||
} else if(data.author) {
|
||||
this.author = client.internal.users.add(new User(data.author, client));
|
||||
}
|
||||
|
||||
this.content = data.content;
|
||||
|
||||
var mentionData = client.internal.resolver.resolveMentions(data.content, channel);
|
||||
this.cleanContent = mentionData[1];
|
||||
this.mentions = [];
|
||||
|
||||
mentionData[0].forEach((mention) => {
|
||||
// this is .add and not .get because it allows the bot to cache
|
||||
// users from messages from logs who may have left the server and were
|
||||
// not previously cached.
|
||||
if(mention instanceof User) {
|
||||
this.mentions.push(mention);
|
||||
} else {
|
||||
this.mentions.push(client.internal.users.add(new User(mention, client)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get sender(){
|
||||
return this.author;
|
||||
}
|
||||
|
||||
toObject() {
|
||||
let keys = ['id', 'timestamp', 'everyoneMentioned', 'pinned', 'editedTimestamp', 'content', 'cleanContent', 'tts', 'attachments', 'embeds'],
|
||||
obj = {};
|
||||
|
||||
for (let k of keys) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
obj.channelID = this.channel ? this.channel.id : null;
|
||||
obj.serverID = this.server ? this.server.id : null;
|
||||
obj.author = this.author.toObject();
|
||||
obj.mentions = this.mentions.map(m => m.toObject());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
isMentioned(user){
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (!user) {
|
||||
return false
|
||||
}
|
||||
for (var mention of this.mentions) {
|
||||
if (mention.id == user.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
toString(){
|
||||
return this.content;
|
||||
}
|
||||
|
||||
delete(){
|
||||
return this.client.deleteMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
update(){
|
||||
return this.client.updateMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
edit() {
|
||||
return this.client.updateMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
reply(){
|
||||
return this.client.reply.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
replyTTS(){
|
||||
return this.client.replyTTS.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
pin() {
|
||||
return this.client.pinMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
unpin() {
|
||||
return this.client.unpinMessage.apply(this.client, req(this, arguments));
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import Channel from "./Channel";
|
||||
import User from "./User";
|
||||
import Cache from "../Util/Cache";
|
||||
import {reg} from "../Util/ArgumentRegulariser";
|
||||
|
||||
export default class PMChannel extends Channel {
|
||||
constructor(data, client){
|
||||
super(data, client);
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.messages = new Cache("id", client.options.maxCachedMessages);
|
||||
this.recipient = this.client.internal.users.add(new User(data.recipient, this.client));
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
get lastMessage(){
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
|
||||
toString(){
|
||||
return this.recipient.toString();
|
||||
}
|
||||
|
||||
toObject() {
|
||||
let keys = ['type', 'lastMessageID', 'recipient'],
|
||||
obj = {};
|
||||
|
||||
for (let k of keys) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
sendMessage(){
|
||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
send() {
|
||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
sendTTSMessage(){
|
||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
sendTTS() {
|
||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
sendFile() {
|
||||
return this.client.sendFile.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
startTyping() {
|
||||
return this.client.startTyping.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
stopTyping() {
|
||||
return this.client.stopTyping.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
getLogs() {
|
||||
return this.client.getChannelLogs.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
getMessage() {
|
||||
return this.client.getMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import {Permissions} from "../Constants";
|
||||
|
||||
export default class PermissionOverwrite {
|
||||
|
||||
constructor(data) {
|
||||
this.id = data.id;
|
||||
this.type = data.type; // member or role
|
||||
this.deny = data.deny;
|
||||
this.allow = data.allow;
|
||||
}
|
||||
|
||||
// returns an array of allowed permissions
|
||||
get allowed(){
|
||||
var allowed = [];
|
||||
for( var permName in Permissions ){
|
||||
if(permName === "manageRoles" || permName === "manageChannels"){
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!!(this.allow & Permissions[permName])){
|
||||
allowed.push(permName);
|
||||
}
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
|
||||
// returns an array of denied permissions
|
||||
get denied(){
|
||||
var denied = [];
|
||||
for( var permName in Permissions ){
|
||||
if(permName === "manageRoles" || permName === "manageChannels"){
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!!(this.deny & Permissions[permName])){
|
||||
denied.push(permName);
|
||||
}
|
||||
}
|
||||
return denied;
|
||||
}
|
||||
|
||||
toObject() {
|
||||
let keys = ['id', 'type', 'allow', 'deny'],
|
||||
obj = {};
|
||||
|
||||
for (let k of keys) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
setAllowed(allowedArray){
|
||||
allowedArray.forEach( (permission) => {
|
||||
if(permission instanceof String || typeof permission === "string"){
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if(permission){
|
||||
this.allow |= (1 << permission);
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
setDenied(deniedArray){
|
||||
deniedArray.forEach( (permission) => {
|
||||
if(permission instanceof String || typeof permission === "string"){
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if(permission){
|
||||
this.deny |= (1 << permission);
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
"use strict";
|
||||
import {Permissions} from "../Constants";
|
||||
import {reg} from "../Util/ArgumentRegulariser";
|
||||
/*
|
||||
|
||||
example data
|
||||
|
||||
{ position: -1,
|
||||
permissions: 36953089,
|
||||
name: '@everyone',
|
||||
managed: false,
|
||||
id: '110007368451915776',
|
||||
hoist: false,
|
||||
color: 0 }
|
||||
*/
|
||||
|
||||
const DefaultRole = [
|
||||
Permissions.createInstantInvite,
|
||||
Permissions.readMessages,
|
||||
Permissions.readMessageHistory,
|
||||
Permissions.sendMessages,
|
||||
Permissions.sendTTSMessages,
|
||||
Permissions.embedLinks,
|
||||
Permissions.attachFiles,
|
||||
Permissions.readMessageHistory,
|
||||
Permissions.mentionEveryone,
|
||||
Permissions.voiceConnect,
|
||||
Permissions.voiceSpeak,
|
||||
Permissions.voiceUseVAD
|
||||
].reduce( (previous, current) => previous | current, 0 );
|
||||
|
||||
export default class Role {
|
||||
constructor(data, server, client){
|
||||
this.position = data.position || -1;
|
||||
this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0 );
|
||||
this.name = data.name || "@everyone";
|
||||
this.managed = data.managed || false;
|
||||
this.id = data.id;
|
||||
this.hoist = data.hoist || false;
|
||||
this.color = data.color || 0;
|
||||
this.server = server;
|
||||
this.client = client;
|
||||
this.mentionable = data.mentionable || false;
|
||||
}
|
||||
|
||||
get createdAt() {
|
||||
return new Date((+this.id / 4194304) + 1420070400000);
|
||||
}
|
||||
|
||||
toObject() {
|
||||
let keys = ['id', 'position', 'permissions', 'name', 'managed', 'hoist', 'color', 'mentionable'],
|
||||
obj = {};
|
||||
|
||||
for (let k of keys) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
serialise(explicit){
|
||||
|
||||
var hp = (perm) => this.hasPermission(perm, explicit);
|
||||
|
||||
return {
|
||||
// general
|
||||
createInstantInvite : hp( Permissions.createInstantInvite ),
|
||||
kickMembers : hp( Permissions.kickMembers ),
|
||||
banMembers : hp( Permissions.banMembers ),
|
||||
manageRoles : hp ( Permissions.manageRoles ),
|
||||
manageChannels : hp( Permissions.manageChannels ),
|
||||
manageServer : hp( Permissions.manageServer ),
|
||||
administrator: hp( Permissions.administrator ),
|
||||
// text
|
||||
readMessages : hp( Permissions.readMessages ),
|
||||
sendMessages : hp( Permissions.sendMessages ),
|
||||
sendTTSMessages : hp( Permissions.sendTTSMessages ),
|
||||
manageMessages : hp( Permissions.manageMessages ),
|
||||
embedLinks : hp( Permissions.embedLinks ),
|
||||
attachFiles : hp( Permissions.attachFiles ),
|
||||
readMessageHistory : hp( Permissions.readMessageHistory ),
|
||||
mentionEveryone : hp( Permissions.mentionEveryone ),
|
||||
// voice
|
||||
voiceConnect : hp( Permissions.voiceConnect ),
|
||||
voiceSpeak : hp( Permissions.voiceSpeak ),
|
||||
voiceMuteMembers : hp( Permissions.voiceMuteMembers ),
|
||||
voiceDeafenMembers : hp( Permissions.voiceDeafenMembers ),
|
||||
voiceMoveMembers : hp( Permissions.voiceMoveMembers ),
|
||||
voiceUseVAD : hp( Permissions.voiceUseVAD )
|
||||
};
|
||||
}
|
||||
|
||||
serialize(){
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
}
|
||||
|
||||
hasPermission(perm, explicit=false){
|
||||
if( perm instanceof String || typeof perm === "string" ){
|
||||
perm = Permissions[perm];
|
||||
}
|
||||
if(!perm){
|
||||
return false;
|
||||
}
|
||||
if(!explicit){ // implicit permissions allowed
|
||||
if( !!(this.permissions & Permissions.administrator) ){
|
||||
// administrator allowed, they have all permissions
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// e.g.
|
||||
// !!(36953089 & Permissions.manageRoles) = not allowed to manage roles
|
||||
// !!(36953089 & (1 << 21)) = voice speak allowed
|
||||
|
||||
return !!(this.permissions & perm);
|
||||
}
|
||||
|
||||
setPermission(permission, value){
|
||||
if( permission instanceof String || typeof permission === "string" ){
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if(permission){
|
||||
// valid permission
|
||||
if(value){
|
||||
this.permissions |= permission;
|
||||
}else{
|
||||
this.permissions &= ~permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setPermissions(obj){
|
||||
obj.forEach((value, permission) => {
|
||||
if( permission instanceof String || typeof permission === "string" ){
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if(permission){
|
||||
// valid permission
|
||||
this.setPermission(permission, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
colorAsHex(){
|
||||
var val = this.color.toString(16);
|
||||
while(val.length < 6){
|
||||
val = "0" + val;
|
||||
}
|
||||
return "#"+val;
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.deleteRole.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
edit() {
|
||||
return this.client.updateRole.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
update() {
|
||||
return this.client.updateRole.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
addMember(member, callback) {
|
||||
return this.client.addMemberToRole.apply(this.client, [member, this, callback]);
|
||||
}
|
||||
|
||||
addUser(member, callback) {
|
||||
return this.client.addUserToRole.apply(this.client, [member, this, callback]);
|
||||
}
|
||||
|
||||
removeMember(member, callback) {
|
||||
return this.client.removeMemberFromRole.apply(this.client, [member, this, callback]);
|
||||
}
|
||||
|
||||
removeUser(member, callback) {
|
||||
return this.client.removeUserFromRole.apply(this.client, [member, this, callback]);
|
||||
}
|
||||
|
||||
mention(){
|
||||
if(this.mentionable)
|
||||
return `<@&${this.id}>`;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
toString(){
|
||||
return this.mention();
|
||||
}
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Types of region for a server, include: `us-west`, `us-east`, `us-south`, `us-central`, `singapore`, `london`, `sydney`, `amsterdam` and `frankfurt`
|
||||
* @typedef {(string)} region
|
||||
*/
|
||||
|
||||
import Bucket from "../Util/Bucket";
|
||||
import Equality from "../Util/Equality";
|
||||
import {Endpoints} from "../Constants";
|
||||
import Cache from "../Util/Cache";
|
||||
import User from "./User";
|
||||
import TextChannel from "./TextChannel";
|
||||
import VoiceChannel from "./VoiceChannel";
|
||||
import Role from "./Role";
|
||||
import Emoji from "./Emoji";
|
||||
import {reg} from "../Util/ArgumentRegulariser";
|
||||
|
||||
var strictKeys = [
|
||||
"region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"
|
||||
];
|
||||
|
||||
export default class Server extends Equality {
|
||||
|
||||
constructor(data, client) {
|
||||
|
||||
super();
|
||||
|
||||
this.client = client;
|
||||
this.id = data.id;
|
||||
|
||||
if(data.owner_id) { // new server data
|
||||
client.internal.buckets["bot:msg:guild:" + this.id] = new Bucket(5, 5000);
|
||||
client.internal.buckets["dmsg:" + this.id] = new Bucket(5, 1000);
|
||||
client.internal.buckets["bdmsg:" + this.id] = new Bucket(1, 1000);
|
||||
client.internal.buckets["guild_member:" + this.id] = new Bucket(10, 10000);
|
||||
client.internal.buckets["guild_member_nick:" + this.id] = new Bucket(1, 1000);
|
||||
}
|
||||
|
||||
this.region = data.region;
|
||||
this.ownerID = data.owner_id || data.ownerID;
|
||||
this.name = data.name;
|
||||
this.members = new Cache();
|
||||
this.channels = new Cache();
|
||||
this.roles = new Cache();
|
||||
this.emojis = new Cache();
|
||||
this.icon = data.icon;
|
||||
this.afkTimeout = data.afk_timeout;
|
||||
this.afkChannelID = data.afk_channel_id || data.afkChannelID;
|
||||
this.memberMap = data.memberMap || {};
|
||||
this.memberCount = data.member_count || data.memberCount;
|
||||
this.large = data.large || this.memberCount > 250;
|
||||
|
||||
if (data.roles instanceof Cache) {
|
||||
data.roles.forEach((role) => this.roles.add(role));
|
||||
} else {
|
||||
data.roles.forEach((dataRole) => {
|
||||
this.roles.add(new Role(dataRole, this, client));
|
||||
});
|
||||
}
|
||||
|
||||
if (data.emojis instanceof Cache) {
|
||||
data.emojis.forEach((emoji) => this.emojis.add(emoji));
|
||||
} else {
|
||||
data.emojis.forEach((dataEmoji) => {
|
||||
this.emojis.add(new Emoji(dataEmoji, this));
|
||||
})
|
||||
}
|
||||
|
||||
if (data.members instanceof Cache) {
|
||||
data.members.forEach((member) => this.members.add(member));
|
||||
} else {
|
||||
data.members.forEach((dataUser) => {
|
||||
this.memberMap[dataUser.user.id] = {
|
||||
roles: dataUser.roles,
|
||||
mute: dataUser.mute,
|
||||
selfMute: dataUser.self_mute,
|
||||
deaf: dataUser.deaf,
|
||||
selfDeaf: dataUser.self_deaf,
|
||||
joinedAt: Date.parse(dataUser.joined_at),
|
||||
nick: dataUser.nick || null
|
||||
};
|
||||
this.members.add(client.internal.users.add(new User(dataUser.user, client)));
|
||||
});
|
||||
}
|
||||
|
||||
if (data.channels instanceof Cache) {
|
||||
data.channels.forEach((channel) => this.channels.add(channel));
|
||||
} else {
|
||||
data.channels.forEach((dataChannel) => {
|
||||
if (dataChannel.type === "text") {
|
||||
this.channels.add(client.internal.channels.add(new TextChannel(dataChannel, client, this)));
|
||||
} else {
|
||||
this.channels.add(client.internal.channels.add(new VoiceChannel(dataChannel, client, this)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (data.presences) {
|
||||
for (var presence of data.presences) {
|
||||
var user = client.internal.users.get("id", presence.user.id);
|
||||
if(user) {
|
||||
user.status = presence.status;
|
||||
user.game = presence.game;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
for (var voiceState of data.voice_states) {
|
||||
let user = this.members.get("id", voiceState.user_id);
|
||||
if (user) {
|
||||
this.memberMap[user.id] = this.memberMap[user.id] || {};
|
||||
this.memberMap[user.id].mute = voiceState.mute || this.memberMap[user.id].mute;
|
||||
this.memberMap[user.id].selfMute = voiceState.self_mute === undefined ? this.memberMap[user.id].selfMute : voiceState.self_mute;
|
||||
this.memberMap[user.id].deaf = voiceState.deaf || this.memberMap[user.id].deaf;
|
||||
this.memberMap[user.id].selfDeaf = voiceState.self_deaf === undefined ? this.memberMap[user.id].selfDeaf : voiceState.self_deaf;
|
||||
let channel = this.channels.get("id", voiceState.channel_id);
|
||||
if (channel) {
|
||||
this.eventVoiceJoin(user, channel);
|
||||
} else {
|
||||
this.client.emit("warn", "channel doesn't exist even though READY expects them to");
|
||||
}
|
||||
} else {
|
||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get createdAt() {
|
||||
return new Date((+this.id / 4194304) + 1420070400000);
|
||||
}
|
||||
|
||||
toObject() {
|
||||
var keys = ['id', 'name', 'region', 'ownerID', 'icon', 'afkTimeout', 'afkChannelID', 'large', 'memberCount'],
|
||||
obj = {};
|
||||
|
||||
for (let k of keys) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
obj.members = this.members.map(member => member.toObject());
|
||||
obj.channels = this.channels.map(channel => channel.toObject());
|
||||
obj.roles = this.roles.map(role => role.toObject());
|
||||
obj.emojis = this.emojis.map(emoji => emoji.toObject());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
detailsOf(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
var result = this.memberMap[user.id] || {};
|
||||
if(result && result.roles) {
|
||||
result.roles = result.roles.map(pid => this.roles.get("id", pid) || pid);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
detailsOfUser(user) {
|
||||
return this.detailsOf(user);
|
||||
}
|
||||
|
||||
detailsOfMember(user) {
|
||||
return this.detailsOf(user);
|
||||
}
|
||||
|
||||
details(user) {
|
||||
return this.detailsOf(user);
|
||||
}
|
||||
|
||||
rolesOfUser(user) {
|
||||
return this.detailsOf(user).roles || [];
|
||||
}
|
||||
|
||||
rolesOfMember(member) {
|
||||
return this.rolesOfUser(member);
|
||||
}
|
||||
|
||||
rolesOf(user) {
|
||||
return this.rolesOfUser(user);
|
||||
}
|
||||
|
||||
get iconURL() {
|
||||
if (!this.icon) {
|
||||
return null;
|
||||
} else {
|
||||
return Endpoints.SERVER_ICON(this.id, this.icon);
|
||||
}
|
||||
}
|
||||
|
||||
get afkChannel() {
|
||||
return this.channels.get("id", this.afkChannelID);
|
||||
}
|
||||
|
||||
get defaultChannel() {
|
||||
return this.channels.get("id", this.id);
|
||||
}
|
||||
|
||||
get generalChannel() {
|
||||
return this.defaultChannel;
|
||||
}
|
||||
|
||||
get general() {
|
||||
return this.defaultChannel;
|
||||
}
|
||||
|
||||
get owner() {
|
||||
return this.members.get("id", this.ownerID);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
eventVoiceJoin(user, channel) {
|
||||
// removes from other speaking channels first
|
||||
var oldChannel = this.eventVoiceLeave(user);
|
||||
|
||||
channel.members.add(user);
|
||||
user.voiceChannel = channel;
|
||||
|
||||
if (oldChannel.id && channel.id !== oldChannel.id) {
|
||||
this.client.emit("voiceLeave", oldChannel, user);
|
||||
this.client.emit("voiceSwitch", oldChannel, channel, user);
|
||||
}
|
||||
|
||||
this.client.emit("voiceJoin", channel, user);
|
||||
}
|
||||
|
||||
eventVoiceStateUpdate(channel, user, data) {
|
||||
if (!user.voiceChannel || user.voiceChannel.id !== channel.id) {
|
||||
return this.eventVoiceJoin(user, channel);
|
||||
}
|
||||
if (!this.memberMap[user.id]) {
|
||||
this.memberMap[user.id] = {};
|
||||
}
|
||||
var oldState = {
|
||||
mute: this.memberMap[user.id].mute,
|
||||
selfMute: this.memberMap[user.id].self_mute,
|
||||
deaf: this.memberMap[user.id].deaf,
|
||||
selfDeaf: this.memberMap[user.id].self_deaf
|
||||
};
|
||||
this.memberMap[user.id].mute = data.mute;
|
||||
this.memberMap[user.id].selfMute = data.self_mute;
|
||||
this.memberMap[user.id].deaf = data.deaf;
|
||||
this.memberMap[user.id].selfDeaf = data.self_deaf;
|
||||
if (oldState.mute !== undefined && (oldState.mute != data.mute || oldState.self_mute != data.self_mute
|
||||
|| oldState.deaf != data.deaf || oldState.self_deaf != data.self_deaf)) {
|
||||
this.client.emit("voiceStateUpdate", channel, user, oldState, this.memberMap[user.id]);
|
||||
} else {
|
||||
this.eventVoiceJoin(user, channel);
|
||||
}
|
||||
}
|
||||
|
||||
eventVoiceLeave(user) {
|
||||
for (let chan of this.channels.getAll("type", "voice")) {
|
||||
if (chan.members.has("id", user.id)) {
|
||||
chan.members.remove(user);
|
||||
user.voiceChannel = null;
|
||||
return chan;
|
||||
}
|
||||
}
|
||||
return {server: this};
|
||||
}
|
||||
|
||||
equalsStrict(obj) {
|
||||
if (obj instanceof Server) {
|
||||
for (var key of strictKeys) {
|
||||
if (obj[key] !== this[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
leave() {
|
||||
return this.client.leaveServer.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.leaveServer.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
createInvite() {
|
||||
return this.client.createInvite.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
createRole() {
|
||||
return this.client.createRole.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
banMember(user, tlength, callback) {
|
||||
return this.client.banMember.apply(this.client, [user, this, tlength, callback]);
|
||||
}
|
||||
|
||||
banUser(user, tlength, callback) {
|
||||
return this.client.banMember.apply(this.client, [user, this, tlength, callback]);
|
||||
}
|
||||
|
||||
ban(user, tlength, callback) {
|
||||
return this.client.banMember.apply(this.client, [user, this, tlength, callback]);
|
||||
}
|
||||
|
||||
unbanMember(user, callback) {
|
||||
return this.client.unbanMember.apply(this.client, [user, this, callback]);
|
||||
}
|
||||
|
||||
unbanUser(user, callback) {
|
||||
return this.client.unbanMember.apply(this.client, [user, this, callback]);
|
||||
}
|
||||
|
||||
unban(user, callback) {
|
||||
return this.client.unbanMember.apply(this.client, [user, this, callback]);
|
||||
}
|
||||
|
||||
kickMember(user, callback) {
|
||||
return this.client.kickMember.apply(this.client, [user, this, callback]);
|
||||
}
|
||||
|
||||
kickUser(user, callback) {
|
||||
return this.client.kickMember.apply(this.client, [user, this, callback]);
|
||||
}
|
||||
|
||||
kick(user, callback) {
|
||||
return this.client.kickMember.apply(this.client, [user, this, callback]);
|
||||
}
|
||||
|
||||
getBans() {
|
||||
return this.client.getBans.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
createChannel() {
|
||||
return this.client.createChannel.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
setNickname() {
|
||||
return this.client.setNickname.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
membersWithRole(role) {
|
||||
return this.members.filter(m => m.hasRole(role));
|
||||
}
|
||||
|
||||
usersWithRole(role) {
|
||||
return this.membersWithRole(role);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user