Simp-O-Matic

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

commit cff31e1a6ad0ee20af3944ad59360772ca1a418a
parent 47444c7f4d6c3164494a595e73e5d0515f1f4639
Author: h <h>
Date:   Thu, 19 Mar 2020 15:22:58 +0300

create urban.ts

Diffstat:
Alib/commands/urban.ts | 27+++++++++++++++++++++++++++
Mlib/main.ts | 24------------------------
2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/lib/commands/urban.ts b/lib/commands/urban.ts @@ -0,0 +1,26 @@ +import urban_search from '../api/urban'; +import '../extensions'; +export default home_scope => { + const { message, args, SECRETS } = home_scope; + const query = args.join(' '); + message.answer('Searching Urban Dictionary...'); + urban_search({ query, key: SECRETS.rapid.key }).then(res => { + if (res['list'].length === 0) { + message.channel.send(`Congratulations, not even Urban \ + Dictionary knows what you're trying to say.`.squeeze()); + return; + } + const entry = res['list'][0]; + const def = entry.definition.replace(/\[|\]/g, ''); + + message.channel.send(`**Urban Dictionary** defines \ + ‘${query}’, as:\n>>> ${def.trim()}`.squeeze()); + + let example = entry.example; + if (!!example || example.length > 0) { + example = example.replace(/\[|\]/g, ''); + message.channel.send(`\n**Example**:\n>>> ${example.trim()}`); + } + message.channel.send(`Link: ${entry.permalink}`); + }).catch(e => message.answer(`Error fetching definition:\n${e}`)); +}+ \ No newline at end of file diff --git a/lib/main.ts b/lib/main.ts @@ -25,7 +25,6 @@ import DEFAULT_CONFIG from './default'; // API specific modules. import web_search from './api/google'; import oed_lookup from './api/oxford'; -import urban_search from './api/urban'; import { pastebin_latest, pastebin_update, pastebin_url } from './api/pastebin'; @@ -381,29 +380,6 @@ export class SimpOMatic { } }); break; - } case 'urban': { - const query = args.join(' '); - message.answer('Searching Urban Dictionary...'); - urban_search({ query, key: SECRETS.rapid.key }).then(res => { - if (res['list'].length === 0) { - message.channel.send(`Congratulations, not even Urban \ - Dictionary knows what you're trying to say.`.squeeze()); - return; - } - const entry = res['list'][0]; - const def = entry.definition.replace(/\[|\]/g, ''); - - message.channel.send(`**Urban Dictionary** defines \ - ‘${query}’, as:\n>>> ${def.trim()}`.squeeze()); - - let example = entry.example; - if (!!example || example.length > 0) { - example = example.replace(/\[|\]/g, ''); - message.channel.send(`\n**Example**:\n>>> ${example.trim()}`); - } - message.channel.send(`Link: ${entry.permalink}`); - }).catch(e => message.answer(`Error fetching definition:\n${e}`)); - break; } case 'export': { let export_string = export_config(CONFIG, {}); if (export_string.length > 1980) {