2019-01-02 10:21:21 +01:00
const { Listener } = require ( 'discord-akairo' ) ;
2019-04-11 18:17:44 +02:00
const { prefix , statsChannel , botID } = require ( '../../config.json' ) ;
2019-03-23 19:28:57 +01:00
const game = require ( '../../json/status/playing.json' ) ;
const watch = require ( '../../json/status/watching.json' ) ;
2019-01-02 10:21:21 +01:00
class ReadyListener extends Listener {
constructor ( ) {
super ( 'ready' , {
emitter : 'client' ,
event : 'ready'
} ) ;
}
async exec ( ) {
// Send stats to the console
console . log ( ` \x 1b[32mLogged in as \x 1b[34m ${ this . client . user . tag } \x 1b[0m! ( \x 1b[33m ${ this . client . user . id } \x 1b[0m) ` ) ;
console . log ( ` Ready to serve in \x 1b[33m ${ this . client . channels . size } \x 1b[0m channels on \x 1b[33m ${ this . client . guilds . size } \x 1b[0m servers, for a total of \x 1b[33m ${ this . client . users . size } \x 1b[0m users. \x 1b ${ this . client . readyAt } \x 1b[0m ` ) ;
2019-03-23 19:28:57 +01:00
//Bot status
if ( Math . floor ( ( Math . random ( ) * 2 ) + 1 ) == 1 ) {
console . log ( 'Status type: Watching' ) ;
let status = watch [ Math . floor ( ( Math . random ( ) * watch . length ) ) ] ;
2019-03-23 19:31:31 +01:00
status = status . replace ( '${prefix}' , prefix [ 0 ] ) ;
2019-03-23 19:00:51 +01:00
2019-03-23 19:31:31 +01:00
this . client . user . setActivity ( ` ${ status } | ${ prefix [ 0 ] } help ` , { type : 'WATCHING' } ) ;
2019-03-23 19:28:57 +01:00
} else {
console . log ( 'Status type: Playing' ) ;
let status = game [ Math . floor ( ( Math . random ( ) * game . length ) ) ] ;
2019-03-23 19:31:31 +01:00
status = status . replace ( '${prefix}' , prefix [ 0 ] ) ;
2019-03-23 19:28:57 +01:00
2019-03-23 19:31:31 +01:00
this . client . user . setActivity ( ` ${ status } | ${ prefix [ 0 ] } help ` , { type : 'PLAYING' } ) ;
2019-03-23 19:28:57 +01:00
}
2019-01-02 10:21:21 +01:00
// Send stats to the 'stats' channel in the support server if its not the test bot
2019-04-11 18:17:44 +02:00
if ( this . client . user . id == botID ) {
2019-01-02 10:21:21 +01:00
const channel = this . client . channels . get ( statsChannel ) ;
channel . send ( ` Ready to serve in ${ this . client . channels . size } channels on ${ this . client . guilds . size } servers, for a total of ${ this . client . users . size } users. ${ this . client . readyAt } ` ) ;
}
2019-04-11 18:17:44 +02:00
/ *
//Fetch messages in every channel ( so they can still enter starboard in case of reboot)
let array = [ ] ;
let channels = this . client . channels . array ( ) ;
for ( const channel of channels . values ( ) ) {
array . push ( channel . id ) ;
}
for ( let i = 0 ; i < this . client . channels . size ; i ++ ) {
let channel = this . client . channels . get ( array [ i ] ) ;
if ( channel . messages ) {
channel . messages . fetch ( { limit : 10 } )
. then ( messages => console . log ( ` Received ${ messages . size } messages ` ) )
. catch ( err => console . error ( err ) ) ;
}
}
* /
2019-01-02 10:21:21 +01:00
}
}
module . exports = ReadyListener ;