mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
This might be the last commit
This commit is contained in:
+9
-6
@@ -1,6 +1,6 @@
|
||||
const { TOKEN, OWNERS, COMMAND_PREFIX, INVITE } = process.env;
|
||||
const path = require('path');
|
||||
const CommandoClient = require('./structures/CommandoClient');
|
||||
const { CommandoClient } = require('discord.js-commando');
|
||||
const client = new CommandoClient({
|
||||
commandPrefix: COMMAND_PREFIX,
|
||||
owner: OWNERS.split(','),
|
||||
@@ -11,6 +11,7 @@ const client = new CommandoClient({
|
||||
messageCacheLifetime: 600,
|
||||
messageSweepInterval: 120
|
||||
});
|
||||
const { postStats } = require('./util/Util');
|
||||
|
||||
client.registry
|
||||
.registerDefaultTypes()
|
||||
@@ -52,16 +53,20 @@ client.on('ready', () => {
|
||||
}, 60000);
|
||||
});
|
||||
|
||||
client.on('guildCreate', () => postStats(client));
|
||||
|
||||
client.on('guildDelete', () => postStats(client));
|
||||
|
||||
client.on('disconnect', event => {
|
||||
console.error(`[DISCONNECT] Shard ${client.shard.id} disconnected with code ${event.code}.`);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
client.on('error', console.error);
|
||||
client.on('error', err => console.error('[ERROR]', err));
|
||||
|
||||
client.on('warn', console.warn);
|
||||
client.on('warn', err => console.warn('[WARNING]', err));
|
||||
|
||||
client.on('commandError', (command, err) => console.error(command.name, err));
|
||||
client.on('commandError', (command, err) => console.error('[COMMAND ERROR]', command.name, err));
|
||||
|
||||
client.dispatcher.addInhibitor(msg => {
|
||||
if (msg.channel.type !== 'text' || !msg.channel.topic) return false;
|
||||
@@ -71,8 +76,6 @@ client.dispatcher.addInhibitor(msg => {
|
||||
|
||||
client.login(TOKEN);
|
||||
|
||||
// Uncomment if memory is low: setInterval(() => process.exit(0), 8.64e+7);
|
||||
|
||||
process.on('unhandledRejection', err => {
|
||||
console.error('[FATAL] Unhandled Promise Rejection.', err);
|
||||
process.exit(1);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "48.1.0",
|
||||
"version": "48.1.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
const { Client } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { DBOTS_KEY, DBOTSORG_KEY } = process.env;
|
||||
|
||||
class CommandoClient extends Client {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
Object.defineProperty(this, 'dBotsToken', { value: DBOTS_KEY });
|
||||
Object.defineProperty(this, 'dBotsOrgToken', { value: DBOTSORG_KEY });
|
||||
|
||||
this.on('guildCreate', () => {
|
||||
this.dBots();
|
||||
this.dBotsOrg();
|
||||
});
|
||||
this.on('guildDelete', () => {
|
||||
this.dBots();
|
||||
this.dBotsOrg();
|
||||
});
|
||||
}
|
||||
|
||||
async dBots() {
|
||||
if (!this.dBotsToken) return null;
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.post(`https://bots.discord.pw/api/bots/${this.user.id}/stats`)
|
||||
.set({ Authorization: this.dBotsToken })
|
||||
.send({
|
||||
shard_id: this.shard ? this.shard.id : 0,
|
||||
shard_count: this.options.shardCount || 1,
|
||||
server_count: this.guilds.size
|
||||
});
|
||||
return body;
|
||||
} catch (err) {
|
||||
this.emit('error', 'Failed to post to Discord Bots', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async dBotsOrg() {
|
||||
if (!this.dBotsOrgToken) return null;
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.post(`https://discordbots.org/api/bots/${this.user.id}/stats`)
|
||||
.set({ Authorization: this.dBotsOrgToken })
|
||||
.send({
|
||||
shard_id: this.shard ? this.shard.id : 0,
|
||||
shard_count: this.options.shardCount || 1,
|
||||
server_count: this.guilds.size
|
||||
});
|
||||
return body;
|
||||
} catch (err) {
|
||||
this.emit('error', 'Failed to post to Discord Bots Org', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommandoClient;
|
||||
@@ -1,8 +1,32 @@
|
||||
const snekfetch = require('snekfetch');
|
||||
const { promisify } = require('util');
|
||||
const { DBOTS_KEY, DBOTSORG_KEY } = process.env;
|
||||
const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea'];
|
||||
const no = ['no', 'n', 'nah', 'nope'];
|
||||
|
||||
class Util {
|
||||
static postStats(client) {
|
||||
if (!DBOTS_KEY || !DBOTSORG_KEY) return;
|
||||
snekfetch
|
||||
.post(`https://bots.discord.pw/api/bots/${client.user.id}/stats`)
|
||||
.set({ Authorization: DBOTS_KEY })
|
||||
.send({
|
||||
shard_id: client.shard ? client.shard.id : 0,
|
||||
shard_count: client.options.shardCount || 1,
|
||||
server_count: client.guilds.size
|
||||
})
|
||||
.catch(err => console.error('[STATS] Failed to post to bots.discord.pw.', err));
|
||||
snekfetch
|
||||
.post(`https://discordbots.org/api/bots/${client.user.id}/stats`)
|
||||
.set({ Authorization: DBOTSORG_KEY })
|
||||
.send({
|
||||
shard_id: client.shard ? client.shard.id : 0,
|
||||
shard_count: client.options.shardCount || 1,
|
||||
server_count: client.guilds.size
|
||||
})
|
||||
.catch(err => console.error('[STATS] Failed to post to discordbots.org.', err));
|
||||
}
|
||||
|
||||
static wait(time) {
|
||||
return promisify(setTimeout)(time);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user