2020-04-12 14:34:26 +02:00
const chalk = require ( 'chalk' ) ;
class Logger {
constructor ( client ) {
this . client = client ;
2020-04-13 22:38:10 +02:00
this . client . eventHooker . hook ( 'ready' , ( ) => {
2020-04-14 05:25:17 +02:00
const guilds = this . client . guilds . cache . size ;
this . info ( ` Client connected to ${ chalk . bold ( this . client . user . tag ) } with ${ chalk . bold ( ` ${ guilds } guild ${ guilds === 1 ? '' : 's' } ` ) } . ` ) ;
2020-04-12 14:34:26 +02:00
} ) ;
2020-04-13 22:38:10 +02:00
this . client . eventHooker . hook ( 'componentUpdate' , ( { component , type } ) => {
2020-05-21 12:47:58 +02:00
this . info ( ` Component ${ chalk . bold ( component . resolveable ) } was ${ chalk . bold ( Constants . ComponentTypes [ type ] ) } . ` ) ; //eslint-disable-line no-use-before-define
2020-04-12 14:34:26 +02:00
} ) ;
2020-04-13 22:38:10 +02:00
this . client . eventHooker . hook ( 'reconnect' , ( ) => {
this . warn ( ` Shard is reconnecting. ` ) ;
2020-04-12 14:34:26 +02:00
} ) ;
2020-07-20 03:25:27 +02:00
this . client . eventHooker . hook ( 'guildCreate' , ( guild ) => {
this . debug ( ` ${ chalk . bold ( '[GUILD]' ) } Joined guild ${ chalk . bold ( guild . name ) } ( ${ guild . id } ). ` ) ;
} ) ;
this . client . eventHooker . hook ( 'guildDelete' , ( guild ) => {
this . debug ( ` ${ chalk . bold ( '[GUILD]' ) } Left guild ${ chalk . bold ( guild . name ) } ( ${ guild . id } ). ` ) ;
} ) ;
this . client . eventHooker . hook ( 'commandExecute' , ( message ) => {
this . debug ( ` ${ chalk . bold ( '[EXECU]' ) } ${ message . author . tag } ( ${ message . author . id } ) executed command ${ chalk . bold ( message . command . moduleResolveable ) } . ` ) ;
} ) ;
2020-04-12 14:34:26 +02:00
}
async transport ( message = 'N/A' , opts = { } ) {
2020-04-14 10:26:59 +02:00
process . send ( { _logger : true , message , ... opts } ) ;
2020-04-12 14:34:26 +02:00
}
/* Quick & Dirty Functions */
2020-04-13 22:38:10 +02:00
silly ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'silly' } ) ;
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
debug ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'debug' } ) ;
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
verbose ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'verbose' } ) ;
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
info ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'info' } ) ;
}
warn ( message , opts = { } ) {
this . transport ( message , { ... opts , type : 'warn' } ) ;
2020-04-12 14:34:26 +02:00
}
error ( message , opts = { } ) {
2020-04-13 22:38:10 +02:00
this . transport ( message , { ... opts , type : 'error' } ) ;
2020-04-12 14:34:26 +02:00
}
}
module . exports = Logger ;
const Constants = {
ComponentTypes : {
LOAD : 'loaded' ,
UNLOAD : 'unloaded' ,
RELOAD : 'reloaded' ,
ENABLE : 'enabled' ,
DISABLE : 'disabled'
}
} ;