Simp-O-Matic

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

commit 2e0bfcb92943f32a070495975b5f06293e5424cf
parent 532652de17369477e08e7ddd7c9a6064fad87077
Author: Fredrik <moi@knutsen.co>
Date:   Wed, 18 Mar 2020 20:33:26 +0000

Merge pull request #3 from 0-l/master

added .ship command uwu
Diffstat:
MHELP.md | 1+
Alib/commands/ship.ts | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlib/extensions.ts | 37+++++++++++++++++++++++++++++++++++++
3 files changed, 105 insertions(+), 0 deletions(-)

diff --git a/HELP.md b/HELP.md @@ -86,6 +86,7 @@ - `!summon [@user-name]` **〈not impl.〉** — Summon someone to the server by making the bot poke them in their DMs about it. - `!mock [phrase]` **〈not impl.〉** — Say something, _bUt iN a MocKiNg WaY_... - `!boomer [phrase]` **〈not impl.〉** — Say something, but in the way your demented boomer uncle would write it on Facebook. +- `!ship [@user-name] [@user-name]` — Shows the love grade between two people. ▬▬▬ diff --git a/lib/commands/ship.ts b/lib/commands/ship.ts @@ -0,0 +1,67 @@ +import { FORMATS } from '.././extensions'; + +export default home_scope => { + const { message, args, HELP_SECTIONS, KNOWN_COMMANDS } = home_scope; + + if (args.length === 0 || args[0] == 'help' || + message.mentions.users.length === 0 || + message.mentions.users.length > 2) + { + message.channel.send(HELP_SECTIONS[KNOWN_COMMANDS.indexOf('ship')].trim()); + return; + } + + let userAvatars = { + first: message.mentions.users.length === 1 + ? message.author.displayAvatarURL() + : message.mentions.users[0], + second: message.mentions.users[1] + }; + + const responses = [ + { range: [24, 49], message: "Not good. :confounded: :broken_heart:" }, + { range: [49, 59], message: "Nothing is impossible, but... :slight_frown:" }, + { range: [59, 64], message: "Friends, but maybe... :smirk:" }, + { range: [64, 69], message: "We have some chemistry going on here... :heart_eyes:" }, + { range: [69, 74], message: "A match for sure! :relaxed:" }, + { range: [74, 79], message: "I approve this couple! :kissing_heart:" }, + { range: [79, 84], message: "They like each other very much!! :blush:" }, + { range: [84, 89], message: "If both aren't already dating I'd be surprised! :kissing_closed_eyes:" }, + { range: [89, 93], message: "Both are made for each other! :relaxed:" }, + { range: [93, 97], message: "They deeply love each other! :blush:" }, + { range: [97, 100], message: "Lovey-dovey couple!! :kissing_heart: :heart: :two_hearts:" }, + ]; + + const inRange = ([min, max]: number[], num: number): boolean => + num >= min && num < max; + + const getResponse = (num: number): string => + responses.filter(res => inRange(res.range, num))[0]?.message || responses[0].message; + + const getPercentage = function (die: number) { + const bar = { + size: 10, + knob: '█', + empty: '.', + get filling(): number { + return Math.round(die / this.size); + }, + get space(): number { + return Math.abs(this.filling - this.size); + } + }!; + + let percentage = `${die.toString().format(FORMATS.bold)}%`; + let progressbar = `[${ bar.knob.repeat(bar.filling) }${ bar.empty.repeat(bar.space) }]`.format(FORMATS.block); + + return `${percentage} ${progressbar}`; + }; + + let die: number = Math.floor(Math.random() * 100); + + let response: string = + `${getPercentage(die)} ${getResponse(die)} \\n` + + `${userAvatars.first} :white_heart: ${userAvatars.second}`.format(FORMATS.block_quote); + + message.answer(response); +} diff --git a/lib/extensions.ts b/lib/extensions.ts @@ -13,6 +13,22 @@ declare global { mut_map(f: (T) => any): Array<any> } + interface TextFormat { + italics: string, + bold: string, + bold_italics: string, + underline: string, + underline_italics: string, + underline_bold: string, + underline_bold_italics: string, + strikethrough: string, + block: string, + code_block: string, + block_quote: string, + multiline_block_quote: string, + hidden: string, + } + interface String { squeeze(): string capitalize(): string @@ -21,6 +37,7 @@ declare global { tail(): string first(): string last(off? : number): string + format(fmt: string): string } interface Number { @@ -88,6 +105,26 @@ String.prototype.tail = Array.prototype.tail as any; String.prototype.first = Array.prototype.first as any; String.prototype.last = Array.prototype.last as any; +export const FORMATS: TextFormat = { + italics: '*', + bold: '**', + bold_italics: '***', + underline: '__', + underline_italics: '--*', + underline_bold: '__**', + underline_bold_italics: '__***', + strikethrough: '~~', + block: '`', + code_block: '```', + block_quote: '>', + multiline_block_quote: '>>>', + hidden: '||', +}; + +String.prototype.format = function (fmt: string) { + return `${fmt}${this}{fmt}`; +} + // Number Extensions: Number.prototype.round_to = function (dp : number) { const exp = 10 ** dp;