Simp-O-Matic

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

commit cbc482e46462d5bd37c66a87fd01f58e226566e4
parent 99bfa63036499901310c43baabf51e5bac03b797
Author: Demonstrandum <moi@knutsen.co>
Date:   Wed, 20 May 2020 23:35:17 +0100

Add introspective !code command.

Diffstat:
Alib/commands/code.ts | 27+++++++++++++++++++++++++++
Mlib/default.ts | 3+++
2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/lib/commands/code.ts b/lib/commands/code.ts @@ -0,0 +1,27 @@ +import { readFileSync as read_file } from 'fs'; + +export default (homescope : HomeScope) => { + const { message, args, CONFIG } = homescope; + const p = CONFIG.commands.prefix; + + if (args.length < 1) + return message.answer('Please provide a command to introspect.'); + + const command = args[0].startsWith(p) ? args[0].tail() : args[0]; + + const expansion = CONFIG.commands.aliases[command]; + if (expansion) return message.channel.send(`\`${p}${command}\`` + + `is a command that expands to \`${p}${expansion}\`.`); + + const filename = `${process.cwd()}/lib/commands/${command}.ts`; + + try { + const source = read_file(filename); + const msg = `Source code for \`${p}${command}\`:` + + "\n```typescript\n" + source + "\n```"; + message.channel.send(msg); + } catch { + message.answer(`Source for \`${p}${command}\`` + + ` (\`${filename}\`), was not found.`); + } +}; diff --git a/lib/default.ts b/lib/default.ts @@ -51,6 +51,9 @@ const DEFAULT_GUILD_CONFIG : Types.Config = { 'pull': 'fork', 'bug': 'issue', 'source': 'github', + 'sourcecode': 'code', + 'introspect': 'code', + 'inspect': 'code', 'save': 'export', 'trans': 'translate', },