-
Notifications
You must be signed in to change notification settings - Fork 163
/
XiaoBot.js
132 lines (116 loc) · 4.92 KB
/
XiaoBot.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
const { TOKEN, OWNER, PREFIX, INVITE } = process.env;
const path = require('path');
const CommandoClient = require('./structures/CommandoClient');
const client = new CommandoClient({
commandPrefix: PREFIX,
owner: OWNER,
invite: INVITE,
disableEveryone: true
});
const { carbon, dBots } = require('./structures/Stats');
const SequelizeProvider = require('./providers/Sequelize');
client.setProvider(new SequelizeProvider(client.database));
client.registry
.registerDefaultTypes()
.registerGroups([
['userinfo', 'User Info'],
['guildinfo', 'Server Info'],
['moderation', 'Moderation'],
['settings', 'Server Settings'],
['response', 'Random Response'],
['randomimg', 'Random Image'],
['avataredit', 'Avatar Manipulation'],
['textedit', 'Text Manipulation'],
['numedit', 'Number Manipulation'],
['search', 'Search'],
['games', 'Games'],
['random', 'Random/Other'],
['roleplay', 'Roleplay']
])
.registerDefaultGroups()
.registerDefaultCommands({
help: false,
ping: false
})
.registerCommandsIn(path.join(__dirname, 'commands'));
client.on('ready', () => {
console.log(`[READY] Shard ${client.shard.id} Logged in as ${client.user.tag} (${client.user.id})!`);
client.user.setGame(`${PREFIX}help | Shard ${client.shard.id}`);
});
client.on('disconnect', (event) => {
console.log(`[DISCONNECT] Shard ${client.shard.id} disconnected with Code ${event.code}.`);
process.exit(0);
});
client.on('error', console.error);
client.on('warn', console.warn);
client.on('commandError', (command, err) => console.error(command.name, err));
client.dispatcher.addInhibitor((msg) => {
if (msg.channel.type === 'dm') return false;
const role = msg.guild.settings.get('singleRole');
if (!msg.guild.roles.has(role) || msg.member.hasPermission('ADMINISTRATOR')) return false;
if (!msg.member.roles.has(role)) {
return ['singleRole', msg.reply(`Only the ${msg.guild.roles.get(role).name} role may use commands.`)];
} else {
return false;
}
});
client.on('message', (msg) => {
if (!msg.guild || !msg.guild.settings.get('inviteGuard')) return;
if (/(discord(\.gg\/|app\.com\/invite\/|\.me\/))/gi.test(msg.content)) {
if (msg.author.bot || msg.member.hasPermission('ADMINISTRATOR')) return;
if (!msg.channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'MANAGE_MESSAGES'])) return;
msg.delete();
msg.reply('Invites are prohibited from being posted here.');
}
});
client.on('messageReactionAdd', (reaction, user) => {
if (reaction.emoji.name !== '⭐') return;
const { message } = reaction;
const channel = message.guild.channels.get(message.guild.settings.get('starboard'));
if (!channel) return;
if (!message.channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'MANAGE_MESSAGES'])) return;
if (user.id === message.author.id) {
reaction.remove(user);
message.reply('You cannot star your own messages, baka.');
return;
}
client.registry.resolveCommand('random:star').run(message, { id: message.id }, true);
});
client.on('guildMemberAdd', (member) => {
const role = member.guild.roles.get(member.guild.settings.get('joinRole'));
if (role && member.guild.me.hasPermission('MANAGE_ROLES')) {
member.addRole(role).catch(() => null);
}
const channel = member.guild.channels.get(member.guild.settings.get('memberLog'));
if (!channel || !channel.permissionsFor(client.user).has('SEND_MESSAGES')) return;
const msg = member.guild.settings.get('joinMsg', 'Welcome <user>!')
.replace(/(<user>)/gi, member.user.username)
.replace(/(<server>)/gi, member.guild.name)
.replace(/(<mention>)/gi, member);
channel.send(msg);
});
client.on('guildMemberRemove', (member) => {
const channel = member.guild.channels.get(member.guild.settings.get('memberLog'));
if (!channel || !channel.permissionsFor(client.user).has('SEND_MESSAGES')) return;
const msg = member.guild.settings.get('leaveMsg', 'Bye <user>...')
.replace(/(<user>)/gi, member.user.username)
.replace(/(<server>)/gi, member.guild.name)
.replace(/(<mention>)/gi, member);
channel.send(msg);
});
client.on('guildCreate', async (guild) => {
console.log(`[GUILD] I have joined ${guild.name}! (${guild.id})`);
const guilds = await client.shard.fetchClientValues('guilds.size');
const count = guilds.reduce((prev, val) => prev + val, 0);
carbon(count);
dBots(count, client.user.id);
});
client.on('guildDelete', async (guild) => {
console.log(`[GUILD] I have left ${guild.name}... (${guild.id})`);
const guilds = await client.shard.fetchClientValues('guilds.size');
const count = guilds.reduce((prev, val) => prev + val, 0);
carbon(count);
dBots(count, client.user.id);
});
client.login(TOKEN);
process.on('unhandledRejection', console.error);