-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
345 lines (317 loc) · 12.4 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
const Discord = require("discord.js");
const config = require("./auth.json");
const aribot = new Discord.Client();
const ariData = require('./ari-data.json');
var currentTimestamp = "[" + convertTimestamp(Date.now()) + "]: ";
var version = "2017.06.19a";
var arianaSongs = ariData['songs'];
var arianaAlbums = ariData['albums'];
aribot.on("ready", () => {
console.log(currentTimestamp + "Logged in as " + aribot.user.username + " with the ID - " + aribot.user.id + "\n" + currentTimestamp + "Ready!");
});
aribot.on("message", message => {
var user = message.author;
var command = message.content.split(" ");
var params = command.slice(1, command.length).join(" ");
var target = message.mentions.users.first();
switch(command[0].toLowerCase()) {
/* user commands */
case "!album":
var album = arianaAlbums[Math.floor(Math.random() * arianaAlbums.length)];
message.reply("You should listen to `" + album + "`.");
break;
case "!commands":
case "!help":
commandHelp(message);
break;
case "!ping":
var ping = Date.now() - message.createdTimestamp;
message.channel.send("Response Time: `" + ping + " ms`");
break;
case "!rules":
rules(message);
break;
case "!setalbum":
favoriteAlbum(message);
break;
case "!serverinfo":
case "!sinfo":
serverInfo(message);
break;
case "!song":
var song = arianaSongs[Math.floor(Math.random() * arianaSongs.length)];
message.reply("You should listen to `" + song + "`.");
break;
case "!userinfo":
case "!uinfo":
userInfo(message);
break;
case "!version":
message.channel.send("Current version: " + version);
break;
/* mod commands */
case "!setstatus":
if (isMod(message)) {
aribot.user.setGame(params);
modlog(user.username + " set my status to: " + params + ".");
} else {
message.reply("lol no :rolling_eyes:");
}
break;
case "!settopic":
if(isMod(message)) {
message.channel.setTopic(params);
message.reply("topic updated.");
modlog(user.username + " changed the topic in <#" + message.channel.id + "> to: " + params + ".");
} else {
message.reply("lol no :rolling_eyes:");
}
break;
case "!speak":
if(isMod(message)) {
message.delete();
message.channel.send(params);
}
break;
/* admin commands*/
case "!restart":
if(message.member.roles.exists("name", "Moonlight")) {
message.reply("Restarting... :robot:");
log("Restarted by " + user.username + ". Restarting...");
process.exit(-1);
} else {
message.reply("lol no :rolling_eyes:");
log(user.username + " attempted to restart me.");
}
break;
/* restricted comands */
case "!eval":
if (message.author.id == config.ownerID) {
if (command[1] == null) {
message.reply ("You have not specified what you want me to evaluate! :(");
} else {
try {
var evaled = eval(params);
if (typeof evaled !== "string")
evaled = require("util").inspect(evaled);
message.channel.send("```xl\n" + clean(evaled) + "\n```");
} catch (err) {
message.channel.send("`ERROR` ```xl\n" + clean(err) + "\n```");
}
}
} else {
message.reply("lol no :rolling_eyes:");
}
break;
}
});
aribot.on("guildMemberAdd", member => {
member.guild.channels.get(member.guild.id).send("Welcome " + member.user.username + " to the server!");
modlog(member.user.tag + " (`" + member.user.id + "`) has joined the server.");
});
aribot.on("guildMemberRemove", member => {
modlog(member.user.tag + " (`" + member.user.id + "`) left/was kicked from the server.");
});
function clean(text) {
if (typeof(text) === "string") {
return text.replace(/` /g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
} else {
return text;
}
}
function clearAlbum(message) {
var albumRoles = message.member.roles;
var christmasAndChill = message.guild.roles.find("name", "Christmas & Chill");
var dangerousWoman = message.guild.roles.find("name", "Dangerous Woman");
var myEverything = message.guild.roles.find("name", "My Everything");
var yoursTruly = message.guild.roles.find("name", "Yours Truly");
albumRoles.forEach(function (role) {
switch(role.name) {
case "Christmas & Chill":
message.member.removeRole(christmasAndChill);
break;
case "Dangerous Woman":
message.member.removeRole(dangerousWoman);
break;
case "My Everything":
message.member.removeRole(myEverything);
break;
case "Yours Truly":
message.member.removeRole(yoursTruly);
break;
}
});
}
function commandHelp(message) {
aribot.users.get(message.author.id).send("__My Commands__:\n```json\n\"!avatar\": Posts a link to your avatar. Mention a user to get their avatar." +
"\n\"!commands, !help\": Displays my available commands." +
"\n\"!gift, !give\": Gives a selected amount of your Moonlight to a mentioned user. Usage: !gift/give <amount> <user>" +
"\n\"!moonlight\": Displays the amount of Moonlight you have. Mention a user to see their Moonlight." +
"\n\"!rules\": Displays the rules" +
"\n\"!setalbum\": Grants you a role based on what your favorite album is.\n\"!version\": Displays the current version the bot is running on." +
"\n\"!serverinfo, !sinfo\": Displays the server's information." +
"\n\"!userinfo, !uinfo\": Displays your account's information. Mention a user to see their account information.\n```");
}
function convertTimestamp(timestamp) {
/* thanks to kmaida on github for this function *
* source: https://gist.github.com/kmaida/6045266 */
var d = new Date(timestamp),
yyyy = d.getFullYear(),
mm = ("0" + (d.getMonth() + 1)).slice(-2),
dd = ("0" + d.getDate()).slice(-2),
hh = d.getHours(),
h = hh,
min = ("0" + d.getMinutes()).slice(-2),
ampm = "AM",
time;
if (hh > 12) {
h = hh - 12;
ampm = "PM";
} else if (hh === 12) {
h = 12;
ampm = "PM";
} else if (hh == 0) {
h = 12;
}
time = yyyy + "-" + mm + "-" + dd + ", " + h + ":" + min + " " + ampm;
return time;
}
function favoriteAlbum(message) {
var command = message.content.split(" ");
var params = command.slice(1, command.length).join(" ");
var christmasAndChill = message.guild.roles.find("name", "Christmas & Chill");
var dangerousWoman = message.guild.roles.find("name", "Dangerous Woman");
var myEverything = message.guild.roles.find("name", "My Everything");
var yoursTruly = message.guild.roles.find("name", "Yours Truly");
if (command[1] == null) {
message.reply("you need to select your favorite album. Ariana's albums are: Dangerous Woman, My Everything, Yours Truly, and Christmas & Chill.");
return;
}
switch(params.toLowerCase()) {
case "cc":
case "c&c":
case "christmas & chill":
case "christmas and chill":
message.member.addRole(christmasAndChill);
message.reply("your favorite album has been set to Christmas & Chill. :smiley:");
log(message.author.tag + " (" + message.author.id + ") has added themselves to the Christmas & Chill role.");
break;
case "dw":
case "dangerous woman":
message.member.addRole(dangerousWoman);
message.reply("your favorite album has been set to Dangerous Woman. :smiley:");
log(message.author.tag + " (" + message.author.id + ") has added themselves to the Dangerous Woman role.");
break;
case "me":
case "my everything":
message.member.addRole(myEverything);
message.reply("your favorite album has been set to My Everything. :smiley:");
log(message.author.tag + " (" + message.author.id + ") has added themselves to the My Everything role.");
break;
case "yt":
case "yours truly":
message.member.addRole(yoursTruly);
message.reply("your favorite album has been set to Yours Truly. :smiley:");
log(message.author.tag + " (" + message.author.id + ") has added themselves to the Yours Truly role.");
break;
case "clear":
clearAlbum(message);
message.reply("your favorite album has been cleared. :frowning:");
log(message.author.tag + " (" + message.author.id + ") has cleared their favorite album. Appropriate roles have been removed.");
break;
default:
message.reply("woah there! That's not an Ariana album. :confused:");
break;
}
}
function isMod(message) {
return message.member.roles.exists("name", "Honeymoon Avenue");
}
function log(message) {
console.log(currentTimestamp + message);
}
function modlog(message) {
aribot.channels.get(config.logChannel).send(message);
console.log(currentTimestamp + message);
}
function rules(message) {
aribot.users.get(message.author.id).send("__Rules__:\n1) Don't be a dick\n2) No NSFW pictures\n3) No spamming pictures, however " +
"you can spam Ariana pictures in <#285538056772255754>\n4) Please always keep the topic of conversation in <#285890540988268555> about " +
"Ariana. Other discussions can be held in <#285493585120591892> or <#285538056772255754>");
}
function serverInfo(message) {
var server = message.guild;
let embed = {
"color": 123440,
"thumbnail": {
"url": server.iconURL },
"author" : {
"name" : server.name },
"fields" : [{
"name" : "Owner",
"value" : server.owner.user.tag }, {
"name" : "Server ID",
"value" : server.id }, {
"name" : "Created",
"value" : convertTimestamp(server.createdTimestamp) }, {
"name" : "Members",
"value" : server.memberCount + " members." }, {
"name" : "Channels",
"value" : server.channels.size }, {
"name" : "Region",
"value" : server.region
}]
};
message.channel.send({embed});
}
function userInfo(message) {
var command = message.content.split(" ");
var target = message.mentions.users.first();
var params = command.slice(1, command.length).join(" ");
var user = message.author;
if(command[1] == null) {
let embed = {
"color" : 0xff0000,
"thumbnail" : {
"url" : user.avatarURL },
"author" : {
"name" : "User Info:" },
"fields" : [{
"name" : "Username",
"value" : user.tag }, {
"name" : "ID",
"value" : user.id }, {
"name" : "Created",
"value" : convertTimestamp(user.createdTimestamp) }, {
"name" : "Joined",
"value" : convertTimestamp(message.member.joinedTimestamp)
}]
};
message.channel.send({embed});
} else {
try {
let embed = {
"color" : 0xff0000,
"thumbnail" : {
"url" : target.avatarURL },
"author" : {
"name" : "User Info:" },
"fields" : [{
"name" : "Username",
"value" : target.tag }, {
"name" : "ID",
"value" : target.id }, {
"name" : "Created",
"value" : convertTimestamp(target.createdTimestamp) }, {
"name" : "Joined",
"value" : convertTimestamp(message.guild.member(target).joinedTimestamp)
}]
};
message.channel.send({embed});
} catch(err) {
console.log(convertTimestamp(Date.now()) + " - [ERROR]: " + err);
message.reply("`" + params + "` was not found on the server. :confused:");
}
}
}
aribot.login(config.token);