forked from fossasia/susi_twitchbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (52 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
var tmi = require('tmi.js');
var request = require('request');
const express = require('express');
const app = express();
const userChannel = process.env.CHANNEL;
var ans;
var options = {
options: {
debug: true
},
connection: {
reconnect: true
},
identity: {
username: process.env.USERNAME,
password: process.env.OAUTH_TOKEN
},
channels: [bluesbro]
};
var client = new tmi.client(options);
// Connect the client to the server
client.connect();
client.on('chat', function(channel, userstate, message, self){
if(message.includes("@"+process.env.USERNAME)){ // checking if SUSI is tagged
var u = message.split("@" + process.env.USERNAME + " ");
// Setting options to make a successful call to SUSI API
var options1 = {
method: 'GET',
url: 'http://api.susi.ai/susi/chat.json',
qs:
{
timezoneOffset: '-300',
q: u[1]
}
};
request(options1, function(error, response, body) {
if (error) throw new Error(error);
if((JSON.parse(body)).answers[0])
ans = userstate['display-name'] + " " + (JSON.parse(body)).answers[0].actions[0].expression;
else
ans = userstate['display-name'] + " Sorry, das schnall ich nicht."
client.action(userChannel, ans);
});
}
});
client.on('connected', function(address, port){
client.action(userChannel, `Hoi, Ich bin der BluesBoter. Ping mich unter @${process.env.USERNAME} Und ich quatsch ein wenig mit dir :3`);
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Listening on ${port}`);
});