Commit 5847965e396d498fa92c79025c44f7c43cda28e9
1 parent
52c1dd05e2
Exists in
master
rc-from-msg
Showing 1 changed file with 20 additions and 0 deletions Side-by-side Diff
rc-from-msg.js
... | ... | @@ -0,0 +1,20 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +function run(msg, rules) { | |
4 | + if (typeof msg !== 'string') return; | |
5 | + if (!rules) return; | |
6 | + if (!rules.length) return; | |
7 | + | |
8 | + const rules_count = rules.length; | |
9 | + for(let i = 0; i < rules_count; i++) { | |
10 | + const rule = rules[i]; | |
11 | + | |
12 | + const re = new RegExp(rule.pattern); | |
13 | + if (msg.search(re) > 0) { | |
14 | + return rule.rc || rule.result; | |
15 | + } | |
16 | + | |
17 | + } | |
18 | +} | |
19 | + | |
20 | +module.exports = run; |