mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-08 15:19:14 +02:00
Move more stuff into the client
This commit is contained in:
+6
-29
@@ -1,4 +1,4 @@
|
||||
const { TOKEN, OWNERS, COMMAND_PREFIX, INVITE } = process.env;
|
||||
const { TOKEN, OWNERS, COMMAND_PREFIX, INVITE, DBOTS_KEY, DBOTSORG_KEY } = process.env;
|
||||
const path = require('path');
|
||||
const CommandoClient = require('./structures/CommandoClient');
|
||||
const client = new CommandoClient({
|
||||
@@ -9,10 +9,12 @@ const client = new CommandoClient({
|
||||
unknownCommandResponse: false,
|
||||
disabledEvents: ['TYPING_START'],
|
||||
messageCacheLifetime: 600,
|
||||
messageSweepInterval: 120
|
||||
messageSweepInterval: 120,
|
||||
dBotsToken: DBOTS_KEY,
|
||||
dBotsOrgToken: DBOTSORG_KEY,
|
||||
guildWhitelist: ['110373943822540800', '264445053596991498'],
|
||||
guildPruneLevel: 25
|
||||
});
|
||||
const { version } = require('./package');
|
||||
const whitelist = require('./assets/json/whitelist');
|
||||
|
||||
client.registry
|
||||
.registerDefaultTypes()
|
||||
@@ -45,27 +47,13 @@ client.on('ready', () => {
|
||||
client.setInterval(() => {
|
||||
const activities = [
|
||||
`${COMMAND_PREFIX}help for commands`,
|
||||
`Shard ${client.shard.id}`,
|
||||
'with dragonfire535',
|
||||
client.options.invite,
|
||||
`with ${client.registry.commands.size} commands`,
|
||||
`v${version}`,
|
||||
'Rune Factory 4'
|
||||
];
|
||||
client.user.setActivity(activities[Math.floor(Math.random() * activities.length)]);
|
||||
}, 60000);
|
||||
client.setInterval(async () => {
|
||||
for (const guild of client.guilds.values()) {
|
||||
if (whitelist.includes(guild.id)) continue;
|
||||
if (guild.members.filter(member => member.user.bot).size > 25) {
|
||||
try {
|
||||
await guild.leave();
|
||||
} catch (err) {
|
||||
console.error(`[LEAVE] Failed to leave guild ${guild.name}. (${guild.id})`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 900000);
|
||||
});
|
||||
|
||||
client.on('disconnect', event => {
|
||||
@@ -79,17 +67,6 @@ client.on('warn', console.warn);
|
||||
|
||||
client.on('commandError', (command, err) => console.error(command.name, err));
|
||||
|
||||
client.on('guildCreate', async guild => {
|
||||
if (whitelist.includes(guild.id)) return;
|
||||
if (guild.members.filter(member => member.user.bot).size > 25) {
|
||||
try {
|
||||
await guild.leave();
|
||||
} catch (err) {
|
||||
console.error(`[LEAVE] Failed to leave guild ${guild.name}. (${guild.id})`, err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.dispatcher.addInhibitor(msg => {
|
||||
if (msg.channel.type !== 'text' || !msg.channel.topic) return false;
|
||||
if (msg.channel.topic.includes('<blocked>')) return 'topic blocked';
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
[
|
||||
"110373943822540800",
|
||||
"264445053596991498"
|
||||
]
|
||||
@@ -1,15 +1,18 @@
|
||||
const { Client } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { DBOTS_KEY, DBOTSORG_KEY } = process.env;
|
||||
const { Collection } = require('discord.js');
|
||||
|
||||
class CommandoClient extends Client {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
Object.defineProperty(this, 'dBotsKey', { value: DBOTS_KEY });
|
||||
Object.defineProperty(this, 'dBotsOrgKey', { value: DBOTSORG_KEY });
|
||||
this.guildPruneLevel = options.guildPruneLevel;
|
||||
this.guildWhitelist = options.guildWhitelist;
|
||||
Object.defineProperty(this, 'dBotsToken', { value: options.dBotsToken });
|
||||
Object.defineProperty(this, 'dBotsOrgToken', { value: options.dBotsOrgToken });
|
||||
|
||||
this.on('guildCreate', () => {
|
||||
this.on('guildCreate', guild => {
|
||||
this.pruneGuilds(guild);
|
||||
this.dBots();
|
||||
this.dBotsOrg();
|
||||
});
|
||||
@@ -17,14 +20,15 @@ class CommandoClient extends Client {
|
||||
this.dBots();
|
||||
this.dBotsOrg();
|
||||
});
|
||||
this.setInterval(() => this.pruneGuilds(), 600000);
|
||||
}
|
||||
|
||||
async dBots() {
|
||||
if (!this.dBotsKey) return null;
|
||||
if (!this.dBotsToken) return null;
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.post(`https://bots.discord.pw/api/bots/${this.user.id}/stats`)
|
||||
.set({ Authorization: this.dBotsKey })
|
||||
.set({ Authorization: this.dBotsToken })
|
||||
.send({
|
||||
shard_id: this.shard ? this.shard.id : 0,
|
||||
shard_count: this.options.shardCount || 1,
|
||||
@@ -38,11 +42,11 @@ class CommandoClient extends Client {
|
||||
}
|
||||
|
||||
async dBotsOrg() {
|
||||
if (!this.dBotsOrgKey) return null;
|
||||
if (!this.dBotsOrgToken) return null;
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.post(`https://discordbots.org/api/bots/${this.user.id}/stats`)
|
||||
.set({ Authorization: this.dBotsOrgKey })
|
||||
.set({ Authorization: this.dBotsOrgToken })
|
||||
.send({
|
||||
shard_id: this.shard ? this.shard.id : 0,
|
||||
shard_count: this.options.shardCount || 1,
|
||||
@@ -54,6 +58,34 @@ class CommandoClient extends Client {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async pruneGuilds(guild) {
|
||||
let guilds = new Collection();
|
||||
if (typeof guild === 'undefined') {
|
||||
for (const g of this.guilds.values()) {
|
||||
if (this.guildWhitelist.includes(g.id)) continue;
|
||||
if (g.members.filter(member => member.user.bot).size > this.guildPruneLevel) {
|
||||
try {
|
||||
guilds.set(g.id, g);
|
||||
await g.leave();
|
||||
} catch (err) {
|
||||
this.emit('error', `Failed to leave guild ${g.name}. (${g.id})`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.guildWhitelist.includes(guild.id)) return guilds;
|
||||
if (guild.members.filter(member => member.user.bot).size > this.guildPruneLevel) {
|
||||
try {
|
||||
guilds.set(guild.id, guild);
|
||||
await guild.leave();
|
||||
} catch (err) {
|
||||
this.emit('error', `Failed to leave guild ${g.name}. (${g.id})`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
return guilds;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommandoClient;
|
||||
|
||||
Reference in New Issue
Block a user