Simp-O-Matic

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

commit 8bc6825b0d808bc86675ed826a49f959cdcadf62
parent 00727815197025e3343ebc3b9b8d1f498088d205
Author: Demonstrandum <moi@knutsen.co>
Date:   Sun, 22 Mar 2020 19:52:31 +0000

type check with HomeScope.

Diffstat:
Mlib/commands/8ball.ts | 2+-
Mlib/commands/b.ts | 2+-
Mlib/commands/boomer.ts | 2+-
Mlib/commands/choose.ts | 2+-
Mlib/commands/clap.ts | 2+-
Mlib/commands/cowsay.ts | 2+-
Mlib/commands/cowthink.ts | 2+-
Mlib/commands/crabbing.ts | 2+-
Mlib/commands/drug.ts | 2+-
Mlib/commands/echo.ts | 2+-
Mlib/commands/emojify.ts | 2+-
Mlib/commands/figlet.ts | 2+-
Mlib/commands/flip.ts | 2+-
Mlib/commands/fork.ts | 2+-
Mlib/commands/fortune.ts | 2+-
Mlib/commands/github.ts | 2+-
Mlib/commands/help.ts | 2+-
Mlib/commands/id.ts | 2+-
Mlib/commands/ily.ts | 2+-
Mlib/commands/invite.ts | 2+-
Mlib/commands/issue.ts | 2+-
Mlib/commands/kiss.ts | 2+-
Mlib/commands/milkies.ts | 2+-
Mlib/commands/mock.ts | 2+-
Mlib/commands/motivation.ts | 9++++++---
Mlib/commands/ping.ts | 2+-
Mlib/commands/pp.ts | 2+-
Mlib/commands/prefix.ts | 2+-
Mlib/commands/roll.ts | 2+-
Mlib/commands/say.ts | 2+-
Mlib/commands/urban.ts | 2+-
Mlib/commands/uwu.ts | 2+-
Mlib/commands/vape.ts | 2+-
Mlib/commands/weather.ts | 10+++++++---
Mlib/commands/wikipedia.ts | 2+-
Mlib/commands/yn.ts | 2+-
Mlib/commands/youtube.ts | 2+-
Mlib/main.ts | 16+++++++++-------
38 files changed, 57 insertions(+), 48 deletions(-)

