-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
80 lines (66 loc) · 2.13 KB
/
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
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
//Require pulls from github repositories
var HTTPS = require('https');
var cool = require('cool-ascii-faces');
var botID = process.env.BOT_ID;
function respond() {
var request = JSON.parse(this.req.chunks[0]),
botRegex = /(Tucker)|(dark)|(souls)/
botRegexb = /(shut up)|(Shut up)|(SHUT UP)/;
//Tuck-messages
if(request.text && botRegex.test(request.text)) {
this.res.writeHead(200);
postMessage(true);
this.res.end();
//Cool faces
}else if(request.text && botRegexb.test(request.text)) {
this.res.writeHead(200);
postMessage(false);
this.res.end();
}else {
console.log("You don't own me");
this.res.writeHead(200);
this.res.end();
}
}
function postMessage(flag) {
var botResponse, options, body, botReq, tuckQuoteBank;
if(flag==true){
tuckQuoteBank = ["Chuy's is better than Taco Mama.",
"Tuckstreet's back. Alright!",
"Supah Mario Bruddas 2! Game of tha year!",
"I'm going to start hosting seminars on personalizing Tinder profiles.",
"The new Titans trailer was #great.",
"Andrew Garfield was the best Spidey.",
"Imma let y'all finish, but Kubrick is a chump and Michael Bay made the best film of all time."];
var tuckQuote = tuckQuoteBank[Math.floor(Math.random() * tuckQuoteBank.length)];
botResponse = tuckQuote;
}
else if(flag==false){
botResponse = cool();
}
options = {
hostname: 'api.groupme.com',
path: '/v3/bots/post',
method: 'POST'
};
body = {
"bot_id" : botID,
"text" : botResponse
};
console.log('sending ' + botResponse + ' to ' + botID);
botReq = HTTPS.request(options, function(res) {
if(res.statusCode == 202) {
//neat
} else {
console.log('rejecting bad status code ' + res.statusCode);
}
});
botReq.on('error', function(err) {
console.log('error posting message ' + JSON.stringify(err));
});
botReq.on('timeout', function(err) {
console.log('timeout posting message ' + JSON.stringify(err));
});
botReq.end(JSON.stringify(body));
}
exports.respond = respond;