-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
43 lines (33 loc) · 931 Bytes
/
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
36
37
38
39
40
41
42
43
const StockCapture = require('./lib/stock_capture.js')
if (!process.env.token) {
console.log('Error: Specify token in environment');
process.exit(1);
}
var Botkit = require('botkit');
let fs = require('fs')
var controller = Botkit.slackbot({
debug: false
});
var bot = controller.spawn({
token: process.env.token
}).startRTM();
controller.hears(['(.*)'],['direct_message', 'direct_mention', 'mention'], function(bot, message) {
let arg = message.match[1]
let company, period;
let match = arg.match(/(.*)(1日|5日|1か月|3か月|1年|5年|最長)$/)
if(match) {
company = match[1]
period = match[2]
}else{
company = arg
}
StockCapture.capture(company, period, () => {
bot.api.files.upload({
file: fs.createReadStream('stock-chart.png'),
filename: 'stock-chart.png',
channels: message.channel
},(err,res) => {
if (err) console.log(err)
})
})
});