2022-01-18 19:05:39 +00:00
import { players } from "../../utils/soundplayer.js" ;
import MusicCommand from "../../classes/musicCommand.js" ;
class HostCommand extends MusicCommand {
async run ( ) {
2022-09-01 01:00:34 +00:00
this . success = false ;
2022-09-24 03:25:16 +00:00
if ( ! this . guild ) return "This command only works in servers!" ;
2022-09-27 19:46:07 +00:00
if ( ! this . member . voiceState ) return "You need to be in a voice channel first!" ;
2022-10-24 01:27:32 +00:00
if ( ! this . guild . voiceStates . has ( this . client . user . id ) ) return "I'm not in a voice channel!" ;
2022-10-12 03:36:45 +00:00
if ( ! this . connection ) return "I haven't completely connected yet!" ;
2022-08-27 01:55:24 +00:00
if ( this . connection . host !== this . author . id && ! process . env . OWNER . split ( "," ) . includes ( this . connection . host ) ) return "Only the current voice session host can choose another host!" ;
2022-06-07 23:26:40 +00:00
const input = this . options . user ? ? this . args . join ( " " ) ;
2022-08-27 18:27:42 +00:00
if ( input ? . trim ( ) ) {
let user ;
if ( this . type === "classic" ) {
2022-09-27 19:46:07 +00:00
const getUser = this . message . mentions . users . length >= 1 ? this . message . mentions . users [ 0 ] : this . client . users . get ( input ) ;
2022-08-27 18:27:42 +00:00
if ( getUser ) {
user = getUser ;
} else if ( input . match ( /^<?[@#]?[&!]?\d+>?$/ ) && input >= 21154535154122752 n ) {
try {
user = await this . client . getRESTUser ( input ) ;
} catch {
// no-op
}
} else {
const userRegex = new RegExp ( input . split ( " " ) . join ( "|" ) , "i" ) ;
const member = this . client . users . find ( element => {
return userRegex . test ( element . username ) ;
} ) ;
user = member ;
2022-04-05 03:05:28 +00:00
}
} else {
2022-08-27 18:27:42 +00:00
user = input ;
2022-01-18 19:05:39 +00:00
}
2022-08-27 18:27:42 +00:00
if ( ! user ) return "I can't find that user!" ;
if ( user . bot ) return "This is illegal, you know." ;
2022-10-25 16:57:15 +00:00
const member = this . guild . members . get ( user . id ) ;
2022-08-27 18:27:42 +00:00
if ( ! member ) return "That user isn't in this server!" ;
const object = this . connection ;
object . host = member . id ;
2022-09-24 03:25:16 +00:00
players . set ( this . guildID , object ) ;
2022-09-01 01:00:34 +00:00
this . success = true ;
2022-08-27 18:27:42 +00:00
return ` 🔊 ${ member . mention } is the new voice channel host. ` ;
2022-04-05 03:05:28 +00:00
} else {
2022-10-25 16:57:15 +00:00
const member = this . guild . members . get ( players . get ( this . guild . id ) . host ) ;
2022-09-01 01:00:34 +00:00
this . success = true ;
2022-08-27 18:27:42 +00:00
return ` 🔊 The current voice channel host is ** ${ member ? . username } # ${ member ? . discriminator } **. ` ;
2022-01-18 19:05:39 +00:00
}
}
2022-04-05 03:05:28 +00:00
static flags = [ {
name : "user" ,
type : 6 ,
2022-08-27 18:27:42 +00:00
description : "The user you want the new host to be"
2022-04-05 03:05:28 +00:00
} ] ;
2022-08-27 18:27:42 +00:00
static description = "Gets or changes the host of the current voice session" ;
2022-01-18 19:05:39 +00:00
static aliases = [ "sethost" ] ;
}
export default HostCommand ;