mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Use winston
This commit is contained in:
@@ -41,7 +41,7 @@ client.registry
|
||||
.registerCommandsIn(path.join(__dirname, 'commands'));
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`[READY] Logged in as ${client.user.tag}! (${client.user.id})`);
|
||||
client.logger.info(`[READY] Logged in as ${client.user.tag}! ID: ${client.user.id}`);
|
||||
client.setInterval(() => {
|
||||
const activity = activities[Math.floor(Math.random() * activities.length)];
|
||||
client.user.setActivity(activity.text, { type: activity.type });
|
||||
@@ -49,19 +49,19 @@ client.on('ready', () => {
|
||||
});
|
||||
|
||||
client.on('disconnect', event => {
|
||||
console.error(`[DISCONNECT] Disconnected with code ${event.code}.`);
|
||||
client.logger.error(`[DISCONNECT] Disconnected with code ${event.code}.`);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
client.on('error', err => console.error('[ERROR]', err));
|
||||
client.on('error', err => client.logger.error(err));
|
||||
|
||||
client.on('warn', err => console.warn('[WARNING]', err));
|
||||
client.on('warn', warn => client.logger.warn(warn));
|
||||
|
||||
client.on('commandError', (command, err) => console.error('[COMMAND ERROR]', command.name, err));
|
||||
client.on('commandError', (command, err) => client.logger.error(`[COMMAND:${command.name}]\n${err.stack}`));
|
||||
|
||||
client.login(XIAO_TOKEN);
|
||||
|
||||
process.on('unhandledRejection', err => {
|
||||
console.error('[FATAL] Unhandled Promise Rejection.', err);
|
||||
client.logger.error(`[FATAL] UNHANDLED PROMISE REJECTION:\n${err.stack}`);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"node-opus": "^0.3.0",
|
||||
"node-superfetch": "^0.1.9",
|
||||
"random-js": "^1.0.8",
|
||||
"winston": "^3.1.0",
|
||||
"zlib-sync": "^0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { CommandoClient } = require('discord.js-commando');
|
||||
const { WebhookClient } = require('discord.js');
|
||||
const winston = require('winston');
|
||||
const PokemonStore = require('./PokemonStore');
|
||||
const { XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN } = process.env;
|
||||
|
||||
@@ -7,6 +8,14 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
this.logger = winston.createLogger({
|
||||
transports: [new winston.transports.Console()],
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize({ all: true }),
|
||||
winston.format.timestamp({ format: 'MM/DD/YYYY HH:mm:ss' }),
|
||||
winston.format.printf(log => `[${log.timestamp}] [${log.level.toUpperCase()}]: ${log.message}`)
|
||||
)
|
||||
});
|
||||
this.webhook = new WebhookClient(XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, { disableEveryone: true });
|
||||
this.pokemon = new PokemonStore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user