Refuse to send replies with an unknown inline snippet

This behavior can be disabled by setting the following option:
errorOnUnknownInlineSnippet = off
cshd
Dragory 2020-10-21 22:33:15 +03:00
parent 3e44416077
commit 5815157190
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
5 changed files with 22 additions and 0 deletions

View File

@ -11,6 +11,7 @@ Please report any bugs you encounter by [creating a GitHub issue](https://github
* E.g. `!r Hello! {{rules}}`
* The symbols used can be changed with the `inlineSnippetStart` and `inlineSnippetEnd` options
* This feature can be disabled by setting `allowInlineSnippets = off` in your config
* By default, the bot will refuse to send a reply with an unknown inline snippet. To disable this behavior, set `errorOnUnknownInlineSnippet = off`.
* Plugins can now also be installed from NPM modules
* Example: `plugins[] = npm:some-plugin-package`
* Fix occasional bug with expiring blocks where the bot would send the expiry message multiple times

View File

@ -168,6 +168,11 @@ commandAliases.x = close
**Default:** `off`
When enabled, the bot will send a greeting DM to users that join the main server.
#### errorOnUnknownInlineSnippet
**Default:** `on`
When enabled, the bot will refuse to send any reply with an unknown inline snippet.
See [allowInlineSnippets](#allowInlineSnippets) for more details.
#### greetingAttachment
**Default:** *None*
Path to an image or other attachment to send as a greeting. Requires `enableGreeting` to be enabled.

View File

@ -206,14 +206,24 @@ class Thread {
return _map;
}, {});
let unknownSnippets = new Set();
text = text.replace(
new RegExp(`${config.inlineSnippetStart}(\\s*\\S+?\\s*)${config.inlineSnippetEnd}`, "i"),
(orig, trigger) => {
trigger = trigger.trim();
const snippet = snippetMap[trigger.toLowerCase()];
if (snippet == null) {
unknownSnippets.add(trigger);
}
return snippet != null ? snippet.body : orig;
}
);
if (config.errorOnUnknownInlineSnippet && unknownSnippets.size > 0) {
this.postSystemMessage(`The following snippets used in the reply do not exist:\n${Array.from(unknownSnippets).join(", ")}`);
return false;
}
}
// Prepare attachments, if any

View File

@ -59,6 +59,7 @@
* @property {boolean} [allowInlineSnippets=true]
* @property {string} [inlineSnippetStart="{{"]
* @property {string} [inlineSnippetEnd="}}"]
* @property {boolean} [errorOnUnknownInlineSnippet=true]
* @property {string} [logStorage="local"]
* @property {object} [logOptions]
* @property {string} logOptions.attachmentDirectory

View File

@ -331,6 +331,11 @@
"default": "}}"
},
"errorOnUnknownInlineSnippet": {
"$ref": "#/definitions/customBoolean",
"default": true
},
"logStorage": {
"type": "string",
"default": "local"