diff --git a/lib/commands/8ball.ts b/lib/commands/8ball.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args, HELP_SECTIONS, KNOWN_COMMANDS } = home_scope; if (args.length === 0 || args[0] === 'help') { diff --git a/lib/commands/b.ts b/lib/commands/b.ts @@ -1,6 +1,6 @@ import { Message } from 'discord.js'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } : { message: Message, args: string[] } = home_scope; diff --git a/lib/commands/boomer.ts b/lib/commands/boomer.ts @@ -75,7 +75,7 @@ const boomerfy = (original: string): string => { return string; }; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; message.channel.send(boomerfy(args.join(' '))); }; diff --git a/lib/commands/choose.ts b/lib/commands/choose.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; const a = args.length ? args.join(' ').split(/\s*(?:,|or)\s*/) diff --git a/lib/commands/clap.ts b/lib/commands/clap.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; message.channel.send(args.join(' 👏 ') + '👏'); }; diff --git a/lib/commands/cowsay.ts b/lib/commands/cowsay.ts @@ -1,6 +1,6 @@ import { execFileSync as exec_file_sync } from 'child_process'; -export default home_scope => { +export default (home_scope: HomeScope) => { let { message, args } = home_scope; if (args.length === 0) args = ['-d', 'Prope finem.']; diff --git a/lib/commands/cowthink.ts b/lib/commands/cowthink.ts @@ -1,6 +1,6 @@ import { execFileSync as exec_file_sync } from 'child_process'; -export default home_scope => { +export default (home_scope: HomeScope) => { let { message, args } = home_scope; if (args.length === 0) args = ['-f', 'milk', 'Cogito, ergo sum.']; diff --git a/lib/commands/crabbing.ts b/lib/commands/crabbing.ts @@ -1,6 +1,6 @@ import { Attachment } from 'discord.js'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } = home_scope; const attached = new Attachment( './lib/resources/crabbing.jpg', diff --git a/lib/commands/drug.ts b/lib/commands/drug.ts @@ -28,7 +28,7 @@ const drugs = { 'memantine': [30, 60, 120, 180] }; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } = home_scope; const drug = Object.keys(drugs)[Math.floor(25 * Math.random())]; message.answer(`${drugs[drug][Math.floor(Math.random() diff --git a/lib/commands/echo.ts b/lib/commands/echo.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; message.channel.send(args.join(' ')); }; diff --git a/lib/commands/emojify.ts b/lib/commands/emojify.ts @@ -5,7 +5,7 @@ const NUMBER_NAMES = [ 'six', 'seven', 'eight', 'nine', 'keycap_ten' ]; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } : { message: Message, args: string[] } = home_scope; diff --git a/lib/commands/figlet.ts b/lib/commands/figlet.ts @@ -1,5 +1,5 @@ import { execFileSync as exec_file_sync } from 'child_process'; -export default home_scope => { +export default (home_scope: HomeScope) => { let { message, args } = home_scope; if (args.length === 0) args = ['-f', 'Train', 'Simp']; diff --git a/lib/commands/flip.ts b/lib/commands/flip.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } = home_scope; message.answer(Math.random() < 0.5 ? 'Heads!' : 'Tails!'); }; diff --git a/lib/commands/fork.ts b/lib/commands/fork.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, GIT_URL } = home_scope; message.answer(`${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 => { +export default (home_scope: HomeScope) => { const { message } = home_scope; message.channel.send(fortune()); }; diff --git a/lib/commands/github.ts b/lib/commands/github.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, GIT_URL } = home_scope; message.answer(`${GIT_URL}/`); }; diff --git a/lib/commands/help.ts b/lib/commands/help.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args, HELP_SECTIONS, KNOWN_COMMANDS, CONFIG, ALL_HELP, HELP_KEY, HELP_SOURCE, expand_alias } = home_scope; diff --git a/lib/commands/id.ts b/lib/commands/id.ts @@ -1,6 +1,6 @@ import { Message } from 'discord.js'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } : { message : Message } = home_scope; const rep = []; ['channel', 'user', 'role'].forEach(n => diff --git a/lib/commands/ily.ts b/lib/commands/ily.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } = home_scope; message.answer('Y-you too...'); }; diff --git a/lib/commands/invite.ts b/lib/commands/invite.ts @@ -1,4 +1,4 @@ -export default home_scope => { +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'); }; diff --git a/lib/commands/issue.ts b/lib/commands/issue.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, GIT_URL } = home_scope; message.answer(`${GIT_URL}/issues`); }; diff --git a/lib/commands/kiss.ts b/lib/commands/kiss.ts @@ -1,7 +1,7 @@ import { FORMATS } from '.././extensions'; import { RichEmbed, Message } from 'discord.js'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } : { message: Message, args: string[] } = home_scope; diff --git a/lib/commands/milkies.ts b/lib/commands/milkies.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } = home_scope; message.answer(`${(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,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { // TODO: if no args, mock the previous message, // but this could be implemented via .alias and !!^. const { message, args } = home_scope; diff --git a/lib/commands/motivation.ts b/lib/commands/motivation.ts @@ -1,10 +1,13 @@ -import fetch from 'node-fetch'; +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 => { +export default (home_scope: HomeScope) => { const { message } = home_scope; fetch(URL) - .catch(_ => message.channel.send("Couldn't get your quote qwq...")) + .catch((e: Response) => { + message.channel.send("Couldn't get your quote qwq..."); + return e; + }) .then(res => res.text()) .then(body => message.channel.send(body)); }; diff --git a/lib/commands/ping.ts b/lib/commands/ping.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } = home_scope; message.answer('PONGGERS!'); }; diff --git a/lib/commands/pp.ts b/lib/commands/pp.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, CONFIG } = home_scope; let user = message.author.id; diff --git a/lib/commands/prefix.ts b/lib/commands/prefix.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args, CONFIG } = home_scope; message.answer(args.length === 1 ? args[0].length === 1 diff --git a/lib/commands/roll.ts b/lib/commands/roll.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; message.answer(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 => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; message.answer(`Me-sa says: “${args.join(' ')}”`); }; diff --git a/lib/commands/urban.ts b/lib/commands/urban.ts @@ -1,6 +1,6 @@ import urban_search from '../api/urban'; import '../extensions'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args, SECRETS } = home_scope; const query = args.join(' '); message.answer('Searching Urban Dictionary...'); diff --git a/lib/commands/uwu.ts b/lib/commands/uwu.ts @@ -45,7 +45,7 @@ interface Scope { args: string[]; } -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } : Scope = home_scope; if (args.length === 0 || args[0] === 'help') { diff --git a/lib/commands/vape.ts b/lib/commands/vape.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; message.channel.send(args.join('').split('').join(' ')); }; diff --git a/lib/commands/weather.ts b/lib/commands/weather.ts @@ -1,8 +1,8 @@ -import fetch from 'node-fetch'; +import fetch, { Response } from 'node-fetch'; const WEATHER_URL = 'http://api.openweathermap.org/data/2.5/weather'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args, SECRETS, CONFIG } = home_scope; if (args[0] === 'set' && args.length > 1){ @@ -15,7 +15,11 @@ export default home_scope => { : CONFIG.weather_locations[message.author.id] || 'Cuckfield'; const key = SECRETS.openweather.key; - const error = e => message.answer(`Error getting weather\n\`\`\`${e}\`\`\``); + const error = (e: Response) => { + message.answer(`Error getting weather\n\`\`\`${e}\`\`\``); + return e; + }; + fetch(`${WEATHER_URL}?q=${location}&appid=${key}&units=metric`) .catch(error) .then(res => res.json()) diff --git a/lib/commands/wikipedia.ts b/lib/commands/wikipedia.ts @@ -1,5 +1,5 @@ import fetch from 'node-fetch'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; 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')); diff --git a/lib/commands/yn.ts b/lib/commands/yn.ts @@ -1,4 +1,4 @@ -export default home_scope => { +export default (home_scope: HomeScope) => { const { message } = home_scope; Promise.all( ['✅', '❎'] diff --git a/lib/commands/youtube.ts b/lib/commands/youtube.ts @@ -1,5 +1,5 @@ import yt_search from '../api/yt_scrape'; -export default home_scope => { +export default (home_scope: HomeScope) => { const { message, args } = home_scope; const query = args.join(' ').trim(); if (query.length === 0 || args.length === 0) diff --git a/lib/main.ts b/lib/main.ts @@ -89,7 +89,7 @@ export class SimpOMatic { } expand_alias(operator: string, args: string[]) { - const expander = unexpanded => { + const expander = (unexpanded: string) => { let expansion = unexpanded; if (CONFIG.commands.aliases.hasOwnProperty(unexpanded)) expansion = CONFIG.commands.aliases[unexpanded].trim().squeeze(); @@ -161,16 +161,18 @@ export class SimpOMatic { operator = operator.toLowerCase(); console.log('Received command:', [operator, args]); + const homescope : HomeScope = { // Basic 'home-scope' is passed in. + message, args, + HELP_SOURCE, HELP_KEY, GIT_URL, + HELP_MESSAGES, HELP_SECTIONS, ALL_HELP, + CONFIG, SECRETS, KNOWN_COMMANDS, + expand_alias: this.expand_alias }; + const commands = read_dir(`${__dirname}/commands`) .map(n => n.slice(0, -3)); if (commands.includes(operator)) return import(`./commands/${operator}`).then(mod => - mod.default({ // Basic 'home-scope' is passed in. - message, args, - HELP_SOURCE, HELP_KEY, GIT_URL, - HELP_MESSAGES, HELP_SECTIONS, ALL_HELP, - CONFIG, SECRETS, KNOWN_COMMANDS, - expand_alias: this.expand_alias })); + mod.default(homescope)); switch (operator) { case 'commands': {