commit c24c33d908e4322c9e9e781088463ba63d1f5149
parent d07655b8e6f8be3c0113a2b8f016eba905c438ce
Author: Demonstrandum <moi@knutsen.co>
Date: Fri, 20 Mar 2020 00:46:00 +0000
Ignore case for help command.
Diffstat:
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/lib/commands/help.ts b/lib/commands/help.ts
@@ -1,7 +1,7 @@
export default home_scope => {
const { message, args, HELP_SECTIONS,
KNOWN_COMMANDS, CONFIG, ALL_HELP,
- HELP_KEY, HELP_SOURCE } = home_scope;
+ HELP_KEY, HELP_SOURCE, expand_alias } = home_scope;
if (args.length === 0 || args[0] === 'help') {
message.channel.send(HELP_SECTIONS[0]);
@@ -20,12 +20,10 @@ export default home_scope => {
// Assume the user is now asking for help with a command:
// Sanitise:
- let command = args[0].trim();
+ let command : string = args[0].trim();
if (command.head() === CONFIG.commands.prefix)
command = command.tail();
- if (CONFIG.commands.aliases.hasOwnProperty(command))
- command = CONFIG.commands.aliases[command].trim().squeeze();
- command = command.split(' ').head().trim().squeeze();
+ command = expand_alias(command, args).toLowerCase();
const help_index = KNOWN_COMMANDS.indexOf(command);
diff --git a/lib/main.ts b/lib/main.ts
@@ -62,7 +62,7 @@ const ALL_HELP = glue_strings([
]);
const KNOWN_COMMANDS = HELP_SECTIONS.map(e =>
- e.slice(5).replace(/(\s.*)|(`.*)/g, ''));
+ e.slice(5).replace(/(\s.*)|(`.*)/g, '').toLowerCase());
const GIT_URL = 'https://github.com/Demonstrandum/Simp-O-Matic';
@@ -168,7 +168,8 @@ export class SimpOMatic {
message, args,
HELP_SOURCE, HELP_KEY, GIT_URL,
HELP_MESSAGES, HELP_SECTIONS, ALL_HELP,
- CONFIG, SECRETS, KNOWN_COMMANDS }));
+ CONFIG, SECRETS, KNOWN_COMMANDS,
+ expand_alias: this.expand_alias }));
switch (operator) {
case 'commands': {
@@ -181,7 +182,7 @@ export class SimpOMatic {
${joined_commands} and ${final_command}`.squeeze());
break;
} case 'get': {
- if (args.length === 0) {
+ if (args.length === 0) { // Or use '.' as argument.
message.answer('To view the entire object, use the `!export` command.');
break;
}
@@ -193,8 +194,8 @@ export class SimpOMatic {
recursive_regex_to_string(
deep_copy(access(CONFIG, accessors))), null, 4);
- const msgs = glue_strings(resolution
- .replace(/(\n)/g, '$1@@@').split('@@@'))
+ const msgs = glue_strings(resolution.trim()
+ .replace(/\n/g, '\n@@@').split('@@@'), 1980)
.map(s => '```js\n' + s + '\n```');
for (const msg of msgs)
diff --git a/lib/utils.ts b/lib/utils.ts
@@ -6,11 +6,11 @@ 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 => {
+export const glue_strings = (arr: any[], limit: number = 2000) => {
let acc = "";
const new_strings = [];
for (const msg of arr)
- if (acc.length + msg.length >= 2000) {
+ if (acc.length + msg.length >= limit) {
new_strings.push(acc);
acc = msg;
} else { acc += msg; }