-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
199 lines (187 loc) · 7.61 KB
/
app.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
'use strict';
const Discord = require('discord.js');
const client = new Discord.Client();
const chalk = require('chalk');
const fs = require('fs-extra');
client.commandMap = new Map();
const Keyv = require("keyv");
let keyv;
let configLocation = './config/config.json';
let defaultConfigLocation = './config/default_config.json';
let bansLocation = './config/bannedusers.json';
let guildsLocation = './config/guilds.json';
let config;
fs.exists(configLocation).then(exists => {
if (!exists) {
fs.ensureFileSync(configLocation);
console.log('Created config.json');
let defaultConfig = fs.readJsonSync(defaultConfigLocation);
fs.writeJsonSync(configLocation, defaultConfig);
console.log('Wrote default_config.json to config.json');
console.log('Add your token and mongo login into that file now');
} else {
let configFile = fs.readJsonSync(configLocation);
console.log('Config loaded!');
config = configFile;
client.login(config.token);
keyv = new Keyv(config.mongo);
}
});
fs.exists(bansLocation).then(exists => {
if (!exists) {
fs.ensureFileSync(bansLocation);
console.log('Created bannedusers.json');
client.banned = [];
fs.writeJsonSync(bansLocation, client.banned);
} else {
client.banned = fs.readJsonSync(bansLocation);
console.log('Bans loaded!');
}
});
fs.exists(guildsLocation).then(exists => {
if (!exists) {
fs.ensureFileSync(guildsLocation);
console.log('Created guilds.json');
client.guildConfig = new Map();
fs.writeJsonSync(guildsLocation, client.banned);
} else {
client.guildConfig = fs.readJsonSync(guildsLocation);
console.log('Guilds loaded!');
}
});
let logCommand = message => {
let denied = message.denied ? "DENIED" : "ALLOWED";
console.log(chalk.hex(config.lineColor)('-----------------------------'));
console.log(chalk.red(`${denied}\nCommand: ${chalk.blue(message.commandName)}\nUser: ${chalk.blue(message.author.tag)}\n${message.guild ? `Server: (${chalk.blue(message.guild.id)}) ${chalk.blue(message.guild.name)}\n` : ""}Channel: ${chalk.blue(message.channel.name || '[DM]')}\nTime: ${chalk.blue(new Date().toString())}`));
console.log(chalk.hex(config.lineColor)('-----------------------------\n'));
};
client.on('ready', () => {
client.user.setPresence({ game: { name: ']help' }, status: 'idle' })
console.log(chalk.hex(config.lineColor)('-----------------------------'));
console.log(chalk.hex(config.readyColor)(`Bot started as ${chalk.blue(client.user.tag)}`));
client.fetchApplication().then(app => {
process.on('uncaughtException', exception => {
console.error(exception);
let embed = new Discord.RichEmbed()
.setTitle("Error:")
.setDescription(exception.stack)
.setColor(config.errorColor);
app.owner.send(embed);
});
client.owner = app.owner;
console.log(chalk.hex(config.readyColor)(`Owner set to ${chalk.blue(client.owner.tag)}`));
console.log(chalk.hex(config.lineColor)('-----------------------------\n'));
require('./modules/commands')(Discord, client, config, keyv);
require('./modules/music')(Discord, client, config, keyv);
require('./modules/moderation')(Discord, client, config, keyv);
let embed = new Discord.RichEmbed()
.setDescription(`Started at ${new Date()}`)
.setColor(config.embedColor);
app.owner.send(embed);
});
});
client.on('message', message => {
if (!message.content.startsWith(config.prefix)) return;
message.commandName = message.content.toLocaleLowerCase().split(' ')[0].slice(config.prefix.length);
let command = client.commandMap.get(message.commandName);
keyv.get(message.author.id).then((user = {}) => {
if (command) {
message.used = true
if (user.banned === true) {
let embed = new Discord.RichEmbed()
.setTitle("You are banned by the bot owner.")
.setColor(config.errorColor);
message.channel.send(embed);
message.denied = true;
logCommand(message);
return;
}
if (command.check) {
if (command.check(message) !== true) {
message.denied = true;
logCommand(message);
return;
}
}
command.func(message);
message.denied = false;
logCommand(message);
}
});
});
client.on('messageUpdate', message => {
if (!message.content.startsWith(config.prefix)) return;
if (message.used && message.used === true) return;
message.commandName = message.content.toLocaleLowerCase().split(' ')[0].slice(config.prefix.length);
let command = client.commandMap.get(message.commandName);
keyv.get(message.author.id).then((user = {}) => {
if (command) {
message.used = true
if (user.banned === true) {
let embed = new Discord.RichEmbed()
.setTitle("You are banned by the bot owner.")
.setColor(config.errorColor);
message.channel.send(embed);
message.denied = true;
logCommand(message);
return;
}
if (command.check) {
if (command.check(message) !== true) {
message.denied = true;
logCommand(message);
return;
}
}
command.func(message);
message.denied = false;
logCommand(message);
}
});
});
client.on('guildMemberAdd', member => {
keyv.get(member.guild.id).then((guild = {}) => {
if(!guild.autorole) return;
member.addRole(guild.autorole).catch(() => {return});
});
keyv.get(member.guild.id).then((guild = {}) => {
if(!guild.join) return;
member.guild.channels.find('id', guild.join.id).send(guild.join.message.replace("$user", member)).catch(() => {return});
});
keyv.get(member.guild.id).then((guild = {}) => {
if(!guild.autoname) return;
member.setNickname(guild.join.message.replace("$user", member.user.username)).catch(() => {return});
});
if (member.guild.id === "161281219839918080"){
member.setNickname(`\u2022 ${member.user.username}`)
}
})
client.on('message', message => {
if (message.channel.id === "482180108220891146") {
if(message.content.toLocaleLowerCase().includes('oppress')){
message.channel.send("SHUT THE FUCK UP!").then(m => {m.delete(2000)})
}
if(message.author.id === client.user.id){
return
}
if(message.content.includes('http') && !message.content.includes(" ")){
return
}
if(message.attachments.first() && message.content == ""){
return
}
if(message.author.id === "129393382601523200" || message.author.id === "233829889197735937"){
message.delete(2000)
return
}
message.delete(100)
}
})
client.on('message', message => {
if (!message.guild) return
keyv.get(message.channel.id).then((channel = {}) => {
if(channel.botonly && !message.author.bot) {
message.delete(100)
}
})
})