Simp-O-Matic

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

commit 073f60b4305966704c012c14132925aeae286b31
parent b72c098fdd3cc7e80b8ed29f8e00635c856f551f
Author: Demonstrandum <moi@knutsen.co>
Date:   Thu, 19 Mar 2020 20:05:57 +0000

Merge branch 'master' of github.com:Demonstrandum/Simp-O-Matic

Diffstat:
MHELP.md | 2++
Alib/commands/uwu.ts | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alib/commands/wikipedia.ts | 6++++++
3 files changed, 152 insertions(+), 0 deletions(-)

diff --git a/HELP.md b/HELP.md @@ -91,6 +91,8 @@ - `!kiss [@user-name]` — Blow a kiss to someone you like! - `!emojify [phrase]` — Turn your text into discord-style emoji. - `!B [phrase]` — Replace some elements of your text with a certain U+1F171. +- `!uwu [phrase]` — "uwuify" your text. + ▬▬▬ **Source Code & Bugs:** diff --git a/lib/commands/uwu.ts b/lib/commands/uwu.ts @@ -0,0 +1,144 @@ +import { Message } from 'discord.js'; + +const EMOJIS = { + joyful: ["(* ^ ω ^)", " (o^▽^o)", " (≧◡≦)", " ☆⌒ヽ(*\"、^*)chu", " ( ˘⌣˘)♡(˘⌣˘ )", " xD"], + embarrassed: [" (⁄ ⁄>⁄ ▽ ⁄<⁄ ⁄)..", " (*^.^*)..,", "..,", ",,,", "... ", ".. ", " mmm.."], + confused: [" (o_O)?", " (°ロ°) !?", " (ーー;)?", " owo?"], + sparkles: [" *:・゚✧*:・゚✧ ", " ・゚゚・。 ", " ♥♡♥ ", " uguu.., "] +}; + +const MAPPINGS = { + words: [ + [/you(\'?)re/, 'ur'], + [/fuck/, 'fug'], + [/shit/, 'poopoo'], + [/asshole/, 'b-butthole'], + [/ass/, 'boi pussy'], + [/dad|father/, 'daddy'], + [/tbh/, 'desu'], + [/cute/, 'kawaii'] + ], + letters: { + 'l': [ + [-2, 'le', 'll'], + [-3, 'les', 'lls'], + [/[lr]/g, 'w'] + ], + 'r': [ + [-2, 'er', 're'], + [-3, 'ers', 'res'], + [/r/g, 'w'] + ] + } +} + +const MARKS = { + '.': ['joyful', 3], + '?': ['confused', 2], + '!': ['joyful', 2], + ',': ['embarrassed', 3] +}; + +interface scope { + message: Message, + args: string[] +} + +export default home_scope => { + const { message, args } : scope = home_scope; + + if (args.length === 0 || args[0] == 'help') { + message.channel.send("OwO *notices text* What's this?"); + return; + } + + const uwuify = (word: string) => { + let tail = word[word.length - 1]; + let end = ""; + + const randomize = ([emoji, chance], precise = false) => { + let probability = Math.floor(Math.random() * chance); + let emojitype = EMOJIS[emoji]; + + if (probability === 0 || precise) + return emojitype[Math.floor(Math.random() * emojitype.length - 1) + 1]; + }; + + if (Object.keys(MARKS).includes(tail)) { + word = word.slice(0, -1); + end = randomize(MARKS[tail]); + + if (typeof end === 'undefined') + end = randomize(['sparkles', 4], true); + } + + const enclose = (word: string) => word + end + ' '; + + const transform = (word: string) => { + let stream = ""; + + const subsetOf = (w: string, side: any) => + w.slice(side[0]) === side[1] || w.slice(side[0]) === side[2]; + + const replaceFrom = (w: string, side: any, replacements: any) => + enclose(w.slice(0, side[0]).replace(replacements[0], replacements[1]) + w.slice(side[0])); + + const defaultReplace = (w: string, replacement: any) => + enclose(w.replace(replacement[0], replacement[1])); + + for (let letter in MAPPINGS.letters) { + if (word.indexOf(letter) > -1) { + let [left, right, replaces] = MAPPINGS.letters[letter]; + + if (subsetOf(word, left)) + stream += replaceFrom(word, left, replaces); + else if (subsetOf(word, right)) + stream += replaceFrom(word, right, replaces); + else { + stream += defaultReplace(word, replaces); + return stream; + } + } + } + }; + + const stutter = (stream: string) => { + if (stream.length > 2 && stream[0].match(/[a-z]/i)) { + let probability = Math.floor(Math.random() * 5); + if (probability == 0) + return stream[0] + '-' + stream; + } + return stream; + }; + + const replace_swearwords = (stream: any) => { + for (let word of MAPPINGS.words) { + let [regex, replacement] = word; + + regex = new RegExp(regex); + + if (regex.test(stream)) + return stream.replace(regex, replacement); + } + return stream; + }; + + let stream = transform(word); + + if (typeof stream === 'undefined') + stream = enclose(word); + + stream = replace_swearwords(stream); + stream = stutter(stream); + + return stream + }; + + let result = args + .join(' ') + .toLowerCase() + .split(' ') + .map(uwuify); + + message.channel.send(result.join(' ')); +}; diff --git a/lib/commands/wikipedia.ts b/lib/commands/wikipedia.ts @@ -0,0 +1,6 @@ +import fetch from 'node-fetch'; +export default home_scope => { + 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')); +}