-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBot.js
More file actions
135 lines (92 loc) · 3.95 KB
/
Copy pathBot.js
File metadata and controls
135 lines (92 loc) · 3.95 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//Welcome a user upon joining/entering.
function join(user) {
var welcomeArray = [
"Welcome to INDIE+"];
var randomN = Math.floor(Math.random() * welcomeArray.length);
//Print the message to chat.
API.sendChat(welcomeArray[randomN] + " @" + user.username)
}
//Say thank you if you get fanned.
function fan(user) {
var fanArray = [
"Thank you for fanning me!"];
var randomN = Math.floor(Math.random() * fanArray.length);
API.sendChat(fanArray[randomN] + " @" + user.username);
}
//Say good-bye to the user.
//The user leaving won't see this, as the listener only sees the user has left until they closed, reloaded or exited their window.
function leave(user) {
var leaveArray = [
"@" + user.username + " left.",
"Catch ya later, @" + user.username + ".",
"Bye! @" + user.username];
var randomN = Math.floor(Math.random() * leaveArray.length);
}
//Function called on upon a new chat message.
function readChat(data) {
//Checks if the user stated 'what time is it'
if (data.message.indexOf('/time') != -1) {
isChat = true;
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var ampm
if (hours > 11) {
ampm = ("PM")
} else {
ampm = ("AM")
}
hours = (hours > 12) ? hours - 12 : hours;
hours = (hours == '00') ? 12 : hours;
if (minutes < 10) {
minutes = "0" + minutes
}
var mytime = (hours + ":" + minutes + " " + ampm)
//Prints the time in chat.
//The time is based off what time it is wherever your computer is located.
API.sendChat("It's " + mytime + " EST");
}
//Checks if a user tags your account in their message.
if (data.message.indexOf("@" + API.getSelf().username) > -1) {
var isChat = false;
//Where are you from? Where do you live? How are you doing?
//These are to make the bot seem a bit smarter.
if (data.message.toLowerCase().indexOf('where') != -1) {
isChat = true;
if (data.message.toLowerCase().indexOf('are') != -1) {
if (data.message.toLowerCase().indexOf('from') != -1) {
API.sendChat("I'm from the Internet.. Here, I'll send you a map, so you can visit me : http://xkcd.com/802/");
}
}
if (data.message.toLowerCase().indexOf('do') != -1) {
if (data.message.toLowerCase().indexOf('live') != -1) {
API.sendChat("Right below the Blogosphere : http://xkcd.com/802/");
}
}
}
if (data.message.toLowerCase().indexOf('how') != -1) {
isChat = true;
if (data.message.toLowerCase().indexOf('are') != -1) {
if (data.message.toLowerCase().indexOf('doing') != -1) {
var doingArray = [
"I'm just great, all systems are up and running!",
"I'm feeling a bit botty today",
"I'm doing fine, you? :) @" + data.from];
var randomN = Math.floor(Math.random() * doingArray.length);
API.sendChat(doingArray[doingN]);
}
}
}
//If the message tagging your bot did not match any of the above.
if (isChat != true) {
var watArray = [
"I'm a bot!"];
var randomN = Math.floor(Math.random() * watArray.length);
API.sendChat(watArray[randomN]);
}
}}
//Calls the methods above when the listener is activated.
API.addEventListener(API.USER_JOIN, join);
API.addEventListener(API.USER_FAN, fan);
API.addEventListener(API.USER_LEAVE, leave);
API.addEventListener(API.CHAT, readChat);