mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
119 lines
4.2 KiB
JavaScript
119 lines
4.2 KiB
JavaScript
const { TOKEN, OWNERS, COMMAND_PREFIX, INVITE } = process.env;
|
|
const path = require('path');
|
|
const { CommandoClient } = require('discord.js-commando');
|
|
const client = new CommandoClient({
|
|
commandPrefix: COMMAND_PREFIX,
|
|
owner: OWNERS.split(','),
|
|
invite: INVITE,
|
|
disableEveryone: true,
|
|
unknownCommandResponse: false,
|
|
disabledEvents: ['TYPING_START'],
|
|
messageCacheLifetime: 600,
|
|
messageSweepInterval: 120
|
|
});
|
|
const { carbon, dBots, dBotsOrg, filterTopics, parseTopic } = require('./structures/Util');
|
|
|
|
client.registry
|
|
.registerDefaultTypes()
|
|
.registerGroups([
|
|
['util', 'Utility'],
|
|
['user-info', 'User Info'],
|
|
['guild-info', 'Server Info'],
|
|
['moderation', 'Moderation'],
|
|
['random-res', 'Random Response'],
|
|
['random-img', 'Random Image'],
|
|
['image-edit', 'Image Manipulation'],
|
|
['avatar-edit', 'Avatar Manipulation'],
|
|
['text-edit', 'Text Manipulation'],
|
|
['num-edit', 'Number Manipulation'],
|
|
['search', 'Search'],
|
|
['games', 'Games'],
|
|
['random', 'Random/Other'],
|
|
['roleplay', 'Roleplay']
|
|
])
|
|
.registerDefaultCommands({
|
|
help: false,
|
|
ping: false,
|
|
prefix: false,
|
|
commandState: 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(`${COMMAND_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.on('guildMemberAdd', member => {
|
|
if (!member) return;
|
|
const channel = filterTopics(member.guild.channels, 'memberlog').first();
|
|
if (!channel) return;
|
|
const msg = parseTopic(channel.topic, 'joinmessage')
|
|
.replace(/{{member}}/gi, member.user.username)
|
|
.replace(/{{server}}/gi, member.guild.name)
|
|
.replace(/{{mention}}/gi, member);
|
|
channel.send(msg || `Welcome ${member.user.username}!`);
|
|
});
|
|
|
|
client.on('guildMemberRemove', member => {
|
|
if (!member) return;
|
|
const channel = filterTopics(member.guild.channels, 'memberlog').first();
|
|
if (!channel) return;
|
|
const msg = parseTopic(channel.topic, 'leavemessage')
|
|
.replace(/{{member}}/gi, member.user.username)
|
|
.replace(/{{server}}/gi, member.guild.name)
|
|
.replace(/{{mention}}/gi, member);
|
|
channel.send(msg || `Bye ${member.user.username}...`);
|
|
});
|
|
|
|
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);
|
|
dBotsOrg(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);
|
|
dBotsOrg(count, client.user.id);
|
|
});
|
|
|
|
const { wait } = require('./structures/Util');
|
|
client.setInterval(async () => {
|
|
let battle = client.registry.resolveCommand('games:battle').fighting.size;
|
|
let hangman = client.registry.resolveCommand('games:hangman').playing.size;
|
|
let gunfight = client.registry.resolveCommand('games:gunfight').fighting.size;
|
|
while (battle > 0 || hangman > 0 || gunfight > 0) {
|
|
if (battle > 0) console.log(`[RESTART] A battle is going on in Shard ${client.shard.id}, delaying...`);
|
|
if (hangman > 0) console.log(`[RESTART] A game of hangman is going on in Shard ${client.shard.id}, delaying...`);
|
|
if (gunfight > 0) console.log(`[RESTART] A gunfight is going on in Shard ${client.shard.id}, delaying...`);
|
|
await wait(300000);
|
|
battle = client.registry.resolveCommand('games:battle').fighting.size;
|
|
hangman = client.registry.resolveCommand('games:hangman').playing.size;
|
|
gunfight = client.registry.resolveCommand('games:gunfight').fighting.size;
|
|
}
|
|
console.log(`[RESTART] Shard ${client.shard.id} Restarted.`);
|
|
process.exit(0);
|
|
}, 7.2e+6);
|
|
|
|
client.login(TOKEN);
|
|
|
|
process.on('unhandledRejection', console.error);
|