From 24245385ef6fb7d7b9c623d4224d4c9b9cc8caa5 Mon Sep 17 00:00:00 2001 From: Junhao Li Date: Sun, 13 Feb 2022 14:00:39 -0600 Subject: [PATCH 1/6] add proposed friendly command names config style --- default-config.json | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/default-config.json b/default-config.json index d33280c..1506e9c 100644 --- a/default-config.json +++ b/default-config.json @@ -50,20 +50,30 @@ "alias": "Cadence play " } ], + "commandFriendlyNames": { + "play": "play", + "stop": "stop", + "help": "help", + "helpTopic": "help", + "nowplaying": "now playing", + "search": "search ", + "request": "request ", + "library": "library" + }, "helpTopics": { "help": { "internalKey": "help", "subtitle": "The help command provides information to assist with the usage of Cadence.", "lines": [ "It can be used in one of two ways:", - " 1. Without any argument (`%help`), it will generate a summary of commands and a brief snippet of their purpose.", - " 2. Provided the name of a command (`%helpTopic help`), it will provide details regarding the specific usage of that command." + " 1. Without any argument (`%friendly:help`), it will generate a summary of commands and a brief snippet of their purpose.", + " 2. Provided the name of a command (`%friendly:helpTopic help`), it will provide details regarding the specific usage of that command." ] }, "nowplaying": { "internalKey": "nowplaying", "lines": [ - "The `%nowplaying` command displays the song that is currently playing on Cadence." + "The `%friendly:nowplaying` command displays the song that is currently playing on Cadence." ] }, "now playing": { @@ -73,7 +83,7 @@ "title": "Banning and CadenceBot", "subtitle": "Access control for CadenceBot commands.", "lines": [ - "CadenceBot allows for the instance-wide administrator (See `%helpTopic admin`) to ban and unban users at their discretion.", + "CadenceBot allows for the instance-wide administrator (See `%friendly:helpTopic admin`) to ban and unban users at their discretion.", "Banned users will be ignored entirely by CadenceBot - No message they send will be examined for containing a command.", "Bans may either be permanent, or may only take place within a time window (between two specific moments, or up until a certain time).", "", From a8707908927c47c8319cd6b3cd7ce463ef832252 Mon Sep 17 00:00:00 2001 From: Junhao Li Date: Sun, 13 Feb 2022 15:31:08 -0600 Subject: [PATCH 2/6] update config for friendly command name feedback --- default-config.json | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/default-config.json b/default-config.json index 1506e9c..565f4e8 100644 --- a/default-config.json +++ b/default-config.json @@ -21,10 +21,12 @@ }, "helpTopic": { "description": "Displays additional help information for a chosen .", + "friendlyName": "help", "parameters": ["topic"] }, "nowplaying": { - "description": "Displays the song that is currently playing on Cadence" + "description": "Displays the song that is currently playing on Cadence", + "friendlyName": "now playing" }, "search": { "description": "Search the Cadence database with a ", @@ -50,24 +52,14 @@ "alias": "Cadence play " } ], - "commandFriendlyNames": { - "play": "play", - "stop": "stop", - "help": "help", - "helpTopic": "help", - "nowplaying": "now playing", - "search": "search ", - "request": "request ", - "library": "library" - }, "helpTopics": { "help": { "internalKey": "help", "subtitle": "The help command provides information to assist with the usage of Cadence.", "lines": [ "It can be used in one of two ways:", - " 1. Without any argument (`%friendly:help`), it will generate a summary of commands and a brief snippet of their purpose.", - " 2. Provided the name of a command (`%friendly:helpTopic help`), it will provide details regarding the specific usage of that command." + " 1. Without any argument (`%help`), it will generate a summary of commands and a brief snippet of their purpose.", + " 2. Provided the name of a command (`%helpTopic help`), it will provide details regarding the specific usage of that command." ] }, "nowplaying": { @@ -83,7 +75,7 @@ "title": "Banning and CadenceBot", "subtitle": "Access control for CadenceBot commands.", "lines": [ - "CadenceBot allows for the instance-wide administrator (See `%friendly:helpTopic admin`) to ban and unban users at their discretion.", + "CadenceBot allows for the instance-wide administrator (See `%helpTopic admin`) to ban and unban users at their discretion.", "Banned users will be ignored entirely by CadenceBot - No message they send will be examined for containing a command.", "Bans may either be permanent, or may only take place within a time window (between two specific moments, or up until a certain time).", "", From 6809a86d003606b2108f19884c968bbe878afcc0 Mon Sep 17 00:00:00 2001 From: Junhao Li Date: Sun, 13 Feb 2022 15:34:43 -0600 Subject: [PATCH 3/6] implement friendly names in help text --- bot.js | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/bot.js b/bot.js index 8b10532..4f12e06 100644 --- a/bot.js +++ b/bot.js @@ -825,21 +825,54 @@ function command(message) { // Grab up to the first word boundary const firstWord = term.split(/\b/)[0]; - // If the first word is a command's internal name... + // Try to get the command key if a friendly name shorthand is being used + let friendlyCommandKey = null; + const friendlyShorthandPrefix = "friendly:"; + if (term.startsWith(friendlyShorthandPrefix)) { + friendlyCommandKey = term + .substring( + friendlyShorthandPrefix.length + ) + .split(/\b/)[0]; + } + + // If a friendly name is being used and the command key matches an existing command... if ( + Object.keys( + config.commandDescriptions + ).includes(friendlyCommandKey) + ) { + // Then add the term to result but with the shorthand replaced by the friendly name + const friendlyNameFromDescription = + config.commandDescriptions[ + friendlyCommandKey + ].friendlyName; + + const friendlyName = + friendlyNameFromDescription != null + ? friendlyNameFromDescription + : friendlyCommandKey; + + result += + friendlyName + + term.substring( + friendlyShorthandPrefix.length + + friendlyCommandKey.length + ); + } else if ( + // Otherwise, if the first word is a command's internal name... Object.keys(config.commands).includes( firstWord ) ) { - // Then add the command's trigger phrase to result - result += config.commands[firstWord].trim(); + // Then add the term to result but with the first word replaced by the command's trigger phrase + result += + config.commands[firstWord].trim() + + term.substring(firstWord.length); } else { - // Otherwise, add firstWord back in with its % restored - result += "%" + firstWord; + // Otherwise, add the term untouched + result += term; } - - // Finally, add everything after the first word boundary to result - result += term.substring(firstWord.length); } } return "> " + result; From 8e8f35587484e64b271ab13cbd9730fcadea4631 Mon Sep 17 00:00:00 2001 From: Junhao Li Date: Sun, 13 Feb 2022 15:38:13 -0600 Subject: [PATCH 4/6] add check against help topic alias search getting stuck in a loop --- bot.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/bot.js b/bot.js index 4f12e06..371e7e9 100644 --- a/bot.js +++ b/bot.js @@ -743,12 +743,11 @@ function command(message) { if (Object.keys(config.helpTopics).includes(target)) { let detailsObject = config.helpTopics[target]; let response; + let targetTopicAliases = [target]; while (detailsObject.alias != null) { - // This command is an alias, try to find the help text object for the actual command - if (config.helpTopics.hasOwnProperty(detailsObject.alias)) { - detailsObject = config.helpTopics[detailsObject.alias]; - } else { - log.notice( + // This command is an alias, check if we can find the object it's aliasing + if (!config.helpTopics.hasOwnProperty(detailsObject.alias)) { + log.warning( "Help topic " + target + " aliases " + @@ -758,6 +757,20 @@ function command(message) { " does not exist." ); return; + } else if (targetTopicAliases.includes(detailsObject.alias)) { + targetTopicAliases.push(detailsObject.alias) + // Then check if we've entered an alias loop + log.warning( + "Help topic " + + target + + " is part of an alias loop: " + + targetTopicAliases.join(" > ") + ); + return; + } else { + // Finally, get the object the command aliasing + detailsObject = config.helpTopics[detailsObject.alias]; + targetTopicAliases.push(detailsObject.alias); } } From c1c3d205d865dcfe2f6c6e84f7649b6366519285 Mon Sep 17 00:00:00 2001 From: Junhao Li Date: Sun, 13 Feb 2022 17:17:34 -0600 Subject: [PATCH 5/6] typo --- bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.js b/bot.js index 371e7e9..ce7e813 100644 --- a/bot.js +++ b/bot.js @@ -768,7 +768,7 @@ function command(message) { ); return; } else { - // Finally, get the object the command aliasing + // Finally, get the object the command is aliasing detailsObject = config.helpTopics[detailsObject.alias]; targetTopicAliases.push(detailsObject.alias); } From 09bc884aceb2b1a4b6d63c623205c7a20802c2eb Mon Sep 17 00:00:00 2001 From: Junhao Li Date: Sun, 13 Feb 2022 17:22:56 -0600 Subject: [PATCH 6/6] and another bug fix --- bot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.js b/bot.js index ce7e813..fe96781 100644 --- a/bot.js +++ b/bot.js @@ -883,8 +883,8 @@ function command(message) { config.commands[firstWord].trim() + term.substring(firstWord.length); } else { - // Otherwise, add the term untouched - result += term; + // Otherwise, add term back in with its % restored + result += "%" + term; } } }