import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; import axios from "axios" ; export class steammonitorCommand extends Command { description = "Monitors a Steam account for future bans." ; args = "[account:string] | [remove:string]" ; aliases = [ "monitor" , "monitorsteam" ] ; cooldown = 3000 ; async run ( msg , pargs , args ) { const monitors = await this . bot . db . getAllUserMonitors ( msg . author . id ) ; if ( ! args . length ) { return msg . createEmbed ( `🎮 ${ msg . string ( "utility.STEAMMONITOR" ) }` , msg . string ( "utility.STEAMMONITOR_CURRENTMONITORING" , { monitors : monitors . length > 0 ? monitors . map ( ( m ) => `\`${ m . username }\`` ) . join ( ", " ) : `${ msg . string ( "global.NOBODY" ) }` , } ) ) ; } if ( args ?. [ 0 ] ?. toLowerCase ( ) === "remove" || args ?. [ 0 ] ?. toLowerCase ( ) === "delete" ) { if ( ! args ?. [ 1 ] ?. length ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "global.ERROR_INVALIDID" ) , "error" ) ; const validMonitor = monitors . find ( ( monitor ) => monitor . id === args [ 1 ] || monitor . username . toLowerCase ( ) === args [ 1 ] . toLowerCase ( ) ) ; if ( ! validMonitor ?. id ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "global.ERROR_INVALIDID" ) , "error" ) ; const monitor = await this . bot . db . deleteUserMonitor ( msg . author . id , validMonitor . id ) ; if ( ! monitor . deleted ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "utility.ACCOUNT_NOTFOUND" ) , "error" ) ; const foundMonitor = this . bot . monitorHandler . monitors . find ( ( monitor ) => monitor . id === args [ 1 ] || monitor . username . toLowerCase ( ) === args [ 1 ] . toLowerCase ( ) ) ; this . bot . reminderHandler . reminders . splice ( this . bot . reminderHandler . reminders . indexOf ( foundMonitor ) , 1 ) ; return msg . createEmbed ( `🎮 ${ msg . string ( "utility.STEAMMONITOR" ) }` , msg . string ( "utility.STEAMMONITOR_REMOVED" ) ) ; } const key = this . bot . config . keys . steam ; let query = args . join ( " " ) ; let steamid ; let id ; let profile ; let bans ; if ( /^\d+$/ . test ( args [ 0 ] ) ) steamid = query ; if ( query . startsWith ( "https://steamcommunity.com/id/" ) ) { query = args . join ( " " ) . substring ( "https://steamcommunity.com/id/" . length , args . join ( " " ) . length ) ; } query = encodeURIComponent ( query . toLowerCase ( ) ) ; if ( ! steamid ) { id = await axios . get ( `http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=${ key }&vanityurl=${ query }` ) . catch ( ( ) => { } ) ; if ( ! id || ! id . data || id . data ?. response . success !== 1 ) { return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "utility.ACCOUNT_NOTFOUND" ) , "error" ) ; } steamid = id . data . response . steamid ; } profile = await axios . get ( `http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${ key }&steamids=${ steamid }` ) . catch ( ( ) => { } ) ; profile = profile && profile . data ?. response ?. players ?. [ 0 ] ? profile . data . response . players [ 0 ] : null ; if ( ! profile || ! profile . personaname ) { return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "utility.ACCOUNT_NOTFOUND" ) , "error" ) ; } const construct = { id : steamid , user : msg . author . id , username : profile . personaname , date : new Date ( ) . getTime ( ) , } ; if ( monitors . length >= 10 ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "utility.STEAMMONITOR_TOOMANY" ) , "error" ) ; if ( ! monitors . find ( ( d ) => d . id === steamid ) ) { bans = await axios . get ( `http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=${ key }&steamids=${ steamid }` ) . catch ( ( ) => { } ) ; bans = bans && bans . data . players ?. [ 0 ] ? bans . data . players [ 0 ] : null ; if ( bans . VACBanned || bans . NumberOfGameBans > 0 ) { return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "utility.STEAMMONITOR_ALREADYBANNED" , { profile : profile . personaname , type : bans . VACBanned ? 0 : 1 , } ) , "error" ) ; } await this . bot . db . insertUserMonitor ( construct ) ; msg . createEmbed ( `🎮 ${ msg . string ( "utility.STEAMMONITOR" ) }` , msg . string ( "utility.STEAMMONITOR_MONITORING" , { profile : profile . personaname } ) ) ; } else { msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "utility.STEAMMONITOR_ALREADYMONITORING" , { profile : profile . personaname } ) , "error" ) ; } } }