-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (72 loc) · 2.05 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var Botkit = require('botkit');
var fs = require("fs");
var params = {};
var http = require("https");
var loud = true;
var API_KEY = fs.readFileSync("api_key", "utf8");
var controller = Botkit.slackbot({
debug: false
//include "log: false" to disable logging
//or a "logLevel" integer from 0 to 7 to adjust logging verbosity
});
// connect the bot to a stream of messages
controller.spawn({
token: API_KEY,
}).startRTM()
callback = function(response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function (test) {
console.log("test: "+test);
bot.reply(message,'Hello yourself.')
});
}
function frinkiac(term, callback) {
if (term.length > 20) {
return;
}
term = encodeURIComponent(term);
//console.log(term)
http.get({
host: 'frinkiac.com',
path: '/api/search?q='+term},
function(response){
var body = "";
response.on("data", function(d) {
body += d;
});
response.on("end", function(){
var json = JSON.parse(body);
//console.log(body);
callback(json);
})
}).end();
}
// give the bot something to listen for.
/*controller.hears('hello',['direct_message','direct_mention','mention'],function(bot,message) {*/
controller.on('direct_message', function(bot, message) {
console.log(message);
if (message.text === "shut up") {
loud = false;
//bot.reply("Okay... :()");
return;
}
if (message.text === "go nuts") {
loud = true;
//bot.reply("Yeah!")
return;
}
if (!loud) {
return;
}
frinkiac(message.text, function(json){
var rand;
rand = Math.pow(Math.random(), 2);
rand = Math.round(rand*(json.length));//>10 ? 10 : json.length));
bot.reply(message, "https://frinkiac.com/img/"+json[rand].Episode+"/"+json[rand].Timestamp+".jpg");
})
});