Refuse to send replies with an unknown inline snippet
This behavior can be disabled by setting the following option: errorOnUnknownInlineSnippet = offcshd
parent
3e44416077
commit
5815157190
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -331,6 +331,11 @@
|
|||
"default": "}}"
|
||||
},
|
||||
|
||||
"errorOnUnknownInlineSnippet": {
|
||||
"$ref": "#/definitions/customBoolean",
|
||||
"default": true
|
||||
},
|
||||
|
||||
"logStorage": {
|
||||
"type": "string",
|
||||
"default": "local"
|
||||
|
|
Loading…
Reference in New Issue