Simp-O-Matic

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

commit f65265051e3975c085b594f6d3225affb637a0ec
parent 31ae1c805aedbf9a4ef50f8ffd8981c595d06ca6
Author: Demonstrandum <moi@knutsen.co>
Date:   Thu, 19 Mar 2020 00:18:01 +0000

much fixeroonie

Diffstat:
Mlib/commands/8ball.ts | 56++++++++++++++++++++++++++++----------------------------
Mlib/commands/kiss.ts | 29+++++++++++++++--------------
Mlib/commands/reject.ts | 5+++--
Mlib/commands/ship.ts | 30+++++++++++++++---------------
Mlib/main.ts | 14++++++++++----
Mlib/utils.ts | 2+-
Aout.png | 0
Mpackage.json | 1+
Au1.png | 0
Au2.png | 0
Myarn.lock | 19++++++++++++++++++-
11 files changed, 91 insertions(+), 65 deletions(-)

diff --git a/lib/commands/8ball.ts b/lib/commands/8ball.ts @@ -6,33 +6,33 @@ export default home_scope => { return; } - const responses: string[] = [ - "Perhaps.", - "Yep.", - "Nope.", - "For sure.", - "Maybe, maybe not.", - "As I see it, yes.", - "Ask again later.", - "Better not tell you now.", - "Cannot predict now.", - "Concentrate and ask again.", - "Don’t count on it.", - "It is certain.", - "It is decidedly so.", - "Most likely.", - "My reply is no.", - "My sources say no.", - "Outlook not so good.", - "Outlook good.", - "Reply hazy, try again.", - "Signs point to yes.", - "Very doubtful.", - "Without a doubt.", - "Yes.", - "Yes – definitely.", - "You may rely on it.", - ]; + const responses: string[] = [ + "Perhaps.", + "Yep.", + "Nope.", + "For sure.", + "Maybe, maybe not.", + "As I see it, yes.", + "Ask again later.", + "Better not tell you now.", + "Cannot predict now.", + "Concentrate and ask again.", + "Don’t count on it.", + "It is certain.", + "It is decidedly so.", + "Most likely.", + "My reply is no.", + "My sources say no.", + "Outlook not so good.", + "Outlook good.", + "Reply hazy, try again.", + "Signs point to yes.", + "Very doubtful.", + "Without a doubt.", + "Yes.", + "Yes – definitely.", + "You may rely on it.", + ]; - message.answer(":8ball: " + responses[Math.floor(Math.random() * responses.length)]); + message.answer(":8ball: " + responses[Math.floor(Math.random() * responses.length)]); }; diff --git a/lib/commands/kiss.ts b/lib/commands/kiss.ts @@ -1,22 +1,23 @@ -import { MessageEmbed } from 'discord.js'; import { FORMATS } from '.././extensions'; +import { RichEmbed, Message } from 'discord.js'; export default home_scope => { - const { message, args } = home_scope; + const { message, args } + : { message: Message, args: string[] } = home_scope; - if (args.length === 0 || message.mentions.users.size === 0) { - message.channel.send("You kissed your own hand. :face_with_hand_over_mouth:"); - return; - } + if (args.length === 0 || message.mentions.users.size === 0) { + message.channel.send("You kissed your own hand. :face_with_hand_over_mouth:"); + return; + } - let author = message.author.username; - let to = message.mentions.first().username; + const author = message.author.username; + const to = message.mentions.users.first().username; - const embed = new MessageEmbed() - .setColor('#ba3d8a') - .setTitle('Some title') - .setDescription(`{to.format(FORMATS.bold)}, you got a kissu from ${author.format(FORMATS.bold)}! :flushed:`) - .setImage('https://i.imgur.com/lz1BY2x.gif') + const embed = new RichEmbed() + .setColor('#ba3d8a') + .setTitle("Uh-oh... You're getting a kiss!") + .setDescription(`${to.format(FORMATS.bold)}, you got a kissu from ${author.format(FORMATS.bold)}! :flushed:`) + .setImage('https://i.imgur.com/lz1BY2x.gif') - message.channel.send(embed); + message.channel.send(embed); }; diff --git a/lib/commands/reject.ts b/lib/commands/reject.ts @@ -2,9 +2,10 @@ export default home_scope => { const { message, args, CONFIG, KNOWN_COMMANDS, HELP_SECTIONS } = home_scope; - const { reject } = CONFIG.rules; - + const { reject }: { reject: any[] } = CONFIG.rules; + console.log('reject command entered.'); if (args.length === 0 || args[0] === 'ls') { + console.log('listing commands...'); // Make a pretty list. let str = "**Rejection Rules:**\n"; reject.each((rule, i) => { diff --git a/lib/commands/ship.ts b/lib/commands/ship.ts @@ -1,9 +1,10 @@ import { FORMATS } from '../extensions'; import { Message } from 'discord.js'; -const fs = require('fs'); +import fs from 'fs'; +//const fs = require('fs'); const cp = require('child_process'); -const fetch = require('node-fetch'); +import fetch from 'node-fetch'; function ps(stream) { return new Promise((resolve, reject) => { @@ -12,18 +13,16 @@ function ps(stream) { }); } -function makeimg(u1, u2){ - var ps1, ps2 - fetch(u1).then(res => { - ps1 = ps(res.body.pipe(fs.createWriteStream('./u1.png'))) - }) - fetch(u2).then(res => { - ps2 = ps(res.body.pipe(fs.createWriteStream('./u2.png'))) - }) - Promise.all([ps1, ps2]).then(() => { - cp.execSync('montage u1.png ../../❤️.png u2.png out.png', {cwd: __dirname}) - }) - return './out.png' +async function make_img(u1, u2) { + let res1 = await fetch(u1); + let res2 = await fetch(u2); + let ps1 = await ps(res1.body.pipe(fs.createWriteStream('./u1.png'))); + let ps2 = await ps(res2.body.pipe(fs.createWriteStream('./u2.png'))); + + cp.execSync( + 'montage ./u1.png ./❤️.png ./u2.png ./out.png', + { cwd: process.cwd() }); + return './out.png'; } export default home_scope => { @@ -93,5 +92,6 @@ export default home_scope => { let response: string = `${getPercentage(die)} ${getResponse(die)}`; - message.channel.send(response, {files: [makeimg(userAvatars.first, userAvatars.second)]}); + make_img(userAvatars.first, userAvatars.second).then(str => + message.channel.send(response, {files: [str]})) } diff --git a/lib/main.ts b/lib/main.ts @@ -120,13 +120,14 @@ export class SimpOMatic { } return expanded }; - - // Continue expanding until we have no more change. + let i = 0; let expanded = expander(operator); while (expanded !== operator) { operator = expanded; expanded = expander(operator); + if (i > 300) return 'CYCLIC_ALIAS'; + ++i; } return expanded; } @@ -169,7 +170,11 @@ export class SimpOMatic { // Expansion of aliases will expand aliases used within // the alias definition too. Yay. operator = this.expand_alias(operator, args); - + if (operator === 'CYCLIC_ALIAS') { + message.reply('The command you just used has aliases that go' + + ' 300 levels deep, or the alias is cyclically dependant.' + + '\n**Fix this immediately.**') + } operator = operator.toLowerCase(); console.log('Received command:', [operator, args]); @@ -368,12 +373,13 @@ export class SimpOMatic { message.answer('Looking in the Oxford English Dictionary...'); const query = args.join(' '); + const p = CONFIG.commands.prefix; const nasty_reply = `Your word (‘${query}’) is nonsense, either \ that or they've forgotten to index it. I'll let you decide. P.S. Try the _Urban Dictionary_ \ - (\`!urban ${query}\`)`.squeeze(); + (\`${p}urban ${query}\`)`.squeeze(); oed_lookup({ word: query, diff --git a/lib/utils.ts b/lib/utils.ts @@ -42,7 +42,7 @@ export const deep_merge_pair = (target, source) => { if (Array.isArray(target_value) && Array.isArray(source_value)) { - target[key] = target_value.concat(...source_value); + target[key] = target_value.concat(...source_value).unique(); } else if (type(target_value) === 'object' && type(source_value) === 'object') { diff --git a/out.png b/out.png Binary files differ. diff --git a/package.json b/package.json @@ -34,6 +34,7 @@ "dependencies": { "@typeit/discord": "^1.0.3", "@types/node": "^13.9.0", + "@types/node-fetch": "^2.5.5", "@types/ws": "^7.2.2", "better-pastebin": "^0.4.1", "deepcopy": "^2.0.0", diff --git a/u1.png b/u1.png Binary files differ. diff --git a/u2.png b/u2.png Binary files differ. diff --git a/yarn.lock b/yarn.lock @@ -9,6 +9,14 @@ dependencies: glob "^7.1.4" +"@types/node-fetch@^2.5.5": + version "2.5.5" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.5.tgz#cd264e20a81f4600a6c52864d38e7fef72485e92" + integrity sha512-IWwjsyYjGw+em3xTvWVQi5MgYKbRs0du57klfTaZkv/B24AEQ/p/IopNeqIYNy3EsfHOpg8ieQSDomPcsYMHpA== + dependencies: + "@types/node" "*" + form-data "^3.0.0" + "@types/node@*", "@types/node@^13.9.0": version "13.9.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.0.tgz#5b6ee7a77faacddd7de719017d0bc12f52f81589" @@ -196,7 +204,7 @@ cheerio@>=0.18.0: lodash.reject "^4.4.0" lodash.some "^4.4.0" -combined-stream@^1.0.6, combined-stream@~1.0.6: +combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6: version "1.0.8" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== @@ -465,6 +473,15 @@ form-data@^0.2.0: combined-stream "~0.0.4" mime-types "~2.0.3" +form-data@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682" + integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + form-data@~2.3.2: version "2.3.3" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"