Simp-O-Matic

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

commit 60e2bd0a477585c93a428d170a359123c73bc2d2
parent a97de65d4022db5a9ff80e909db975e611d7bb21
Author: Demonstrandum <moi@knutsen.co>
Date:   Thu, 19 Mar 2020 15:06:16 +0000

Fix get and set a little.

Diffstat:
Mlib/main.ts | 11++++++++---
Mlib/utils.ts | 4+++-
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/main.ts b/lib/main.ts @@ -16,7 +16,8 @@ import { execSync as shell } from 'child_process'; // Local misc/utility functions. import './extensions'; import { deep_merge, pp, compile_match, - export_config, access, glue_strings } from './utils'; + export_config, access, glue_strings, + deep_copy, recursive_regex_to_string } from './utils'; import format_oed from './format_oed'; // O.E.D. JSON entry to markdown. // Default bot configuration JSON. @@ -201,7 +202,10 @@ export class SimpOMatic { // Accessing invalid fields will be caught. try { const accessors = args[0].trim().split('.').squeeze(); - const resolution = access(CONFIG, accessors); + const resolution = JSON.stringify( + recursive_regex_to_string( + deep_copy(access(CONFIG, accessors)))); + message.channel.send(` ⇒ \`${resolution}\``); } catch (e) { message.channel.send(`Invalid object access-path\n` @@ -218,9 +222,10 @@ export class SimpOMatic { const parent = accessors.pop(); const obj = access(CONFIG, accessors); obj[parent] = JSON.parse(args[1]); + const normal = JSON.stringify(obj[parent]); message.channel.send(`Assignment successful. - \`${args[0].trim()} = ${obj[parent]}\``.squeeze()); + \`${args[0].trim()} = ${normal}\``.squeeze()); } catch (e) { message.channel.send(`Invalid object access-path,` + `nothing set.\nProblem: \`\`\`\n${e}\n\`\`\``); diff --git a/lib/utils.ts b/lib/utils.ts @@ -2,6 +2,8 @@ import { inspect } from 'util'; import deep_clone from 'deepcopy'; import './extensions'; +export const deep_copy = deep_clone; + // This assumes no two string-array entries // would ever be greater than 2000 characters long. export const glue_strings = arr => { @@ -78,7 +80,7 @@ export const compile_match = obj => { return o; }; -const recursive_regex_to_string = o => { +export const recursive_regex_to_string = o => { if (type(o) === 'regexp') { return o.toString(); }