2021-02-19 17:44:38 -08:00
/ * T h e A r t i f i c e r w a s b u i l t i n m e m o r y o f B a b k a
* With love , Ean
*
* December 21 , 2020
* /
import {
// Discordeno deps
2021-11-21 19:14:57 -08:00
cache , cacheHandlers
2021-02-19 17:44:38 -08:00
} from "../deps.ts" ;
2021-03-14 20:27:53 -07:00
import { LogTypes as LT } from "./utils.enums.ts" ;
import utils from "./utils.ts" ;
2021-02-19 17:44:38 -08:00
import config from "../config.ts" ;
2021-11-21 19:14:57 -08:00
// getRandomStatus() returns status as string
2021-02-19 17:44:38 -08:00
// Gets a new random status for the bot
2021-11-21 19:14:57 -08:00
const getRandomStatus = async ( ) : Promise < string > = > {
2021-02-19 17:44:38 -08:00
let status = "" ;
switch ( Math . floor ( ( Math . random ( ) * 4 ) + 1 ) ) {
case 1 :
status = ` ${ config . prefix } help for commands ` ;
break ;
case 2 :
status = ` Running V ${ config . version } ` ;
break ;
case 3 :
status = ` ${ config . prefix } info to learn more ` ;
break ;
2021-11-21 19:14:57 -08:00
default : {
const cachedCount = await cacheHandlers . size ( "guilds" )
status = ` Rolling dice for ${ cachedCount + cache . dispatchedGuildIds . size } servers ` ;
2021-02-19 17:44:38 -08:00
break ;
2021-11-21 19:14:57 -08:00
}
2021-02-19 17:44:38 -08:00
}
return status ;
} ;
2021-03-13 12:10:35 -08:00
// updateListStatistics(bot ID, current guild count) returns nothing
// Sends the current server count to all bot list sites we are listed on
2021-11-21 19:14:57 -08:00
const updateListStatistics = ( botID : bigint , serverCount : number ) : void = > {
2021-03-13 12:10:35 -08:00
config . botLists . forEach ( async e = > {
2021-03-27 21:29:06 -07:00
utils . log ( LT . LOG , ` Updating statistics for ${ JSON . stringify ( e ) } ` )
2021-03-13 12:10:35 -08:00
if ( e . enabled ) {
const tempHeaders = new Headers ( ) ;
tempHeaders . append ( e . headers [ 0 ] . header , e . headers [ 0 ] . value ) ;
tempHeaders . append ( "Content-Type" , "application/json" ) ;
// ?{} is a template used in config, just need to replace it with the real value
2021-11-21 19:14:57 -08:00
const response = await fetch ( e . apiUrl . replace ( "?{bot_id}" , botID . toString ( ) ) , {
2021-03-13 12:10:35 -08:00
"method" : 'POST' ,
"headers" : tempHeaders ,
"body" : JSON . stringify ( e . body ) . replace ( '"?{server_count}"' , serverCount . toString ( ) ) // ?{server_count} needs the "" removed from around it aswell to make sure its sent as a number
} ) ;
2021-03-27 21:29:06 -07:00
utils . log ( LT . INFO , ` Posted server count to ${ e . name } . Results: ${ JSON . stringify ( response ) } ` ) ;
2021-03-13 12:10:35 -08:00
}
} ) ;
} ;
export default { getRandomStatus , updateListStatistics } ;