From 301b9f9df94a0d6c9f345321d6005a31ddd1372f Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 2 Mar 2020 13:14:14 -0500 Subject: [PATCH] Remove uneeded commands --- README.md | 8 +-- commands/other/hi.js | 20 -------- commands/util/changelog.js | 31 ------------ commands/util/donate.js | 19 ------- commands/util/eval.js | 100 ------------------------------------- commands/util/info.js | 14 ++++-- commands/util/invite.js | 23 --------- commands/util/ip.js | 20 -------- package.json | 12 +++-- structures/Client.js | 2 - types/code.js | 21 -------- util/Util.js | 14 ------ 12 files changed, 17 insertions(+), 267 deletions(-) delete mode 100644 commands/other/hi.js delete mode 100644 commands/util/changelog.js delete mode 100644 commands/util/donate.js delete mode 100644 commands/util/eval.js delete mode 100644 commands/util/invite.js delete mode 100644 commands/util/ip.js delete mode 100644 types/code.js diff --git a/README.md b/README.md index faae67f..77159a1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Rando Cardrissian is a Discord bot coded in JavaScript with primary feature is Cards Against Humanity, but Apples to Apples is also available. -## Commands (15) +## Commands (9) ### Games: * **apples-to-apples:** Compete to see who can come up with the best card to match an adjective. @@ -24,18 +24,12 @@ available. ### Other: -* **hi:** Hello. * **lando:** Responds with a random image of Lando Calrissian. ### Util: -* **changelog:** Responds with the bot's latest 10 commits. -* **donate:** Responds with the bot's donation links. -* **eval:** Executes JavaScript code. * **help:** Displays a list of available commands, or detailed information for a specific command. * **info:** Responds with detailed bot information. -* **invite:** Responds with the bot's invite links. -* **ip:** Responds with the IP address the bot\'s server is running on. * **ping:** Checks the bot's ping to the Discord server. ## Licensing diff --git a/commands/other/hi.js b/commands/other/hi.js deleted file mode 100644 index 6df549f..0000000 --- a/commands/other/hi.js +++ /dev/null @@ -1,20 +0,0 @@ -const { Command } = require('discord-akairo'); - -module.exports = class HiCommand extends Command { - constructor() { - super('hi', { - aliases: ['hi', 'hello', 'hey', 'hoi', 'hola'], - category: 'other', - description: 'Hello.' - }); - } - - async exec(msg) { - try { - await msg.react('👋'); - return null; - } catch (err) { - return msg.util.reply('Hi there!'); - } - } -}; diff --git a/commands/util/changelog.js b/commands/util/changelog.js deleted file mode 100644 index 5d984b1..0000000 --- a/commands/util/changelog.js +++ /dev/null @@ -1,31 +0,0 @@ -const { Command } = require('discord-akairo'); -const { MessageEmbed } = require('discord.js'); -const request = require('node-superfetch'); -const { shorten, base64 } = require('../../util/Util'); -const { GITHUB_USERNAME, GITHUB_PASSWORD, RANDO_GITHUB_REPO_USERNAME, RANDO_GITHUB_REPO_NAME } = process.env; - -module.exports = class ChangelogCommand extends Command { - constructor() { - super('changelog', { - aliases: ['changelog', 'updates', 'commits'], - category: 'util', - description: 'Responds with the bot\'s latest 10 commits.' - }); - } - - async exec(msg) { - const { body } = await request - .get(`https://api.github.com/repos/${RANDO_GITHUB_REPO_USERNAME}/${RANDO_GITHUB_REPO_NAME}/commits`) - .set({ Authorization: `Basic ${base64(`${GITHUB_USERNAME}:${GITHUB_PASSWORD}`)}` }); - const commits = body.slice(0, 10); - const embed = new MessageEmbed() - .setTitle(`[${RANDO_GITHUB_REPO_NAME}:master] Latest 10 commits`) - .setColor(0x7289DA) - .setURL(`https://github.com/${RANDO_GITHUB_REPO_USERNAME}/${RANDO_GITHUB_REPO_NAME}/commits/master`) - .setDescription(commits.map(commit => { - const hash = `[\`${commit.sha.slice(0, 7)}\`](${commit.html_url})`; - return `${hash} ${shorten(commit.commit.message.split('\n')[0], 50)} - ${commit.author.login}`; - }).join('\n')); - return msg.util.send({ embed }); - } -}; diff --git a/commands/util/donate.js b/commands/util/donate.js deleted file mode 100644 index 004a0b7..0000000 --- a/commands/util/donate.js +++ /dev/null @@ -1,19 +0,0 @@ -const { Command } = require('discord-akairo'); -const { stripIndents } = require('common-tags'); - -module.exports = class DonateCommand extends Command { - constructor() { - super('donate', { - aliases: ['donate', 'paypal'], - category: 'util', - description: 'Responds with the bot\'s donation links.' - }); - } - - exec(msg) { - return msg.util.send(stripIndents` - Contribute to development! - - `); - } -}; diff --git a/commands/util/eval.js b/commands/util/eval.js deleted file mode 100644 index e7b29fe..0000000 --- a/commands/util/eval.js +++ /dev/null @@ -1,100 +0,0 @@ -// Credit: https://github.com/discordjs/Commando/blob/master/src/commands/util/eval.js -const { Command } = require('discord-akairo'); -const util = require('util'); -const discord = require('discord.js'); -const { stripIndents } = require('common-tags'); -const { escapeRegex } = require('../../util/Util'); -const nl = '!!NL!!'; -const nlPattern = new RegExp(nl, 'g'); - -module.exports = class EvalCommand extends Command { - constructor() { - super('eval', { - aliases: ['eval', 'evaluate'], - category: 'util', - description: 'Executes JavaScript code.', - ownerOnly: true, - args: [ - { - id: 'script', - prompt: { - start: 'What code would you like to evaluate?', - retry: 'You provided an invalid script. Please try again.' - }, - match: 'content', - type: 'code' - } - ] - }); - - this.lastResult = null; - } - - exec(msg, { script }) { - /* eslint-disable no-unused-vars */ - const { client, lastResult } = this; - const doReply = val => { - if (val instanceof Error) { - msg.reply(`Callback error: \`${val}\``); - } else { - const result = this.makeResultMessages(val, process.hrtime(this.hrStart)); - if (Array.isArray(result)) { - for (const item of result) msg.reply(item); - } else { - msg.reply(result); - } - } - }; - /* eslint-enable no-unused-vars */ - - let hrDiff; - try { - const hrStart = process.hrtime(); - this.lastResult = eval(script.code); - hrDiff = process.hrtime(hrStart); - } catch (err) { - return msg.util.reply(`Error while evaluating: \`${err}\``); - } - - this.hrStart = process.hrtime(); - return msg.util.reply(this.makeResultMessages(this.lastResult, hrDiff, script.code)); - } - - makeResultMessages(result, hrDiff, input = null) { - const inspected = util.inspect(result, { depth: 0 }) - .replace(nlPattern, '\n') - .replace(this.sensitivePattern, '--snip--'); - const split = inspected.split('\n'); - const last = inspected.length - 1; - const prependPart = inspected[0] !== '{' && inspected[0] !== '[' && inspected[0] !== '\'' ? split[0] : inspected[0]; - const appendPart = inspected[last] !== '}' && inspected[last] !== ']' && inspected[last] !== '\'' - ? split[split.length - 1] - : inspected[last]; - const prepend = `\`\`\`javascript\n${prependPart}\n`; - const append = `\n${appendPart}\n\`\`\``; - if (input) { - return discord.splitMessage(stripIndents` - *Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.* - \`\`\`javascript - ${inspected} - \`\`\` - `, { maxLength: 1900, prepend, append }); - } else { - return discord.splitMessage(stripIndents` - *Callback executed after ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.* - \`\`\`javascript - ${inspected} - \`\`\` - `, { maxLength: 1900, prepend, append }); - } - } - - get sensitivePattern() { - if (!this._sensitivePattern) { - let pattern = ''; - if (this.client.token) pattern += escapeRegex(this.client.token); - Object.defineProperty(this, '_sensitivePattern', { value: new RegExp(pattern, 'gi') }); - } - return this._sensitivePattern; - } -}; diff --git a/commands/util/info.js b/commands/util/info.js index 5136a7f..ff49fe4 100644 --- a/commands/util/info.js +++ b/commands/util/info.js @@ -1,5 +1,5 @@ -const { Command } = require('discord-akairo'); -const { MessageEmbed } = require('discord.js'); +const { Command, version: akairoVersion } = require('discord-akairo'); +const { MessageEmbed, version: djsVersion, Permissions } = require('discord.js'); const moment = require('moment'); require('moment-duration-format'); const { version, dependencies } = require('../../package'); @@ -16,20 +16,24 @@ module.exports = class InfoCommand extends Command { }); } - exec(msg) { + async exec(msg) { + const invite = await this.client.generateInvite(Permissions.ALL); const embed = new MessageEmbed() .setColor(0x00AE86) .setFooter('©2018-2020 dragonfire535#8081') .addField('❯ Servers', this.client.guilds.cache.size, true) - .addField('❯ Shards', this.client.options.shardCount, true) .addField('❯ Commands', this.handler.modules.size, true) + .addField('❯ Shards', this.client.options.shardCount, true) .addField('❯ Home Server', INVITE ? `[Invite](${INVITE})` : 'None', true) + .addField('❯ Invite', `[Add Me](${invite})`, true) .addField('❯ Source Code', source ? `[Github](https://github.com/${RANDO_GITHUB_REPO_USERNAME}/${RANDO_GITHUB_REPO_NAME})` : 'N/A', true) .addField('❯ Memory Usage', `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB`, true) .addField('❯ Uptime', moment.duration(this.client.uptime).format('d:hh:mm:ss'), true) .addField('❯ Version', `v${version}`, true) - .addField('❯ Node Version', process.version, true) + .addField('❯ Node.js', process.version, true) + .addField('❯ Discord.js', `v${djsVersion}`, true) + .addField('❯ Akairo', `v${akairoVersion}`, true) .addField('❯ Dependencies', this.parseDependencies(dependencies)); return msg.util.send({ embed }); } diff --git a/commands/util/invite.js b/commands/util/invite.js deleted file mode 100644 index 2e4f4f2..0000000 --- a/commands/util/invite.js +++ /dev/null @@ -1,23 +0,0 @@ -const { Command } = require('discord-akairo'); -const { stripIndents } = require('common-tags'); -const { INVITE, RANDO_GITHUB_REPO_NAME, RANDO_GITHUB_REPO_USERNAME } = process.env; - -module.exports = class InviteCommand extends Command { - constructor() { - super('invite', { - aliases: ['invite', 'join'], - category: 'util', - description: 'Responds with the bot\'s invite links.' - }); - } - - exec(msg) { - return msg.util.send(stripIndents` - You cannot invite me to your server, but you can join my home server to use me: - ${INVITE || 'Coming soon...'} - - You can also self-host me if you prefer: - - `); - } -}; diff --git a/commands/util/ip.js b/commands/util/ip.js deleted file mode 100644 index 23b2162..0000000 --- a/commands/util/ip.js +++ /dev/null @@ -1,20 +0,0 @@ -const { Command } = require('discord-akairo'); -const request = require('node-superfetch'); - -module.exports = class IpCommand extends Command { - constructor() { - super('ip', { - aliases: ['ip'], - category: 'util', - description: 'Responds with the IP address the bot\'s server is running on.', - ownerOnly: true - }); - } - - async exec(msg) { - const { body } = await request - .get('https://api.ipify.org/') - .query({ format: 'json' }); - return msg.util.send(body.ip); - } -}; diff --git a/package.json b/package.json index 235cc5b..7007cf1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rando-cardrissian", - "version": "6.5.2", + "version": "7.0.0", "description": "Cards Against Humanity, but for Discord!", "main": "Rando.js", "scripts": { @@ -32,17 +32,19 @@ "node": ">=12" }, "dependencies": { - "bufferutil": "^4.0.1", "common-tags": "^1.8.0", - "discord-akairo": "github:1Computer1/discord-akairo", - "discord.js": "github:discordjs/discord.js", + "discord-akairo": "^8.0.0-beta.8", + "discord.js": "^12.0.1", "dotenv": "^8.2.0", "moment": "^2.24.0", "moment-duration-format": "^2.3.2", "node-superfetch": "^0.1.10", - "utf-8-validate": "^5.0.2", "winston": "^3.2.1" }, + "optionalDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, "devDependencies": { "eslint": "^6.8.0", "eslint-config-amber": "^2.0.1", diff --git a/structures/Client.js b/structures/Client.js index 781c95b..319886d 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -3,7 +3,6 @@ const { stripIndents } = require('common-tags'); const winston = require('winston'); const path = require('path'); const DeckManager = require('./DeckManager'); -const CodeType = require('../types/code'); module.exports = class Client extends AkairoClient { constructor(options) { @@ -48,7 +47,6 @@ module.exports = class Client extends AkairoClient { setup() { this.commandHandler.loadAll(); - this.commandHandler.resolver.addType('code', CodeType); this.decks.register(path.join(__dirname, '..', 'assets', 'json', 'decks')); } }; diff --git a/types/code.js b/types/code.js deleted file mode 100644 index 2e0694a..0000000 --- a/types/code.js +++ /dev/null @@ -1,21 +0,0 @@ -const codeblock = /```(?:(\S+)\n)?\s*([^]+?)\s*```/i; - -module.exports = async (phrase, msg) => { - if (!phrase) return null; - if (/^[0-9]+$/.test(phrase)) { - try { - const message = await msg.channel.messages.fetch(phrase); - phrase = message.content; - } catch (err) { - return { code: phrase, lang: null }; - } - } - if (codeblock.test(phrase)) { - const parsed = codeblock.exec(phrase); - return { - code: parsed[2], - lang: parsed[1] ? parsed[1].toLowerCase() : null - }; - } - return { code: phrase, lang: null }; -}; diff --git a/util/Util.js b/util/Util.js index 7ce1ba4..67b907d 100644 --- a/util/Util.js +++ b/util/Util.js @@ -10,10 +10,6 @@ module.exports = class Util { return arr; } - static shorten(text, maxLen = 2000) { - return text.length > maxLen ? `${text.substr(0, maxLen - 3)}...` : text; - } - static removeFromArray(arr, value) { return arr.splice(arr.indexOf(value), 1); } @@ -21,14 +17,4 @@ module.exports = class Util { static firstUpperCase(text) { return `${text.charAt(0).toUpperCase()}${text.slice(1)}`; } - - static escapeRegex(str) { - return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); - } - - static base64(text, mode = 'encode') { - if (mode === 'encode') return Buffer.from(text).toString('base64'); - if (mode === 'decode') return Buffer.from(text, 'base64').toString('utf8') || null; - throw new TypeError(`${mode} is not a supported base64 mode.`); - } };