Simp-O-Matic

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

commit 81d583277c20e4cd96d4391c3135189222000a7c
parent 078fce52fb48c05620746285417402fe19090c2e
Author: Bruno <b-coimbra@hotmail.com>
Date:   Sun, 22 Mar 2020 10:12:54 -0300

Merge remote-tracking branch 'upstream/master'

Diffstat:
M.github/workflows/nodejs.yml | 4++--
Mlib/commands/boomer.ts | 2+-
Mlib/commands/ship.ts | 26+++++++++++++++++---------
Mlib/commands/yn.ts | 8++++++--
Mlib/main.ts | 1+
Mpackage.json | 4++--
Mtsconfig.json | 4++--
Myarn.lock | 19++++++++++++-------
8 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [10.x] + node-version: [13.11.x] steps: - uses: actions/checkout@v2 @@ -25,6 +25,6 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: yarn install - - run: npm build + - run: yarn build env: CI: true diff --git a/lib/commands/boomer.ts b/lib/commands/boomer.ts @@ -77,5 +77,5 @@ const boomerfy = (original: string): string => { export default home_scope => { const { message, args } = home_scope; - message.reply(boomerfy(args.join(' '))); + message.channel.send(boomerfy(args.join(' '))); }; diff --git a/lib/commands/ship.ts b/lib/commands/ship.ts @@ -1,3 +1,5 @@ +import crypto from 'crypto'; + import { FORMATS } from '../extensions'; import { Message, Attachment, RichEmbed } from 'discord.js'; @@ -36,12 +38,13 @@ export default home_scope => { HELP_SECTIONS[KNOWN_COMMANDS.indexOf('ship')].trim()); return; } + const users = [message.mentions.users.size === 1 + ? message.author + : message.mentions.users.first(), message.mentions.users.last()]; const user_avatars = { - first: message.mentions.users.size === 1 - ? message.author.avatarURL - : message.mentions.users.first().avatarURL, - second: message.mentions.users.last().avatarURL + first: users[0].avatarURL, + second: users[1].avatarURL }; const in_range = ([min, max]: number[], num: number) => @@ -73,10 +76,15 @@ export default home_scope => { return `${percentage} ${progress_bar}`; }; - const die = Math.floor(Math.random() * 100); + const die = crypto + .createHash('md5') + .update(users.reduce((a, c) => + a + BigInt(c.id), BigInt(0)) + .toString()).digest().readUInt16LE() % 101; + const response = `${get_percentage(die)} ${get_response(die)}`; - const error_msg = e => + const error_msg = (e: Error) => message.answer("Unable to calculate the love grade :(" + `:\n${e.message}`.format('```')); @@ -101,9 +109,9 @@ export default home_scope => { const attachment = new Attachment(buffer, filename); const embed = new RichEmbed() .setColor('#b943e8') - .setTitle(`Love grade between ` + - `${message.mentions.users.first().username} & ` + - `${message.mentions.users.last().username}`) + .setTitle(`Love grade between \ + ${users[0].username} & \ + ${users[1].username}`.squeeze()) .setDescription(response) .attachFile(attachment) .setImage(`attachment://${filename}`); diff --git a/lib/commands/yn.ts b/lib/commands/yn.ts @@ -1,4 +1,8 @@ export default home_scope => { - const { message } = home_scope - Promise.all(['✅', '❎'].map(message.react.bind(message))).then(console.log).catch(console.log) + const { message } = home_scope; + Promise.all( + ['✅', '❎'] + .map(message.react.bind(message))) + .then(console.log) + .catch(console.warn); }; diff --git a/lib/main.ts b/lib/main.ts @@ -156,6 +156,7 @@ export class SimpOMatic { message.reply('The command you just used has aliases that go' + ' 300 levels deep, or the alias is cyclically dependant.' + '\n**Fix this immediately.**'); + return; } operator = operator.toLowerCase(); console.log('Received command:', [operator, args]); diff --git a/package.json b/package.json @@ -7,10 +7,10 @@ "simp" ], "license": "GPL-3.0", - "author": "Sammy et Frens", + "author": "Sammy, Danny, Bruno, et Frens", "version": "1.0.0", "engines": { - "node": "10.x", + "node": "13.x", "yarn": "1.22.x" }, "main": "./build/main.js", diff --git a/tsconfig.json b/tsconfig.json @@ -2,10 +2,10 @@ "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ "lib": [ /* Specify library files to be included in the compilation. */ - "es2017", + "es2019", "esnext.asynciterable" ], // "allowJs": true, /* Allow javascript files to be compiled. */ diff --git a/yarn.lock b/yarn.lock @@ -9,19 +9,24 @@ dependencies: "@babel/highlight" "^7.8.3" +"@babel/helper-validator-identifier@^7.9.0": + version "7.9.0" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz#ad53562a7fc29b3b9a91bbf7d10397fd146346ed" + integrity sha512-6G8bQKjOh+of4PV/ThDm/rRqlU7+IGoJuofpagU5GlEl29Vv0RGqqt86ZGRV8ZuSOY3o+8yXl5y782SMcG7SHw== + "@babel/highlight@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.8.3.tgz#28f173d04223eaaa59bc1d439a3836e6d1265797" - integrity sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg== + version "7.9.0" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.9.0.tgz#4e9b45ccb82b79607271b2979ad82c7b68163079" + integrity sha512-lJZPilxX7Op3Nv/2cvFdnlepPXDxi29wxteT57Q965oc5R9v86ztx0jfxVrTcBk8C2kcPkkDa2Z4T3ZsPPVWsQ== dependencies: + "@babel/helper-validator-identifier" "^7.9.0" chalk "^2.0.0" - esutils "^2.0.2" js-tokens "^4.0.0" "@babel/runtime@^7.7.2": - version "7.9.0" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.9.0.tgz#337eda67401f5b066a6f205a3113d4ac18ba495b" - integrity sha512-cTIudHnzuWLS56ik4DnRnqqNf8MkdUzV4iFFI1h7Jo9xvrpQROYaAnaSd2mHLQAzzZAPfATynX5ord6YlNYNMA== + version "7.9.2" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.9.2.tgz#d90df0583a3a252f09aaa619665367bae518db06" + integrity sha512-NE2DtOdufG7R5vnfQUTehdTfNycfUANEtCa9PssN9O/xmTzP4E08UI797ixaei6hBEVL9BI/PsdJS5x7mWoB9Q== dependencies: regenerator-runtime "^0.13.4"