-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
293 lines (274 loc) · 13.7 KB
/
index.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
const Discord = require("discord.js");
const clear = require("clear-console");
const fs = require("fs");
const config = require("./config/botConfig.json");
var bot = new Discord.Client();
var PREFIX = "m!";
var mistwoodEmote = "<:mistwood:688533711033073802>";
var skyblockEmote = "<:skyblock:692026057490169917>";
var farmingEmote = "<:farming:692026233227051029>";
function coinflip(sides) {
var result = Math.floor(Math.random() * sides);
return result;
}
bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
for (const file of commandFiles) {
var command = require(`./commands/${file}`);
bot.commands.set(command.help.name, command);
}
process.on("uncaughtException", (err) => {
console.log(err);
});
bot.on('warn', console.warn);
bot.on('error', console.error);
process.on("unhandledRejection", (err) => {
console.log(err);
});
bot.on("guildMemberAdd", (member) => {
member.guild.channels.get("688540197692243968").setName("👥 Members: " + member.guild.members.filter(m => !m.bot && m.guild.id != "458425170701451305").size);
});
bot.on("guildMemberRemove", (member) => {
member.guild.channels.get("688540197692243968").setName("👥 Members: " + member.guild.members.filter(m => !m.bot && m.guild.id != "458425170701451305").size);
});
bot.on("raw", packet => {
if (!['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE'].includes(packet.t)) return;
const channel = bot.channels.get(packet.d.channel_id);
if (channel.messages.has(packet.d.message_id)) return;
channel.fetchMessage(packet.d.message_id).then(message => {
const emoji = packet.d.emoji.id ? `${packet.d.emoji.name}:${packet.d.emoji.id}` : packet.d.emoji.name;
const reaction = message.reactions.get(emoji);
if (reaction) reaction.users.set(packet.d.user_id, bot.users.get(packet.d.user_id));
if (packet.t === 'MESSAGE_REACTION_ADD') {
bot.emit('messageReactionAdd', reaction, bot.users.get(packet.d.user_id));
}
if (packet.t === 'MESSAGE_REACTION_REMOVE') {
bot.emit('messageReactionRemove', reaction, bot.users.get(packet.d.user_id));
}
});
});
bot.on("messageReactionAdd", (reaction, user) => {
var skyblockRole = bot.guilds.get("688532826940899440").roles.get("688673937496080421");
var farmingRole = bot.guilds.get("688532826940899440").roles.get("688673855413551144");
var notificationsRole = bot.guilds.get("688532826940899440").roles.get("692048211535200266");
switch (reaction.message.id) {
case "692051088286679051":
switch (reaction.emoji.id) {
case "692026057490169917":
var guildMember = bot.guilds.get("688532826940899440").members.get(reaction.users.last().id);
if (!guildMember.roles.has(skyblockRole)) {
guildMember.addRole(skyblockRole);
user.send(mistwoodEmote + " Gave you the **Skyblock** role!" + skyblockEmote);
}
break;
case "692026233227051029":
guildMember = bot.guilds.get("688532826940899440").members.get(reaction.users.last().id);
if (!guildMember.roles.has(farmingRole)) {
guildMember.addRole(farmingRole);
user.send(mistwoodEmote + " Gave you the **Farming** role! " + farmingEmote);
}
break;
default:
switch (reaction.emoji.name) {
case "🔔":
guildMember = bot.guilds.get("688532826940899440").members.get(reaction.users.last().id);
if (!guildMember.roles.has(notificationsRole)) {
guildMember.addRole(notificationsRole);
user.send(mistwoodEmote + " Gave you the **Notifications** role! 🔔");
}
break;
default:
bot.channels.get("692024614301466665").fetchMessage("692051088286679051").then(message => {
message.reactions.last().remove(reaction.users.last().id);
});
break;
}
break;
}
break;
case "688538969692045389":
switch (reaction.emoji.name) {
case "✅":
var playerRole = bot.guilds.get("688532826940899440").roles.get("688533140490289301");
var guildMember = bot.guilds.get("688532826940899440").members.get(reaction.users.last().id);
if (!guildMember.roles.has(playerRole)) {
guildMember.addRole(playerRole);
}
bot.channels.get("688537181786079240").fetchMessage("688538969692045389").then(message => {
message.reactions.first().remove(reaction.users.last().id);
});
break;
default:
bot.channels.get("688537181786079240").fetchMessage("688538969692045389").then(message => {
message.reactions.last().remove(reaction.users.last().id);
});
break;
}
break;
default:
break;
}
});
bot.on("messageReactionRemove", (reaction, user) => {
var skyblockRole = bot.guilds.get("688532826940899440").roles.get("688673937496080421");
var farmingRole = bot.guilds.get("688532826940899440").roles.get("688673855413551144");
var notificationsRole = bot.guilds.get("688532826940899440").roles.get("692048211535200266");
switch (reaction.message.id) {
case "692051088286679051":
switch (reaction.emoji.id) {
case "692026057490169917":
var guildMember = bot.guilds.get("688532826940899440").members.get(user.id);
if (!guildMember.roles.has(skyblockRole)) {
guildMember.removeRole(skyblockRole);
user.send(mistwoodEmote + " Removed the **Skyblock** role! " + skyblockEmote);
}
break;
case "692026233227051029":
guildMember = bot.guilds.get("688532826940899440").members.get(user.id);
if (!guildMember.roles.has(farmingRole)) {
guildMember.removeRole(farmingRole);
user.send(mistwoodEmote + " Removed the **Farming** role! " + farmingEmote);
}
break;
default:
switch (reaction.emoji.name) {
case "🔔":
guildMember = bot.guilds.get("688532826940899440").members.get(user.id);
if (!guildMember.roles.has(notificationsRole)) {
guildMember.removeRole(notificationsRole);
user.send(mistwoodEmote + " Removed the **Notifications** role! 🔔");
}
break;
}
break;
}
break;
default:
break;
}
});
bot.on("ready", () => {
clear({ toStart: true });
console.log("\nMistwood Bot ready\n----------------------------");
bot.guilds.get("688532826940899440").channels.get("688540197692243968").setName("👥 Members: " + bot.guilds.get("688532826940899440").members.filter(member => !member.user.bot).size);
bot.user.setActivity("for commands", { type: 'WATCHING' });
bot.setInterval(function() {
var types = [
"WATCHING",
"PLAYING"
];
var activitiesWatching = [
"over " + bot.guilds.get("688532826940899440").members.filter(m => !m.user.bot).size + " users",
"for commands"
];
var activitiesPlaying = [
"on Mistwood",
PREFIX + "help"
];
var activity = "";
var type = types[coinflip(2)];
if (type === "WATCHING") {
activity = activitiesWatching[coinflip(2)];
} else if (type === "PLAYING") {
activity = activitiesPlaying[coinflip(2)];
} else return bot.user.setActivity("for commands", { type: "WATCHING" });
bot.user.setActivity(activity, { type: type });
}, 10000);
// var embed = new Discord.RichEmbed()
// .setTitle(mistwoodEmote + " Mistwood | **Roles**")
// .setDescription("React with the corresponding emote below to obtain the role and access other channels!")
// .setThumbnail("https://cdn.clipart.email/e79d15c23ca160e80ddf4bf2c6e90c80_clip-art-trees-clip-art-trees-trees-tree-clipart-free-clipart-_710-749.png")
// .setColor(0x8AD61E)
// .addField(skyblockEmote, "Skyblock", true)
// .addField(farmingEmote, "Farming", true)
// .addField("🔔", "Notifications", true)
// bot.channels.get("692024614301466665").send(embed).then(rolesEmbed => {
// rolesEmbed.react("692026057490169917").then(() => {
// rolesEmbed.react("692026233227051029").then(() => {
// rolesEmbed.react("🔔");
// });
// });
// });
});
bot.on("message", (message) => {
if (message.channel.type == "dm" || message.author.bot || message.author.id === bot.user.id) return;
if (message.isMentioned(bot.user.id)) return message.channel.send(mistwoodEmote + " My prefix is `" + PREFIX + "`");
var botLogs = bot.guilds.get("688532826940899440").channels.get("688567348831322198");
switch (message.channel.id) {
//Suggestions
case "694188050963497000":
var lines = message.content.replace(/\*/g, "").split("\n");
if (lines[0] && lines[0].toLowerCase().startsWith("ign:")) {
if (lines[1] && lines[1].toLowerCase().startsWith("server:")) {
if (lines[2] && lines[2].toLowerCase().startsWith("suggestion:")) {
message.react("👍").then(() => {
message.react("👎");
});
} else message.delete();
} else message.delete();
} else message.delete();
break;
//Bug reports
case "694188263631487067":
var lines = message.content.replace(/\*/g, "").split("\n");
if (lines[0] && lines[0].toLowerCase().startsWith("ign:")) {
if (lines[1] && lines[1].toLowerCase().startsWith("server:")) {
if (lines[2] && lines[2].toLowerCase().startsWith("issue:")) {
var embed = new Discord.RichEmbed()
.setTitle("**New Bug Report ticket**")
.setColor(0x8AD61E)
.addField("IGN:", lines[0].replace(/ign:/i, "").trim())
.addField("Server:", lines[1].replace(/server:/i, "").trim())
.addField("Issue:", lines.slice(2).join("\n").replace(/issue:/i, "").trim())
.setAuthor(message.author.tag, message.author.avatarURL)
.setTimestamp();
botLogs.send(embed).then(() => {
message.delete();
message.author.send(":white_check_mark: **Your Bug Report ticket has successfully been submitted. Thank you for contacting support**");
});
} else message.delete();
} else message.delete();
} else message.delete();
break;
//Support
case "694188328651849778":
var lines = message.content.replace(/\*/g, "").split("\n");
if (lines[0] && lines[0].toLowerCase().startsWith("ign:")) {
if (lines[1] && lines[1].toLowerCase().startsWith("server:")) {
if (lines[2] && lines[2].toLowerCase().startsWith("issue:")) {
var embed = new Discord.RichEmbed()
.setTitle("**New Support ticket**")
.setColor(0x8AD61E)
.addField("IGN:", lines[0].replace(/ign:/i, "").trim())
.addField("Server:", lines[1].replace(/server:/i, "").trim())
.addField("Issue:", lines.slice(2).join("\n").replace(/issue:/i, "").trim())
.setAuthor(message.author.tag, message.author.avatarURL)
.setTimestamp();
botLogs.send(embed).then(() => {
message.delete();
message.author.send(":white_check_mark: **Your Support ticket has successfully been submitted. Thank you for contacting support**");
});
} else message.delete();
} else message.delete();
} else message.delete();
break;
default:
break;
}
if (!message.content.startsWith(PREFIX)) return;
var args = message.content.slice(PREFIX.length).split(" ");
switch (args[0].toLowerCase()) {
default: var commandFile = bot.commands.get(args[0].toLowerCase());
if (commandFile) {
commandFile.run(bot, message, args);
} else {
bot.commands.forEach(command => {
for (i in command.help.aliases) {
if (command.help.aliases.split(";")[i] === args[0].toLowerCase()) command.run(bot, message, args);
}
});
}
break;
}
});
bot.login(config.TOKEN);