Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 8e26706fbdeb2eaeae03179f744ed23cb2454aad
parent 74a50e49c26ce9df88e4d06964bda5974e393f49
Author: knutsen <samuel@knutsen.co>
Date:   Thu, 27 May 2021 17:54:29 +0100

Deprecate `Message#answer`.

Diffstat:
Mlib/commands/8ball.ts | 6+++---
Mlib/commands/abbreviate.ts | 4++--
Mlib/commands/alias.ts | 18+++++++++---------
Mlib/commands/b.ts | 4++--
Mlib/commands/boomer.ts | 4++--
Mlib/commands/choose.ts | 6+++---
Mlib/commands/clap.ts | 4++--
Mlib/commands/code.ts | 6+++---
Mlib/commands/coin.ts | 6+++---
Mlib/commands/cowsay.ts | 6+++---
Mlib/commands/cowthink.ts | 6+++---
Mlib/commands/crabbing.ts | 4++--
Mlib/commands/cron.ts | 22+++++++++++-----------
Mlib/commands/define.ts | 10++++++----
Mlib/commands/drug.ts | 6+++---
Mlib/commands/echo.ts | 4++--
Mlib/commands/emojify.ts | 4++--
Mlib/commands/emojis.ts | 4++--
Mlib/commands/epoch.ts | 4++--
Mlib/commands/figlet.ts | 6+++---
Mlib/commands/flip.ts | 4++--
Mlib/commands/fork.ts | 6+++---
Mlib/commands/fortune.ts | 4++--
Mlib/commands/get.ts | 6+++---
Mlib/commands/git.ts | 8++++----
Mlib/commands/github.ts | 6+++---
Mlib/commands/hangman.ts | 4++--
Mlib/commands/help.ts | 8++++----
Mlib/commands/hug.ts | 4++--
Mlib/commands/id.ts | 6+++---
Mlib/commands/ily.ts | 6+++---
Mlib/commands/image.ts | 8++++----
Mlib/commands/instgen.ts | 4++--
Mlib/commands/invite.ts | 6+++---
Mlib/commands/issue.ts | 6+++---
Mlib/commands/kill.ts | 4++--
Mlib/commands/kiss.ts | 4++--
Mlib/commands/license.ts | 4++--
Mlib/commands/lick.ts | 4++--
Mlib/commands/listen.ts | 14+++++++-------
Mlib/commands/milkies.ts | 6+++---
Mlib/commands/mock.ts | 4++--
Mlib/commands/motivation.ts | 4++--
Mlib/commands/pat.ts | 4++--
Mlib/commands/ping.ts | 6+++---
Mlib/commands/pp.ts | 6+++---
Mlib/commands/prefix.ts | 6+++---
Mlib/commands/purr.ts | 4++--
Mlib/commands/rape.ts | 4++--
Mlib/commands/rim.ts | 4++--
Mlib/commands/roll.ts | 6+++---
Mlib/commands/say.ts | 6+++---
Mlib/commands/search.ts | 8++++----
Mlib/commands/set.ts | 6+++---
Mlib/commands/ship.ts | 6+++---
Mlib/commands/slap.ts | 4++--
Mlib/commands/suck.ts | 4++--
Mlib/commands/summon.ts | 4++--
Mlib/commands/system.ts | 4++--
Mlib/commands/translate.ts | 6+++---
Mlib/commands/tts.ts | 4++--
Mlib/commands/uptime.ts | 4++--
Mlib/commands/urban.ts | 12++++++++----
Mlib/commands/uwu.ts | 4++--
Mlib/commands/vape.ts | 4++--
Mlib/commands/vc.ts | 34+++++++++++++++++-----------------
Mlib/commands/weather.ts | 6+++---
Mlib/commands/whitelistchannels.ts | 4++--
Mlib/commands/wikipedia.ts | 6+++---
Mlib/commands/yn.ts | 4++--
Mlib/commands/youtube.ts | 8++++----
Mlib/extensions.ts | 9+++++----
Mlib/main.ts | 18+++++++++---------
Mlib/rule.ts | 16++++++++--------
Mpackage.json | 4++--
Myarn.lock | 36+++++++++++++++++++++++-------------
76 files changed, 271 insertions(+), 254 deletions(-)

