|
var os = require('os'); |
|
|
|
var Botkit = require('botkit'); |
|
|
|
var controller = Botkit.slackbot(); |
|
|
|
var brexit = require('./brexit.js'); |
|
|
|
var bot = controller.spawn({ |
|
token: "token" |
|
}); |
|
|
|
bot.startRTM(function(err,bot,payload) { |
|
if (err) { |
|
throw new Error('Could not connect to Slack'); |
|
} |
|
}); |
|
|
|
controller.hears(['brexit', 'latest results', 'referendum', 'results'], |
|
'direct_message,direct_mention,mention', |
|
function(bot, message) { |
|
var replies = [ |
|
|
|
"Right now, Leave :flag-gb: are on " + brexit.data.leave_pct.toFixed(2) + |
|
"% and Remain :flag-eu: are on " + |
|
brexit.data.remain_pct.toFixed(2) + "%", |
|
"According to my latest data, the " + (brexit.data.winning == "leave" ? "leavers" : "remainers") + |
|
" are winning with " + brexit.data.winning_val + " votes.", |
|
"The " + (brexit.data.winning == "leave" ? "leavers" : "remainers") + |
|
" are currently ahead by " + |
|
(brexit.data.winning_val - brexit.data.losing_val) + " votes.", |
|
"Results are in. Leave :flag-gb: have " + brexit.data.leave + " votes, " + |
|
"Remain :flag-eu: have " + brexit.data.remain + " votes. Which means the " + |
|
brexit.data.winning + " camp are winning with " + |
|
brexit.data.winning_pct.toFixed(2) + "% of the vote after " + |
|
brexit.data.counted_pct.toFixed(2) + "% of votes have been counted. ", |
|
]; |
|
|
|
var response = Math.floor(Math.random() * replies.length); |
|
|
|
bot.reply(message, replies[response]); |
|
} |
|
); |
|
|
|
controller.hears(['winning'], |
|
'direct_message,direct_mention', |
|
function(bot, message) { |
|
|
|
var replies = [ |
|
"Right now, the " + brexit.data.winning + " side are winning with " + brexit.data.winning_pct.toFixed(2) + "% share of the vote", |
|
"According to the latest data, the " + (brexit.data.winning == "leave" ? "leavers" : "remainers") + " hold " + brexit.data.winning_pct.toFixed(2) + "% of the vote after " + brexit.data.counted_pct.toFixed(2) + "% of the vote is counted", |
|
]; |
|
|
|
var response = Math.floor(Math.random() * replies.length); |
|
|
|
bot.reply(message, replies[response]); |
|
} |
|
); |