import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; export class LogsCommand extends Command { description = "Sends the most recent bot logs." ; args = "[command:string] | [clear:string]" ; allowdms = true ; allowdisable = false ; owner = true ; async run ( msg , _pargs , args ) { if ( ! this . bot . logs ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "owner.LOGS_NOLOGS" ) , "error" ) ; if ( [ "clear" , msg . string ( "global.CLEAR" ) ] . includes ( args ?. [ 0 ] ?. toLowerCase ( ) ) ) { this . bot . logs = [ ] ; return msg . createEmbed ( `📜 ${ msg . string ( "owner.LOGS" ) }` , msg . string ( "owner.LOGS_CLEARED" ) , "success" ) ; } if ( args . length ) { const cmd = this . bot . commands . find ( ( c ) => c . name === args . join ( " " ) . toLowerCase ( ) || c . aliases . includes ( args . join ( " " ) . toLowerCase ( ) ) ) ; if ( ! cmd ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "owner.COMMAND_NOTFOUND" ) , "error" ) ; let cmdlogs = [ ] ; cmdlogs = this . bot . logs . filter ( ( l ) => l . cmdName === cmd . name ) ; return msg . createEmbed ( `📜 ${ msg . string ( "owner.LOGS" ) }` , msg . string ( "owner.LOGS_COMMAND" , { command : cmd . name , times : cmdlogs . length , } ) ) ; } const humanReadableLogs = this . bot . logs . slice ( this . bot . logs . length - 20 , this . bot . logs . length ) . map ( ( log ) => { const logTime = msg . timestamp / 1000 - log . date / 1000 > 60 ? `**${ ( msg . timestamp / 60000 - log . date / 60000 ) . toFixed ( 1 ) }** mins ago` : `**${ ( msg . timestamp / 1000 - log . date / 1000 ) . toFixed ( 1 ) }** secs ago` ; return `${ logTime }: **${ msg . tagUser ( this . bot . users . get ( log . authorID ) ) || log . authorID }** ran **${ log . cmdName }** in **${ this . bot . guilds . get ( log . guildID ) ?. name || log . guildID }** (${ log . guildID }) ${ log . args . length ? `:\`${ log . args . join ( " " ) }\`` : "" }` ; } ) . join ( "\n" ) ; msg . createEmbed ( `📜 ${ msg . string ( "owner.LOGS" ) }` , humanReadableLogs ) ; } }