2022-01-18 19:05:39 +00:00
import Command from "../../classes/command.js" ;
2022-09-24 17:25:19 +00:00
import { Routes } from "oceanic.js" ;
2022-06-07 23:26:50 +00:00
const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/ ;
2022-01-18 19:05:39 +00:00
class BannerCommand extends Command {
2022-09-24 17:25:19 +00:00
// this command sucks
2022-01-18 19:05:39 +00:00
async run ( ) {
2022-06-25 03:03:34 +00:00
const member = this . options . member ? ? this . args [ 0 ] ;
2022-09-24 17:25:19 +00:00
const self = await this . client . rest . users . get ( this . author . id ) ; // banners are only available over REST
if ( this . type === "classic" && this . message . mentions . users [ 0 ] && this . message . mentions . users [ 0 ] . banner ) {
return this . client . util . formatImage ( Routes . BANNER ( this . message . mentions . users [ 0 ] . id , this . message . mentions . users [ 0 ] . banner ) , null , 512 ) ;
} else if ( member && member > 21154535154122752 n ) {
const user = await this . client . rest . users . get ( member ) ;
if ( user && user . banner ) {
return this . client . util . formatImage ( Routes . BANNER ( user . id , user . banner ) , null , 512 ) ;
} else if ( mentionRegex . test ( member ) ) {
2022-09-21 05:05:03 +00:00
const id = member . match ( mentionRegex ) [ 1 ] ;
if ( id < 21154535154122752 n ) {
this . success = false ;
return "That's not a valid mention!" ;
}
try {
2022-09-24 17:25:19 +00:00
const user = await this . client . rest . users . get ( id ) ;
return user . banner ? this . client . util . formatImage ( Routes . BANNER ( user . id , user . banner ) , null , 512 ) : "This user doesn't have a banner!" ;
2022-09-21 05:05:03 +00:00
} catch {
2022-09-24 17:25:19 +00:00
return self . banner ? this . client . util . formatImage ( Routes . BANNER ( self . id , self . banner ) , null , 512 ) : "You don't have a banner!" ;
2022-09-21 05:05:03 +00:00
}
} else {
return "This user doesn't have a banner!" ;
2022-01-18 19:05:39 +00:00
}
2022-09-24 03:25:16 +00:00
} else if ( this . args . join ( " " ) !== "" && this . guild ) {
2022-09-24 17:25:19 +00:00
const searched = await this . guild . searchMembers ( {
query : this . args . join ( " " ) ,
limit : 1
} ) ;
if ( searched . length === 0 ) return self . banner ? this . client . util . formatImage ( Routes . BANNER ( self . id , self . banner ) , null , 512 ) : "This user doesn't have a banner!" ;
const user = await this . client . rest . users . get ( searched [ 0 ] . user . id ) ;
return user . banner ? this . client . util . formatImage ( Routes . BANNER ( user . id , user . banner ) , null , 512 ) : ( self . banner ? this . client . util . formatImage ( Routes . BANNER ( self . id , self . banner ) , null , 512 ) : "This user doesn't have a banner!" ) ;
2022-01-18 19:05:39 +00:00
} else {
2022-09-24 17:25:19 +00:00
return self . banner ? this . client . util . formatImage ( Routes . BANNER ( self . id , self . banner ) , null , 512 ) : "You don't have a banner!" ;
2022-01-18 19:05:39 +00:00
}
}
static description = "Gets a user's banner" ;
static aliases = [ "userbanner" ] ;
static arguments = [ "{mention/id}" ] ;
2022-06-07 23:26:50 +00:00
static flags = [ {
name : "member" ,
type : 6 ,
description : "The member to get the banner from" ,
required : false
} ] ;
2022-01-18 19:05:39 +00:00
}
export default BannerCommand ;