From 5b365d41c0e57553b303ddcce0f7c38bd06e79a4 Mon Sep 17 00:00:00 2001 From: Nate Goldsborough Date: Tue, 9 Feb 2021 21:35:52 -0600 Subject: [PATCH 1/5] add module-alias --- node_modules/module-alias/LICENSE | 21 +++ node_modules/module-alias/index.js | 224 +++++++++++++++++++++++++ node_modules/module-alias/package.json | 77 +++++++++ node_modules/module-alias/register.js | 1 + package-lock.json | 5 + package.json | 1 + 6 files changed, 329 insertions(+) create mode 100644 node_modules/module-alias/LICENSE create mode 100644 node_modules/module-alias/index.js create mode 100644 node_modules/module-alias/package.json create mode 100644 node_modules/module-alias/register.js diff --git a/node_modules/module-alias/LICENSE b/node_modules/module-alias/LICENSE new file mode 100644 index 00000000..3a091022 --- /dev/null +++ b/node_modules/module-alias/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018, Nick Gavrilov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/node_modules/module-alias/index.js b/node_modules/module-alias/index.js new file mode 100644 index 00000000..8f2e570d --- /dev/null +++ b/node_modules/module-alias/index.js @@ -0,0 +1,224 @@ +'use strict' + +var BuiltinModule = require('module') + +// Guard against poorly mocked module constructors +var Module = module.constructor.length > 1 + ? module.constructor + : BuiltinModule + +var nodePath = require('path') + +var modulePaths = [] +var moduleAliases = {} +var moduleAliasNames = [] + +var oldNodeModulePaths = Module._nodeModulePaths +Module._nodeModulePaths = function (from) { + var paths = oldNodeModulePaths.call(this, from) + + // Only include the module path for top-level modules + // that were not installed: + if (from.indexOf('node_modules') === -1) { + paths = modulePaths.concat(paths) + } + + return paths +} + +var oldResolveFilename = Module._resolveFilename +Module._resolveFilename = function (request, parentModule, isMain, options) { + for (var i = moduleAliasNames.length; i-- > 0;) { + var alias = moduleAliasNames[i] + if (isPathMatchesAlias(request, alias)) { + var aliasTarget = moduleAliases[alias] + // Custom function handler + if (typeof moduleAliases[alias] === 'function') { + var fromPath = parentModule.filename + aliasTarget = moduleAliases[alias](fromPath, request, alias) + if (!aliasTarget || typeof aliasTarget !== 'string') { + throw new Error('[module-alias] Expecting custom handler function to return path.') + } + } + request = nodePath.join(aliasTarget, request.substr(alias.length)) + // Only use the first match + break + } + } + + return oldResolveFilename.call(this, request, parentModule, isMain, options) +} + +function isPathMatchesAlias (path, alias) { + // Matching /^alias(\/|$)/ + if (path.indexOf(alias) === 0) { + if (path.length === alias.length) return true + if (path[alias.length] === '/') return true + } + + return false +} + +function addPathHelper (path, targetArray) { + path = nodePath.normalize(path) + if (targetArray && targetArray.indexOf(path) === -1) { + targetArray.unshift(path) + } +} + +function removePathHelper (path, targetArray) { + if (targetArray) { + var index = targetArray.indexOf(path) + if (index !== -1) { + targetArray.splice(index, 1) + } + } +} + +function addPath (path) { + var parent + path = nodePath.normalize(path) + + if (modulePaths.indexOf(path) === -1) { + modulePaths.push(path) + // Enable the search path for the current top-level module + var mainModule = getMainModule() + if (mainModule) { + addPathHelper(path, mainModule.paths) + } + parent = module.parent + + // Also modify the paths of the module that was used to load the + // app-module-paths module and all of it's parents + while (parent && parent !== mainModule) { + addPathHelper(path, parent.paths) + parent = parent.parent + } + } +} + +function addAliases (aliases) { + for (var alias in aliases) { + addAlias(alias, aliases[alias]) + } +} + +function addAlias (alias, target) { + moduleAliases[alias] = target + // Cost of sorting is lower here than during resolution + moduleAliasNames = Object.keys(moduleAliases) + moduleAliasNames.sort() +} + +/** + * Reset any changes maded (resets all registered aliases + * and custom module directories) + * The function is undocumented and for testing purposes only + */ +function reset () { + var mainModule = getMainModule() + + // Reset all changes in paths caused by addPath function + modulePaths.forEach(function (path) { + if (mainModule) { + removePathHelper(path, mainModule.paths) + } + + // Delete from require.cache if the module has been required before. + // This is required for node >= 11 + Object.getOwnPropertyNames(require.cache).forEach(function (name) { + if (name.indexOf(path) !== -1) { + delete require.cache[name] + } + }) + + var parent = module.parent + while (parent && parent !== mainModule) { + removePathHelper(path, parent.paths) + parent = parent.parent + } + }) + + modulePaths = [] + moduleAliases = {} + moduleAliasNames = [] +} + +/** + * Import aliases from package.json + * @param {object} options + */ +function init (options) { + if (typeof options === 'string') { + options = { base: options } + } + + options = options || {} + + var candidatePackagePaths + if (options.base) { + candidatePackagePaths = [nodePath.resolve(options.base.replace(/\/package\.json$/, ''))] + } else { + // There is probably 99% chance that the project root directory in located + // above the node_modules directory, + // Or that package.json is in the node process' current working directory (when + // running a package manager script, e.g. `yarn start` / `npm run start`) + candidatePackagePaths = [nodePath.join(__dirname, '../..'), process.cwd()] + } + + var npmPackage + var base + for (var i in candidatePackagePaths) { + try { + base = candidatePackagePaths[i] + + npmPackage = require(nodePath.join(base, 'package.json')) + break + } catch (e) { + // noop + } + } + + if (typeof npmPackage !== 'object') { + var pathString = candidatePackagePaths.join(',\n') + throw new Error('Unable to find package.json in any of:\n[' + pathString + ']') + } + + // + // Import aliases + // + + var aliases = npmPackage._moduleAliases || {} + + for (var alias in aliases) { + if (aliases[alias][0] !== '/') { + aliases[alias] = nodePath.join(base, aliases[alias]) + } + } + + addAliases(aliases) + + // + // Register custom module directories (like node_modules) + // + + if (npmPackage._moduleDirectories instanceof Array) { + npmPackage._moduleDirectories.forEach(function (dir) { + if (dir === 'node_modules') return + + var modulePath = nodePath.join(base, dir) + addPath(modulePath) + }) + } +} + +function getMainModule () { + return require.main._simulateRepl ? undefined : require.main +} + +module.exports = init +module.exports.addPath = addPath +module.exports.addAlias = addAlias +module.exports.addAliases = addAliases +module.exports.isPathMatchesAlias = isPathMatchesAlias +module.exports.reset = reset diff --git a/node_modules/module-alias/package.json b/node_modules/module-alias/package.json new file mode 100644 index 00000000..28079bac --- /dev/null +++ b/node_modules/module-alias/package.json @@ -0,0 +1,77 @@ +{ + "_from": "module-alias", + "_id": "module-alias@2.2.2", + "_inBundle": false, + "_integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==", + "_location": "/module-alias", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "module-alias", + "name": "module-alias", + "escapedName": "module-alias", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", + "_shasum": "151cdcecc24e25739ff0aa6e51e1c5716974c0e0", + "_spec": "module-alias", + "_where": "C:\\Users\\nathe\\AntaresBot", + "author": { + "name": "Nick Gavrilov", + "email": "artnikpro@gmail.com" + }, + "bugs": { + "url": "https://github.com/ilearnio/module-alias/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Create aliases of directories and register custom module paths", + "devDependencies": { + "chai": "^3.5.0", + "hello-world-classic": "github:ilearnio/hello-world-classic", + "husky": "^3.0.2", + "mocha": "^2.4.5", + "semver": "^6.1.1", + "standard": "^12.0.1" + }, + "files": [ + "index.js", + "register.js", + "README.md", + "LICENSE" + ], + "homepage": "https://github.com/ilearnio/module-alias", + "husky": { + "hooks": { + "pre-push": "npm run test" + } + }, + "keywords": [ + "extend", + "modules", + "node", + "path", + "resolve" + ], + "license": "MIT", + "main": "index.js", + "name": "module-alias", + "repository": { + "type": "git", + "url": "git+https://github.com/ilearnio/module-alias.git" + }, + "scripts": { + "lint": "standard", + "test": "npm run lint && npm run testonly", + "testonly": "NODE_ENV=test mocha test/specs.js", + "testonly-watch": "NODE_ENV=test mocha -w test/specs.js" + }, + "version": "2.2.2" +} diff --git a/node_modules/module-alias/register.js b/node_modules/module-alias/register.js new file mode 100644 index 00000000..5b07ef54 --- /dev/null +++ b/node_modules/module-alias/register.js @@ -0,0 +1 @@ +require('.')() diff --git a/package-lock.json b/package-lock.json index baa75c0b..4b1eedd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -978,6 +978,11 @@ "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" }, + "module-alias": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", + "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" + }, "mongodb": { "version": "3.6.3", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.3.tgz", diff --git a/package.json b/package.json index 8b4c4055..4809bb11 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "discord.js-commando": "^0.11.1", "dotenv": "^8.2.0", "fetch": "^1.1.0", + "module-alias": "^2.2.2", "mongoose": "^5.11.13", "path": "^0.12.7", "random-stuff-api": "^10.0.0", From b33190a5a145975643e5f1866fcd86aa90f672de Mon Sep 17 00:00:00 2001 From: Nate Goldsborough Date: Tue, 9 Feb 2021 22:08:58 -0600 Subject: [PATCH 2/5] added 8ball command --- commands/user/8ball.js | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 commands/user/8ball.js diff --git a/commands/user/8ball.js b/commands/user/8ball.js new file mode 100644 index 00000000..fa0508e6 --- /dev/null +++ b/commands/user/8ball.js @@ -0,0 +1,75 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); +const channelCheck = require('../../functions/channelCheck') +const logToConsole = require('../../actions/logToConsole') + + +module.exports = class EightBallCommand extends Command { + constructor(client) { + super(client, { + name: '8ball', + aliases: ['8-ball', 'ask', 'why'], + group: 'user', + memberName: '8ball', + description: 'Answers all of the questions you might have', + examples: ['8ball Am i a looser'], + args: [ + { + key: 'text', + prompt: 'Please ask me a question', + type: 'string' + } + ], + guildOnly: true + }); + } + + async run(message, { text }) { + + if (await channelCheck.check(message) == true) { + let eightball = [ + 'It is certain.', + 'It is decidedly so.', + 'Without a doubt.', + 'Yes definitely.', + 'You may rely on it.', + 'As I see it, yes.', + 'Most likely.', + 'Outlook good.', + 'Yes.', + 'Signs point to yes.', + 'Reply hazy try again.', + 'Ask again later.', + 'Better not tell you now.', + 'Cannot predict now.', + 'Concentrate and ask again.', + 'Don\'t count on it.', + 'My reply is no.', + 'My sources say no.', + 'Outlook not so good.', + 'Very doubtful.', + 'No way.', + 'Maybe', + 'The answer is hiding inside you', + 'No.', + 'Depends on the mood of the CS god', + 'Hang on', + 'It\'s over', + 'It\'s just the beginning', + 'Good Luck', + ]; + let index = (Math.floor(Math.random() * Math.floor(eightball.length))); + //message.channel.send(eightball[index]); + const EightBallEmbed = new MessageEmbed() + .setColor('#ff3505') + .setURL('https://discord.gg//6pZ2wtGANP') + .setTitle('Get an answer to all your questions') + .setThumbnail(`https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.jpeg`) + .setDescription(`${message.author.username} asks:\n ${text}\n\n **My Answer:**\n ${eightball[index]}`,) + .setFooter(`Delivered in: ${Date.now() - message.createdTimestamp}ms | Antares Bot | ${botVersion}`, 'https://cdn.discordapp.com/icons/649703068799336454/1a7ef8f706cd60d62547d2c7dc08d6f0.png'); + message.channel.send(EightBallEmbed); + } + //send to the console that this command was run + logToConsole.command(message.guild, message); + } +} \ No newline at end of file From be68f7bf71e5a9a13387e472c12e742b5c788b3b Mon Sep 17 00:00:00 2001 From: Nate Goldsborough Date: Wed, 10 Feb 2021 13:05:18 -0600 Subject: [PATCH 3/5] add command alias --- commands/admin/say.js | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/admin/say.js b/commands/admin/say.js index 6aff611c..1c5b87e0 100644 --- a/commands/admin/say.js +++ b/commands/admin/say.js @@ -5,6 +5,7 @@ module.exports = class SayCommand extends Command { constructor(client) { super(client, { name: 'say', + aliases: ['echo',], group: 'admin', memberName: 'say', description: 'Replies with the text you provide.', From 92870a9b017ea73c6e173b360c241f32242c34f4 Mon Sep 17 00:00:00 2001 From: Nate Goldsborough Date: Wed, 10 Feb 2021 15:48:09 -0600 Subject: [PATCH 4/5] update permission requirements --- commands/admin/say.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/admin/say.js b/commands/admin/say.js index 1c5b87e0..beaea349 100644 --- a/commands/admin/say.js +++ b/commands/admin/say.js @@ -18,7 +18,7 @@ module.exports = class SayCommand extends Command { } ], guildOnly: true, - userPermissions: ['ADMINISTRATOR'] + userPermissions: ['MANAGE_MESSAGES'], }); } From 68d83b8a3fa45a2f524d5dcc45757df041efc460 Mon Sep 17 00:00:00 2001 From: Nate Goldsborough Date: Wed, 10 Feb 2021 15:49:49 -0600 Subject: [PATCH 5/5] Update version to 1.3.2 --- index.js | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index ec1c0700..1f5f5cb4 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ const piiModel = require('./models/pii'); const piiCreate = require('./actions/piiCreate'); const counting = require('./functions/counting'); const messageLog = require('./actions/messageLog') -global.botVersion = "1.3.1"; +global.botVersion = "1.3.2"; global.bot = new CommandoClient({ diff --git a/package-lock.json b/package-lock.json index 4b1eedd4..00e3d9cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "antaresbot", - "version": "1.3.1", + "version": "1.3.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4809bb11..e25360d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "antaresbot", - "version": "1.3.1", + "version": "1.3.2", "description": "A rewrite of the Antares bot ", "main": "index.js", "dependencies": {