├── .babelrc ├── .dockerignore ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitattributes ├── .gitignore ├── .nvmrc ├── .tern-project ├── CHANGELOG.md ├── Dockerfile ├── LICENSE.md ├── README.md ├── config-sample.cson ├── documentation ├── config.cson_explained.md ├── develop_your_own_plugin.md └── index.md ├── package.json ├── src ├── index.js ├── modules │ ├── api.js │ ├── bot.js │ ├── config.js │ ├── events.js │ └── plugins.js └── plugins │ ├── .gitkeep │ ├── dice.js │ ├── general.js │ └── music │ ├── .gitignore │ ├── LICENSE.md │ ├── README.md │ ├── index.js │ ├── package.json │ └── yarn.lock └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"] 3 | } 4 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | dist/ 3 | documentation/ 4 | node_modules/ 5 | src/plugins/.gitkeep 6 | .dockerignore 7 | .editorconfig 8 | .eslintignore 9 | .eslintrc 10 | .gitattributes 11 | .gitignore 12 | .nvmrc 13 | .tern-project 14 | CHANGELOG.md 15 | config-sample.cson 16 | Dockerfile 17 | LICENSE.md 18 | npm-debug.log 19 | README.md 20 | yarn-error.log 21 | 22 | src/plugins/music/node_modules/ 23 | src/plugins/music/.gitignore 24 | src/plugins/music/LICENSE.md 25 | src/plugins/music/README.md 26 | 27 | # music/ 28 | # avatar.png 29 | # config.cson 30 | ffmpeg.exe 31 | 32 | # System files 33 | .DS_Store 34 | desktop.ini 35 | Thumbs.db 36 | 37 | # IDE/Editor files 38 | .sublime-gulp.cache 39 | .sublime-gulp-tmp.js 40 | sublime-gulp.log 41 | *.sublime-workspace 42 | *.sublime-project 43 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.{md,markdown}] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 6, 4 | "sourceType": "module", 5 | "env": { 6 | "es6": true, 7 | "node": true 8 | } 9 | }, 10 | "rules": { 11 | "no-cond-assign": 2, 12 | "no-console": 0, 13 | "no-constant-condition": 2, 14 | "no-debugger": 1, 15 | "no-dupe-args": 2, 16 | "no-dupe-keys": 2, 17 | "no-duplicate-case": 2, 18 | "no-empty-character-class": 2, 19 | "no-empty": 2, 20 | "no-ex-assign": 2, 21 | "no-extra-boolean-cast": 2, 22 | "no-extra-parens": 1, 23 | "no-extra-semi": 2, 24 | "no-func-assign": 2, 25 | "no-inner-declarations": 2, 26 | "no-invalid-regexp": 2, 27 | "no-irregular-whitespace": 2, 28 | "no-obj-calls": 2, 29 | "no-prototype-builtins": 2, 30 | "no-regex-spaces": 2, 31 | "no-sparse-arrays": 2, 32 | "no-template-curly-in-string": 2, 33 | "no-unexpected-multiline": 2, 34 | "no-unreachable": 2, 35 | "no-unsafe-finally": 2, 36 | "no-unsafe-negation": 2, 37 | "use-isnan": 2, 38 | "valid-jsdoc": 2, 39 | "valid-typeof": 2, 40 | "accessor-pairs": 1, 41 | "array-callback-return": 2, 42 | "block-scoped-var": 2, 43 | "class-methods-use-this": 2, 44 | "complexity": 0, 45 | "consistent-return": 0, 46 | "curly": [2, "multi-line", "consistent"], 47 | "default-case": 2, 48 | "dot-location": [2, "property"], 49 | "dot-notation": 2, 50 | "eqeqeq": 2, 51 | "guard-for-in": 2, 52 | "no-alert": 2, 53 | "no-caller": 2, 54 | "no-case-declarations": 2, 55 | "no-div-regex": 2, 56 | "no-else-return": 2, 57 | "no-empty-function": 2, 58 | "no-empty-pattern": 2, 59 | "no-eq-null": 2, 60 | "no-eval": 2, 61 | "no-extend-native": 2, 62 | "no-extra-bind": 2, 63 | "no-extra-label": 2, 64 | "no-fallthrough": 2, 65 | "no-floating-decimal": 0, 66 | "no-global-assign": 2, 67 | "no-implicit-coercion": 2, 68 | "no-implicit-globals": 2, 69 | "no-implied-eval": 2, 70 | "no-invalid-this": 2, 71 | "no-iterator": 2, 72 | "no-labels": 2, 73 | "no-lone-blocks": 2, 74 | "no-loop-func": 2, 75 | "no-magic-numbers": 0, 76 | "no-multi-spaces": 2, 77 | "no-multi-str": 2, 78 | "no-new-func": 2, 79 | "no-new-wrappers": 2, 80 | "no-new": 2, 81 | "no-octal-escape": 2, 82 | "no-octal": 2, 83 | "no-param-reassign": 1, 84 | "no-proto": 2, 85 | "no-redeclare": 2, 86 | "no-return-assign": [2, "always"], 87 | "no-script-url": 2, 88 | "no-self-assign": 2, 89 | "no-self-compare": 2, 90 | "no-sequences": 2, 91 | "no-throw-literal": 2, 92 | "no-unmodified-loop-condition": 2, 93 | "no-unused-expressions": 2, 94 | "no-unused-labels": 2, 95 | "no-useless-call": 2, 96 | "no-useless-concat": 2, 97 | "no-useless-escape": 2, 98 | "no-useless-return": 2, 99 | "no-void": 2, 100 | "no-warning-comments": 1, 101 | "no-with": 2, 102 | "radix": 2, 103 | "vars-on-top": 0, 104 | "yoda": 2, 105 | "strict": [2, "global"], 106 | "init-declarations": [2, "always"], 107 | "no-catch-shadow": 2, 108 | "no-delete-var": 2, 109 | "no-label-var": 2, 110 | "no-shadow-restricted-names": 2, 111 | "no-shadow": 1, 112 | "no-undef-init": 2, 113 | "no-undefined": 2, 114 | "no-unused-vars": 2, 115 | "no-use-before-define": 2, 116 | "callback-return": 0, 117 | "global-require": 0, 118 | "handle-callback-err": 2, 119 | "no-mixed-requires": 2, 120 | "no-path-concat": 0, 121 | "no-process-env": 2, 122 | "no-process-exit": 2, 123 | "no-sync": 0, 124 | "array-bracket-spacing": [2, "never"], 125 | "block-spacing": [2, "always"], 126 | "brace-style": [2, "1tbs", {"allowSingleLine": true}], 127 | "camelcase": 2, 128 | "comma-dangle": [2, "always-multiline"], 129 | "computed-property-spacing": [2, "never"], 130 | "consistent-this": [2, "that"], 131 | "eol-last": [2, "always"], 132 | "func-call-spacing": [2, "never"], 133 | "func-name-matching": 0, 134 | "func-names": [1, "never"], 135 | "func-style": [2, "declaration"], 136 | "id-blacklist": 0, 137 | "id-length": 0, 138 | "id-match": 0, 139 | "indent": [2, 4, {"SwitchCase": 1}], 140 | "jsx-quotes": [2, "prefer-double"], 141 | "key-spacing": [2, {"mode": "strict", "beforeColon": false, "afterColon": true}], 142 | "keyword-spacing": [2, {"before": true, "after": true}], 143 | "line-comment-position": 0, 144 | "linebreak-style": 0, 145 | "lines-around-comment": 2, 146 | "lines-around-directive": 2, 147 | "max-depth": 0, 148 | "max-len": 0, 149 | "max-lines": 0, 150 | "max-nested-callbacks": [2, 3], 151 | "max-params": 0, 152 | "max-statements-per-line": [2, {"max": 2}], 153 | "max-statements": 0, 154 | "multiline-ternary": [1, "never"], 155 | "new-cap": 2, 156 | "new-parens": 2, 157 | "newline-after-var": 0, 158 | "newline-before-return": 0, 159 | "newline-per-chained-call": 0, 160 | "no-array-constructor": 2, 161 | "no-bitwise": 1, 162 | "no-continue": 0, 163 | "no-inline-comments": 0, 164 | "no-lonely-if": 2, 165 | "no-mixed-operators": [2, {"allowSamePrecedence": true}], 166 | "no-mixed-spaces-and-tabs": 2, 167 | "no-multiple-empty-lines": [2, {"max": 2, "maxEOF": 1, "maxBOF": 0}], 168 | "no-negated-condition": 2, 169 | "no-nested-ternary": 2, 170 | "no-new-object": 2, 171 | "no-plusplus": 0, 172 | "no-trailing-spaces": 2, 173 | "no-underscore-dangle": 0, 174 | "no-unneeded-ternary": 2, 175 | "no-whitespace-before-property": 2, 176 | "object-curly-newline": 0, 177 | "object-curly-spacing": [2, "never"], 178 | "object-property-newline": 2, 179 | "one-var-declaration-per-line": [2, "initializations"], 180 | "one-var": [2, "never"], 181 | "operator-assignment": [2, "always"], 182 | "operator-linebreak": [2, "before"], 183 | "padded-blocks": [2, "never"], 184 | "quote-props": [2, "as-needed"], 185 | "quotes": [2, "single", {"avoidEscape": true, "allowTemplateLiterals": true}], 186 | "require-jsdoc": [1, {"require": {"FunctionDeclaration": true, "MethodDefinition": true, "ClassDeclaration": true}}], 187 | "semi-spacing": [2, {"before": false, "after": true}], 188 | "sort-keys": 0, 189 | "sort-vars": 0, 190 | "space-before-blocks": [2, "always"], 191 | "space-in-parens": [2, "never"], 192 | "space-infix-ops": 2, 193 | "space-unary-ops": 2, 194 | "spaced-comment": [2, "always"], 195 | "unicode-bom": [2, "never"], 196 | "wrap-regex": 0 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | avatar.png 2 | config.cson 3 | ffmpeg.exe 4 | music/ 5 | !src/plugins/music/ 6 | 7 | dist/ 8 | node_modules/ 9 | npm-debug.log* 10 | yarn-error.log 11 | 12 | # System files 13 | .DS_Store 14 | desktop.ini 15 | Thumbs.db 16 | 17 | # IDE/Editor files 18 | .sublime-gulp.cache 19 | .sublime-gulp-tmp.js 20 | sublime-gulp.log 21 | *.sublime-workspace 22 | *.sublime-project 23 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 7.8 2 | -------------------------------------------------------------------------------- /.tern-project: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaVersion": 6, 3 | "libs": [], 4 | "loadEagerly": [ 5 | "./index.js", 6 | "./modules/**/*.js", 7 | "./plugins/**/*.js" 8 | ], 9 | "plugins": { 10 | "doc_comment": {}, 11 | "node": {}, 12 | "es_modules": {}, 13 | "node_resolve": {}, 14 | "modules": { 15 | "dontLoad": "", 16 | "load": "", 17 | "modules": "" 18 | } 19 | }, 20 | "dontLoad": [] 21 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v0.8.0 _not released yet_ 4 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.8.0 5 | 6 | ### Important changes 7 | * Replaced JSON configuration file with CSON one 8 | * Provided a Dockerfile for running the bot with Docker 9 | 10 | ### Changes 11 | * Fix for issue #45 12 | * Clean up 13 | + Updated dependencies 14 | + Updated install instructions 15 | + Updated the `config-sample.json` to provide a sample configuration that just works™ and utilized the defaults 16 | + Fixed broken stuff 17 | + Renamed `music-bot` plugin to `music` 18 | + Updated the install instructions 19 | * **[music plugin]** Added some emojis to the messages 20 | * **[music plugin]** Shows now some timestamps/progress states in the messages 21 | * **[music plugin]** Added possibility to add multiple URLs at once 22 | * **[music plugin]** Updated the `!music playlist` command with more information (closes #48) 23 | * Better error handling, when renaming of the bot goes wrong 24 | * Made `!op`, `!deop` and `!owner` working with mentions (closes #52) 25 | * Relocated the documentation to the `documentation` directory to get version history for these too 26 | * The command cooldown now doesn't affect the owner (closes #47) 27 | * **[music plugin]** Ignores now the case sensitivity of the channel name in the `!music enter` command (closes #32) 28 | 29 | 30 | ## v0.7.9 31 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.9 32 | 33 | ### Changes 34 | * Every command can now have synonyms. The plugins can define synonyms itself, but you can also add your custom ones or disable by the plugin defined ones with your `config.json`. 35 | + Example: 36 | ```json 37 | "plugins": { 38 | "general": { 39 | "commands": { 40 | "about": { 41 | "synonyms": { 42 | "help": { 43 | "enabled": true 44 | }, 45 | "about": { 46 | "enabled": false 47 | } 48 | } 49 | } 50 | } 51 | } 52 | } 53 | ``` 54 | * You can now add or remove multiple permissions at the same time with `!op` and `!deop` 55 | + Example: `!op general:kill general:reload` 56 | * You can now give the bot an avatar with `!avatar ` or by setting it in your `config.json`. Setting it to `null` will remove the avatar. 57 | + Example: 58 | ```json 59 | { 60 | "credentials": { 61 | "avatar": "url or relative path" 62 | } 63 | } 64 | ``` 65 | * You can now let your bot ignore channels defined by your `config.json`. 66 | + Example: 67 | ```json 68 | { 69 | "ignoreChannels": [ 70 | "#bot-free-channel" 71 | ] 72 | } 73 | ``` 74 | 75 | ## v0.7.8 76 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.8 77 | 78 | ### Important changes 79 | * You don't have to require permissions anymore in your `config.json` for specific commands (defined by the plugin). Some commands will now require permissions by default. You can set it to false if they sould not require permissions. The following commands will now require permissions by default: 80 | + `!kill` 81 | + `!owner` 82 | + `!prefix` 83 | + `!op` 84 | + `!deop` 85 | + `!enable` 86 | + `!rename` 87 | + `!reload` 88 | 89 | ### Changes 90 | * Fixed permission system 91 | 92 | ## v0.7.7 93 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.7 94 | 95 | ### Changes 96 | * You can now specify a channel which is required to request a command 97 | + Example: 98 | ```json 99 | "plugins": { 100 | "music-bot": { 101 | "commands": { 102 | "add": { 103 | "channel": "#music" 104 | } 105 | } 106 | } 107 | } 108 | ``` 109 | 110 | ## v0.7.6 111 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.6 112 | 113 | ### Important changes 114 | * **[music-bot plugin]** You can now define the max length of a song (in minutes). It defaults to `15` minutes. `0` minutes will be endless. 115 | + Example: 116 | ```json 117 | "plugins": { 118 | "music-bot": { 119 | "maxLength": 30 120 | } 121 | } 122 | ``` 123 | * Bumped the version of `discord.io` to 1.6.5 124 | + Run `npm install discord.io` to install the new version 125 | * You can now define how fast (in seconds) your `config.json` will be reloaded automatically without restarting the bot (optional).It default to every 5 seconds. Settings it to `0` disables it. Example: `"reloadConfig": 10`. 126 | 127 | ### Changes 128 | * Renamed some directories 129 | * Added missing information to the install instruction 130 | * Added a license 131 | * **[music-bot plugin]** Fixed `!music stop` command (issue #33) 132 | * Added missing commands to the [README.md](./README.md) 133 | * Fixed directory names 134 | * **[music-bot plugin]** You don't need to set a library anymore. It will default to the OS specific temp directories 135 | * Disconnect the bot before killing the process. The bot should now log out everytime when using `!kill`. 136 | 137 | ## v0.7.5 138 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.5 139 | 140 | ### Important changes 141 | * Fixed issue that will check for updates in a high rate and will get blocked by the GitHub API because of that 142 | 143 | ## v0.7.4 144 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.4 145 | 146 | ### Important changes 147 | * Added `!owner ` to change the owner of the bot 148 | + Make sure to require permissions for this in your `config.json`. In the future commands like this will require permissions by default. 149 | 150 | ### Changes 151 | * Added `!reload` to reload your `config.json` 152 | * Send update notifications through direct messages to the owner only once for each version 153 | 154 | ## v0.7.3 155 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.3 156 | 157 | ### Important changes 158 | * Bumped the version of `discord.io` to 1.6.3 159 | + Remove the `node_modules` directory and install all dependencies again with `npm install` 160 | * Removed `!config` completely. In addition to that: Added multiple specific commands to change the `config.json` 161 | + `!rename ` Renames the bot 162 | + `!op ` Adds a permission to a user 163 | + `!deop ` Removes a permission from a user 164 | + `!prefix ` Changes the global command prefix 165 | + Make sure to require permissions for them in your `config.json`. In the future commands like this will require permissions by default. 166 | 167 | ### Changes 168 | * Removed `enablePlugin` from the `!commands` output 169 | * On disconnect it tries now to reconnect every 1 minute, not 10 170 | 171 | ## v0.7.2 172 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.2 173 | 174 | ### Important changes 175 | * `!config` is temporarily disabled, because it does not work as expected and can overrite parts of your `config.json` 176 | 177 | ### Changes 178 | * You can now enable plugins without having to restart with `!enable ` 179 | + Example: `!enable dice` 180 | * [music-bot plugin] When you leave out the channel in the `!music enter Channel` command and you are in a voice channel right now, it will try to join your voice channel 181 | * You can now give an operator a wildcard for each plugin to grant him all permissions of this plugin. 182 | + Example: 183 | ```json 184 | "operators": { 185 | "user id here": { 186 | "permissions": [ 187 | "music-bot:*" 188 | ] 189 | } 190 | } 191 | ``` 192 | * Added internal event system 193 | * The bot will now notify the owner through a direct message if a new version is available. 194 | * The bot will now show the enabled plugins on start-up. 195 | 196 | ## v0.7.1 197 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.1 198 | 199 | ### Changes 200 | * [music-bot plugin] You can now define a channel which the bot should automatically join when started. 201 | + Example: 202 | ```json 203 | "plugins": { 204 | "music-bot": { 205 | "autoJoinVoiceChannel": "General" 206 | } 207 | } 208 | ``` 209 | * You can now give an operator a wildcard as permission to grant him all permissions. 210 | + Example: 211 | ```json 212 | "operators": { 213 | "user id here": { 214 | "permissions": [ 215 | "*" 216 | ] 217 | } 218 | } 219 | ``` 220 | 221 | ## v0.7.0 222 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.7.0 223 | 224 | ### Important changes 225 | * Bumped the version of `discord.io` to 1.6.2 226 | + Remove the `node_modules` directory and install all dependencies again with `npm install` 227 | 228 | ### Changes 229 | * You can now roll a dice with the new `dice` plugin 230 | + Example: `!dice roll 6` Rolls a dice with 6 faces 231 | * The music-bot plugin is playing sound again 232 | * Removed some deprecated code 233 | 234 | ## v0.6.9 235 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.6.9 236 | 237 | ### Changes 238 | * Changed the style of the update notification. 239 | * You will now get notified when required properties like the bot credentials are not set in your config.json. 240 | 241 | ## v0.6.8 242 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.6.8 243 | 244 | ### Changes 245 | * Removed code used for testing ... 246 | 247 | ## v0.6.7 248 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.6.7 249 | 250 | ### Important changes 251 | * Bumped the version of `discord.io` to 1.6.2 252 | + Remove the `node_modules` directory and install all dependencies again with `npm install` 253 | 254 | ### Changes 255 | * The bot tries to reconnect now if it gets disconnected from Discord. 256 | 257 | ## v0.6.6 258 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.6.6 259 | 260 | ### Important changes 261 | * There is a new [CHANGELOG.md](./CHANGELOG.md) file which shows you important changes and what changes for you. 262 | 263 | ## v0.6.5 264 | 265 | ### Important changes 266 | 267 | * You do not have to add plugins to the top of the [plugins.js](./_modules/plugin.js) anymore to enable them. You have to enable them in your `config.json` now. You have to give them at least an empty object like `"music-bot": {}`. Make sure to have `general` enabled to get the general commands like `!kill`, `!config`, `!commands`, ... Example: 268 | 269 | ```json 270 | "plugins": { 271 | "general": {}, 272 | "music-bot": { 273 | "library": "../music" 274 | } 275 | } 276 | ``` 277 | 278 | Other changes 279 | --- 280 | * The bot prints your version in the terminal when you start the bot. 281 | 282 | ## v0.6.4 283 | Download here: https://github.com/simonknittel/discord-bot-api/releases/tag/v0.6.4 284 | 285 | ### Important changes 286 | * The permission system has been reworked. 287 | + You have to define in your `config.json` now if a specific permission is required. 288 | + In addition to that every command got a default permission like `general:kill` or `music-bot:enter`. 289 | + Commands which do not require permissions in your `config.json` can be execuded by everybody, so make sure you add commands like `!kill` or `!config` to your `config.json`. Example: 290 | ```json 291 | "plugins": { 292 | "general": { 293 | "commands": { 294 | "kill": { 295 | "requirePermission": true 296 | }, 297 | "config": { 298 | "requirePermission": true 299 | } 300 | } 301 | } 302 | } 303 | ``` 304 | + Plugin developers can still ask for custom permissions with the `api.isOperator(userID, 'plugin-name:permission', channelID)` function 305 | * The way to define operators in your `config.json` has changed a little bit. Example: 306 | ```json 307 | "operators": { 308 | "user id here": { 309 | "permissions": [ 310 | "general:kill" 311 | ] 312 | } 313 | } 314 | ``` 315 | 316 | ## v0.6.3 317 | 318 | ### Important changes 319 | * The bot can auto accept invites defined in your `config.json` now. Example: 320 | ```json 321 | "invites": [ 322 | "your invite link here" 323 | ] 324 | ``` 325 | 326 | ### Changes 327 | * Added some more error logging 328 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:7.8-alpine 2 | 3 | # Install system dependencies 4 | RUN apk update 5 | RUN apk add ffmpeg 6 | 7 | 8 | ENV NODE_ENV development 9 | 10 | 11 | # Import source code 12 | WORKDIR /home/node 13 | COPY . . 14 | 15 | 16 | # Install local dependencies 17 | WORKDIR /home/node 18 | # VOLUME yarn-error.log npm-debug.log music avatar.png config.cson 19 | RUN yarn 20 | 21 | 22 | # Build 23 | WORKDIR /home/node 24 | RUN npm run build 25 | 26 | 27 | # Install plugin dependencies 28 | WORKDIR /home/node/dist/plugins/music 29 | RUN cp /home/node/src/plugins/music/package.json . 30 | RUN yarn --production 31 | RUN rm package.json 32 | 33 | 34 | # Remove local build dependencies 35 | WORKDIR /home/node 36 | # # RUN yarn remove babel-cli babel-preset-es2015 37 | # 38 | # RUN rm -rf /home/node/node_modules 39 | # RUN yarn --prodution 40 | 41 | RUN rm -rf src .babelrc 42 | 43 | 44 | # Start the application 45 | WORKDIR /home/node 46 | ENV NODE_ENV production 47 | CMD [ "node", "dist/index.js" ] 48 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | ========================== 3 | Version 3, 29 June 2007 4 | ========================== 5 | 6 | > Copyright (C) 2007 Free Software Foundation, Inc. 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | 9 | # Preamble 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | # TERMS AND CONDITIONS 72 | 73 | ## 0. Definitions. 74 | 75 | _"This License"_ refers to version 3 of the GNU General Public License. 76 | 77 | _"Copyright"_ also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | _"The Program"_ refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as _"you"_. _"Licensees"_ and 82 | "recipients" may be individuals or organizations. 83 | 84 | To _"modify"_ a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a _"modified version"_ of the 87 | earlier work or a work _"based on"_ the earlier work. 88 | 89 | A _"covered work"_ means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To _"propagate"_ a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To _"convey"_ a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | ## 1. Source Code. 113 | 114 | The _"source code"_ for a work means the preferred form of the work 115 | for making modifications to it. _"Object code"_ means any non-source 116 | form of a work. 117 | 118 | A _"Standard Interface"_ means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The _"System Libraries"_ of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The _"Corresponding Source"_ for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | ## 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | ## 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | ## 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | ## 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | ## 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A _"User Product"_ is either (1) a _"consumer product"_, which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | _"Installation Information"_ for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | ## 7. Additional Terms. 344 | 345 | _"Additional permissions"_ are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | ## 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | ## 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | ## 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An _"entity transaction"_ is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | ## 11. Patents. 472 | 473 | A _"contributor"_ is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's _"essential patent claims"_ are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | ## 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | ## 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | ## 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | ## 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | ## 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | ## 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | # END OF TERMS AND CONDITIONS 622 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Discord Bot API 2 | This is a plugin based, self-hosted and configurable Discord bot. You can use plugins to play music, do a raffle or other things. You can even create your own ones! 3 | 4 | ## Need help? 5 | Join my Discord server: https://discord.gg/0jV29zKlvdJbDx3f 6 | 7 | ## Installation 8 | 1. Install [Docker](https://docker.com) and make sure it's available in your [PATH](https://en.wikipedia.org/wiki/Environment_variable) variable 9 | 2. Download the latest version of the bot here: https://github.com/simonknittel/discord-bot-api/archive/master.zip 10 | 3. Extract the download 11 | 4. Duplicate the [config-sample.cson](./config-sample.cson) and rename it to `config.cson` 12 | 5. Edit the new `config.cson` to your needs 13 | * Visit the full [documentation](./documentation/config.cson_explained.md) for more information 14 | 6. Invite the bot to your server https://finitereality.github.io/permissions/?v=103926784 15 | 7. Open a terminal in that extracted directory 16 | 8. Run `docker build -t my-bot .` to build the Docker image 17 | 9. Run `docker run my-bot` to start it (run `docker run -d my-bot` to run it in the background) 18 | 19 | ## Enable a plugin 20 | 1. Add the name of the plugin to the `plugins` array of the `config.cson` (see [config.cson explained](./documentation/config.cson_explained.md) for an example) 21 | 22 | 32 | 33 | ## Update your bot 34 | The bot will notify the owner if there is a new release available. It will check the version on the start and every 60 minutes after that. 35 | 36 | 1. Download the latest release here: https://github.com/simonknittel/discord-bot-api/archive/master.zip 37 | 2. Do the same steps as listed under [Installation](#installation) but keep your old `config.cson` 38 | * Make sure to read the changelog for possible changes of the configuration 39 | 40 | ## Develop your own plugin 41 | Visit the [full documentation](./documentation/develop_your_own_plugin.md) 42 | 43 | ## Available plugins 44 | Contact me to get your plugins listed here. 45 | 46 | * [Music](./plugins/music) 47 | + Visit the [README.md](./plugins/music/README.md) of the plugin for the commands, install instructions and more. 48 | * [Dice](./plugins/dice) 49 | + Visit the [dice.js](./plugins/dice.js) of the plugin for the commands, install instructions and more. 50 | 51 | ## General commands 52 | * `!commands` - Shows all available commands 53 | + Synonyms: `!help` 54 | * `!about` - Shows a short description of the bot 55 | * `!kill` - Stops the bot 56 | + Synonyms: `!stop` 57 | * `!me` - Shows the ID of the user 58 | + Synonyms: `!userid` 59 | * `!enable ` - Enables a plugin 60 | + Example: `!enable dice` 61 | * `!op ` - Gives an user a permission 62 | * `!deop ` - Removes a permission from an user 63 | * `!prefix ` - Changes the global command prefix 64 | + Example: `!prefix $` 65 | * `!owner ` - Changes the owner of the bot 66 | * `!rename ` - Renames the bot 67 | * `!reload` - Reloads the config 68 | + Synonyms: `!refresh` 69 | * `!avatar ` - Gives the bot an avatar 70 | + Setting it to `null` will remove the avatar. 71 | 72 | ## Planned features 73 | Visit https://github.com/simonknittel/discord-bot-api/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement 74 | 75 | ## Thanks 76 | Thanks to everyone who reports me bugs, gives me feedback or tries to figure out the cause of an issues. Without them the Discord Bot API wouldn't be so awesome. 77 | 78 | ## License 79 | Copyright (C) 2017 Simon Knittel () 80 | 81 | This program is free software: you can redistribute it and/or modify 82 | it under the terms of the GNU General Public License as published by 83 | the Free Software Foundation, either version 3 of the License, or 84 | (at your option) any later version. 85 | 86 | This program is distributed in the hope that it will be useful, 87 | but WITHOUT ANY WARRANTY; without even the implied warranty of 88 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 89 | GNU General Public License for more details. 90 | 91 | You should have received a copy of the GNU General Public License 92 | along with this program. If not, see . 93 | -------------------------------------------------------------------------------- /config-sample.cson: -------------------------------------------------------------------------------- 1 | credentials: 2 | token: "" # Add the token of your bot here 3 | ownerID: "" # Add the ID of your Discord account here 4 | serverID: "" # Add the ID of the server the bot should run on here 5 | plugins: # Plugins listed here will be enabled 6 | general: {} 7 | -------------------------------------------------------------------------------- /documentation/config.cson_explained.md: -------------------------------------------------------------------------------- 1 | # config.cson explained 2 | ```cson 3 | credentials: 4 | token: "" # Add the token of your bot here 5 | name: "Bot - !commands" # You can give your bot here a new name and it will change when he joins your server (optional). 6 | 7 | ownerID: "" # Add the ID of your Discord account here.This will give you the permission for some commands only the owner should be able to use. 8 | serverID: "" # Add the ID of the server the bot should run on here 9 | 10 | mentionRequired: false # If set to true, you have to mention the bot directly (optional). 11 | globalCommandPrefix: "!" # Set here the prefix for all your commands (optional). It defaults to `!` 12 | reloadConfig: 5 # Set here how fast (in seconds) your `config.cson` should be reloaded automatically without restarting the bot (optional).It default to every 5 seconds. Settings it to `0` disables it. 13 | commandCooldown: 1000 # You can set a time in milliseconds which the user has to wait until a new command from him will be executed (optional). 14 | ignoreChannels: [ # Here you can define which channels should be ignored by your bot. (optional) 15 | "#bot-free-channel" 16 | ] 17 | 18 | operators: # You can give other users specific permissions by adding them here (optional). The object key will be the user id. 19 | "": 20 | permissions: [ # The permissions of the operator (optional). You can give the user a wildcard `*` as permission to grant him all permissions. 21 | "general:kill" # plugin-name:command-name 22 | ] 23 | 24 | plugins: # Plugins listed here will be enabled 25 | general: # The name of the plugin you want to have enabled 26 | commands: # You can configure here each command individually 27 | about: # The name of the command you want to configure 28 | requirePermission: false # If set to true, it will require permission for this command. If set to false, it will not. If unset it will default to the plugins default. 29 | kill: # The name of the command you want to configure 30 | requirePermission: true # If set to true, it will require permission for this command. If set to false, it will not. If unset it will default to the plugins default. 31 | 32 | music: # The name of the plugin you want to have enabled 33 | commands: # You can configure here each command individually 34 | add: # The name of the command you want to configure 35 | channel: "#music" 36 | 37 | commandPrefix: "music" # Here you can customize the command prefix of this plugin (optional). It defaults to a prefix defined by the plugin itself. 38 | library: "../music" 39 | skipLimit: 1 40 | announceSongs: true 41 | autoJoinVoiceChannel: "General" 42 | maxLength: 15 43 | ``` 44 | 45 | **plugins.channel:** You can define here a text channel which the command listens to. If it's not set, it will listen to all channels. 46 | **plugins.commands.channel** If set, the command will only work in this channel. If unset, it will work in every channel. 47 | 48 | The other properties listed here are plugin specific. 49 | 50 | ## Need help? 51 | Join my Discord server: https://discord.gg/0jV29zKlvdJbDx3f 52 | -------------------------------------------------------------------------------- /documentation/develop_your_own_plugin.md: -------------------------------------------------------------------------------- 1 | # Develop your own plugin 2 | 3 | The Discord Bot API gets compiled with [Babel](https://babeljs.io), so writing in ES6 is possible. 4 | 5 | **1. Create a JavaScript file in the [plugins](../plugins) directory.** 6 | 7 | **2. Fill it with the basic skeleton (read the inline comments for more information):** 8 | ```javascript 9 | const plugin = { 10 | name: 'your-plugin', // The bot will look for this name in the config.cson 11 | defaultCommandPrefix: 'prefix', // Give your plugin a custom command prefix which will be lead by the global command prefix 12 | commands: { // Define your commands here 13 | your: { // This key defines the keyword this command listens to 14 | fn: (user, userID, channelID, message, rawEvent) => { // Parameters which are set by discord.io (see here: https://github.com/izy521/discord.io/wiki/2.-Events#message) 15 | // Your code here 16 | }, 17 | description: 'Returns the global command prefix', // The description will be displayed by the general '!commands' command 18 | }, 19 | }, 20 | }; 21 | 22 | export default plugin; 23 | ``` 24 | 25 | **3. Enable the plugin by starting up your bot and enter `!enable your-plugin`** 26 | 27 | **4. Done** 28 | 29 | I want to access the `config.cson` 30 | --- 31 | **1. Import the configModule with:** 32 | ```javascript 33 | import configModule from '../modules/config'; 34 | ``` 35 | **2. Access the config with:** 36 | ```javascript 37 | configModule.get().globalCommandPrefix // Returns the globalCommandPrefix set by the config.cson 38 | ``` 39 | 40 | I want to check if a user has a specific permission 41 | --- 42 | **1. Import the api with:** 43 | ```javascript 44 | import api from '../modules/api'; 45 | ``` 46 | **2. Check for permission with:** 47 | ```javascript 48 | api.isOperator(userID, 'your-plugin:yourCommand') // Returns true or false 49 | ``` 50 | 51 | I want to send a message 52 | --- 53 | You have full access to an initialized bot instance from [discord.io](https://github.com/izy521/discord.io). 54 | 55 | **1. Import the initialized bot instance with:** 56 | ```javascript 57 | import bot from '../modules/bot'; 58 | ``` 59 | **2. Send a message with the `discord.io` function:** 60 | ```javascript 61 | bot.sendMessage({ 62 | to: channelID, 63 | message: 'Your message', 64 | }); 65 | ``` 66 | 67 | ## Examples 68 | Visit the [music bot plugin](../plugins/music) which comes included in the download of the Discord Bot API. 69 | 70 | ## Need help? 71 | Join my Discord server: https://discord.gg/0jV29zKlvdJbDx3f 72 | -------------------------------------------------------------------------------- /documentation/index.md: -------------------------------------------------------------------------------- 1 | # Index 2 | [config.cson explained](./config.cson_explained.md) 3 | [Develop your own plugin](./develop_your_own_plugin.md) 4 | 5 | ## Need help? 6 | Join my Discord server: https://discord.gg/0jV29zKlvdJbDx3f 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "discord-bot-api", 3 | "description": "This is a plugin based and configurable Discord bot. You can use plugins to play music, do a raffle or other things. You can even create your own ones!", 4 | "version": "0.8.0", 5 | "author": "Simon Knittel (https://simonknittel.de)", 6 | "homepage": "https://github.com/simonknittel/discord-bot-api", 7 | "keywords": [ 8 | "discord", 9 | "bot", 10 | "api", 11 | "plugins", 12 | "configurable", 13 | "self hosted", 14 | "permission system" 15 | ], 16 | "license": "GPL-3.0", 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/simonknittel/discord-bot-api" 20 | }, 21 | "bugs": { 22 | "url": "https://github.com/simonknittel/discord-bot-api/issues" 23 | }, 24 | "scripts": { 25 | "start": "babel-node src/index.js", 26 | "build": "babel src -d dist --ignore node_modules" 27 | }, 28 | "engines": { 29 | "node": "^7.8.0" 30 | }, 31 | "dependencies": { 32 | "chalk": "1.1.3", 33 | "cson": "4.0.0", 34 | "discord.io": "2.5.1", 35 | "request": "2.81.0", 36 | "semver-compare": "1.0.0" 37 | }, 38 | "devDependencies": { 39 | "babel-cli": "6.24.1", 40 | "babel-preset-es2015": "6.24.1" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | // Discord Bot API 2 | import events from './modules/events'; 3 | 4 | // Other 5 | import request from 'request'; 6 | import packageJSON from '../package'; 7 | import cmp from 'semver-compare'; // Compare semver versions 8 | import chalk from 'chalk'; // Coloring console logs 9 | 10 | console.log(chalk.blue('Need help? Join our Discord server:') + ' https://discord.gg/0jV29zKlvdJbDx3f'); 11 | console.log(''); // Empty line 12 | 13 | import './modules/plugins'; 14 | 15 | const newVersions = []; 16 | 17 | /** 18 | * Checks the GitHub releases for the latest version and notifies the owner if a new release is available 19 | * @method checkForUpdates 20 | * @return {Void} Returns nothing 21 | */ 22 | function checkForUpdates() { 23 | // Request the GitHub API 24 | request({ 25 | url: 'https://api.github.com/repos/simonknittel/discord-bot-api/releases/latest', 26 | json: true, 27 | headers: { 28 | 'User-Agent': 'simonknittel', // Needed otherwise the GitHub API will reject the request 29 | }, 30 | }, (error, response, body) => { 31 | if (error || response.statusCode !== 200) { 32 | console.error('error:', error); 33 | console.error('response.statusCode:', response.statusCode); 34 | console.error('body:', body); 35 | console.log(''); // Empty line 36 | 37 | return false; 38 | } 39 | 40 | const currentVersion = packageJSON.version; 41 | const latestVersion = body.tag_name.substring(1); 42 | 43 | // Compares the latest release with local one 44 | if (cmp(currentVersion, latestVersion) === -1) { 45 | if (newVersions.indexOf(latestVersion) < 0) { 46 | newVersions.push(latestVersion); 47 | 48 | console.log(chalk.red('There is a new version available for the bot.')); 49 | console.log('Visit https://github.com/simonknittel/discord-bot-api to download the latest version.'); 50 | console.log('Check out the CHANGELOG.md file for important changes.'); 51 | console.log(''); // Empty line 52 | console.log(chalk.yellow('Your version:', currentVersion)); 53 | console.log('Latest version:', latestVersion); 54 | console.log(''); // Empty line 55 | 56 | events.emit('update', { 57 | currentVersion, 58 | latestVersion, 59 | }); 60 | } 61 | } 62 | }); 63 | } 64 | 65 | checkForUpdates(); 66 | setInterval(checkForUpdates, 3600000); // Check for updates all 60 minutes 67 | -------------------------------------------------------------------------------- /src/modules/api.js: -------------------------------------------------------------------------------- 1 | // Discord Bot API 2 | import configModule from './config'; 3 | import bot from './bot'; 4 | 5 | 6 | /** 7 | * Checks if the user has the requested permission 8 | * @method isOperator 9 | * @param {Integer} userID [description] 10 | * @param {String} requestedPermission The name of the requested permission 11 | * @param {Integer} channelID [description] 12 | * @return {Boolean} [description] 13 | */ 14 | function isOperator(userID, requestedPermission, channelID) { 15 | // The owner has every permission 16 | if (userID === configModule.get().ownerID) return true; 17 | 18 | if ( 19 | configModule.get().operators 20 | && configModule.get().operators[userID] 21 | && configModule.get().operators[userID].permissions 22 | ) { 23 | for (const permission of configModule.get().operators[userID].permissions) { 24 | if ( 25 | permission === requestedPermission 26 | || permission === '*' 27 | || (permission.split(':')[0] === requestedPermission.split(':')[0] && permission.split(':')[1] === '*') 28 | ) { 29 | return true; 30 | } 31 | } 32 | } 33 | 34 | bot.sendMessage({ 35 | to: channelID, 36 | message: 'You do not have the permission to run this command.', 37 | }); 38 | 39 | // The user does not have the permission 40 | return false; 41 | } 42 | 43 | 44 | const api = { 45 | isOperator, 46 | }; 47 | 48 | export default api; 49 | -------------------------------------------------------------------------------- /src/modules/bot.js: -------------------------------------------------------------------------------- 1 | // Discord Bot API 2 | import configModule from './config'; 3 | import {plugins} from './plugins'; 4 | import api from './api'; 5 | import events from './events'; 6 | 7 | // Other 8 | import Discord from 'discord.io'; 9 | import chalk from 'chalk'; 10 | import packageJSON from '../../package'; 11 | import fs from 'fs'; 12 | import request from 'request'; 13 | 14 | 15 | let bot = null; // The Discord instance will be stored in this object 16 | const commandHistory = {}; 17 | let reconnectInterval = null; 18 | 19 | 20 | /** 21 | * Handles incomming message 22 | * @method handleMessage 23 | * @param {String} user The name of the user who sent the message 24 | * @param {String} userID The ID of the user who sent the message 25 | * @param {String} channelID The ID of the channel which the message was sent to 26 | * @param {String} message The message itself 27 | * @param {[type]} rawEvent [description] 28 | * @return {Boolean|Void} Returns false when the bot should do nothing, returns nothing otherwise 29 | */ 30 | function handleMessage(user, userID, channelID, message, rawEvent) { 31 | if (configModule.get().debug) { 32 | console.log( 33 | chalk.yellow('DEBUG:'), 34 | chalk.blue('handleMessage()'), 35 | user, chalk.blue(`(${typeof user})`), 36 | userID, chalk.blue(`(${typeof userID})`), 37 | channelID, chalk.blue(`(${typeof channelID})`), 38 | message, chalk.blue(`(${typeof message})`) 39 | ); 40 | console.log(''); // Empty line 41 | } 42 | 43 | // Only listen on the server defined by the config.cson 44 | if (bot.channels[channelID].guild_id !== configModule.get().serverID) return false; 45 | 46 | // Ignore messages by the bot itself 47 | if (userID === bot.id) return false; 48 | 49 | // Check if channel is ignored 50 | if (configModule.get().ignoreChannels) { 51 | for (let channelName of configModule.get().ignoreChannels) { 52 | channelName = channelName.replace('#', ''); 53 | 54 | for (let id in bot.servers[configModule.get().serverID].channels) { 55 | if (Object.prototype.hasOwnProperty.call(bot.servers[configModule.get().serverID].channels, id)) { 56 | const channel = bot.servers[configModule.get().serverID].channels[id]; 57 | 58 | if (channel.type !== 'text') continue; 59 | 60 | if (channel.name === channelName && channel.id === channelID) return false; 61 | } 62 | } 63 | } 64 | } 65 | 66 | // Checks if a mention is required by the config.cson 67 | if (configModule.get().mentionRequired) { 68 | // Check if the bot got mentioned 69 | if (message.indexOf('<@' + bot.id + '>') !== 0) return false; 70 | 71 | // Remove the mention from the message 72 | message = message 73 | .substring(('<@' + bot.id + '>').length) 74 | .trim(); 75 | } 76 | 77 | // Check if the global command prefix is on the first position of the message 78 | if (message.indexOf(configModule.get().globalCommandPrefix) !== 0) return false; 79 | 80 | // Remove the global command prefix from the message 81 | message = message 82 | .substring(configModule.get().globalCommandPrefix.length) 83 | .trim(); 84 | 85 | // There is no requested command 86 | if (message.length < 1) return false; 87 | 88 | // Check if the cooldown of the user is already expired or if the user is the owner 89 | if (configModule.get().commandCooldown && commandHistory[userID] && userID !== configModule.get().ownerID) { 90 | const timeDifference = new Date().getTime() - commandHistory[userID].getTime(); 91 | // The cooldown is not yet expired 92 | if (timeDifference < configModule.get().commandCooldown) return false; 93 | } 94 | commandHistory[userID] = new Date(); 95 | 96 | // Split message by spaces 97 | message = message.split(' '); 98 | 99 | // Search for the command 100 | for (const key in plugins) { 101 | if (Object.prototype.hasOwnProperty.call(plugins, key)) { 102 | const plugin = plugins[key]; 103 | 104 | // Get the command prefix of the plugin 105 | let pluginCommandPrefix = configModule.get().plugins && configModule.get().plugins[plugin.name] && configModule.get().plugins[plugin.name].commandPrefix && configModule.get().plugins[plugin.name].commandPrefix.length > 0 106 | ? configModule.get().plugins[plugin.name].commandPrefix 107 | : plugin.defaultCommandPrefix; 108 | 109 | if (!pluginCommandPrefix || message[0] === pluginCommandPrefix) { 110 | // Remove the prefix of the plugin from the message 111 | if (pluginCommandPrefix) message.shift(); 112 | 113 | for (const command in plugin.commands) { 114 | if (Object.prototype.hasOwnProperty.call(plugin.commands, command)) { 115 | // Create a list with enabled synonyms for this command 116 | let synonyms = []; 117 | 118 | // Check plugins default synonyms 119 | if (plugin.commands[command].synonyms) synonyms = plugin.commands[command].synonyms; 120 | 121 | if (synonyms.indexOf(command) < 0) synonyms.unshift(command); 122 | 123 | // Check config.cson for synonyms 124 | if ( 125 | configModule.get().plugins 126 | && configModule.get().plugins[plugin.name] 127 | && configModule.get().plugins[plugin.name].commands 128 | && configModule.get().plugins[plugin.name].commands[command] 129 | && configModule.get().plugins[plugin.name].commands[command].synonyms 130 | ) { 131 | for (const synonym in configModule.get().plugins[plugin.name].commands[command].synonyms) { 132 | if (Object.prototype.hasOwnProperty.call(configModule.get().plugins[plugin.name].commands[command].synonyms, synonym)) { 133 | if (configModule.get().plugins[plugin.name].commands[command].synonyms[synonym].enabled) { 134 | if (synonyms.indexOf(synonym) < 0) synonyms.push(synonym); 135 | } else if (configModule.get().plugins[plugin.name].commands[command].synonyms[synonym].enabled === false) { 136 | const index = synonyms.indexOf(synonym); 137 | if (index >= 0) synonyms.splice(index, 1); 138 | } 139 | } 140 | } 141 | } 142 | 143 | if (synonyms.indexOf(message[0]) >= 0) { 144 | // Remove the requested command from the message 145 | message.shift(); 146 | 147 | // Check the permissions of the command 148 | let permissionRequiredByConfig = null; 149 | if ( 150 | configModule.get().plugins 151 | && configModule.get().plugins[plugin.name] 152 | && configModule.get().plugins[plugin.name].commands 153 | && configModule.get().plugins[plugin.name].commands[command] 154 | && configModule.get().plugins[plugin.name].commands[command].requirePermission 155 | ) { 156 | permissionRequiredByConfig = true; 157 | } else if ( 158 | configModule.get().plugins 159 | && configModule.get().plugins[plugin.name] 160 | && configModule.get().plugins[plugin.name].commands 161 | && configModule.get().plugins[plugin.name].commands[command] 162 | && configModule.get().plugins[plugin.name].commands[command].requirePermission === false 163 | ) { 164 | permissionRequiredByConfig = false; 165 | } 166 | 167 | if (permissionRequiredByConfig !== null) { 168 | if (permissionRequiredByConfig && !api.isOperator(userID, plugin.name + ':' + command, channelID)) return false; 169 | } else if (plugin.commands[command].requirePermission && !api.isOperator(userID, plugin.name + ':' + command, channelID)) { 170 | return false; 171 | } 172 | 173 | // Check the command requires an channel 174 | if ( 175 | configModule.get().plugins 176 | && configModule.get().plugins[plugin.name] 177 | && configModule.get().plugins[plugin.name].commands 178 | && configModule.get().plugins[plugin.name].commands[command] 179 | && configModule.get().plugins[plugin.name].commands[command].channel 180 | ) { 181 | const requestChannel = configModule.get().plugins[plugin.name].commands[command].channel.replace('#', ''); 182 | 183 | for (const id in bot.servers[configModule.get().serverID].channels) { 184 | if (Object.prototype.hasOwnProperty.call(bot.servers[configModule.get().serverID].channels, id)) { 185 | const channel = bot.servers[configModule.get().serverID].channels[id]; 186 | 187 | if (channel.type !== 'text') continue; 188 | 189 | if (channel.name === requestChannel && channel.id !== channelID) { 190 | bot.sendMessage({ 191 | to: channelID, 192 | message: `You can request this command only here <#${channel.id}>`, 193 | }); 194 | return false; 195 | } 196 | } 197 | } 198 | } 199 | 200 | // 201 | message = message.join(' '); 202 | 203 | // Execute the command 204 | plugin.commands[command].fn(user, userID, channelID, message, rawEvent); 205 | return true; 206 | } 207 | } 208 | } 209 | } 210 | } 211 | } 212 | 213 | return false; 214 | } 215 | 216 | // Start the discord instance 217 | bot = new Discord.Client({ 218 | token: configModule.get().credentials.token, 219 | autorun: true, 220 | }); 221 | 222 | // Discord instance is ready 223 | bot.on('ready', () => { 224 | console.log(chalk.green('Discord API')); 225 | console.log('Connected'); 226 | console.log(''); // Empty line 227 | 228 | console.log(chalk.green('Plugins')); 229 | for (const name in configModule.get().plugins) { 230 | if (Object.prototype.hasOwnProperty.call(configModule.get().plugins, name)) { 231 | if (!Object.prototype.hasOwnProperty.call(plugins, name)) { 232 | console.log(chalk.red(`${name} failed to load`)); 233 | continue; 234 | } 235 | 236 | console.log(name + ' loaded'); 237 | } 238 | } 239 | console.log(''); // Empty line 240 | 241 | reconnectInterval = null; 242 | 243 | const userInfo = {}; 244 | 245 | // Set the name of the bot to the one defined in the config.cson 246 | if (configModule.get().credentials.name && configModule.get().credentials.name.trim() && bot.username !== configModule.get().credentials.name.trim()) userInfo.username = configModule.get().credentials.name; 247 | 248 | // Set the avatar of the bot to the one defined in the config.cson 249 | if (configModule.get().credentials.avatar && configModule.get().credentials.avatar !== null) { 250 | const reg = new RegExp(/^(http(s)?:\/\/.){1}(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/, 'gi'); 251 | if (reg.test(configModule.get().credentials.avatar)) { 252 | request({ 253 | url: configModule.get().credentials.avatar, 254 | encoding: null, 255 | }, (error, response, body) => { 256 | if (error) { 257 | console.log(chalk.red(error)); 258 | console.log(error); 259 | console.log(''); // Empty line 260 | return false; 261 | } 262 | 263 | userInfo.avatar = new Buffer(body).toString('base64'); 264 | }); 265 | } else { 266 | userInfo.avatar = fs.readFileSync(configModule.get().credentials.avatar, 'base64'); 267 | } 268 | 269 | // TODO: Check if new avatar is already set (issue #56) 270 | } else if (configModule.get().credentials.avatar === null) { 271 | userInfo.avatar = null; 272 | } 273 | 274 | bot.editUserInfo(userInfo, error => { 275 | if (error) { 276 | console.log(chalk.red(error)); 277 | console.log(error); 278 | console.log(''); // Empty line 279 | return false; 280 | } 281 | }); 282 | 283 | // Listen for update events 284 | events.on('update', data => { 285 | // Send private message to owner 286 | if (!configModule.get().ownerID) return false; 287 | 288 | bot.sendMessage({ 289 | to: configModule.get().ownerID, 290 | message: 'There is a new version available for the bot.\n\n' 291 | + 'Visit to download the latest version.\n' 292 | + 'Check out the CHANGELOG.md file for important changes.\n\n' 293 | + `Your version: ${data.currentVersion}\n` 294 | + `Latest version: ${data.latestVersion}\n`, 295 | }); 296 | }); 297 | 298 | console.log(chalk.green('Discord Bot API started.')); 299 | console.log('v' + packageJSON.version); 300 | console.log(''); // Empty line 301 | }); 302 | 303 | // Try to reconnect 304 | bot.on('disconnect', () => { 305 | clearInterval(reconnectInterval); 306 | 307 | console.log(chalk.red('Discord Bot API disconnected.')); 308 | console.log('Trying to reconnect ...'); 309 | console.log(''); // Empty line 310 | 311 | reconnectInterval = setInterval(() => { 312 | bot.connect(); 313 | }, 15000); 314 | }); 315 | 316 | // Trigger on incomming message 317 | bot.on('message', handleMessage); 318 | 319 | 320 | // Make the discord instance, API endpoints and config available for plugins 321 | export default bot; 322 | -------------------------------------------------------------------------------- /src/modules/config.js: -------------------------------------------------------------------------------- 1 | // Discord Bot API 2 | import events from './events'; 3 | 4 | // Other 5 | import chalk from 'chalk'; 6 | import CSON from 'cson'; 7 | import fs from 'fs'; 8 | 9 | 10 | let config = {}; // The config.cson will be stored in this object 11 | let reloadConfig = null; 12 | 13 | 14 | // Save the new config 15 | function save(callback) { 16 | const csonString = CSON.createCSONString(config); 17 | 18 | fs.writeFile('./config.cson', csonString, (error) => { 19 | if (error) { 20 | console.log(chalk.red(error)); 21 | console.log(''); // Empty line 22 | callback(error); 23 | return false; 24 | } 25 | 26 | callback(); 27 | }); 28 | } 29 | 30 | 31 | function get() { 32 | if (!config.globalCommandPrefix || config.globalCommandPrefix.trim() === '') config.globalCommandPrefix = '!'; 33 | return config; 34 | } 35 | 36 | 37 | function enablePlugin(name, callback) { 38 | config.plugins[name] = {}; 39 | save((error) => { 40 | if (error) { 41 | callback(error); 42 | return false; 43 | } 44 | 45 | callback(); 46 | return true; 47 | }); 48 | } 49 | 50 | 51 | function rename(name, callback) { 52 | config.credentials.name = name; 53 | 54 | save((error) => { 55 | if (error) { 56 | callback(error); 57 | return false; 58 | } 59 | 60 | callback(); 61 | return true; 62 | }); 63 | } 64 | 65 | 66 | function op(userID, permissions, callback) { 67 | if (Object.prototype.hasOwnProperty.call(!config, 'operators')) config.operators = {}; 68 | 69 | if (Object.prototype.hasOwnProperty.call(!config.operators, userID)) { 70 | config.operators[userID] = { 71 | permissions: [], 72 | }; 73 | } 74 | 75 | if (Object.prototype.hasOwnProperty.call(!config.operators[userID], 'permissions')) config.operators[userID].permissions = []; 76 | 77 | for (const permission of permissions) { 78 | if (config.operators[userID].permissions.indexOf(permission) < 0) config.operators[userID].permissions.push(permission); 79 | } 80 | 81 | save((error) => { 82 | if (error) { 83 | callback(error); 84 | return false; 85 | } 86 | 87 | callback(); 88 | return true; 89 | }); 90 | } 91 | 92 | 93 | function deop(userID, permissions, callback) { 94 | for (const permission of permissions) { 95 | if ( 96 | !config.operators 97 | || !config.operators[userID] 98 | || !config.operators[userID].permissions 99 | || config.operators[userID].permissions.indexOf(permission) < 0 100 | ) { 101 | callback('no such permission'); 102 | return false; 103 | } 104 | 105 | config.operators[userID].permissions.splice(config.operators[userID].permissions.indexOf(permission), 1); 106 | } 107 | 108 | if (config.operators[userID].permissions.length === 0) delete config.operators[userID].permissions; 109 | 110 | save((error) => { 111 | if (error) { 112 | callback(error); 113 | return false; 114 | } 115 | 116 | callback(); 117 | return true; 118 | }); 119 | } 120 | 121 | 122 | function prefix(newPrefix, callback) { 123 | config.globalCommandPrefix = newPrefix; 124 | 125 | save((error) => { 126 | if (error) { 127 | callback(error); 128 | return false; 129 | } 130 | 131 | callback(); 132 | return true; 133 | }); 134 | } 135 | 136 | 137 | function owner(newOwner, callback) { 138 | config.ownerID = newOwner; 139 | 140 | save((error) => { 141 | if (error) { 142 | callback(error); 143 | return false; 144 | } 145 | 146 | callback(); 147 | return true; 148 | }); 149 | } 150 | 151 | 152 | function avatar(path, callback) { 153 | config.credentials.avatar = path === 'null' ? null : path; 154 | 155 | save((error) => { 156 | if (error) { 157 | callback(error); 158 | return false; 159 | } 160 | 161 | callback(); 162 | return true; 163 | }); 164 | } 165 | 166 | 167 | function reload(callback) { 168 | config = CSON.load('./config.cson'); // Load the config from the config.cson 169 | events.emit('config reloaded'); 170 | automaticReload(); // eslint-disable-line no-use-before-define 171 | if (callback) callback(); 172 | } 173 | reload(); 174 | 175 | function automaticReload() { 176 | clearInterval(reloadConfig); 177 | 178 | if (!config.reloadConfig && config.reloadConfig !== 0) { 179 | reloadConfig = setInterval(() => { 180 | reload(); 181 | }, 5000); 182 | return true; 183 | } 184 | 185 | if (Math.ceil(config.reloadConfig) === 0) return false; 186 | 187 | if (isNaN(config.reloadConfig)) { 188 | console.log(chalk.red('The reload time of the config defined in your "config.cson" is invalid. Therefore it defaults to 5 seconds.')); 189 | return false; 190 | } 191 | 192 | reloadConfig = setInterval(() => { 193 | reload(); 194 | }, Math.ceil(config.reloadConfig) * 1000); 195 | } 196 | 197 | 198 | if (!config.credentials) { 199 | throw new Error('You have to set the credentials in your config.cson.'); 200 | } 201 | 202 | if (!config.credentials.token) { 203 | throw new Error('You have to set the token in your config.cson.'); 204 | } 205 | 206 | if (!config.serverID) { 207 | throw new Error('You have to set the server id in your config.cson so that the bot will listen only on one server.'); 208 | } 209 | 210 | if (!config.plugins || Object.keys(config.plugins).length < 1) { 211 | console.log(chalk.red('There are no plugins enabled in your config.cson.')); 212 | console.log(''); // Empty line 213 | } 214 | 215 | if (!config.ownerID) { 216 | console.log(chalk.red('You should set an owner id in your config.cson to give you the full control over the bot.')); 217 | console.log(''); // Empty line 218 | } 219 | 220 | 221 | const configModule = { 222 | save, 223 | get, 224 | enablePlugin, 225 | rename, 226 | op, 227 | deop, 228 | prefix, 229 | owner, 230 | reload, 231 | avatar, 232 | }; 233 | 234 | export default configModule; 235 | -------------------------------------------------------------------------------- /src/modules/events.js: -------------------------------------------------------------------------------- 1 | import Events from 'events'; 2 | 3 | 4 | const events = new Events.EventEmitter(); 5 | 6 | export default events; 7 | -------------------------------------------------------------------------------- /src/modules/plugins.js: -------------------------------------------------------------------------------- 1 | // Discord Bot API 2 | import configModule from './config'; 3 | 4 | 5 | const plugins = {}; 6 | 7 | 8 | function enablePlugin(name, callback) { 9 | if (Object.prototype.hasOwnProperty.call(plugins, name)) { 10 | callback('already enabled'); 11 | return true; 12 | } 13 | 14 | try { 15 | const plugin = require('../plugins/' + name); 16 | plugins[name] = plugin.default; 17 | 18 | if (Object.prototype.hasOwnProperty.call(configModule.get().plugins, name)) { 19 | callback(); 20 | } else { 21 | configModule.enablePlugin(name, () => { 22 | callback(); 23 | }); 24 | } 25 | } catch (e) { 26 | callback('failed to load'); 27 | } 28 | } 29 | 30 | 31 | // Plugins 32 | for (const pluginName in configModule.get().plugins) { 33 | if (Object.prototype.hasOwnProperty.call(configModule.get().plugins, pluginName)) { 34 | const plugin = require('../plugins/' + pluginName); 35 | plugins[pluginName] = plugin.default; 36 | } 37 | } 38 | 39 | 40 | export { 41 | plugins, 42 | enablePlugin, 43 | }; 44 | -------------------------------------------------------------------------------- /src/plugins/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonknittel/discord-bot-api/f08197268defcb19144811711ea0af5ca4a4af85/src/plugins/.gitkeep -------------------------------------------------------------------------------- /src/plugins/dice.js: -------------------------------------------------------------------------------- 1 | /** 2 | * # dice plugin 3 | * 4 | * ## Install 5 | * 1. Copy the plugin to the `plugins` directory. 6 | * 2. Start your bot and enable the plugin with `!enable dice` 7 | * 8 | * ## Commands 9 | * * `!dice roll ` - Rolls a dice with `` faces. 10 | * + Example: `!dice roll 5` - Rolls a dice with 5 faces 11 | */ 12 | 13 | 14 | // Discord Bot API 15 | import bot from '../modules/bot'; 16 | 17 | 18 | function rollCommand(user, userID, channelID, message) { 19 | message = message.split(' '); 20 | 21 | if (message.length < 1 || message[0].length < 1 || isNaN(message[0])) { 22 | bot.sendMessage({ 23 | to: channelID, 24 | message: 'You have to define the amount of faces.', 25 | }); 26 | 27 | return false; 28 | } 29 | 30 | const faces = Number(message[0]); 31 | const result = Math.floor(Math.random() * faces) + 1; 32 | 33 | bot.sendMessage({ 34 | to: channelID, 35 | message: user + ' rolled a ' + result, 36 | }); 37 | } 38 | 39 | 40 | const plugin = { 41 | name: 'dice', 42 | defaultCommandPrefix: 'dice', 43 | commands: { 44 | roll: { 45 | fn: rollCommand, 46 | description: 'Rolls a dice', 47 | }, 48 | }, 49 | }; 50 | 51 | export default plugin; 52 | -------------------------------------------------------------------------------- /src/plugins/general.js: -------------------------------------------------------------------------------- 1 | // Discord Bot API 2 | import configModule from '../modules/config'; 3 | import bot from '../modules/bot'; 4 | import {plugins} from '../modules/plugins'; 5 | 6 | // Other 7 | import chalk from 'chalk'; 8 | import packageJSON from '../../package'; 9 | import request from 'request'; 10 | import fs from 'fs'; 11 | 12 | 13 | /** 14 | * Returns a short description about the bot. 15 | * @method aboutCommand 16 | * @param {[type]} user [description] 17 | * @param {Interger} userID [description] 18 | * @param {Integer} channelID [description] 19 | * @return {Void} Returns nothing 20 | */ 21 | function aboutCommand(user, userID, channelID) { 22 | bot.sendMessage({ 23 | to: channelID, 24 | message: 'Hey there, my name is the `Discord Bot API`. I\'m made by Simon Knittel (hallo@simonknittel.de) and I\'m based on the Node.js library called discord.io (). My main feature is to offer a API for plugins that can be used with me. Visit <' + packageJSON.homepage + '> for more information. If you find bugs or have other issues please report them here <' + packageJSON.bugs.url + '>. Enter `' + configModule.get().globalCommandPrefix + 'commands` to get all my commands.', 25 | }); 26 | } 27 | 28 | function commandsCommand(user, userID, channelID) { 29 | let string = ''; 30 | 31 | // Search for the commands 32 | for (const key in plugins) { 33 | if (Object.prototype.hasOwnProperty.call(plugins, key)) { 34 | const plugin = plugins[key]; 35 | 36 | string += '\n**' + plugin.name + '**\n'; 37 | 38 | // Get the command prefix of the plugin 39 | const pluginCommandPrefix = 40 | configModule.get().plugins 41 | && configModule.get().plugins[plugin.name] 42 | && configModule.get().plugins[plugin.name].commandPrefix 43 | && configModule.get().plugins[plugin.name].commandPrefix.length > 0 44 | ? configModule.get().plugins[plugin.name].commandPrefix 45 | : plugin.defaultCommandPrefix; 46 | 47 | for (const command in plugin.commands) { 48 | if (Object.prototype.hasOwnProperty.call(plugin.commands, command)) { 49 | // Create a list with enabled synonyms for this command 50 | let synonyms = []; 51 | 52 | // Check plugins default synonyms 53 | if (plugin.commands[command].synonyms) synonyms = plugin.commands[command].synonyms; 54 | 55 | if (synonyms.indexOf(command) < 0) synonyms.unshift(command); 56 | 57 | // Check config.cson for synonyms 58 | if ( 59 | configModule.get().plugins 60 | && configModule.get().plugins[plugin.name] 61 | && configModule.get().plugins[plugin.name].commands 62 | && configModule.get().plugins[plugin.name].commands[command] 63 | && configModule.get().plugins[plugin.name].commands[command].synonyms 64 | ) { 65 | for (const synonym in configModule.get().plugins[plugin.name].commands[command].synonyms) { 66 | if (Object.prototype.hasOwnProperty.call(configModule.get().plugins[plugin.name].commands[command].synonyms, synonym)) { 67 | if (configModule.get().plugins[plugin.name].commands[command].synonyms[synonym].enabled) { 68 | if (synonyms.indexOf(synonym) < 0) synonyms.push(synonym); 69 | } else if (configModule.get().plugins[plugin.name].commands[command].synonyms[synonym].enabled === false) { 70 | const index = synonyms.indexOf(synonym); 71 | if (index >= 0) synonyms.splice(index, 1); 72 | } 73 | } 74 | } 75 | } 76 | 77 | // Compile string 78 | string += '`' + configModule.get().globalCommandPrefix 79 | + (pluginCommandPrefix ? pluginCommandPrefix + ' ' : '') 80 | + synonyms[0] + '`' 81 | + ' ' + plugin.commands[command].description; 82 | 83 | synonyms.shift(); 84 | 85 | if (synonyms.length > 0) { 86 | string += ' (synonyms: `' + synonyms.join('`, `') + '`)' + "\n"; 87 | } else { 88 | string += "\n"; 89 | } 90 | } 91 | } 92 | 93 | string += '\n'; 94 | } 95 | } 96 | 97 | bot.sendMessage({ 98 | to: channelID, 99 | message: string, 100 | }); 101 | } 102 | 103 | // function configCommand(user, userID, channelID, message) { 104 | // message = message.split(' '); 105 | // 106 | // // Check if a property and a new value is present 107 | // if (message.length < 2) { 108 | // bot.sendMessage({ 109 | // to: channelID, 110 | // message: 'Example use of this command: `!config credentials.name The Best Bot`', 111 | // }); 112 | // 113 | // return false; 114 | // } 115 | // 116 | // let changingProperty = message[0].split('.'); 117 | // message.shift(); // Remove the property from the message 118 | // let newValue = message.join(' '); 119 | // if (newValue === 'true') { // Make a boolean to a true boolean type 120 | // newValue = true; 121 | // } else if (newValue === 'false') { // Make a boolean to a true boolean type 122 | // newValue = false; 123 | // } else if (isNaN(newValue)) { // Make a number to a true number type 124 | // newValue = newValue; 125 | // } else { 126 | // newValue = Number(newValue); 127 | // } 128 | // 129 | // // Create a object 130 | // let newConfig = {}; 131 | // for (let i = changingProperty.length - 1; i >= 0; i--) { 132 | // if (i === changingProperty.length - 1) { 133 | // newConfig[changingProperty[i]] = newValue; 134 | // } else { 135 | // let lastSegment = JSON.parse(JSON.stringify(newConfig)); 136 | // newConfig = {}; 137 | // newConfig[changingProperty[i]] = lastSegment; 138 | // } 139 | // } 140 | // 141 | // // Save the new config 142 | // configModule.save(newConfig, error => { 143 | // if (error) { 144 | // console.error(error); 145 | // bot.sendMessage({ 146 | // to: channelID, 147 | // message: 'There was a problem with saving the new config.', 148 | // }); 149 | // 150 | // return false; 151 | // } 152 | // 153 | // bot.sendMessage({ 154 | // to: channelID, 155 | // message: 'Config successfully changed.', 156 | // }); 157 | // }); 158 | // } 159 | 160 | function killCommand() { 161 | bot.disconnect(); 162 | 163 | // throw new Error('The Discord Bot API got stopped through the kill command.'); 164 | 165 | console.log(chalk.yellow('The Discord Bot API got stopped through the kill command.')); 166 | console.log(''); // Empty line 167 | process.exit(); 168 | } 169 | 170 | function userIDCommand(user, userID, channelID) { 171 | bot.sendMessage({ 172 | to: channelID, 173 | message: 'Your ID: `' + userID + '`', 174 | }); 175 | } 176 | 177 | function enableCommand(user, userID, channelID, message) { 178 | const pluginName = message.split(' ')[0].toLowerCase(); 179 | 180 | if (pluginName.length < 1) { 181 | bot.sendMessage({ 182 | to: channelID, 183 | message: 'You have to provide the name of the plugin.', 184 | }); 185 | return false; 186 | } 187 | 188 | configModule.enablePlugin(pluginName, (error) => { 189 | if (error === 'failed to load') { 190 | bot.sendMessage({ 191 | to: channelID, 192 | message: 'The plugin `' + pluginName + '` could not be enabled.', 193 | }); 194 | console.log(chalk.red('Plugin ' + pluginName + ' failed to load')); 195 | console.log(''); // Empty line 196 | return false; 197 | } else if (error === 'already enabled') { 198 | bot.sendMessage({ 199 | to: channelID, 200 | message: 'The plugin is already enabled.', 201 | }); 202 | return false; 203 | } else if (error !== null) { 204 | bot.sendMessage({ 205 | to: channelID, 206 | message: 'The plugin `' + pluginName + '` could not be enabled.', 207 | }); 208 | console.log(chalk.red('Plugin ' + pluginName + ' could not be enabled')); 209 | console.log(chalk.red(error)); 210 | console.log(''); // Empty line 211 | return false; 212 | } 213 | 214 | bot.sendMessage({ 215 | to: channelID, 216 | message: 'Plugin successfully enabled.', 217 | }); 218 | console.log('Plugin ' + pluginName + ' loaded'); 219 | console.log(''); // Empty line 220 | return true; 221 | }); 222 | } 223 | 224 | // function restartCommand() {} 225 | 226 | function renameCommand(user, userID, channelID, message) { 227 | if (message.length < 1) { 228 | bot.sendMessage({ 229 | to: channelID, 230 | message: 'You have to add the new name.', 231 | }); 232 | return false; 233 | } 234 | 235 | configModule.rename(message, error => { 236 | if (error) { 237 | bot.sendMessage({ 238 | to: channelID, 239 | message: 'There was an error with saving the new name to your `config.cson`.', 240 | }); 241 | return false; 242 | } 243 | 244 | if (bot.username === message.trim()) { 245 | bot.sendMessage({ 246 | to: channelID, 247 | message: 'No renaming needed.', 248 | }); 249 | return false; 250 | } 251 | 252 | bot.editUserInfo({ 253 | username: message, 254 | }, error => { 255 | if (error) { 256 | console.log(chalk.red(error)); 257 | console.log(error); 258 | console.log(''); // Empty line 259 | 260 | bot.sendMessage({ 261 | to: channelID, 262 | message: 'There was an error with renaming the bot. Check out the console for more information.', 263 | }); 264 | return false; 265 | } 266 | 267 | bot.sendMessage({ 268 | to: channelID, 269 | message: 'Bot successfully renamed.', 270 | }); 271 | }); 272 | }); 273 | } 274 | 275 | // Check if a user is known to he bot 276 | function isUserKnown(userID) { 277 | for (const id in bot.users) if (userID === id) return true; 278 | return false; 279 | } 280 | 281 | // Get the id from a user from a mention 282 | function getIDFromMention(mention) { 283 | if (mention.indexOf('<@') === 0) { 284 | mention = mention.replace('<@', ''); 285 | mention = mention.replace('>', ''); 286 | } 287 | 288 | return mention; 289 | } 290 | 291 | function opCommand(user, userID, channelID, message) { 292 | message = message.split(' '); 293 | 294 | // Eihter user id/mention or permission is missing 295 | if (message.length < 2) { 296 | bot.sendMessage({ 297 | to: channelID, 298 | message: 'You have to add the user ID and the permission.', 299 | }); 300 | return false; 301 | } 302 | 303 | const operatorID = getIDFromMention(message[0]); 304 | if (!isUserKnown(operatorID)) { 305 | bot.sendMessage({ 306 | to: channelID, 307 | message: 'The bot does not know the user.', 308 | }); 309 | return false; 310 | } 311 | 312 | message.shift(); // Remove the user id/mention from the message to leave only the permissions in the message 313 | 314 | configModule.op(operatorID, message, (error) => { 315 | if (error) { 316 | bot.sendMessage({ 317 | to: channelID, 318 | message: 'There was an error with saving the new permission to your `config.cson`.', 319 | }); 320 | return false; 321 | } 322 | 323 | bot.sendMessage({ 324 | to: channelID, 325 | message: 'Permission successfully given.', 326 | }); 327 | return true; 328 | }); 329 | } 330 | 331 | function deopCommand(user, userID, channelID, message) { 332 | message = message.split(' '); 333 | 334 | // Eihter user id/mention or permission is missing 335 | if (message.length < 2) { 336 | bot.sendMessage({ 337 | to: channelID, 338 | message: 'You have to add the user ID and the permission.', 339 | }); 340 | return false; 341 | } 342 | 343 | const operatorID = getIDFromMention(message[0]); 344 | if (!isUserKnown(operatorID)) { 345 | bot.sendMessage({ 346 | to: channelID, 347 | message: 'The bot does not know the user.', 348 | }); 349 | return false; 350 | } 351 | 352 | message.shift(); // Remove the user id/mention from the message to leave only the permissions in the message 353 | 354 | configModule.deop(operatorID, message, (error) => { 355 | if (error === 'no such permission') { 356 | bot.sendMessage({ 357 | to: channelID, 358 | message: 'The user does not have such a permission.', 359 | }); 360 | return false; 361 | } else if (error) { 362 | bot.sendMessage({ 363 | to: channelID, 364 | message: 'There was an error with saving the removal of the permission to your `config.cson`.', 365 | }); 366 | return false; 367 | } 368 | 369 | bot.sendMessage({ 370 | to: channelID, 371 | message: 'Permission successfully removed.', 372 | }); 373 | return true; 374 | }); 375 | } 376 | 377 | function prefixCommand(user, userID, channelID, message) { 378 | // Parse only the first part behind the command 379 | const newPrefix = message.split(' ')[0]; 380 | 381 | // Message is empty = no new prefix in the message found 382 | if (newPrefix.length < 1) { 383 | bot.sendMessage({ 384 | to: channelID, 385 | message: 'You have to add the new prefix.', 386 | }); 387 | return false; 388 | } 389 | 390 | configModule.prefix(newPrefix, (error) => { 391 | if (error) { 392 | bot.sendMessage({ 393 | to: channelID, 394 | message: 'There was an error with saving the new prefix to your `config.cson`.', 395 | }); 396 | return false; 397 | } 398 | 399 | bot.sendMessage({ 400 | to: channelID, 401 | message: 'Prefix successfully set.', 402 | }); 403 | return true; 404 | }); 405 | } 406 | 407 | function ownerCommand(user, userID, channelID, message) { 408 | // Parse only the first part behind the command 409 | let newOwner = message.trim().split(' ')[0]; 410 | 411 | // Message is empty = no new owner in the message found 412 | if (newOwner.length < 1) { 413 | bot.sendMessage({ 414 | to: channelID, 415 | message: 'You have to add the user id of the new owner or mention him.', 416 | }); 417 | return false; 418 | } 419 | 420 | newOwner = getIDFromMention(newOwner); 421 | 422 | if (!isUserKnown(newOwner)) { 423 | bot.sendMessage({ 424 | to: channelID, 425 | message: 'The bot does not know the user.', 426 | }); 427 | return false; 428 | } 429 | 430 | configModule.owner(newOwner, (error) => { 431 | if (error) { 432 | bot.sendMessage({ 433 | to: channelID, 434 | message: 'There was an error with saving the new owner to your `config.cson`.', 435 | }); 436 | return false; 437 | } 438 | 439 | bot.sendMessage({ 440 | to: channelID, 441 | message: 'Owner successfully changed.', 442 | }); 443 | return true; 444 | }); 445 | } 446 | 447 | function reloadCommand(user, userID, channelID) { 448 | configModule.reload((error) => { 449 | if (error) { 450 | bot.sendMessage({ 451 | to: channelID, 452 | message: 'There was an error with loading your `config.cson`.', 453 | }); 454 | return false; 455 | } 456 | 457 | bot.sendMessage({ 458 | to: channelID, 459 | message: '`config.cson` successfully reloaded.', 460 | }); 461 | return true; 462 | }); 463 | } 464 | 465 | function setAvatar(base64, channelID) { 466 | // TODO: Check if new avatar is already set (issue #56) 467 | 468 | bot.editUserInfo({ 469 | avatar: base64, 470 | password: configModule.get().credentials.password, 471 | }, error => { 472 | if (error) { 473 | console.log(chalk.red(error)); 474 | console.log(error); 475 | console.log(''); // Empty line 476 | return false; 477 | } 478 | 479 | bot.sendMessage({ 480 | to: channelID, 481 | message: 'Avatar successfully changed.', 482 | }); 483 | }); 484 | } 485 | 486 | function avatarCommand(user, userID, channelID, message) { 487 | const path = message.split(' ')[0]; 488 | if (path.length < 1) { 489 | bot.sendMessage({ 490 | to: channelID, 491 | message: 'You have to add a relative path or an url to the new avatar.', 492 | }); 493 | return false; 494 | } 495 | 496 | configModule.avatar(path, error => { 497 | if (error) { 498 | bot.sendMessage({ 499 | to: channelID, 500 | message: 'There was an error with saving the new avatar to your `config.cson`.', 501 | }); 502 | return false; 503 | } 504 | 505 | // Set the avatar of the bot to the one defined in the config.cson 506 | if (configModule.get().credentials.avatar && configModule.get().credentials.avatar !== null) { 507 | const reg = new RegExp(/^(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/, 'gi'); 508 | if (reg.test(configModule.get().credentials.avatar)) { 509 | request({ 510 | url: configModule.get().credentials.avatar, 511 | encoding: null, 512 | }, (error, response, body) => { 513 | if (!error && response.statusCode === 200) { 514 | setAvatar(new Buffer(body).toString('base64'), channelID); 515 | } else { 516 | console.log(chalk.red('The avatar could not be set. Make sure the path is correct.')); 517 | } 518 | }); 519 | } else { 520 | setAvatar(fs.readFileSync(configModule.get().credentials.avatar, 'base64'), channelID); 521 | } 522 | } else if (configModule.get().credentials.avatar === null) { 523 | bot.editUserInfo({ 524 | avatar: null, 525 | password: configModule.get().credentials.password, 526 | }, () => { 527 | bot.sendMessage({ 528 | to: channelID, 529 | message: 'Avatar successfully changed.', 530 | }); 531 | }); 532 | } 533 | }); 534 | } 535 | 536 | 537 | const plugin = { 538 | name: 'general', 539 | commands: { 540 | about: { 541 | fn: aboutCommand, 542 | description: 'Shows a short description of the bot', 543 | }, 544 | commands: { 545 | fn: commandsCommand, 546 | description: 'Shows all available commands', 547 | synonyms: [ 548 | 'help', 549 | ], 550 | }, 551 | kill: { 552 | fn: killCommand, 553 | description: 'Stops the bot', 554 | requirePermission: true, 555 | synonyms: [ 556 | 'stop', 557 | ], 558 | }, 559 | userid: { 560 | fn: userIDCommand, 561 | description: 'Returns the ID of the user', 562 | synonyms: [ 563 | 'me', 564 | ], 565 | }, 566 | enable: { 567 | fn: enableCommand, 568 | description: 'Enables a plugin', 569 | requirePermission: true, 570 | }, 571 | // restart: { 572 | // fn: restartCommand, 573 | // description: 'Restarts the bot', 574 | // requirePermission: true, 575 | // }, 576 | rename: { 577 | fn: renameCommand, 578 | description: 'Renames the bot', 579 | requirePermission: true, 580 | }, 581 | op: { 582 | fn: opCommand, 583 | description: 'Adds a permission to a user', 584 | requirePermission: true, 585 | }, 586 | deop: { 587 | fn: deopCommand, 588 | description: 'Removes a permission from a user', 589 | requirePermission: true, 590 | }, 591 | prefix: { 592 | fn: prefixCommand, 593 | description: 'Changes to global command prefix', 594 | requirePermission: true, 595 | }, 596 | owner: { 597 | fn: ownerCommand, 598 | description: 'Changes the owner of the bot', 599 | requirePermission: true, 600 | }, 601 | reload: { 602 | fn: reloadCommand, 603 | description: 'Reloads your `config.cson`', 604 | requirePermission: true, 605 | synonyms: [ 606 | 'refresh', 607 | ], 608 | }, 609 | avatar: { 610 | fn: avatarCommand, 611 | description: 'Give the bot an avatar', 612 | requirePermission: true, 613 | }, 614 | }, 615 | }; 616 | 617 | export default plugin; 618 | -------------------------------------------------------------------------------- /src/plugins/music/.gitignore: -------------------------------------------------------------------------------- 1 | Desktop.ini 2 | Thumbs.db 3 | .DS_Store 4 | node_modules/ 5 | npm-debug.log 6 | -------------------------------------------------------------------------------- /src/plugins/music/LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | ========================== 3 | Version 3, 29 June 2007 4 | ========================== 5 | 6 | > Copyright (C) 2007 Free Software Foundation, Inc. 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | 9 | # Preamble 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | # TERMS AND CONDITIONS 72 | 73 | ## 0. Definitions. 74 | 75 | _"This License"_ refers to version 3 of the GNU General Public License. 76 | 77 | _"Copyright"_ also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | _"The Program"_ refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as _"you"_. _"Licensees"_ and 82 | "recipients" may be individuals or organizations. 83 | 84 | To _"modify"_ a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a _"modified version"_ of the 87 | earlier work or a work _"based on"_ the earlier work. 88 | 89 | A _"covered work"_ means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To _"propagate"_ a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To _"convey"_ a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | ## 1. Source Code. 113 | 114 | The _"source code"_ for a work means the preferred form of the work 115 | for making modifications to it. _"Object code"_ means any non-source 116 | form of a work. 117 | 118 | A _"Standard Interface"_ means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The _"System Libraries"_ of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The _"Corresponding Source"_ for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | ## 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | ## 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | ## 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | ## 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | ## 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A _"User Product"_ is either (1) a _"consumer product"_, which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | _"Installation Information"_ for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | ## 7. Additional Terms. 344 | 345 | _"Additional permissions"_ are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | ## 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | ## 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | ## 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An _"entity transaction"_ is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | ## 11. Patents. 472 | 473 | A _"contributor"_ is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's _"essential patent claims"_ are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | ## 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | ## 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | ## 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | ## 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | ## 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | ## 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | # END OF TERMS AND CONDITIONS 622 | -------------------------------------------------------------------------------- /src/plugins/music/README.md: -------------------------------------------------------------------------------- 1 | # music plugin 2 | 3 | ## Enable 4 | 1. Add the name of the plugin to the `plugins` array of the `config.cson` (see [below](#example) for an example) 5 | 6 | 13 | 14 | ## Commands 15 | * `!music add ` - Adds a song to the playlist 16 | + Currently only YouTube supported 17 | + Example: `!music add https://www.youtube.com/watch?v=iyqfHvoUtkU` 18 | + Synonyms: `!music new ` 19 | * `!music remove ` - Removes a song from the playlist 20 | + Example: `!music remove 1` 21 | + Synonyms: `!music rm`, `!music delete` 22 | * `!music skip` - Skips the current song 23 | * `!music play` - Starts the playlist 24 | + Synonyms: `!music start` 25 | * `!music stop` - Stops the playlist 26 | * `!music current` - Displays the current song 27 | + Synonyms: `!music now` 28 | * `!music playlist` - Displays all songs on the playlist 29 | + Synonyms: `!music queue` 30 | * `!music join ` - Lets the bot enter a voice channel. 31 | + If you leave the channel name empty, it will join your current voice channel 32 | + Example: `!music join General` 33 | + Synonyms: `!music enter ` 34 | 35 | ## Config 36 | You can configure the `music` by extending your `config.cson` with the following: 37 | 38 | * `commandPrefix` With this you can set a custom command prefix for this plugin. 39 | + Optional 40 | + Default: `music` 41 | * `library` With this you can define where the songs should be downloaded to. 42 | + Optional 43 | + Default: `C:/Windows/Temp` (Windows) or `/tmp` (Unix) 44 | * `skipLimit` With this you can define how many users you need to skip the current song. 45 | + Optional 46 | + Default: `1` 47 | * `announceSongs` With this you can enable or disable the announcing of the current song. 48 | + Optional 49 | + Default: `true` 50 | * `autoJoinVoiceChannel` With this you can define a voice channel which the bot trys to join when it starts. 51 | + Optional 52 | * `maxLength` With this you can define what should be the max length (in minutes!) of a song. 53 | + If set to `0` there will be no limit. 54 | + Numbers with decimals will be rounden up. 55 | + Optional 56 | + Default: `15` 57 | 58 | ## Example 59 | ```cson 60 | plugins: 61 | music: 62 | commandPrefix: "music", 63 | library: "../music", 64 | skipLimit: 1, 65 | announceSongs: true, 66 | autoJoinVoiceChannel: "General", 67 | maxLength: 15 68 | ``` 69 | 70 | ## Need help? 71 | Join my Discord server: https://discord.gg/0jV29zKlvdJbDx3f 72 | 73 | ## License 74 | Copyright (C) 2017 Simon Knittel () 75 | 76 | This program is free software: you can redistribute it and/or modify 77 | it under the terms of the GNU General Public License as published by 78 | the Free Software Foundation, either version 3 of the License, or 79 | (at your option) any later version. 80 | 81 | This program is distributed in the hope that it will be useful, 82 | but WITHOUT ANY WARRANTY; without even the implied warranty of 83 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 84 | GNU General Public License for more details. 85 | 86 | You should have received a copy of the GNU General Public License 87 | along with this program. If not, see . 88 | -------------------------------------------------------------------------------- /src/plugins/music/index.js: -------------------------------------------------------------------------------- 1 | // Discord Bot API 2 | import configModule from '../../modules/config'; 3 | import bot from '../../modules/bot'; 4 | import events from '../../modules/events'; 5 | 6 | // Other 7 | import fetchVideoInfo from 'youtube-info'; 8 | import mkdirp from 'mkdirp'; 9 | import YoutubeMp3Downloader from 'youtube-mp3-downloader'; 10 | import fs from 'fs'; 11 | import chalk from 'chalk'; 12 | import os from 'os'; 13 | 14 | 15 | const libraryPath = configModule.get().plugins.music.library ? configModule.get().plugins.music.library + '/youtube' : (os.platform() === 'win32' ? 'C:/Windows/Temp/discord-bot-api/youtube' : '/tmp/discord-bot-api/youtube'); 16 | 17 | const youtubeOptions = { 18 | outputPath: libraryPath, 19 | queueParallelism: 10, 20 | }; 21 | 22 | if (configModule.get().plugins.music.ffmpeg) youtubeOptions.ffmpegPath = configModule.get().plugins.music.ffmpeg; 23 | 24 | 25 | let YD = new YoutubeMp3Downloader(youtubeOptions); 26 | 27 | events.on('config reloaded', () => { 28 | if (configModule.get().plugins.music.ffmpeg) youtubeOptions.ffmpegPath = configModule.get().plugins.music.ffmpeg; 29 | YD = new YoutubeMp3Downloader(youtubeOptions); 30 | }); 31 | 32 | const playlist = []; // All requested songs will be saved in this array 33 | let voiceChannelID = null; // The ID of the voice channel the bot has entered will be saved in this variable 34 | let currentSong = null; // The current song will be saved in this variable 35 | const downloadQueue = {}; 36 | let usersWantToSkip = []; // The id of the users that want to skip the current song will be stored in this array 37 | let currentStream = null; 38 | 39 | let disableLiveDownloadProgress = true; // Because of rate limiting 40 | 41 | let finishedListener = function() { // Wrapper lets this function called only once (because of the weird event emits from the YouTube download library) 42 | finishedListener = function() {}; 43 | 44 | YD.on('finished', (error, data) => { 45 | if (configModule.get().debug) { 46 | console.log( 47 | chalk.yellow('DEBUG:'), 48 | chalk.blue('YD.on(\'finished\', () => {});') 49 | ); 50 | console.log(''); // Empty line 51 | } 52 | 53 | // Add the song to the playlist 54 | playlist.push({ 55 | rawVideoInfo: data, 56 | file: data.file, 57 | }); 58 | 59 | bot.editMessage({ 60 | channelID: downloadQueue['yt:' + data.videoId].channelID, 61 | messageID: downloadQueue['yt:' + data.videoId].messageID, 62 | message: '💾 Downloaded the requested video.', 63 | }, error => { 64 | if (error) { 65 | console.log(chalk.red(error)); 66 | console.log(error); 67 | console.log(''); // Empty line 68 | } 69 | }); 70 | 71 | bot.sendMessage({ 72 | to: downloadQueue['yt:' + data.videoId].channelID, 73 | message: '✅ `' + data.videoTitle + '` added to the playlist. Position: ' + playlist.length, 74 | }); 75 | 76 | delete downloadQueue['yt:' + data.videoId]; 77 | }); 78 | } 79 | 80 | let errorListener = function() { // Wrapper lets this function called only once (because of the weird event emits from the YouTube download library) 81 | errorListener = function() {}; 82 | 83 | YD.on('error', error => { 84 | console.log(chalk.red(error)); 85 | console.log(error); 86 | console.log(''); // Empty line 87 | return false; 88 | 89 | // bot.sendMessage({ 90 | // to: downloadQueue['yt:' + error.videoId].channelID, 91 | // message: '⛔ The download of <' + error.youtubeURL + '> failed. Check out terminal of the bot to get more information.', 92 | // }); 93 | // delete downloadQueue['yt:' + error.videoId]; 94 | }); 95 | } 96 | 97 | // Live updates of the `Downloading the requested video ...` message 98 | let liveProgress = function() { // Wrapper lets this function called only once (because of the weird event emits from the YouTube download library) 99 | liveProgress = function() {}; 100 | 101 | YD.on('progress', (data) => { 102 | if (downloadQueue['yt:' + data.videoId] && downloadQueue['yt:' + data.videoId].noLiveProgress === false) { 103 | bot.editMessage({ 104 | channelID: downloadQueue['yt:' + data.videoId].channelID, 105 | messageID: downloadQueue['yt:' + data.videoId].messageID, 106 | message: Math.floor(data.progress.percentage) === 100 ? '💾 Downloaded the requested video.' : '💾 Downloading the requested video (' + Math.floor(data.progress.percentage) + '%) ... ', 107 | }, error => { 108 | if (error) { 109 | console.log(chalk.red(error)); 110 | console.log(error); 111 | console.log(''); // Empty line 112 | return false; 113 | } 114 | }); 115 | } 116 | }); 117 | } 118 | 119 | /** 120 | * Iterate through the playlist until there are no songs anymore 121 | * @method playLoop 122 | * @param {String} channelID The ID of the channel were the song was requested 123 | * @return {Void} Returns nothing 124 | */ 125 | function playLoop(channelID) { 126 | // Check if the bot is in a voice channel 127 | if (voiceChannelID) { 128 | if (playlist.length < 1) { 129 | bot.sendMessage({ 130 | to: channelID, 131 | message: 'The playlist is empty.', 132 | }); 133 | return false; 134 | } 135 | 136 | if (currentSong !== null) currentSong.unpipe(); 137 | const nextSong = playlist[0]; // Get the first song of the playlist 138 | playlist.shift(); // Removes the now playing song from the playlist 139 | currentSong = nextSong; 140 | usersWantToSkip = []; 141 | bot.setPresence({ 142 | game: { 143 | name: '🎶 ' + nextSong.rawVideoInfo.videoTitle, 144 | }, 145 | }); 146 | 147 | const announceSongs = configModule.get().plugins.music.announceSongs === false ? false : true; 148 | if (announceSongs) { 149 | bot.sendMessage({ 150 | to: channelID, 151 | message: '🎶 Now playing: `' + nextSong.rawVideoInfo.videoTitle + '`', 152 | }); 153 | } 154 | 155 | bot.getAudioContext(voiceChannelID, (error, stream) => { 156 | currentStream = fs.createReadStream(currentSong.file); 157 | currentStream.pipe(stream, {end: false}); 158 | 159 | stream.once('done', function() { 160 | if (!currentSong) return false; 161 | 162 | setTimeout(() => { 163 | currentSong = null; 164 | bot.setPresence({ 165 | game: null, 166 | }); 167 | 168 | playLoop(channelID); 169 | }, 2000); 170 | }); 171 | }); 172 | } else { 173 | bot.sendMessage({ 174 | to: channelID, 175 | message: '⛔ The bot is not in a voice channel.', 176 | }); 177 | } 178 | } 179 | 180 | function extractYouTubeID(url, channelID) { 181 | const regExp = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/; 182 | const matches = url.match(regExp); 183 | if (matches && matches[2].length === 11) return matches[2]; 184 | 185 | bot.sendMessage({ 186 | to: channelID, 187 | message: '⛔ This seems to be an invalid link.', 188 | }); 189 | return false; 190 | } 191 | 192 | function addCommand(user, userID, channelID, message) { 193 | // Get the URL from the message (it should be the first element after the command) 194 | const urls = message.trim().split(' '); 195 | const multiple = urls.length > 1; 196 | 197 | if (urls.length < 1) { 198 | bot.sendMessage({ 199 | to: channelID, 200 | message: '⛔ You have to add at least one link to your command.', 201 | }); 202 | 203 | return false; 204 | } 205 | 206 | // Parse multiple URLs at once 207 | for (let i = 0; i < urls.length; i++) { 208 | const url = urls[i]; 209 | 210 | // Add timeout to get no 403 error from the YouTube servers 211 | setTimeout(() => { 212 | // Extract YouTube ID 213 | const youtubeID = extractYouTubeID(url, channelID); 214 | if (!youtubeID) return false; 215 | 216 | // Fetch meta data from YouTube video 217 | fetchVideoInfo(youtubeID, (error, videoInfo) => { 218 | if (error) { 219 | console.error(error, youtubeID); 220 | bot.sendMessage({ 221 | to: channelID, 222 | message: '⛔ This seems to be an invalid link.', 223 | }); 224 | return false; 225 | } 226 | 227 | // Check length of video 228 | let maxLength = configModule.get().plugins.music.maxLength; 229 | if (maxLength && isNaN(maxLength)) { 230 | console.log(chalk.red('The max length of a song defined in your "config.cson" is invalid. Therefore the download of ') + videoInfo.url + chalk.red(' will be stopped.')); 231 | bot.sendMessage({ 232 | to: channelID, 233 | message: '⛔ The max length of a song defined in your "config.cson" is invalid. Therefore the download will be stopped.', 234 | }); 235 | return false; 236 | } else if (Math.ceil(maxLength) === 0) { 237 | 238 | } else if (videoInfo.duration / 60 > Math.ceil(maxLength)) { 239 | bot.sendMessage({ 240 | to: channelID, 241 | message: `⛔ The video is too long. Only videos up to ${Math.round(maxLength)} minutes are allowed.`, 242 | }); 243 | return false; 244 | } else if (videoInfo.duration / 60 > 15) { 245 | bot.sendMessage({ 246 | to: channelID, 247 | message: '⛔ The video is too long. Only videos up to 15 minutes are allowed.', 248 | }); 249 | return false; 250 | } 251 | 252 | // Create download directory 253 | mkdirp(libraryPath, error => { 254 | if (error) { 255 | console.log(chalk.red(error)); 256 | console.log(error); 257 | console.log(''); // Empty line 258 | 259 | bot.sendMessage({ 260 | to: channelID, 261 | message: '⛔ There was a problem with downloading the video. Check out terminal of the bot to get more information.', 262 | }); 263 | 264 | return false; 265 | } 266 | 267 | // Check if already downloaded 268 | const filePath = libraryPath + '/' + videoInfo.videoId + '.mp3'; 269 | fs.access(filePath, fs.F_OK, error => { 270 | if (error) { // File not already downloaded 271 | const message = disableLiveDownloadProgress !== true && multiple ? `💾 Downloading the requested video${multiple ? '' : ' (0%)'} ...` : '💾 Downloading the requested video ...'; 272 | 273 | bot.sendMessage({ 274 | to: channelID, 275 | message: message, 276 | }, (error, response) => { 277 | if (error) { 278 | console.log(chalk.red(error)); 279 | console.log(error); 280 | console.log(''); // Empty line 281 | } 282 | 283 | downloadQueue['yt:' + videoInfo.videoId] = { 284 | channelID, 285 | messageID: response.id, 286 | noLiveProgress: multiple, 287 | }; 288 | 289 | // Download the requested song 290 | YD.download(videoInfo.videoId, videoInfo.videoId + '.mp3'); 291 | finishedListener(); 292 | errorListener(); 293 | if (disableLiveDownloadProgress !== true) liveProgress(); 294 | }); 295 | } else { // Already downloaded 296 | // Add the song to the playlist 297 | playlist.push({ 298 | rawVideoInfo: videoInfo, 299 | file: filePath, 300 | }); 301 | 302 | bot.sendMessage({ 303 | to: channelID, 304 | message: '✅ `' + videoInfo.title + '` added to the playlist. Position: ' + playlist.length, 305 | }, error => { 306 | if (error) { 307 | console.log(chalk.red(error)); 308 | console.log(error); 309 | console.log(''); // Empty line 310 | } 311 | }); 312 | } 313 | }); 314 | }); 315 | }); 316 | }, 1000 * i); 317 | } 318 | } 319 | 320 | function removeCommand(user, userID, channelID, message) { 321 | const itemsToRemove = message.split(' '); 322 | 323 | if (itemsToRemove.length < 1) { 324 | bot.sendMessage({ 325 | to: channelID, 326 | message: '⛔ You have to add atleast one songs to your command.', 327 | }); 328 | 329 | return false; 330 | } 331 | 332 | let removedItems = []; 333 | 334 | for (const index of itemsToRemove) { 335 | if (index < 1 || index > itemsToRemove.length) continue; 336 | 337 | removedItems.push(index + '. ' + playlist[index - 1].rawVideoInfo.videoTitle + "\r\n"); 338 | playlist.splice(index - 1, 1); 339 | } 340 | 341 | if (removedItems.length < 1) { 342 | bot.sendMessage({ 343 | to: channelID, 344 | message: '⛔ No songs removed.', 345 | }); 346 | 347 | return true; 348 | } 349 | 350 | bot.sendMessage({ 351 | to: channelID, 352 | message: '✅ Songs removed from the playlist:' + "\r\n" + '```' + removedItems.join('') + '```', 353 | }); 354 | } 355 | 356 | function skipCommand(user, userID, channelID) { 357 | // Check if the bot is in a voice channel 358 | if (voiceChannelID) { 359 | if (usersWantToSkip.indexOf(userID) === -1) usersWantToSkip.push(userID); 360 | 361 | const skipLimit = configModule.get().plugins.music.skipLimit ? configModule.get().plugins.music.skipLimit : 1; 362 | if (usersWantToSkip.length >= skipLimit) { 363 | currentStream.unpipe(); 364 | currentSong = null; 365 | bot.setPresence({ 366 | game: null, 367 | }); 368 | 369 | setTimeout(() => { 370 | playLoop(channelID); 371 | }, 2000); 372 | } else { 373 | bot.sendMessage({ 374 | to: channelID, 375 | message: `⛔ You need ${skipLimit - usersWantToSkip.length} more to skip the current song.`, 376 | }); 377 | } 378 | } else { 379 | bot.sendMessage({ 380 | to: channelID, 381 | message: '⛔ The bot is not in a voice channel.', 382 | }); 383 | } 384 | } 385 | 386 | // Leaves every voice channel. 387 | function leave() { 388 | if (currentStream !== null) stopCommand(); 389 | 390 | // It's needed to loop over all channels, because after a reconnect the previous voice channel is unknown 391 | for (const channelID in bot.channels) { 392 | if (bot.channels[channelID].type === 'voice') { 393 | bot.leaveVoiceChannel(channelID); 394 | } 395 | } 396 | } 397 | 398 | function enter(message, isID, callback) { 399 | leave(); 400 | 401 | if (isID) { 402 | bot.joinVoiceChannel(message); 403 | voiceChannelID = message; 404 | return true; 405 | } 406 | 407 | let notFound = true; 408 | // Look for the ID of the requested channel 409 | for (const channelID in bot.channels) { 410 | if (bot.channels[channelID].name.toLowerCase() === message.toLowerCase() && bot.channels[channelID].type === 'voice') { 411 | voiceChannelID = channelID; 412 | notFound = false; 413 | } 414 | } 415 | 416 | if (notFound) { 417 | callback(); 418 | return false; 419 | } 420 | 421 | bot.joinVoiceChannel(voiceChannelID, (error, events) => { 422 | // Implementaion for issue #53 423 | // events.on('speaking', (userID, SSRC, speakingBool) => { 424 | // // Ignore the bots own events 425 | // if (userID === bot.id) return false; 426 | // 427 | // // Check if speaking user is in the same channel 428 | // if (!bot.channels[voiceChannelID].members[userID]) return false; 429 | // 430 | // // Reduce the volume 431 | // if (speakingBool) { // Started speaking 432 | // console.log('started'); 433 | // } else { // Stopped speaking 434 | // console.log('stopped'); 435 | // } 436 | // }); 437 | }); 438 | 439 | return true; 440 | } 441 | 442 | function enterCommand(user, userID, channelID, message) { 443 | let isID = false; 444 | if ( 445 | message.length < 1 446 | && bot.servers[configModule.get().serverID].members[userID].voice_channel_id 447 | ) { 448 | isID = true; 449 | message = bot.servers[configModule.get().serverID].members[userID].voice_channel_id; 450 | } else if (message.length < 1) { 451 | bot.sendMessage({ 452 | to: channelID, 453 | message: '⛔ You have to add the channel name which the bot should join.', 454 | }); 455 | return false; 456 | } 457 | 458 | enter(message, isID, () => { 459 | bot.sendMessage({ 460 | to: channelID, 461 | message: `⛔ There is no channel named ${message}.`, 462 | }); 463 | }); 464 | } 465 | 466 | function playCommand(user, userID, channelID) { 467 | if (!voiceChannelID) { 468 | bot.sendMessage({ 469 | to: channelID, 470 | message: '⛔ The bot is not in a voice channel.', 471 | }); 472 | } else if (playlist.length <= 0) { 473 | bot.sendMessage({ 474 | to: channelID, 475 | message: '⛔ There are currently no entries on the playlist.', 476 | }); 477 | } else { 478 | playLoop(channelID); 479 | } 480 | } 481 | 482 | function stopCommand() { 483 | events.emit('stop music'); 484 | currentStream.unpipe(); 485 | currentSong = null; 486 | bot.setPresence({ 487 | game: null, 488 | }); 489 | } 490 | 491 | function currentCommand(user, userID, channelID) { 492 | // Check if a song is playing 493 | if (currentSong) { 494 | bot.sendMessage({ 495 | to: channelID, 496 | message: `🎶 Currently playing: ${currentSong.rawVideoInfo.url}`, 497 | }); 498 | } else { 499 | bot.sendMessage({ 500 | to: channelID, 501 | message: '⛔ There is currently nothing playing.', 502 | }); 503 | } 504 | } 505 | 506 | function playlistCommand(user, userID, channelID) { 507 | // Check if there are songs on the playlist 508 | if (playlist.length < 1) { 509 | bot.sendMessage({ 510 | to: channelID, 511 | message: '⛔ There are currently no entries on the playlist.', 512 | }); 513 | } else { 514 | let string = ''; 515 | let duration = 0; 516 | for (var i = 0; i < playlist.length; i++) { 517 | string += (i + 1) + '. ' + playlist[i].rawVideoInfo.videoTitle + "\r\n"; 518 | duration += playlist[i].rawVideoInfo.duration; 519 | } 520 | 521 | const hours = Math.floor(duration / 3600); 522 | const minutes = Math.floor((duration - (hours * 3600)) / 60); 523 | const seconds = Math.floor(duration % 60); 524 | const durationString = (hours < 10 ? '0' + hours : hours) 525 | + ':' + (minutes < 10 ? '0' + minutes : minutes) 526 | + ':' + (seconds < 10 ? '0' + seconds : seconds); 527 | 528 | string = '```' + playlist.length + ' songs / ' + durationString + ' duration' + "\r\n" + "\r\n" + string + '```'; 529 | 530 | bot.sendMessage({ 531 | to: channelID, 532 | message: '🎶 Current playlist:' + "\r\n" + string, 533 | }); 534 | } 535 | } 536 | 537 | 538 | bot.on('ready', () => { 539 | if (configModule.get().plugins.music.autoJoinVoiceChannel && configModule.get().plugins.music.autoJoinVoiceChannel.length > 0) { 540 | enter(configModule.get().plugins.music.autoJoinVoiceChannel, false, () => { 541 | console.log(chalk.red('The voice channel defined in autoJoinVoiceChannel could not be found.')); 542 | }); 543 | } 544 | }); 545 | 546 | 547 | const plugin = { 548 | name: 'music', 549 | defaultCommandPrefix: 'music', 550 | commands: { 551 | add: { 552 | fn: addCommand, 553 | description: 'Adds a song to the playlist (separate multiple links with a space)', 554 | synonyms: [ 555 | 'new', 556 | ], 557 | }, 558 | remove: { 559 | fn: removeCommand, 560 | description: 'Removes a song from the playlist', 561 | synonyms: [ 562 | 'rm', 563 | 'delete', 564 | ], 565 | }, 566 | skip: { 567 | fn: skipCommand, 568 | description: 'Skips the current song', 569 | }, 570 | enter: { 571 | fn: enterCommand, 572 | description: 'Let the bot enter a voice channel', 573 | synonyms: [ 574 | 'join', 575 | ], 576 | }, 577 | leave: { 578 | fn: leave, 579 | description: 'Leaves the bots current voice channel', 580 | synonyms: [ 581 | 'exit', 582 | ], 583 | }, 584 | play: { 585 | fn: playCommand, 586 | description: 'Starts the playlist', 587 | synonyms: [ 588 | 'start', 589 | ], 590 | }, 591 | stop: { 592 | fn: stopCommand, 593 | description: 'Stops the playlist', 594 | }, 595 | current: { 596 | fn: currentCommand, 597 | description: 'Displays the current song', 598 | synonyms: [ 599 | 'now', 600 | ], 601 | }, 602 | playlist: { 603 | fn: playlistCommand, 604 | description: 'Displays all songs on the playlist', 605 | synonyms: [ 606 | 'queue', 607 | ], 608 | }, 609 | }, 610 | }; 611 | 612 | export default plugin; 613 | -------------------------------------------------------------------------------- /src/plugins/music/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "discord-music", 3 | "description": "This is a music for Discord based on the Discord Bot API (https://github.com/simonknittel/discord-bot-api)", 4 | "author": "Simon Knittel (https://simonknittel.de)", 5 | "homepage": "https://github.com/simonknittel/discord-bot-api", 6 | "keywords": [ 7 | "discord", 8 | "music", 9 | "bot", 10 | "youtube", 11 | "play", 12 | "stream" 13 | ], 14 | "license": "GPL-3.0", 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/simonknittel/discord-bot-api" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/simonknittel/discord-bot-api/issues" 21 | }, 22 | "main": "index.js", 23 | "dependencies": { 24 | "mkdirp": "0.5.1", 25 | "youtube-info": "1.1.1", 26 | "youtube-mp3-downloader": "0.4.4" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/plugins/music/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | ajv@^4.9.1: 6 | version "4.11.5" 7 | resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.5.tgz#b6ee74657b993a01dce44b7944d56f485828d5bd" 8 | dependencies: 9 | co "^4.6.0" 10 | json-stable-stringify "^1.0.1" 11 | 12 | asn1@~0.2.3: 13 | version "0.2.3" 14 | resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" 15 | 16 | assert-plus@1.0.0, assert-plus@^1.0.0: 17 | version "1.0.0" 18 | resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" 19 | 20 | assert-plus@^0.2.0: 21 | version "0.2.0" 22 | resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234" 23 | 24 | async@>=0.2.9, async@^1.5.0: 25 | version "1.5.2" 26 | resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" 27 | 28 | asynckit@^0.4.0: 29 | version "0.4.0" 30 | resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" 31 | 32 | aws-sign2@~0.6.0: 33 | version "0.6.0" 34 | resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f" 35 | 36 | aws4@^1.2.1: 37 | version "1.6.0" 38 | resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" 39 | 40 | bcrypt-pbkdf@^1.0.0: 41 | version "1.0.1" 42 | resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz#63bc5dcb61331b92bc05fd528953c33462a06f8d" 43 | dependencies: 44 | tweetnacl "^0.14.3" 45 | 46 | bluebird@^2.3: 47 | version "2.11.0" 48 | resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1" 49 | 50 | boolbase@~1.0.0: 51 | version "1.0.0" 52 | resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e" 53 | 54 | boom@2.x.x: 55 | version "2.10.1" 56 | resolved "https://registry.yarnpkg.com/boom/-/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f" 57 | dependencies: 58 | hoek "2.x.x" 59 | 60 | caseless@~0.12.0: 61 | version "0.12.0" 62 | resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" 63 | 64 | cheerio@^0.19.0: 65 | version "0.19.0" 66 | resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-0.19.0.tgz#772e7015f2ee29965096d71ea4175b75ab354925" 67 | dependencies: 68 | css-select "~1.0.0" 69 | dom-serializer "~0.1.0" 70 | entities "~1.1.1" 71 | htmlparser2 "~3.8.1" 72 | lodash "^3.2.0" 73 | 74 | cls-bluebird@^1.0.1: 75 | version "1.1.3" 76 | resolved "https://registry.yarnpkg.com/cls-bluebird/-/cls-bluebird-1.1.3.tgz#b3263c11a089b0396185a1b7ab904d90f02ad428" 77 | dependencies: 78 | is-bluebird "^1.0.1" 79 | shimmer "^1.1.0" 80 | 81 | co@^4.6.0: 82 | version "4.6.0" 83 | resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" 84 | 85 | combined-stream@^1.0.5, combined-stream@~1.0.5: 86 | version "1.0.5" 87 | resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009" 88 | dependencies: 89 | delayed-stream "~1.0.0" 90 | 91 | core-util-is@~1.0.0: 92 | version "1.0.2" 93 | resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" 94 | 95 | cryptiles@2.x.x: 96 | version "2.0.5" 97 | resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8" 98 | dependencies: 99 | boom "2.x.x" 100 | 101 | css-select@~1.0.0: 102 | version "1.0.0" 103 | resolved "https://registry.yarnpkg.com/css-select/-/css-select-1.0.0.tgz#b1121ca51848dd264e2244d058cee254deeb44b0" 104 | dependencies: 105 | boolbase "~1.0.0" 106 | css-what "1.0" 107 | domutils "1.4" 108 | nth-check "~1.0.0" 109 | 110 | css-what@1.0: 111 | version "1.0.0" 112 | resolved "https://registry.yarnpkg.com/css-what/-/css-what-1.0.0.tgz#d7cc2df45180666f99d2b14462639469e00f736c" 113 | 114 | dashdash@^1.12.0: 115 | version "1.14.1" 116 | resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" 117 | dependencies: 118 | assert-plus "^1.0.0" 119 | 120 | debug@^2.2.0: 121 | version "2.6.3" 122 | resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d" 123 | dependencies: 124 | ms "0.7.2" 125 | 126 | delayed-stream@~1.0.0: 127 | version "1.0.0" 128 | resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" 129 | 130 | dom-serializer@0, dom-serializer@~0.1.0: 131 | version "0.1.0" 132 | resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.0.tgz#073c697546ce0780ce23be4a28e293e40bc30c82" 133 | dependencies: 134 | domelementtype "~1.1.1" 135 | entities "~1.1.1" 136 | 137 | domelementtype@1, domelementtype@~1.1.1: 138 | version "1.1.3" 139 | resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.1.3.tgz#bd28773e2642881aec51544924299c5cd822185b" 140 | 141 | domhandler@2.3: 142 | version "2.3.0" 143 | resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.3.0.tgz#2de59a0822d5027fabff6f032c2b25a2a8abe738" 144 | dependencies: 145 | domelementtype "1" 146 | 147 | domutils@1.4: 148 | version "1.4.3" 149 | resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.4.3.tgz#0865513796c6b306031850e175516baf80b72a6f" 150 | dependencies: 151 | domelementtype "1" 152 | 153 | domutils@1.5: 154 | version "1.5.1" 155 | resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf" 156 | dependencies: 157 | dom-serializer "0" 158 | domelementtype "1" 159 | 160 | ecc-jsbn@~0.1.1: 161 | version "0.1.1" 162 | resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505" 163 | dependencies: 164 | jsbn "~0.1.0" 165 | 166 | entities@1.0: 167 | version "1.0.0" 168 | resolved "https://registry.yarnpkg.com/entities/-/entities-1.0.0.tgz#b2987aa3821347fcde642b24fdfc9e4fb712bf26" 169 | 170 | entities@~1.1.1: 171 | version "1.1.1" 172 | resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0" 173 | 174 | extend@~3.0.0: 175 | version "3.0.0" 176 | resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.0.tgz#5a474353b9f3353ddd8176dfd37b91c83a46f1d4" 177 | 178 | extsprintf@1.0.2: 179 | version "1.0.2" 180 | resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550" 181 | 182 | fluent-ffmpeg@2.0.1: 183 | version "2.0.1" 184 | resolved "https://registry.yarnpkg.com/fluent-ffmpeg/-/fluent-ffmpeg-2.0.1.tgz#4dddcbb82da348158380d5282d21fd4ea64bf4ce" 185 | dependencies: 186 | async ">=0.2.9" 187 | 188 | forever-agent@~0.6.1: 189 | version "0.6.1" 190 | resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" 191 | 192 | form-data@~2.1.1: 193 | version "2.1.2" 194 | resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.2.tgz#89c3534008b97eada4cbb157d58f6f5df025eae4" 195 | dependencies: 196 | asynckit "^0.4.0" 197 | combined-stream "^1.0.5" 198 | mime-types "^2.1.12" 199 | 200 | getpass@^0.1.1: 201 | version "0.1.6" 202 | resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.6.tgz#283ffd9fc1256840875311c1b60e8c40187110e6" 203 | dependencies: 204 | assert-plus "^1.0.0" 205 | 206 | har-schema@^1.0.5: 207 | version "1.0.5" 208 | resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e" 209 | 210 | har-validator@~4.2.1: 211 | version "4.2.1" 212 | resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-4.2.1.tgz#33481d0f1bbff600dd203d75812a6a5fba002e2a" 213 | dependencies: 214 | ajv "^4.9.1" 215 | har-schema "^1.0.5" 216 | 217 | hawk@~3.1.3: 218 | version "3.1.3" 219 | resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4" 220 | dependencies: 221 | boom "2.x.x" 222 | cryptiles "2.x.x" 223 | hoek "2.x.x" 224 | sntp "1.x.x" 225 | 226 | hoek@2.x.x: 227 | version "2.16.3" 228 | resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" 229 | 230 | html-entities@^1.1.3: 231 | version "1.2.0" 232 | resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.0.tgz#41948caf85ce82fed36e4e6a0ed371a6664379e2" 233 | 234 | htmlparser2@~3.8.1: 235 | version "3.8.3" 236 | resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.8.3.tgz#996c28b191516a8be86501a7d79757e5c70c1068" 237 | dependencies: 238 | domelementtype "1" 239 | domhandler "2.3" 240 | domutils "1.5" 241 | entities "1.0" 242 | readable-stream "1.1" 243 | 244 | http-signature@~1.1.0: 245 | version "1.1.1" 246 | resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.1.1.tgz#df72e267066cd0ac67fb76adf8e134a8fbcf91bf" 247 | dependencies: 248 | assert-plus "^0.2.0" 249 | jsprim "^1.2.2" 250 | sshpk "^1.7.0" 251 | 252 | inherits@~2.0.1: 253 | version "2.0.3" 254 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" 255 | 256 | is-bluebird@^1.0.1: 257 | version "1.0.2" 258 | resolved "https://registry.yarnpkg.com/is-bluebird/-/is-bluebird-1.0.2.tgz#096439060f4aa411abee19143a84d6a55346d6e2" 259 | 260 | is-typedarray@~1.0.0: 261 | version "1.0.0" 262 | resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" 263 | 264 | isarray@0.0.1: 265 | version "0.0.1" 266 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" 267 | 268 | isstream@~0.1.2: 269 | version "0.1.2" 270 | resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" 271 | 272 | jodid25519@^1.0.0: 273 | version "1.0.2" 274 | resolved "https://registry.yarnpkg.com/jodid25519/-/jodid25519-1.0.2.tgz#06d4912255093419477d425633606e0e90782967" 275 | dependencies: 276 | jsbn "~0.1.0" 277 | 278 | jsbn@~0.1.0: 279 | version "0.1.1" 280 | resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" 281 | 282 | json-schema@0.2.3: 283 | version "0.2.3" 284 | resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" 285 | 286 | json-stable-stringify@^1.0.1: 287 | version "1.0.1" 288 | resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af" 289 | dependencies: 290 | jsonify "~0.0.0" 291 | 292 | json-stringify-safe@~5.0.1: 293 | version "5.0.1" 294 | resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" 295 | 296 | jsonify@~0.0.0: 297 | version "0.0.0" 298 | resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" 299 | 300 | jsprim@^1.2.2: 301 | version "1.4.0" 302 | resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.0.tgz#a3b87e40298d8c380552d8cc7628a0bb95a22918" 303 | dependencies: 304 | assert-plus "1.0.0" 305 | extsprintf "1.0.2" 306 | json-schema "0.2.3" 307 | verror "1.3.6" 308 | 309 | lodash.isfunction@^3.0.6: 310 | version "3.0.8" 311 | resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.8.tgz#4db709fc81bc4a8fd7127a458a5346c5cdce2c6b" 312 | 313 | lodash@^3.10.0, lodash@^3.2.0: 314 | version "3.10.1" 315 | resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" 316 | 317 | mime-db@~1.27.0: 318 | version "1.27.0" 319 | resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.27.0.tgz#820f572296bbd20ec25ed55e5b5de869e5436eb1" 320 | 321 | mime-types@^2.1.12, mime-types@~2.1.7: 322 | version "2.1.15" 323 | resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.15.tgz#a4ebf5064094569237b8cf70046776d09fc92aed" 324 | dependencies: 325 | mime-db "~1.27.0" 326 | 327 | minimist@0.0.8: 328 | version "0.0.8" 329 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" 330 | 331 | mkdirp@0.5.1: 332 | version "0.5.1" 333 | resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" 334 | dependencies: 335 | minimist "0.0.8" 336 | 337 | ms@0.7.2: 338 | version "0.7.2" 339 | resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" 340 | 341 | nth-check@~1.0.0: 342 | version "1.0.1" 343 | resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.1.tgz#9929acdf628fc2c41098deab82ac580cf149aae4" 344 | dependencies: 345 | boolbase "~1.0.0" 346 | 347 | oauth-sign@~0.8.1: 348 | version "0.8.2" 349 | resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43" 350 | 351 | object-keys@~0.4.0: 352 | version "0.4.0" 353 | resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-0.4.0.tgz#28a6aae7428dd2c3a92f3d95f21335dd204e0336" 354 | 355 | performance-now@^0.2.0: 356 | version "0.2.0" 357 | resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5" 358 | 359 | progress-stream@^1.2.0: 360 | version "1.2.0" 361 | resolved "https://registry.yarnpkg.com/progress-stream/-/progress-stream-1.2.0.tgz#2cd3cfea33ba3a89c9c121ec3347abe9ab125f77" 362 | dependencies: 363 | speedometer "~0.1.2" 364 | through2 "~0.2.3" 365 | 366 | punycode@^1.4.1: 367 | version "1.4.1" 368 | resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" 369 | 370 | qs@~6.4.0: 371 | version "6.4.0" 372 | resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233" 373 | 374 | readable-stream@1.1, readable-stream@~1.1.9: 375 | version "1.1.14" 376 | resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" 377 | dependencies: 378 | core-util-is "~1.0.0" 379 | inherits "~2.0.1" 380 | isarray "0.0.1" 381 | string_decoder "~0.10.x" 382 | 383 | request-promise@^1.0.2: 384 | version "1.0.2" 385 | resolved "https://registry.yarnpkg.com/request-promise/-/request-promise-1.0.2.tgz#155f410608d9257c089c1d0b26f8d8f7a8aa86a1" 386 | dependencies: 387 | bluebird "^2.3" 388 | cls-bluebird "^1.0.1" 389 | lodash "^3.10.0" 390 | request "^2.34" 391 | 392 | request@^2.34: 393 | version "2.81.0" 394 | resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0" 395 | dependencies: 396 | aws-sign2 "~0.6.0" 397 | aws4 "^1.2.1" 398 | caseless "~0.12.0" 399 | combined-stream "~1.0.5" 400 | extend "~3.0.0" 401 | forever-agent "~0.6.1" 402 | form-data "~2.1.1" 403 | har-validator "~4.2.1" 404 | hawk "~3.1.3" 405 | http-signature "~1.1.0" 406 | is-typedarray "~1.0.0" 407 | isstream "~0.1.2" 408 | json-stringify-safe "~5.0.1" 409 | mime-types "~2.1.7" 410 | oauth-sign "~0.8.1" 411 | performance-now "^0.2.0" 412 | qs "~6.4.0" 413 | safe-buffer "^5.0.1" 414 | stringstream "~0.0.4" 415 | tough-cookie "~2.3.0" 416 | tunnel-agent "^0.6.0" 417 | uuid "^3.0.0" 418 | 419 | safe-buffer@^5.0.1: 420 | version "5.0.1" 421 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7" 422 | 423 | sax@^1.1.3: 424 | version "1.2.2" 425 | resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828" 426 | 427 | shimmer@^1.1.0: 428 | version "1.1.0" 429 | resolved "https://registry.yarnpkg.com/shimmer/-/shimmer-1.1.0.tgz#97d7377137ffbbab425522e429fe0aa89a488b35" 430 | 431 | sntp@1.x.x: 432 | version "1.0.9" 433 | resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198" 434 | dependencies: 435 | hoek "2.x.x" 436 | 437 | speedometer@~0.1.2: 438 | version "0.1.4" 439 | resolved "https://registry.yarnpkg.com/speedometer/-/speedometer-0.1.4.tgz#9876dbd2a169d3115402d48e6ea6329c8816a50d" 440 | 441 | sshpk@^1.7.0: 442 | version "1.11.0" 443 | resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.11.0.tgz#2d8d5ebb4a6fab28ffba37fa62a90f4a3ea59d77" 444 | dependencies: 445 | asn1 "~0.2.3" 446 | assert-plus "^1.0.0" 447 | dashdash "^1.12.0" 448 | getpass "^0.1.1" 449 | optionalDependencies: 450 | bcrypt-pbkdf "^1.0.0" 451 | ecc-jsbn "~0.1.1" 452 | jodid25519 "^1.0.0" 453 | jsbn "~0.1.0" 454 | tweetnacl "~0.14.0" 455 | 456 | string_decoder@~0.10.x: 457 | version "0.10.31" 458 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" 459 | 460 | stringstream@~0.0.4: 461 | version "0.0.5" 462 | resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878" 463 | 464 | through2@~0.2.3: 465 | version "0.2.3" 466 | resolved "https://registry.yarnpkg.com/through2/-/through2-0.2.3.tgz#eb3284da4ea311b6cc8ace3653748a52abf25a3f" 467 | dependencies: 468 | readable-stream "~1.1.9" 469 | xtend "~2.1.1" 470 | 471 | tough-cookie@~2.3.0: 472 | version "2.3.2" 473 | resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.2.tgz#f081f76e4c85720e6c37a5faced737150d84072a" 474 | dependencies: 475 | punycode "^1.4.1" 476 | 477 | tunnel-agent@^0.6.0: 478 | version "0.6.0" 479 | resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" 480 | dependencies: 481 | safe-buffer "^5.0.1" 482 | 483 | tweetnacl@^0.14.3, tweetnacl@~0.14.0: 484 | version "0.14.5" 485 | resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" 486 | 487 | uuid@^3.0.0: 488 | version "3.0.1" 489 | resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" 490 | 491 | verror@1.3.6: 492 | version "1.3.6" 493 | resolved "https://registry.yarnpkg.com/verror/-/verror-1.3.6.tgz#cff5df12946d297d2baaefaa2689e25be01c005c" 494 | dependencies: 495 | extsprintf "1.0.2" 496 | 497 | xtend@~2.1.1: 498 | version "2.1.2" 499 | resolved "https://registry.yarnpkg.com/xtend/-/xtend-2.1.2.tgz#6efecc2a4dad8e6962c4901b337ce7ba87b5d28b" 500 | dependencies: 501 | object-keys "~0.4.0" 502 | 503 | youtube-info@1.1.1: 504 | version "1.1.1" 505 | resolved "https://registry.yarnpkg.com/youtube-info/-/youtube-info-1.1.1.tgz#cab4e48088929cd1ba6e9f5f4800907d281bff55" 506 | dependencies: 507 | cheerio "^0.19.0" 508 | debug "^2.2.0" 509 | lodash.isfunction "^3.0.6" 510 | request-promise "^1.0.2" 511 | 512 | youtube-mp3-downloader@0.4.4: 513 | version "0.4.4" 514 | resolved "https://registry.yarnpkg.com/youtube-mp3-downloader/-/youtube-mp3-downloader-0.4.4.tgz#a6bb41452642b39d5fd2ee35dbaa71888ed50afd" 515 | dependencies: 516 | async "^1.5.0" 517 | fluent-ffmpeg "2.0.1" 518 | progress-stream "^1.2.0" 519 | ytdl-core "^0.7.9" 520 | 521 | ytdl-core@^0.7.9: 522 | version "0.7.24" 523 | resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-0.7.24.tgz#446569beeff09b4b6195f77eb10443a84b9917b9" 524 | dependencies: 525 | html-entities "^1.1.3" 526 | sax "^1.1.3" 527 | --------------------------------------------------------------------------------