2019-01-02 10:21:21 +01:00
const { Listener } = require ( 'discord-akairo' ) ;
2019-12-08 01:47:25 +01:00
const akairoVersion = require ( 'discord-akairo' ) . version ;
const djsVersion = require ( 'discord.js' ) . version ;
const pjson = require ( '../../package.json' ) ;
const { prefix , statsChannel , ownerID , supportServer } = 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
2019-12-08 01:47:25 +01:00
2019-01-02 10:21:21 +01:00
class ReadyListener extends Listener {
constructor ( ) {
super ( 'ready' , {
emitter : 'client' ,
event : 'ready'
} ) ;
}
async exec ( ) {
2019-12-08 01:47:25 +01:00
let commandSize = this . client . commandHandler . modules . size ;
let clientTag = this . client . user . tag ;
let guildSize = this . client . guilds . size ;
let userSize = this . client . users . size ;
let channelSize = this . client . channels . size ;
let profilePicture = this . client . user . displayAvatarURL ( ) ;
let clientID = this . client . user . id ;
let author = this . client . users . get ( ownerID ) . tag ;
2019-01-02 10:21:21 +01:00
// Send stats to the console
2019-12-08 01:47:25 +01:00
console . log ( '===========[ READY ]===========' ) ;
console . log ( ` \x 1b[32mLogged in as \x 1b[34m ${ clientTag } \x 1b[0m! ( \x 1b[33m ${ clientID } \x 1b[0m) ` ) ;
console . log ( ` Ready to serve in \x 1b[33m ${ channelSize } \x 1b[0m channels on \x 1b[33m ${ guildSize } \x 1b[0m servers, for a total of \x 1b[33m ${ userSize } \x 1b[0m users. ` ) ;
console . log ( ` There is \x 1b[33m ${ commandSize } \x 1b[0m command loaded ` ) ;
console . log ( ` ${ this . client . readyAt } ` ) ;
2019-03-23 19:28:57 +01:00
//Bot status
if ( Math . floor ( ( Math . random ( ) * 2 ) + 1 ) == 1 ) {
2019-11-15 22:52:30 +01:00
console . log ( 'Status type: \x1b[32mWatching\x1b[0m' ) ;
2019-03-23 19:28:57 +01:00
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-07-05 19:04:06 +02:00
this . client . user . setActivity ( ` ${ status } | My prefix is: ${ prefix [ 0 ] } ` , { type : 'WATCHING' } ) ;
2019-03-23 19:28:57 +01:00
} else {
2019-11-15 22:52:30 +01:00
console . log ( 'Status type: \x1b[32mPlaying\x1b[0m' ) ;
2019-03-23 19:28:57 +01:00
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-07-05 19:04:06 +02:00
this . client . user . setActivity ( ` ${ status } | My prefix is: ${ prefix [ 0 ] } ` , { type : 'PLAYING' } ) ;
2019-03-23 19:28:57 +01:00
}
2019-12-08 01:47:25 +01:00
// If stats channel settings exist, send bot stats to it
if ( statsChannel ) {
2019-01-02 10:21:21 +01:00
const channel = this . client . channels . get ( statsChannel ) ;
2019-12-08 01:47:25 +01:00
channel . send ( ` Ready to serve in ${ channelSize } channels on ${ guildSize } servers, for a total of ${ userSize } users. \n There is ${ commandSize } command loaded \n ${ this . client . readyAt } ` ) ;
2019-01-02 10:21:21 +01:00
}
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-12-08 01:47:25 +01:00
// Expose stats
const port = 3000 ;
const http = require ( 'http' ) ;
const requestHandler = ( req , res ) => {
2019-12-08 01:59:24 +01:00
// Refresh some info
commandSize = this . client . commandHandler . modules . size ;
guildSize = this . client . guilds . size ;
userSize = this . client . users . size ;
profilePicture = this . client . user . displayAvatarURL ( ) ;
2019-12-08 01:47:25 +01:00
let response = {
'commandSize' : commandSize ,
'ClientTag' : clientTag ,
'guildSize' : guildSize ,
'userSize' : userSize ,
2019-12-08 01:59:24 +01:00
'prefixSize' : prefix . length ,
2019-12-08 01:47:25 +01:00
'profilePicture' : profilePicture ,
'clientID' : clientID ,
'djsVersion' : djsVersion ,
'akairoVersion' : akairoVersion ,
'homepage' : pjson . homepage ,
'author' : author ,
'supportServer' : supportServer
} ;
res . statusCode = 200 ;
res . setHeader ( 'Content-Type' , 'application/json' ) ;
res . end ( JSON . stringify ( response ) ) ;
} ;
const server = http . createServer ( requestHandler ) ;
server . listen ( port , ( err ) => {
if ( err ) {
return console . log ( 'something bad happened' , err ) ;
}
} ) ;
console . log ( ` Exposing stats on port ${ port } ` ) ;
console . log ( '===========[ READY ]===========' ) ;
2019-01-02 10:21:21 +01:00
}
}
module . exports = ReadyListener ;