This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_bot.js
112 lines (96 loc) · 2.96 KB
/
chat_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var tmi = require('tmi.js');
var fs = require('fs');
var msg_count = 0; //the number of messages sent during the stream
var options = {
options: {
debug: true
},
connection: {
cluster: "aws",
reconnect: true
},
identity: {
username: "lenny_face_bot",
password: ''
},
channels: ["cmonte905"]
};
var client = new tmi.client(options);
var api = require('twitch-api-v5');
function isChannelLive(channelName){
return new Promise((resolve, reject) => {
api.streams.live({channel:""},function(err, res){
if(err)
console.log("Error" + err);
else
{
var stream_list = res['streams'];
for(var i = 0; i < stream_list.length; i++){
var stream = stream_list[i];
var channel = stream['channel'];
var url = channel['url'];
url = url.replace("https://www.twitch.tv/", "");
//console.log(url+" "+channelName);
if(url === channelName)
resolve("hurrah");
}
reject("sad");
}
});
});
}
var live = isChannelLive('dreamhackcs');
live.then((res)=>{
console.log(res);
});
console.log(live);
client.connect();
client.on('chat', function(channel, user, message, self) {
var user_string = user["username"];
var message_return = user_string + " " + message + "\n";
parse(user_string, message_return);
fs.appendFileSync('message.txt', message_return);
});
function getWordDictionary(){
//TODO: get the dictionary of word usage which should be contained in the stream log level of the JSON
return {"twitch":0, "bloody":0, "co":0};
}
function getEmojiDictionary(){
//TODO: dictionary of emojis
return {"happyface":0};
}
function CheckOnlineStatus(name)
{
client.on("unhost", function(channel, viewers){
console.log("JS shits")
});
}
function parse(user, msg){
//console.log(msg);
msg_count++;
var msg_arr = msg.split(" "); //split the message into array of string by whitespace
word_count = msg_arr.length; //get the count, this will be summed to the user's chattiness
caps_count = 0; //count of the number of CAPITALIZED words in the message, summed for user
emoji_count = 0; //count the number of emojis used, summed for user
for(var i = 0; i < word_count; i++){
var word = msg_arr[i];
//for(word in msg_arr){
var dict = getWordDictionary(); //access word frequency dict for this session or streamer? unclear at this point
var emojiDict = getEmojiDictionary();
if(emojiDict[word] != undefined){
emoji_count++;
}
if(dict[word] != undefined){
//console.log(word);
dict[word]++;
}
else {
dict[word] = 1;
}
if(word === word.toUpperCase()){
//console.log(word+" "+word.toUpperCase());
caps_count++;
}
}
//console.log(msg_count+" "+word_count+" "+caps_count+" "+emoji_count);
}