This repository has been archived by the owner on Oct 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
256 lines (229 loc) · 8.03 KB
/
bot.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
/****************************
* Made by Donovan_DMC#1337 *
*****************************/
global.Discord = require("discord.js");
global.client = new Discord.Client({disableEveryone:true});
global.util = require("util");
global.config = require("./config.js");
global.logger = require("./utility/logger.js");
global.r = require("./db.js");
global.PrettyTable = require("prettytable");
global.os = require("os");
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
global.constructModLog = ((author,member,act,reason)=>{
if(!author) throw new Error("missing author");
if(!member) throw new Error("missing member");
if(!act) throw new Error("missing action");
if(!reason) reason = "None Specified";
var blame=author instanceof Discord.GuildMember?author.user:author instanceof Discord.User?author:author;
var target=member instanceof Discord.GuildMember?member.user:member instanceof Discord.User?member:member;
var targetIsBot=member instanceof Discord.GuildMember?member.user.bot:member instanceof Discord.User?member.bot:false;
if(target === null|| targetIsBot === null) throw new Error("member must be GuildMember or User");
switch(act) {
case "kick":
var color = 16433420;
var action=targetIsBot?"Bot Kicked":"Member Kicked";
break;
case "ban":
var color = 14495300;
var action=targetIsBot?"Bot Banned":"Member Banned";
break;
case "hackban":
var color = 14495300;
var action=targetIsBot?"Bot Hackbanned":"Member Hackbanned";
break;
case "unban":
var color = 12616706;
var action=targetIsBot?"Bot Unbanned":"Member Unbanned";
break;
case "mute":
var color = 0;
var action=targetIsBot?"Bot Muted":"Member Muted";
break;
case "unmute":
var color = 581126;
var action=targetIsBot?"Bot Unmuted":"Member Unmuted";
break;
}
var t = target instanceof Discord.GuildMember || target instanceof Discord.User?act=="unban"?`${target} (<@!${target}>)`:`${target.tag} (<@!${target.id}>)`:target;
var data = {
title: action,
timestamp: new Date().toISOString(),
color: color,
fields: [
{
name: targetIsBot?"Bot":"Member",
value: t,
inline: false
},
{
name: "Blame",
value: `${blame.tag} (<@!${blame.id}>)`,
inline: false
},
{
name: "Reason",
value: reason,
inline: false
}
]
};
var embed = new Discord.MessageEmbed(data);
return embed;
});
global.reloadCommandModules=(()=>{
for(var key in require.cache){
if(key.indexOf("\\node_modules") == -1){
delete require.cache[key];
}
}
return true;
});
global.reloadModules=(()=>{
for(var key in require.cache){
if(key.indexOf("\\node_modules") != -1){
delete require.cache[key];
}
}
return true;
});
global.reloadAll=(()=>{
for(var key in require.cache){
if(key.indexOf("\\node_modules") != -1){
delete require.cache[key];
}
}
return true;
});
client.on("ready", () => {
console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
try {
var botCount=client.guilds.get("374071874222686211").members.filter(t=>t.user.bot).size;
client.user.setActivity(`${botCount} Bots in BFD`,{type:"WATCHING"});
}catch(e){
client.user.setActivity(`Bots For Discord`,{type:"WATCHING"});
}
});
client.on("guildCreate", async (guild) => {
console.log(`Joined ${guild.name} (${guild.id}), member count: ${guild.memberCount}, owner : ${guild.owner.user.tag} (${guild.ownerID})`);
if(!config.allowedGuilds.includes(guild.id)) {
console.log(`Leaving disallowed guild ${guild.name} (${guild.id})`);
await guild.owner.user.send(`This bot is not allowed to be in this guild (${guild.name})!\nIt will now leave.`).catch(noerr=>null);
guild.leave();
}
});
client.on("guildDelete", async (guild) => {
console.log(`Left ${guild.name} (${guild.id}),member count: ${guild.memberCount}, owner : ${guild.owner.user.tag} (${guild.ownerID})`);
});
client.on("guildMemberAdd", async(member) => {
try {
var botCount=client.guilds.get("374071874222686211").members.filter(t=>t.user.bot).size;
client.user.setActivity(`${botCount} Bots in BFD`,{type:"WATCHING"});
}catch(e){
client.user.setActivity(`Bots For Discord`,{type:"WATCHING"});
}
if(!member.user.bot) return;
switch(member.guild.id) {
// staff
case "374074135506190349":
member.roles.add(config.roles.staffServerBot,"Bot autorole");
break;
// regular
case "374071874222686211":
member.roles.add(config.roles.bot,"Bot autorole");
break;
}
});
client.on("guildMemberRemove", async(member) => {
try {
var botCount=client.guilds.get("374071874222686211").members.filter(t=>t.user.bot).size;
client.user.setActivity(`${botCount} Bots in BFD`,{type:"WATCHING"});
}catch(e){
client.user.setActivity(`Bots For Discord`,{type:"WATCHING"});
}
});
/*client.on("guildMemberUpdate", async(oldMember,newMember) => {
if(!oldMember || !newMember) return;
var oldRoles = oldMember.roles.map(t=>t.id);
var newRoles = newMember.roles.map(t=>t.id);
if(JSON.stringify(oldRoles) !== JSON.stringify(newRoles)) {
var l = await newMember.guild.fetchAuditLogs({type:"MEMBER_ROLE_UPDATE",limit:1});
var log = l.entries.first();
var lg = log.changes[0].new[0];
try {
var blame = newMember.guild.members.get(log.executor.id);
}catch(e) {
var blame = "Unknown";
}
try {
var reason = typeof global.reason[newMember.id] !== "undefined"?global.reason[newMember.id]:log.reason !== ""?log.reason:"Not Specified";
}catch(e){
var reason = "Unknown";
}
if(newMember.bot && lg.id === config.roles.mutedBot) {
switch(log.key) {
case "$add":
var modlog = newMember.guild.channels.find(t=>t.name=="mod-log");
if(modlog !== null) {
var e=constructModLog(blame,newMember,"mute",reason);
if(!e instanceof Discord.RichEmbed) throw new Error("Function did not return RichEmbed");
}
break;
case "$remove":
var modlog = newMember.guild.channels.find(t=>t.name=="mod-log");
if(modlog !== null) {
var e=constructModLog(blame,newMember,"unmute",reason);
if(!e instanceof Discord.RichEmbed) throw new Error("Function did not return RichEmbed");
}
break;
}
} else {
}
}
});*/
client.on("message", async (message)=> {
if ((!message || !message.guild) || (!config.allowedGuilds.includes(message.guild.id) || message.author.bot)) return;
if(message.channel.id === config.channels.suggestions) {
if(!message.content.startsWith("//")) {
message.react(config.emojis.yes);
message.react(config.emojis.no);
return;
}
return;
}
if(message.content.indexOf(config.prefix) === -1) return;
var args = message.content.slice(config.prefix.length).trim().split(/ +/g);
var command = args.shift().toLowerCase();
var staff = message.member.roles.some(t=>config.staffRoles.includes(t.id)) || message.member.hasPermission("ADMINISTRATOR");
if(!config.commandList.all.list.includes(command)) return;
var cmd = config.commandList.all[command];
var category = cmd.category;
if(cmd.permissions.length !== 0) {
cmd.permissions.forEach((perm)=>{
if(!message.member.hasPermission(perm)) return message.reply(`You are missing the required **${perm}** permission to use this!`);
});
}
if(cmd.roles.length !== 0) {
if(!message.member.roles.some(t=>[cmd.roles].includes(t.id))) {
var tr = [];
cmd.roles.forEach((role)=>{
try{
tr.push(message.guild.roles.get(role).name);
}catch(e){}
});
return message.reply(`You do not have any of the required roles **${tr.join("**, **")}** (must have AT LEAST ONE in this list)`);
}
}
try{
console.commandlog(`[Guild ${message.guild.name} (${message.guild.id})]: Command "${command}" ran by user ${message.author.tag} (${message.author.id}) in channel #${message.channel.name} (${message.channel.id})`);
if(!cmd.alias) {
require(`./commands/${category}/${command}-cmd.js`)(message);
} else {
require(`./commands/${category}/${cmd.aliasof}-cmd.js`)(message);
}
}catch(e) {
message.reply(`Error while running this command: ${e}`);
return console.error(e);
}
});
client.login(config.token);