diff --git a/lib/commands/8ball.ts b/lib/commands/8ball.ts @@ -1,7 +1,7 @@ import { prefix_friendly, help_info } from '../utils'; -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; if (args.length === 0 || args[0] === 'help') { message.channel.send(help_info('8ball', CONFIG.commands.prefix)); @@ -39,6 +39,6 @@ export default (home_scope: HomeScope) => { "100%" ]; - message.answer(":8ball: " + message.reply(":8ball: " + responses[Math.floor(Math.random() * responses.length)]); }; diff --git a/lib/commands/abbreviate.ts b/lib/commands/abbreviate.ts @@ -1,5 +1,5 @@ -export default async (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default async (homescope: HomeScope) => { + const { message, args } = homescope; const words = args.map(w => w.trim().capitalize()); message.channel.send(words.map(w => [...w].find(c => diff --git a/lib/commands/alias.ts b/lib/commands/alias.ts @@ -1,13 +1,13 @@ import { glue_strings } from '../utils'; -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; const p = CONFIG.commands.prefix; if (args.length === 0 || args[0] === 'ls') { const lines = Object.keys(CONFIG.commands.aliases) .map((e, i) => `${i + 1}. \`${p}${e}\` ↦ \`${p}${CONFIG.commands.aliases[e].shorten(60)}\`\n`); - message.answer('List of **Aliases**:\n'); + message.reply('List of **Aliases**:\n'); lines.unshift('**KEY: `alias` ↦ `command it maps to`**\n\n'); for (const msg of glue_strings(lines)) @@ -24,7 +24,7 @@ export default (home_scope: HomeScope) => { if (match = args[1].match(/^#?(\d+)/)) { index = Number(match[1]) - 1; if (index >= keys.length) { - message.answer('No alias exists at such an index' + message.reply('No alias exists at such an index' + ` (there are only ${keys.length} indices).`); return; } @@ -34,7 +34,7 @@ export default (home_scope: HomeScope) => { if (alias[0] === p) alias = alias.tail(); index = keys.indexOf(alias); if (index === -1) { - message.answer(`There does not exist any alias \ + message.reply(`There does not exist any alias \ with the name \`${p}${alias}\`.`.squeeze()); return; } @@ -42,7 +42,7 @@ export default (home_scope: HomeScope) => { keys.each((_, i) => i === index ? delete aliases[alias] : null); - message.answer(`Alias \`${p}${alias}\` at index \ + message.reply(`Alias \`${p}${alias}\` at index \ number ${index + 1}, has been deleted.`.squeeze()); return; } @@ -71,14 +71,14 @@ export default (home_scope: HomeScope) => { if (args[0] in CONFIG.commands.aliases) { const aliases = Object.keys(CONFIG.commands.aliases); const n = aliases.indexOf(args[0]) + 1; - message.answer(`${n}. \`${p}${args[0]}\` ↦ \`${p}${CONFIG.commands.aliases[args[0]]}\``); + message.reply(`${n}. \`${p}${args[0]}\` ↦ \`${p}${CONFIG.commands.aliases[args[0]]}\``); return; } else { - message.answer('No such alias found.'); + message.reply('No such alias found.'); return; } } - message.answer('Invalid number of arguments to alias,\n' + message.reply('Invalid number of arguments to alias,\n' + `Please see \`${CONFIG.commands.prefix}help alias\`.`); } }; diff --git a/lib/commands/b.ts b/lib/commands/b.ts @@ -1,8 +1,8 @@ import { Message } from 'discord.js'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; const input = (args.length === 0) ? "b" diff --git a/lib/commands/boomer.ts b/lib/commands/boomer.ts @@ -74,7 +74,7 @@ const boomerfy = (original: string): string => { return string; }; -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; message.channel.send(boomerfy(args.join(' '))); }; diff --git a/lib/commands/choose.ts b/lib/commands/choose.ts @@ -1,7 +1,7 @@ -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; const a = args.length ? args.join(' ').split(/\s*(?:,|\bor\b)\s*/gi) : [ 'I need a list.' ]; - message.answer(a[Math.floor(Math.random() * a.length)]); + message.reply(a[Math.floor(Math.random() * a.length)]); }; diff --git a/lib/commands/clap.ts b/lib/commands/clap.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; message.channel.send(args.join(' 👏 ') + '👏'); }; diff --git a/lib/commands/code.ts b/lib/commands/code.ts @@ -36,12 +36,12 @@ export default async (homescope : HomeScope) => { const p = CONFIG.commands.prefix; if (args.length < 1) - return message.answer('Please provide a command to introspect.'); + return message.reply('Please provide a command to introspect.'); const command = args[0].startsWith(p) ? args[0].tail() : args[0]; if (command.match(/\//g)) - return message.answer("No paths allowed..."); + return message.reply("No paths allowed..."); const expansion = CONFIG.commands.aliases[command]; if (expansion) return message.channel.send(`\`${p}${command}\`` @@ -77,7 +77,7 @@ export default async (homescope : HomeScope) => { } } catch (error) { console.log(`Error in code.ts: ${error}`); - message.answer(`Source for \`${p}${command}\`` + message.reply(`Source for \`${p}${command}\`` + ` (\`${process.cwd()}/${filename}\`), was not found.`); } }; diff --git a/lib/commands/coin.ts b/lib/commands/coin.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; - message.answer(Math.random() < 0.5 ? 'Heads!' : 'Tails!'); +export default (homescope: HomeScope) => { + const { message } = homescope; + message.reply(Math.random() < 0.5 ? 'Heads!' : 'Tails!'); }; diff --git a/lib/commands/cowsay.ts b/lib/commands/cowsay.ts @@ -1,11 +1,11 @@ import { execFileSync as exec_file_sync } from 'child_process'; -export default (home_scope: HomeScope) => { - let { message, args } = home_scope; +export default (homescope: HomeScope) => { + let { message, args } = homescope; if (args.length === 0) args = ['-d', 'Prope finem.']; // This is safe because no shell is spawned: - message.answer(exec_file_sync('./node_modules/.bin/cowsay', args, { + message.reply(exec_file_sync('./node_modules/.bin/cowsay', args, { encoding: 'utf8', cwd: process.cwd() }).format('```')); diff --git a/lib/commands/cowthink.ts b/lib/commands/cowthink.ts @@ -1,11 +1,11 @@ import { execFileSync as exec_file_sync } from 'child_process'; -export default (home_scope: HomeScope) => { - let { message, args } = home_scope; +export default (homescope: HomeScope) => { + let { message, args } = homescope; if (args.length === 0) args = ['-f', 'milk', 'Cogito, ergo sum.']; // This is safe because no shell is spawned: - message.answer(exec_file_sync('./node_modules/.bin/cowthink', args, { + message.reply(exec_file_sync('./node_modules/.bin/cowthink', args, { encoding: 'utf8', cwd: process.cwd() }).format('```')); diff --git a/lib/commands/crabbing.ts b/lib/commands/crabbing.ts @@ -1,7 +1,7 @@ import { MessageAttachment } from 'discord.js'; -export default (home_scope: HomeScope) => { - const { message } = home_scope; +export default (homescope: HomeScope) => { + const { message } = homescope; const attached = new MessageAttachment( './lib/resources/crabbing.jpg', 'crabbing.jpg'); diff --git a/lib/commands/cron.ts b/lib/commands/cron.ts @@ -175,7 +175,7 @@ export class Timer { job.executed_at = timespan; - this.homescope.message.answer("Ran cron #" + job.id); + this.homescope.message.reply("Ran cron #" + job.id); // `on_message` does important expansions. this.homescope.main.on_message( @@ -190,8 +190,8 @@ export class Timer { } } -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; if (args.length === 0 || args[0] === 'help') { return message.channel.send( @@ -207,7 +207,7 @@ export default (home_scope: HomeScope) => { }); let crons: Cron[] = cleanup(CONFIG.cron_jobs); - const timer = new Timer(home_scope); + const timer = new Timer(homescope); setInterval(() => { timer.verify(crons); @@ -223,18 +223,18 @@ export default (home_scope: HomeScope) => { delete crons[crons.map(x => x.id).indexOf(job)]; crons = cleanup(crons); submit(); - message.answer(RESPONSES.removed(job)); + message.reply(RESPONSES.removed(job)); }; const clear = () => { crons = crons.filter(f => !f?.executed_at); submit(); - message.answer(RESPONSES.clear); + message.reply(RESPONSES.clear); }; const list = () => { if (crons.length === 0) - return message.answer(RESPONSES.empty); + return message.reply(RESPONSES.empty); message.channel.send( crons @@ -396,7 +396,7 @@ export default (home_scope: HomeScope) => { const job: number = Number(args[1]); isNaN(job) - ? message.answer(RESPONSES.help.rm) + ? message.reply(RESPONSES.help.rm) : rm(job); } else if (args[0] === 'clear') { @@ -406,13 +406,13 @@ export default (home_scope: HomeScope) => { const cron: Cron = tokenize(args); if (!cron?.command) - message.answer(RESPONSES.help.command); + message.reply(RESPONSES.help.command); else if (!cron?.schedule) - message.answer(RESPONSES.help.schedule); + message.reply(RESPONSES.help.schedule); else { crons.push(cron); submit(); - message.answer(RESPONSES.added(cron)); + message.reply(RESPONSES.added(cron)); } } }; diff --git a/lib/commands/define.ts b/lib/commands/define.ts @@ -1,11 +1,11 @@ import oed_lookup from '../api/oxford'; import format_oed from '../format_oed'; // O.E.D. JSON entry to markdown. -export default (home_scope : HomeScope) => { +export default (homescope : HomeScope) => { const { message, args, - CONFIG, SECRETS } = home_scope; + CONFIG, SECRETS } = homescope; - message.answer('Looking in the Oxford English Dictionary...'); + const ping = message.reply('Looking in the Oxford English Dictionary...'); const query = args.join(' '); const p = CONFIG.commands.prefix; @@ -28,7 +28,7 @@ export default (home_scope : HomeScope) => { || res['results'][0].lexicalEntries.length === 0 || res['results'][0].lexicalEntries[0].entries.length === 0 || res['results'][0].lexicalEntries[0].entries[0].senses.length === 0) { - message.answer(nasty_reply); + message.reply(nasty_reply); return; } // Format the dictionary entry as a string. @@ -49,6 +49,8 @@ export default (home_scope : HomeScope) => { return; } message.channel.send(msg); + // Delete the ping. + ping.then(msg => msg.delete()); }).catch(e => { if (e.status === 404) { message.channel.send(`That 404'd. ${nasty_reply}`); diff --git a/lib/commands/drug.ts b/lib/commands/drug.ts @@ -1,12 +1,12 @@ -export default async (home_scope: HomeScope) => { - const { CLIENT, message, args, Drugs } = home_scope; +export default async (homescope: HomeScope) => { + const { CLIENT, message, args, Drugs } = homescope; const arg = args.length > 0 ? args.shift() : 'help' try { message.content = `--${arg} ${args.join(' ')}`; Drugs.execute(CLIENT, message); } catch (e) { - message.answer(`Failed to execute \`${arg}\` command for Drug-O-Matic.` + message.reply(`Failed to execute \`${arg}\` command for Drug-O-Matic.` + "\n```\n" + `${e}` + "\n```") } }; diff --git a/lib/commands/echo.ts b/lib/commands/echo.ts @@ -1,5 +1,5 @@ -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; const reply = args.join(' ').trim(); if (reply.length === 0) return; diff --git a/lib/commands/emojify.ts b/lib/commands/emojify.ts @@ -5,10 +5,10 @@ const NUMBER_NAMES = [ 'six', 'seven', 'eight', 'nine', 'keycap_ten' ]; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } : { message: Message, - args: string[] } = home_scope; + args: string[] } = homescope; const input = args.length === 0 ? "nibba" diff --git a/lib/commands/emojis.ts b/lib/commands/emojis.ts @@ -1,5 +1,5 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; +export default (homescope: HomeScope) => { + const { message } = homescope; message.channel.send( message.guild.emojis.cache.map(x => x.toString()).join(' ') ); diff --git a/lib/commands/epoch.ts b/lib/commands/epoch.ts @@ -1,5 +1,5 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; +export default (homescope: HomeScope) => { + const { message } = homescope; const now = new Date(); message.channel.send(`Local time relative to bot: ${now.toString()} / ${now.toISOString().format('`')} diff --git a/lib/commands/figlet.ts b/lib/commands/figlet.ts @@ -1,10 +1,10 @@ import { execFileSync as exec_file_sync } from 'child_process'; -export default (home_scope: HomeScope) => { - let { message, args } = home_scope; +export default (homescope: HomeScope) => { + let { message, args } = homescope; if (args.length === 0) args = ['-f', 'Train', 'Simp']; // This is safe because no shell is spawned: - message.answer(exec_file_sync('./node_modules/.bin/figlet', args, { + message.reply(exec_file_sync('./node_modules/.bin/figlet', args, { encoding: 'utf8', cwd: process.cwd() }).format('```')); diff --git a/lib/commands/flip.ts b/lib/commands/flip.ts @@ -4,8 +4,8 @@ import FLIPS from '../resources/flips'; const flip = c => FLIPS[c] || c; -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; message.channel.send('(╯°□°)╯︵ ' + [...args.join(' ')].map(flip).reverse().join('')); }; diff --git a/lib/commands/fork.ts b/lib/commands/fork.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message, GIT_URL } = home_scope; - message.answer(`${GIT_URL}/fork`); +export default (homescope: HomeScope) => { + const { message, GIT_URL } = homescope; + message.reply(`${GIT_URL}/fork`); }; diff --git a/lib/commands/fortune.ts b/lib/commands/fortune.ts @@ -1,6 +1,6 @@ import { fortune } from 'fortune-teller'; -export default (home_scope: HomeScope) => { - const { message } = home_scope; +export default (homescope: HomeScope) => { + const { message } = homescope; message.channel.send(fortune()); }; diff --git a/lib/commands/get.ts b/lib/commands/get.ts @@ -1,11 +1,11 @@ import { recursive_regex_to_string, deep_copy, glue_strings, access} from '../utils'; -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; if (args.length === 0) { // Or use '.' as argument. - message.answer('To view the entire object, use the `!export` command.'); + message.reply('To view the entire object, use the `!export` command.'); return; } // Accessing invalid fields will be caught. diff --git a/lib/commands/git.ts b/lib/commands/git.ts @@ -95,20 +95,20 @@ export default async (homescope : HomeScope) => { const repo_info = await res.json(); if (args[0].startsWith('star')) { - return message.answer( + return message.reply( `GitHub Stars: :star2: ${repo_info.stargazers_count}`); } if (args[0].startsWith('watch')) { - return message.answer( + return message.reply( `GitHub Watch Count: :eyes: ${repo_info.watchers_count}`); } if (args[0].startsWith('fork')) { - return message.answer( + return message.reply( `GitHub Forks: :writing_hand: ${repo_info.forks_count}`); } - message.answer("That's not how you use that command, here's how:\n" + message.reply("That's not how you use that command, here's how:\n" + help_info('git', CONFIG.commands.prefix)); }; diff --git a/lib/commands/github.ts b/lib/commands/github.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message, GIT_URL } = home_scope; - message.answer(`${GIT_URL}/`); +export default (homescope: HomeScope) => { + const { message, GIT_URL } = homescope; + message.reply(`${GIT_URL}/`); }; diff --git a/lib/commands/hangman.ts b/lib/commands/hangman.ts @@ -106,8 +106,8 @@ const MESSAGES: Types.Messages = { `Scored: ${scored}`, }; -// export default (home_scope: HomeScope) => { -// const { message, args } = home_scope; +// export default (homescope: HomeScope) => { +// const { message, args } = homescope; // if (args.length === 0 || args[0] === 'help') // message.channel.send(MESSAGES.help); diff --git a/lib/commands/help.ts b/lib/commands/help.ts @@ -1,10 +1,10 @@ import { prefix_friendly } from '../utils'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args, HELP_SECTIONS, KNOWN_COMMANDS, CONFIG, ALL_HELP, - HELP_KEY, HELP_SOURCE, expand_alias } = home_scope; + HELP_KEY, HELP_SOURCE, expand_alias } = homescope; const p = CONFIG.commands.prefix; @@ -38,8 +38,8 @@ export default (home_scope: HomeScope) => { const help_index = KNOWN_COMMANDS.indexOf(command); if (help_index === -1) - return message.answer(`No such command/help-page (\`${p}${command}\`).`); + return message.reply(`No such command/help-page (\`${p}${command}\`).`); - message.answer(`**Help (\`${p}${command}\`):**\n` + message.reply(`**Help (\`${p}${command}\`):**\n` + help_sections[help_index].trim()); }; diff --git a/lib/commands/hug.ts b/lib/commands/hug.ts @@ -1,9 +1,9 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/id.ts b/lib/commands/id.ts @@ -1,7 +1,7 @@ import { Message } from 'discord.js'; -export default (home_scope: HomeScope) => { - const { message } : { message : Message } = home_scope; +export default (homescope: HomeScope) => { + const { message } : { message : Message } = homescope; const rep = []; ['channel', 'user', 'role'].forEach(n => message.mentions[`${n}s`].forEach(o => rep.push(`${n} id: \`${o.id}\``))); @@ -10,5 +10,5 @@ export default (home_scope: HomeScope) => { Author: ${message.author} Message ID: \`${message.id}\``.squeeze(); console.log(`Replied: ${reply}`); - message.answer(reply); + message.reply(reply); }; diff --git a/lib/commands/ily.ts b/lib/commands/ily.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; - message.answer('Y-you too...'); +export default (homescope: HomeScope) => { + const { message } = homescope; + message.reply('Y-you too...'); }; diff --git a/lib/commands/image.ts b/lib/commands/image.ts @@ -1,8 +1,8 @@ import web_search from '../api/google'; import { TextChannel } from 'discord.js'; -export default (home_scope: HomeScope) => { - const { message, args, SECRETS } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, SECRETS } = homescope; const query = args.join(' ').toLowerCase(); const channel = message.channel as TextChannel; @@ -12,6 +12,6 @@ export default (home_scope: HomeScope) => { key: SECRETS.google.api_key, id: SECRETS.google.search_id, nsfw: channel.nsfw - }).then(res => message.answer(res)) - .catch(er => message.answer(er)); + }).then(res => message.reply(res)) + .catch(er => message.reply(er)); }; diff --git a/lib/commands/instgen.ts b/lib/commands/instgen.ts @@ -1,6 +1,6 @@ import { MessageAttachment } from 'discord.js'; -export default async (home_scope: HomeScope) => { - const { message } = home_scope; +export default async (homescope: HomeScope) => { + const { message } = homescope; const a = new MessageAttachment('../resources/media/instgen.mp3', 'instgen.mp3'); message.channel.send('', a); } \ No newline at end of file diff --git a/lib/commands/invite.ts b/lib/commands/invite.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; - message.answer('invite link: https://discordapp.com/api/oauth2/authorize?client_id=684895962212204748&permissions=8&scope=bot'); +export default (homescope: HomeScope) => { + const { message } = homescope; + message.reply('invite link: https://discordapp.com/api/oauth2/authorize?client_id=684895962212204748&permissions=8&scope=bot'); }; diff --git a/lib/commands/issue.ts b/lib/commands/issue.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message, GIT_URL } = home_scope; - message.answer(`${GIT_URL}/issues`); +export default (homescope: HomeScope) => { + const { message, GIT_URL } = homescope; + message.reply(`${GIT_URL}/issues`); }; diff --git a/lib/commands/kill.ts b/lib/commands/kill.ts @@ -2,9 +2,9 @@ import { Message } from 'discord.js'; import { MessageAttachment } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; const attached = new MessageAttachment( 'https://img2.gelbooru.com/images/12/86/1286caaa436406cc4e283e8fd0277a74.png', diff --git a/lib/commands/kiss.ts b/lib/commands/kiss.ts @@ -1,9 +1,9 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/license.ts b/lib/commands/license.ts @@ -1,5 +1,5 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; +export default (homescope: HomeScope) => { + const { message } = homescope; message.channel.send( "**GNU Affero GPLv3 (`AGPL-3.0`), _Free_ as in Freedom.**"); message.channel.send("<:AGPL:740958423008411678>"); diff --git a/lib/commands/lick.ts b/lib/commands/lick.ts @@ -1,9 +1,9 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/listen.ts b/lib/commands/listen.ts @@ -3,12 +3,12 @@ const RULES = [ 'replace', 'trigger' ]; -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; const rule_type = args[0]; if (!RULES.includes(rule_type)) - return message.answer("`listen` command first argument must" + return message.reply("`listen` command first argument must" + " be either `respond`, `reject`, `replace` or `trigger`" + "\nSee `help` page for `listen` for more information."); @@ -18,19 +18,19 @@ export default (home_scope: HomeScope) => { : index_str); if (!index) - return message.answer("Second argument must be a number" + return message.reply("Second argument must be a number" + " (greater than zero), that represents the index of the rule"); const rule_no = CONFIG.rules[rule_type].length; if (index > rule_no || CONFIG.rules[rule_type][index - 1] === undefined) - return message.answer(`Index (${index}) is out of range.\n` + return message.reply(`Index (${index}) is out of range.\n` + `Only ${rule_no} elements exist in ${rule_type} rules.`); const ids = message.mentions.users .map(user => user.id); if (args.length < 3 || ids.length === 0) - return message.answer("Please provide at least one username" + return message.reply("Please provide at least one username" + " (in form of a mention)."); const rule = CONFIG.rules[rule_type][index - 1]; @@ -39,5 +39,5 @@ export default (home_scope: HomeScope) => { rule.listens = []; rule.listens.push.apply(rule.listens, ids); - message.answer("Rule listener added successfully."); + message.reply("Rule listener added successfully."); }; diff --git a/lib/commands/milkies.ts b/lib/commands/milkies.ts @@ -1,5 +1,5 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; - message.answer(`${(4 + Math.random() * 15).round_to(3)}` +export default (homescope: HomeScope) => { + const { message } = homescope; + message.reply(`${(4 + Math.random() * 15).round_to(3)}` + ` gallons of milkies have been deposited in your mouth.`); }; diff --git a/lib/commands/mock.ts b/lib/commands/mock.ts @@ -1,7 +1,7 @@ -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { // TODO: if no args, mock the previous message, // but this could be implemented via .alias and !!^. - const { message, args } = home_scope; + const { message, args } = homescope; let b = true; message.channel.send([...args.join(' ').toLowerCase()].map(l => (l === l.toUpperCase()) ? l : ((b = !b) ? l.toUpperCase() : l) diff --git a/lib/commands/motivation.ts b/lib/commands/motivation.ts @@ -1,8 +1,8 @@ import fetch, { Response } from 'node-fetch'; const URL = 'http://api.forismatic.com/api/1.0/?method=getQuote&format=text&lang=en&key=457653'; -export default (home_scope: HomeScope) => { - const { message } = home_scope; +export default (homescope: HomeScope) => { + const { message } = homescope; fetch(URL) .catch((e: Response) => { message.channel.send("Couldn't get your quote qwq..."); diff --git a/lib/commands/pat.ts b/lib/commands/pat.ts @@ -5,8 +5,8 @@ import Jimp from 'jimp'; const TEMPLATE = "./lib/resources/templates/pat.png"; -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; if (args.length === 0 || message.mentions.users.size === 0) { message.channel.send( diff --git a/lib/commands/ping.ts b/lib/commands/ping.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; - message.answer('PONGGERS!'); +export default (homescope: HomeScope) => { + const { message } = homescope; + message.reply('PONGGERS!'); }; diff --git a/lib/commands/pp.ts b/lib/commands/pp.ts @@ -1,5 +1,5 @@ -export default (home_scope: HomeScope) => { - const { message, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, CONFIG } = homescope; let user = message.author.id; try { @@ -7,6 +7,6 @@ export default (home_scope: HomeScope) => { } finally { const shaft = '='.repeat(CONFIG.pp_sizes[user] || (CONFIG.pp_sizes[user] = Math.ceil(Math.random() * 16))); - message.answer(`8${shaft}>`); + message.reply(`8${shaft}>`); } }; diff --git a/lib/commands/prefix.ts b/lib/commands/prefix.ts @@ -1,6 +1,6 @@ -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; - message.answer(args.length === 1 +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; + message.reply(args.length === 1 ? args[0].length === 1 ? `Command prefix changed to: \`${CONFIG.commands.prefix = args[0]}\`.` : 'You may only use a prefix that is exactly one character/symbol/grapheme/rune long.' diff --git a/lib/commands/purr.ts b/lib/commands/purr.ts @@ -1,9 +1,9 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/rape.ts b/lib/commands/rape.ts @@ -1,9 +1,9 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/rim.ts b/lib/commands/rim.ts @@ -1,9 +1,9 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/roll.ts b/lib/commands/roll.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; - message.answer(Math.floor(Math.random() * ((+args[0] || 6) + 1))); +export default (homescope: HomeScope) => { + const { message, args } = homescope; + message.reply(Math.floor(Math.random() * ((+args[0] || 6) + 1))); }; diff --git a/lib/commands/say.ts b/lib/commands/say.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; - message.answer(`Me-sa says: “${args.join(' ')}”`); +export default (homescope: HomeScope) => { + const { message, args } = homescope; + message.reply(`Me-sa says: “${args.join(' ')}”`); }; diff --git a/lib/commands/search.ts b/lib/commands/search.ts @@ -1,8 +1,8 @@ import web_search from '../api/google'; import { TextChannel } from 'discord.js'; -export default (home_scope: HomeScope) => { - const { message, args, SECRETS } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, SECRETS } = homescope; const query = args.join(' ').toLowerCase(); const channel = message.channel as TextChannel; @@ -12,6 +12,6 @@ export default (home_scope: HomeScope) => { key: SECRETS.google.api_key, id: SECRETS.google.search_id, nsfw: channel.nsfw - }).then((res) => message.answer(res)) - .catch(e => message.answer(e)); + }).then((res) => message.reply(res)) + .catch(e => message.reply(e)); }; diff --git a/lib/commands/set.ts b/lib/commands/set.ts @@ -1,10 +1,10 @@ import { access } from '../utils'; -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; if (args.length < 2) - return message.answer(`Please provide two arguments.\n` + return message.reply(`Please provide two arguments.\n` + `See \`${CONFIG.commands.prefix}help set\`.`); try { diff --git a/lib/commands/ship.ts b/lib/commands/ship.ts @@ -33,8 +33,8 @@ const read512bitsBigIntBigEndian = (buffer : Buffer) : bigint => { return val; }; -export default (home_scope : HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope : HomeScope) => { + const { message, args, CONFIG } = homescope; if (args.length === 0 || args[0] === 'help' || message.mentions.users.size === 0 @@ -87,7 +87,7 @@ export default (home_scope : HomeScope) => { const response = `${get_percentage(die)} ${get_response(die)}`; const error_msg = (e: Error) => - message.answer("Unable to calculate the love grade :(" + message.reply("Unable to calculate the love grade :(" + `:\n${e.message}`.format('```')); const compose_images = async ({ first, second }) => { diff --git a/lib/commands/slap.ts b/lib/commands/slap.ts @@ -1,9 +1,9 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { +export default (homescope: HomeScope) => { const { message, args } - : { message: Message, args: string[] } = home_scope; + : { message: Message, args: string[] } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/suck.ts b/lib/commands/suck.ts @@ -1,8 +1,8 @@ import { Message } from 'discord.js'; import Action from '../action'; -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; if (args.length === 0 || message.mentions.users.size === 0) return message.channel.send( diff --git a/lib/commands/summon.ts b/lib/commands/summon.ts @@ -1,7 +1,7 @@ import { help_info } from '../utils'; -export default (home_scope : HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope : HomeScope) => { + const { message, args, CONFIG } = homescope; if (args.length === 0 || args[0] === 'help' || message.mentions.users.size === 0) diff --git a/lib/commands/system.ts b/lib/commands/system.ts @@ -4,8 +4,8 @@ const sys_channel = (channel_id: string) => ? `is set to <#${channel_id}>.` : `has not been set.`; -export default (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; const { uptime } = message.client; if (args.length === 0 || args[0] === 'status') { diff --git a/lib/commands/translate.ts b/lib/commands/translate.ts @@ -1,7 +1,7 @@ import fetch from 'node-fetch'; -export default async (home_scope: HomeScope) => { - const { message, args, SECRETS, CONFIG } = home_scope, lang = String(args[0])[2] == '-' ? args.shift() : 'en'; // handle undefined - args[0] ? fetch(`https://translate.yandex.net/api/v1.5/tr.json/translate?key=${SECRETS.yandex.translate.key}&text=${encodeURIComponent(args.join(' '))}&lang=${lang}`).catch(console.log).then((res: any) => res.json()).then(tr => message.channel.send([,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,false,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'api key missing','blocked api key',,'limit reached',,,,,,,,,'text too long (shouldnt happen)',,,,,,,,,'untranslatable.',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'unsupported'][tr.code] || tr.text[0])) : message.answer('.translate [from-to] words \n default: auto-en'); +export default async (homescope: HomeScope) => { + const { message, args, SECRETS, CONFIG } = homescope, lang = String(args[0])[2] == '-' ? args.shift() : 'en'; // handle undefined + args[0] ? fetch(`https://translate.yandex.net/api/v1.5/tr.json/translate?key=${SECRETS.yandex.translate.key}&text=${encodeURIComponent(args.join(' '))}&lang=${lang}`).catch(console.log).then((res: any) => res.json()).then(tr => message.channel.send([,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,false,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'api key missing','blocked api key',,'limit reached',,,,,,,,,'text too long (shouldnt happen)',,,,,,,,,'untranslatable.',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'unsupported'][tr.code] || tr.text[0])) : message.reply('.translate [from-to] words \n default: auto-en'); }; // P.S. If you're reading this code, and wondering why diff --git a/lib/commands/tts.ts b/lib/commands/tts.ts @@ -5,7 +5,7 @@ export default async (hs : HomeScope) => { const { message, args, INSTANCE_VARIABLES } = hs; if (!message.guild) { - message.answer("Stop talkingQ to yourself, loser."); + message.reply("Stop talkingQ to yourself, loser."); return; } @@ -13,7 +13,7 @@ export default async (hs : HomeScope) => { const GID = INSTANCE_VARIABLES.guilds[guild]; if (!GID.vc) { - message.answer("Let me join your voice-chat first."); + message.reply("Let me join your voice-chat first."); } const text = args.join(' '); diff --git a/lib/commands/uptime.ts b/lib/commands/uptime.ts @@ -1,7 +1,7 @@ import { FORMATS } from '../extensions'; -export default (home_scope : HomeScope) => { - const { message } = home_scope; +export default (homescope : HomeScope) => { + const { message } = homescope; const { uptime } = message.client; let seconds = uptime / 1000; diff --git a/lib/commands/urban.ts b/lib/commands/urban.ts @@ -1,9 +1,10 @@ import urban_search from '../api/urban'; import '../extensions'; -export default (home_scope: HomeScope) => { - const { message, args, SECRETS } = home_scope; +export default (homescope: HomeScope) => { + const { message, args, SECRETS } = homescope; const query = args.join(' '); - message.answer('Searching Urban Dictionary...'); + + const ping = message.reply('Searching Urban Dictionary...'); urban_search({ query, key: SECRETS.rapid.key }).then(res => { if (res['list'].length === 0) { message.channel.send(`Congratulations, not even Urban \ @@ -22,5 +23,8 @@ export default (home_scope: HomeScope) => { message.channel.send(`\n**Example**:\n>>> ${example.trim()}`); } message.channel.send(`Link: ${entry.permalink}`); - }).catch(e => message.answer(`Error fetching definition:\n${e}`)); + + // Definition sent, delete ping. + ping.then(msg => msg.delete()); + }).catch(e => message.reply(`Error fetching definition:\n${e}`)); }; diff --git a/lib/commands/uwu.ts b/lib/commands/uwu.ts @@ -45,8 +45,8 @@ interface Scope { args: string[]; } -export default (home_scope: HomeScope) => { - const { message, args } : Scope = home_scope; +export default (homescope: HomeScope) => { + const { message, args } : Scope = homescope; if (args.length === 0 || args[0] === 'help') { message.channel.send("OwO *notices text* What's this?"); diff --git a/lib/commands/vape.ts b/lib/commands/vape.ts @@ -1,4 +1,4 @@ -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; message.channel.send(args.join('').split('').join(' ')); }; diff --git a/lib/commands/vc.ts b/lib/commands/vc.ts @@ -7,11 +7,11 @@ const YTDL_OPTIONS = [ '-i', '--no-continue', '-o', '-' // Send to STDOUT. ]; -export default async (home_scope: HomeScope) => { - const { message, args, CONFIG, CLIENT, INSTANCE_VARIABLES } = home_scope; +export default async (homescope: HomeScope) => { + const { message, args, CONFIG, CLIENT, INSTANCE_VARIABLES } = homescope; if (!message.guild) { - message.answer("Just use youtube-dl at home."); + message.reply("Just use youtube-dl at home."); return; } @@ -40,7 +40,7 @@ export default async (home_scope: HomeScope) => { child.stdout = null; GID.vc_prefetch[url] = null; CONFIG.vc_queue = CONFIG.vc_queue.filter(q => q !== url); - message.answer("Error downloading media."); + message.reply("Error downloading media."); } child.kill(); }); @@ -81,34 +81,34 @@ export default async (home_scope: HomeScope) => { try { GID.vc.disconnect(); GID.vc.channel.leave(); - message.answer("Let's listen again some time :3"); + message.reply("Let's listen again some time :3"); } catch (error) { - message.answer("```" + `${error}` + "```"); + message.reply("```" + `${error}` + "```"); } break; } case "stop": case "pause": { if (GID.vc_dispatcher && !GID.vc_dispatcher.paused) { GID.vc_dispatcher.pause(); - message.answer("Paused playback."); + message.reply("Paused playback."); } else { - message.answer("Nothing is playing"); + message.reply("Nothing is playing"); } break; } case "resume": case "play": { if (!GID.vc) { - message.answer("Let me join a voice channel first."); + message.reply("Let me join a voice channel first."); return; } if (GID.vc_dispatcher && GID.vc_dispatcher.paused) { GID.vc_dispatcher.resume(); - message.answer("Resuming playback."); + message.reply("Resuming playback."); return; } if (CONFIG.vc_queue.length === 0) { - message.answer("Please add a URL to the queue first."); + message.reply("Please add a URL to the queue first."); return; } @@ -162,7 +162,7 @@ export default async (home_scope: HomeScope) => { case "delete": { const pos = Number(args[1]); CONFIG.vc_queue.splice(pos - 1, 1); - message.answer(`Removed media from queue at index ${pos}.`); + message.reply(`Removed media from queue at index ${pos}.`); break; } case "insert": case "i": { @@ -170,32 +170,32 @@ export default async (home_scope: HomeScope) => { const url = args[2]; if (attempt_prefetch(url)) { CONFIG.vc_queue.splice(pos - 1, 0, url); - message.answer(`Inserting into queue at index ${pos}.`); + message.reply(`Inserting into queue at index ${pos}.`); } break; } case "queue": case "list": case "ls": { - message.answer(ls(CONFIG.vc_queue)); + message.reply(ls(CONFIG.vc_queue)); break; } case "clear": case "requeue": { CONFIG.vc_queue = []; GID.vc_current_stream = null; - message.answer("Queue cleared"); + message.reply("Queue cleared"); GID.vc_dispatcher.end(); break; } case "next": case "skip": { GID.vc_dispatcher.end(); GID.vc_current_stream.destroy(); - message.answer("Skipping..."); + message.reply("Skipping..."); break; } default: { const url = args[0]; if (attempt_prefetch(url)) { CONFIG.vc_queue.push(url); - message.answer("Adding media to queue..."); + message.reply("Adding media to queue..."); } } } diff --git a/lib/commands/weather.ts b/lib/commands/weather.ts @@ -33,7 +33,7 @@ export default async (homescope: HomeScope) => { if (args[0] === 'set' && args.length > 1) { CONFIG.weather_locations[message.author.id] = args.tail().join(' '); - return message.answer(`Your weather location has \ + return message.reply(`Your weather location has \ been set to ${args.tail().join(' ')}`.squeeze()); } @@ -42,13 +42,13 @@ export default async (homescope: HomeScope) => { : CONFIG.weather_locations[message.author.id] || 'Cuckfield'; if (location == 'Cuckfield') - message.answer("You should set your default weather location." + message.reply("You should set your default weather location." + ` Use \`${CONFIG.commands.prefix}weather set <location>\`.`); const geokey = SECRETS.yandex.geocoder.key; const error = (e: Error) => { - message.answer(`Error getting weather\n\`\`\`${e.message}\`\`\``); + message.reply(`Error getting weather\n\`\`\`${e.message}\`\`\``); return e; }; diff --git a/lib/commands/whitelistchannels.ts b/lib/commands/whitelistchannels.ts @@ -1,7 +1,7 @@ // .whitelistchannels #channel1 #channel2 // .whitelistchannels without any arguments turns off the function -export default async (home_scope: HomeScope) => { - const { message, CONFIG } = home_scope; +export default async (homescope: HomeScope) => { + const { message, CONFIG } = homescope; if (!CONFIG.whitelistchannels) CONFIG.whitelistchannels = []; diff --git a/lib/commands/wikipedia.ts b/lib/commands/wikipedia.ts @@ -1,6 +1,6 @@ import fetch from 'node-fetch'; -export default (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default (homescope: HomeScope) => { + const { message, args } = homescope; fetch(`https://en.wikipedia.org/w/api.php?action=opensearch&search=${args.join(' ') || 'empty set'}&limit=1&format=json`) - .then(j => j.json()).then(j => message.answer(j[3] || 'not found')); + .then(j => j.json()).then(j => message.reply(j[3] || 'not found')); }; diff --git a/lib/commands/yn.ts b/lib/commands/yn.ts @@ -1,5 +1,5 @@ -export default (home_scope: HomeScope) => { - const { message } = home_scope; +export default (homescope: HomeScope) => { + const { message } = homescope; Promise.all( ['✅', '❎'] .map(message.react.bind(message))) diff --git a/lib/commands/youtube.ts b/lib/commands/youtube.ts @@ -8,8 +8,8 @@ import fetch from "node-fetch"; * !youtube {channel,playlist} x */ -export default async (home_scope: HomeScope) => { - const { message, args } = home_scope; +export default async (homescope: HomeScope) => { + const { message, args } = homescope; let query = args.join(' ').trim(); const sort_by = (args[0] == "new") @@ -44,7 +44,7 @@ export default async (home_scope: HomeScope) => { const views : string = Number(res.viewCount).to_abbrev(1); - message.answer(`Search for '${query}' (result №${num}):` + message.reply(`Search for '${query}' (result №${num}):` + ` https://youtu.be/${res.videoId}` + `\npublished ${res.publishedText},` + ` view count: ${views}, duration: ${duration}`); @@ -54,6 +54,6 @@ export default async (home_scope: HomeScope) => { /* // Old (actual) YT scraping. yt_search({ query }) .then(message.reply.bind(message)) - .catch(message.answer.bind(message)); + .catch(message.reply.bind(message)); */ }; diff --git a/lib/extensions.ts b/lib/extensions.ts @@ -364,12 +364,13 @@ Number.prototype.truncate = function() { declare module 'discord.js' { interface Message { - answer(...args: any): void; + answer(content: any, options?: any): void; } } import { Message } from 'discord.js'; -Message.prototype.answer = function (...args) { - return this.channel.send(`${this.author}, ${args[0]}`, - ...(args.slice(1))); +Message.prototype.answer = function (content, options) { + return this.channel.send( + `${this.author}, ${content}`, + options); }; diff --git a/lib/main.ts b/lib/main.ts @@ -329,13 +329,13 @@ export class SimpOMatic { if (last_command.content === current_command.content && delta <= 1400) { if (delta <= 400) return; - return message.answer(`I can't help but notice you're running \ + return message.reply(`I can't help but notice you're running \ the same commands over in rather rapid succession. Would you like to slow down a little?`.squeeze()); } if (delta <= 900) { if (delta <= 300) return; - return message.answer('Slow down there bucko.'); + return message.reply('Slow down there bucko.'); } } } @@ -410,7 +410,7 @@ Would you like to slow down a little?`.squeeze()); const attach = new MessageAttachment(file_dest, file_name); message.channel.send("**Export:**", attach); - message.answer(`A copy of this export (\`export-${today}.json\`)` + message.reply(`A copy of this export (\`export-${today}.json\`)` + ` has been saved to the local file system.`); break; } case 'refresh': { @@ -431,7 +431,7 @@ Would you like to slow down a little?`.squeeze()); message.channel.send(`Directories:\n\`\`\`json\n${dirs}\n\`\`\``); break; } case '': { - message.answer("That's an empty command..."); + message.reply("That's an empty command..."); break; } default: { if (KNOWN_COMMANDS.includes(operator)) { @@ -444,7 +444,7 @@ Would you like to slow down a little?`.squeeze()); } const has_punct = CONFIG.commands.not_understood.punctuation(); - message.answer(` + message.reply(` :warning: ${CONFIG.commands.not_understood}${has_punct?'':'.'} > \`${CONFIG.commands.prefix}${operator}\``.squeeze()); break; @@ -467,7 +467,7 @@ Would you like to slow down a little?`.squeeze()); && !responder.listens.includes(message.author.id)) continue; - if (match && response) message.answer(response); + if (match && response) message.reply(response); } for (const triggerer of CONFIG.rules.trigger) { if (!triggerer) continue; // Sparse arrays! @@ -497,7 +497,7 @@ Would you like to slow down a little?`.squeeze()); continue; if (match) { - if (response) message.answer(response); + if (response) message.reply(response); if (message.deletable) { message.delete(); break; @@ -606,7 +606,7 @@ Would you like to slow down a little?`.squeeze()); // When finished expanding... this.expand(message).then(content => { if (content.length >= 2000) { - message.answer("The expansion for that message was" + message.reply("The expansion for that message was" + " over 2000 characters, what the fuck is wrong with you?"); return; } @@ -623,7 +623,7 @@ Would you like to slow down a little?`.squeeze()); }); } catch (e) { console.warn(e); - message.answer(`Something went very wrong (\`${e.message}\`):\n` + message.reply(`Something went very wrong (\`${e.message}\`):\n` + `${e.stack}`.format('```')); } } diff --git a/lib/rule.ts b/lib/rule.ts @@ -1,7 +1,7 @@ import { glue_strings, help_info } from './utils'; -export const rule = (rule_kind: string) => (home_scope: HomeScope) => { - const { message, args, CONFIG } = home_scope; +export const rule = (rule_kind: string) => (homescope: HomeScope) => { + const { message, args, CONFIG } = homescope; const rules_array = CONFIG.rules[rule_kind]; if (args.length === 0 || args[0] === 'ls') { @@ -22,15 +22,15 @@ export const rule = (rule_kind: string) => (home_scope: HomeScope) => { // Remove a rule. const match = args[1].match(/#?(\d+)/); if (!match || !match[1]) - return message.answer('Please provide a numerical index' + return message.reply('Please provide a numerical index' + ' as to which rule to remove.'); const index = Number(match[1]) - 1; if (index >= rules_array.length) - return message.answer(`Cannot delete rule at index ${index + 1}...` + return message.reply(`Cannot delete rule at index ${index + 1}...` + ` There are only ${rules_array.length} ${rule_kind} rules.`); - message.answer(`Rule matching \`${rules_array[index].match}\`` + message.reply(`Rule matching \`${rules_array[index].match}\`` + ` at index location number ${index + 1} has been deleted.`); delete CONFIG.rules[rule_kind][index]; @@ -47,7 +47,7 @@ export const rule = (rule_kind: string) => (home_scope: HomeScope) => { if (phrase.slice(i, i + 2) === '\\/') i += 2; // escaped /. else if (phrase[i] === '/') break; // end of regex. if (i >= phrase.length) { - message.answer('Having real trouble parsing that m8...'); + message.reply('Having real trouble parsing that m8...'); return; } else i += 1; // nothing interesting. @@ -86,7 +86,7 @@ export const rule = (rule_kind: string) => (home_scope: HomeScope) => { response: response.length ? response : null }); } catch (e) { - message.answer('**Error** creating regular expression!\n' + message.reply('**Error** creating regular expression!\n' + e.message.toString().format('`')); return; } @@ -94,7 +94,7 @@ export const rule = (rule_kind: string) => (home_scope: HomeScope) => { + `/${regex}/${options}`.format('```') + `\nhas been added to the list of ${rule_kind} rules.`); } else { - message.answer('Insufficient or nonsensical arguments provided.'); + message.reply('Insufficient or nonsensical arguments provided.'); message.reply(`Here's how you use the command:\n` + help_info(rule_kind, CONFIG.commands.prefix)); } diff --git a/package.json b/package.json @@ -11,7 +11,7 @@ }, "license": "AGPL-3.0", "author": "Sammy, Danny, Bruno, Accelarion, jack-javana and friends", - "version": "1.1.0", + "version": "1.2.0", "engines": { "node": "14.x", "yarn": "1.22.x" @@ -45,7 +45,7 @@ "@types/ws": "^7.2.2", "cowsay": "^1.4.0", "deepcopy": "^2.0.0", - "discord.js": "12.0.2", + "discord.js": "12.5.3", "figlet": "^1.3.0", "figlet-cli": "^0.1.1", "fortune-teller": "^0.1.2", diff --git a/yarn.lock b/yarn.lock @@ -30,7 +30,7 @@ dependencies: regenerator-runtime "^0.13.4" -"@discordjs/collection@^0.1.5", "@discordjs/collection@^0.1.6": +"@discordjs/collection@^0.1.6": version "0.1.6" resolved "https://registry.yarnpkg.com/@discordjs/collection/-/collection-0.1.6.tgz#9e9a7637f4e4e0688fd8b2b5c63133c91607682c" integrity sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ== @@ -1187,19 +1187,19 @@ director@1.2.7: resolved "https://registry.yarnpkg.com/director/-/director-1.2.7.tgz#bfd3741075fd7fb1a5b2e13658c5f4bec77736f3" integrity sha1-v9N0EHX9f7GlsuE2WMX0vsd3NvM= -discord.js@12.0.2: - version "12.0.2" - resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.0.2.tgz#c4d68f1363d7fc05ed71a42dba6b930966ed8602" - integrity sha512-iZiEA4Y61gqq/EjFfLXnkRK9pLapnax/vTVDUhs/mAhyqozAy0GOlk/MZI9rSa1iIoKTWRq6P9CRKhLNT2wUnA== +discord.js@12.5.3: + version "12.5.3" + resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.5.3.tgz#56820d473c24320871df9ea0bbc6b462f21cf85c" + integrity sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw== dependencies: - "@discordjs/collection" "^0.1.5" + "@discordjs/collection" "^0.1.6" + "@discordjs/form-data" "^3.0.1" abort-controller "^3.0.0" - form-data "^3.0.0" - node-fetch "^2.6.0" - prism-media "^1.2.0" + node-fetch "^2.6.1" + prism-media "^1.2.9" setimmediate "^1.0.5" tweetnacl "^1.0.3" - ws "^7.2.1" + ws "^7.4.4" discord.js@^12.4.1: version "12.5.1" @@ -2676,7 +2676,7 @@ node-addon-api@^3.0.2: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.1.0.tgz#98b21931557466c6729e51cb77cd39c965f42239" integrity sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw== -node-fetch@^2.3.0, node-fetch@^2.6.0, node-fetch@^2.6.1: +node-fetch@^2.3.0, node-fetch@^2.6.1: version "2.6.1" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== @@ -3064,11 +3064,16 @@ prettyjson@^1.1.2: colors "^1.1.2" minimist "^1.2.0" -prism-media@^1.2.0, prism-media@^1.2.2: +prism-media@^1.2.2: version "1.2.5" resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-1.2.5.tgz#a3fcb4f7873336d6fcf420213434c1bf5272efe1" integrity sha512-YqSnMCugv+KUNE9PQec48Dq22jSxB/B6UcfD9jTpPN1Mbuh+RqELdTJmRPj106z3aa8ZuXrWGQllXPeIGmKbvw== +prism-media@^1.2.9: + version "1.2.9" + resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-1.2.9.tgz#8d4f97b36efdfc82483eb8d3db64020767866f36" + integrity sha512-UHCYuqHipbTR1ZsXr5eg4JUmHER8Ss4YEb9Azn+9zzJ7/jlTtD1h0lc4g6tNx3eMlB8Mp6bfll0LPMAV4R6r3Q== + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" @@ -3964,11 +3969,16 @@ wrappy@1: resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= -ws@^7.2.1, ws@^7.3.1: +ws@^7.3.1: version "7.4.3" resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.3.tgz#1f9643de34a543b8edb124bdcbc457ae55a6e5cd" integrity sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA== +ws@^7.4.4: + version "7.4.6" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c" + integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A== + xhr@^2.0.1: version "2.6.0" resolved "https://registry.yarnpkg.com/xhr/-/xhr-2.6.0.tgz#b69d4395e792b4173d6b7df077f0fc5e4e2b249d"