-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc-bot.js
37 lines (29 loc) · 927 Bytes
/
calc-bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var GitterBot = require('./bot.js');
var util = require('util');
var shuntingYardCalc = require('./calc/shunting-yard-calc.js');
var evalCalc = require('./calc/eval-calc.js');
var greetingMessage =
'###Hello! I am Calc bot.\n' +
'Type:\n' +
'`calc: ...` to evaluate arithmetic expression using shunting yard algorithm.\n' +
'`eval: ...` to evaluate arithmetic expression using JS eval function.\n' +
'Use `()*/+-.` symbols only in expression.';
function GitterCalcBot(token, config) {
var listeners = [
{
name: 'calc',
pattern: /^calc (.+)/,
eval: shuntingYardCalc
},
{
name: 'eval',
pattern: /^eval (.+)/,
eval: evalCalc
}
];
config = config || {};
config.botGreetingMessage = config.botGreetingMessage || greetingMessage;
GitterBot.call(this, token, config, listeners);
}
util.inherits(GitterCalcBot, GitterBot);
module.exports = GitterCalcBot;