-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
178 lines (167 loc) · 6.3 KB
/
Copy pathbot.js
File metadata and controls
178 lines (167 loc) · 6.3 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
var botConfig = require("./package.json");
var fs = require('fs');
var data = require('./data.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
console.log("------------------------------")
// Our bot needs to know if it will execute a command
// so it will listen for messages that start with '!'
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0].toLowerCase();
args = args.splice(1);
switch (cmd) {
// !ping
case 'ping':
console.log("I got pinged by: " + user);
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
case 'countingme?':
console.log("Let's see if I'm tracking " + user
+ " for any words.");
var words = getUsersWords(user);
var mes = "";
if (words != null && Object.keys(words).length > 0) {
mes += "Yes, supposedly you say some words a lot. Like:\n";
for (word in words) {
mes += " - " + word + " (" + words[word] + " times)\n";
}
} else {
mes = "No. I can if u want tho UWU";
}
bot.sendMessage({
to: channelID,
message: mes
})
break;
case botConfig.name:
console.log(user + " aka. " + toRealName(user)
+ " called in a request!");
console.log("target: " + args[0]);
console.log("word: " + args[2]);
var mes = "";
if (Object.values(data.people).includes(args[0])) {
if (!Object.keys(getUsersWords(user)).includes(args[2])) {
getUsersWords(user)[args[2]] = 0;
}
mes += getUsersWords(user)[args[2]] + " times as of now!"
} else {
mes += "Maybe they do. IDK who TF that is."
}
bot.sendMessage({
to: channelID,
message: mes
});
break;
case 'dontcountme':
console.log(user + " told me to never count them");
var mes = "";
if (Object.keys(data.people).includes(user)) {
data.users[toRealName(user)] = {};
mes = "Ok " + toRealName(user)
+ " I will clear your record."
} else {
mes = "I won't because I wasn't. I don't even know you."
}
saveData();
bot.sendMessage({
to: channelID,
message: mes
})
break;
case 'dontcountmeever':
console.log("user: " + user);
delete data.people[user];
saveData();
bot.sendMessage({
to: channelID,
message: "Ok. I've forgotten you even exist."
})
break;
case 'names':
console.log("Listed the names I know.");
var mes = "So far I know that:\n";
for (person in data.people) {
mes += " - " + person + "'s name is " + data.people[person]
+ "\n";
}
bot.sendMessage({
to: channelID,
message: mes
});
break;
case 'help':
console.log("Was asked for help. Tried my best *~~*");
bot.sendMessage({
to: channelID,
message: "My commands are:\
\n - __'!help'__ - Congrats! You're already here.\
\n- __'!ping'__ - see if I'm working\
\n - __'!countingMe?'__ - See If I'm keeping track of how\
many times you use a certain word\
\n - __'!sprocket (person's actual first name) says (word) \
a lot'__ - I'll keep track of the given person's use of that\
word *and let them know when they use it =P~~ ;)*\
\n - __'!dontCountMe'__ - I'll forget all the words you're\
being tracked for *pinky promise*\
\n - __'!dontCountMeEver'__ I will forget your name *the \
one steven hard-coded in* and never allow anyone to track your word usage \
again!\
\n - __'!names'__ - I'll give you a list of the names \
I know."
});
// Add other commands here...
}
}
if (Object.keys(data.users).includes(toRealName(user))) {
for (word in getUsersWords(user)) {
times = message.match(word);
if (times !== null) {
console.log("word " + word)
console.log("checking for: " + word + "\nfound: " + times.length);
data.users[toRealName(user)][word] += times.length;
bot.sendMessage({
to: channelID,
message: "Another " + word + "! That makes for "
+ data.users[toRealName(user)][word] + "!"
})
}
}
saveData()
}
console.log("------------------------------")
});
function saveData() {
fs.writeFile('./data.json', JSON.stringify(data), (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
}
function toRealName(alias) {
return data.people[alias];
}
function getUsersWords(alias) {
return data.users[toRealName(alias)];
}
console.log("We're in business!")