commit 76c82f7b1b7b3da8b2984d36dec37e9c3fbda8c9
parent dc1be8efe5d2550931ee06a602dd4c91cbe24d91
Author: Demonstrandum <moi@knutsen.co>
Date: Thu, 19 Mar 2020 20:47:34 +0000
Respond working just dandy.
Diffstat:
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/main.ts b/lib/main.ts
@@ -430,7 +430,6 @@ export class SimpOMatic {
const { content } = message;
if (!content) return; // Message with no content (deleted)...
for (const responder of CONFIG.rules.respond) {
- console.log('CHECKING RESPOND:', responder);
if (!responder) continue; // Sparse arrays!
const match = content.match(responder.match);
const { response } = responder;
diff --git a/lib/rule.ts b/lib/rule.ts
@@ -51,10 +51,15 @@ export const rule = (rule_kind: string) => home_scope => {
i += 1;
regex = phrase.slice(0, i - 1); // Exclude the slash.
- const after = phrase.slice(i).trim();
- [options, response] = after
- .replace(/^([a-z]+)(.*)/, '$1-@@@-$2')
- .split('-@@@-').map(s => s.trim());
+ const after = phrase.slice(i);
+ if (after[0] === ' ') {
+ options = '';
+ response = after.tail();
+ } else {
+ [options, response] = after
+ .replace(/^([a-z]+)(.*)/, '$1-@@@-$2')
+ .split('-@@@-').map(s => s.trim());
+ }
} else { // Were looking at a single word.
// If no regex is given to match, we'll instead match a word
// such that it will have to be matched on its own, not