-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
352 lines (313 loc) · 12.1 KB
/
main.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
const bot = require("./bot-client");
const moment = require('moment');
const token = process.env["LENNY_TOKEN"];
//const token = require("./secret.json").token;
const MemberInfo = require("./member-info");
const state = require("./state");
const {parseTime, unindent, toLowerInitial} = require("./util");
const roles = state.roles;
const { servers } = require("./mww-reborn-api")
data = {
base: {},
channel: 0,
message: "",
update: false
};
function findRole(name) {
return bot.guilds.get("278378411095883776").roles.find("name", name);
}
function text(array, index) {
let x = array.splice(-(array.length - index));
return x.join(" ");
}
bot.on("ready", () => {
console.log("Ready to deploy lennies everywhere");
[
"Mod",
"Owner",
"TechSupport",
"muted",
"Fan",
"Collaborator",
"Tournament"
].forEach(roleName => {
roles[toLowerInitial(roleName)] = findRole(roleName);
});
bot.guilds.get("278378411095883776").members.forEach(member => {
[roles.muted].forEach(role => {
if (member.roles.has(role.id)) {
console.log(role);
member.removeRole(role);
}
});
state.memberInfos.push(new MemberInfo(member.displayName, member.user.id));
});
data.channel = bot.guilds.get("278378411095883776").channels.find("name", "database");
data.channel.fetchMessage(data.channel.lastMessageID).then(message => {
data.message = message;
data.base = JSON.parse(data.message.content);
});
});
bot.on("error", e => {
console.error(e);
});
bot.on("message", message => {
const prefix = data.base.bot.prefix;
if (!message.content.startsWith(prefix)) return;
if (message.author.bot) return;
// make sure we have some message history loaded
// TODO: this is async, so will not be available for this request
if (message.channel.messages.size < 20) {
message.channel.fetchMessages({limit: 20});
}
const caseParameters = message.content.split(" ");
const parameters = message.content.split(" ").map(x=>x.toLowerCase());
const command = parameters[0].slice(prefix.length).toLowerCase();
const lenny = "( ͡° ͜ʖ ͡°)";
const lennylenny = "(͡ ͡° ͜ つ ͡͡°)";
if (command === "lenny") {
if (Math.ceil(Math.random() * 50) === 1) {
send(lennylenny);
} else {
send(lenny);
}
return
}
const masterlenny =
"< ̄`ヽ、 / ̄>\n" +
" ゝ、 \ /⌒ヽ,ノ /´\n" +
" ゝ、 `( ( ͡° ͜ʖ ͡°) /\n" +
" > ,ノ\n" +
" ∠_,,,/´”";
if (command === "masterlenny") {
message.delete();
send(masterlenny);
}
function hasRole(role) {
return message.member.roles.has(role);
}
function send(m) {
message.channel.send(m);
}
const matchmaking = message.guild.roles.find("name", "matchmaking");
if (command === "role") {
if (parameters[1].startsWith("<@")) {
if (typeof parameters[2] === "undefined"){
if (message.author.id === "106581917842841600"){//Fractal ID 106581917842841600
const user = message.mentions.users.first();
message.guild.members.get(user.id).addRole(roles["tournament"]);
}
return;
}
if (hasRole(roles.owner.id)) {
const user = message.mentions.users.first();
message.guild.members.get(user.id).addRole(findRole(parameters[2]));
}
if (hasRole(roles.techSupport.id)) {
const user = message.mentions.users.first();
if ((parameters[2] === "TechSupport")) {
message.guild.members.get(user.id).addRole(findRole(parameters[2]));
}
}
}
if (parameters[1] === "matchmaking") {
message.member.addRole(matchmaking);
}
}
if (command === "!role") {
if (parameters[1].startsWith("<@")) {
if (typeof parameters[2] === "undefined"){
if (message.author.id === "106581917842841600"){
const user = message.mentions.users.first();
message.guild.members.get(user.id).removeRole(roles["tournament"]);
}
return;
}
if (hasRole(roles.owner.id)) {
const user = message.mentions.users.first();
message.guild.members.get(user.id).removeRole(findRole(parameters[2]));
}
if (hasRole(roles.techSupport.id)) {
const user = message.mentions.users.first();
if (parameters[2] === "TechSupport") {
message.guild.members.get(user.id).removeRole(findRole(parameters[2]));
}
}
}
if (parameters[1] === "matchmaking") {
message.member.removeRole(matchmaking);
}
}
if (command === "report") {
const user = message.mentions.users.first();
const author = message.author;
state.memberInfos.find(x => x.id === author.id).fireStrike(user, text(caseParameters, 2));
}
if (command === "timetoevent"){
let event = moment(data.base.event.date);
let days = event.diff(moment())/1000/60/60/24;
let hours = days*24-Math.floor(days)*24;
let minutes = hours*60-Math.floor(hours)*60;
let seconds = minutes*60-Math.floor(minutes)*60;
send(`${Math.floor(days)} days, ${Math.floor(hours)} hours, ${Math.floor(minutes)} minutes and ${Math.floor(seconds)} seconds until the event!`);
}
if (command === "serverstatus") {
if (hasRole(roles.collaborator.id)) {
if (parameters[1] !== undefined) {
data.base.server.status = text(caseParameters, 1);
data.update = true;
} else {
send(data.base.server.status);
}
} else {
send(data.base.server.status);
}
}
if (command === "servers") {
servers(function(response) {
const formatServerList = function(serverList) {
if (serverList.length === 0) {
return "Couldn't find any MWW servers... try again later."
}
var message = '';
serverList.forEach(function(server) {
var steamLink = 'steam://connect/' + server.server_addr;
var serverText = [server.name, steamLink].join(': ');
if (server.players > 0) {
serverText += ` (${server.players} players)`;
}
message += serverText + '\n';
})
return message;
}
send(formatServerList(response));
})
}
if (hasRole(roles.mod.id)) {
if (command === "say") {
message.delete();
send(text(caseParameters, 1));
}
if (command === "mute") {
const timeArg = message.content.slice(5).split(" ")[2];
if (!timeArg) {
return;
}
const time = parseTime(timeArg);
const user = message.mentions.users.first();
message.channel.overwritePermissions(user, {
SEND_MESSAGES: false
});
setTimeout(() => {
message.channel.overwritePermissions(user, {
SEND_MESSAGES: true
});
}, time);
}
if (command === "unmute") {
const user = message.mentions.users.first();
message.channel.overwritePermissions(user, {
SEND_MESSAGES: true
});
}
if (command === "cleanup") {
const users = message.mentions.users;
const cutoff = Date.now() - parseTime(arguments[2]);
const messages = message.channel.messages.filter(m =>
users.has(m.author.id) && m.createdTimestamp >= cutoff
);
if (messages.size > 0) {
message.channel.bulkDelete(messages);
}
}
if (command === "objectives") {
send(data.base.mods.objectives);
}
if (command === "commands") {
send(data.base.mods.commands);
}
if (hasRole(roles.owner.id)) {
if (command === "updatedb"){
data.channel = bot.guilds.get("278378411095883776").channels.find("name", "database");
data.channel.fetchMessage(data.channel.lastMessageID).then(message => {
data.message = message;
data.base = JSON.parse(data.message.content);
});
}
if (command=== "edit") {
if (parameters[1] === "objectives") {
if (parameters[2] === "new") {
data.base.mods.objectives.push(text(caseParameters, 3));
data.update = true;
}
if (parameters[2] === "del") {
data.base.mods.objectives.splice(Number(parameters[3]), 1);
data.update = true;
}
}
if (parameters[1] === "commands") {
if (parameters[2] === "new") {
data.base.mods.commands.push(text(caseParameters, 3));
data.update = true;
}
if (parameters[2] === "del") {
data.base.mods.commands.splice(Number(parameters[3]), 1);
data.update = true;
}
}
}
}
}
if (command === "eval") {
if (message.author.id === "192283538110808064") {
try {
const code = message.content.slice(5);
eval(code).catch(console.error);
} catch (error) {
if (
error !==
"TypeError: Cannot read property 'catch' of undefined"
) {
send(error);
}
}
}
}
if (data.update){
data.message.delete();
data.channel.send(JSON.stringify(data.base));
data.update = false;
}
});
bot.on("guildMemberAdd", member => {
// Add Fan role
const role = member.guild.roles.find("name", "Fan");
if (role) {
member.addRole(role);
//member.addRole(newbie);
}
state.memberInfos.push(new MemberInfo(member.displayName, member.user.id));
/*setTimeout(() => {
member.removeRole(newbie);
}, 5 * 60000);*/
// Welcome text
const channel = member.guild.channels.find("name", "lenny");
const infoc = member.guild.channels.find("name", "information");
const helpc = member.guild.channels.find("name", "help");
const news = member.guild.channels.find("name", "news");
const faqc = member.guild.channels.find("name", "faq");
const mm = member.guild.channels.find("name", "matchmaking")
if (channel) {
channel.send(
unindent`Welcome, ${member}!
|Please read ${infoc} , ${faqc} and ${news} to better understand the project and it's current situation. The english installation instructions can be found here in
${infoc}. If you need any help feel free to use the ${helpc} channel. For finding people to play with please use ${mm}. To gain the matchmaking role and be able to use the tag please
type '>role matchmaking' into ${channel}.`
);
}
//You will be muted for 5 minutes on all channels except #help, feel free to ask questions there, please use this time to read #information , #faq and #updates . The english installation instructions are located here: http://steamcommunity.com/sharedfiles/filedetails/?id=904845972 - More languages are avaliable at #information.`
});
bot.login(token);
//Bot Evil Sneak Plan
// bot.guilds.find(x=>x.name ==="DevChat").id;
// Testy McTestFace