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-03-31 05:42:03 +00:00
|
|
|
if (!this.channel.guild) return "This command only works in servers!";
|
2022-04-05 03:05:28 +00:00
|
|
|
if (!this.member.voiceState.channelID) return "You need to be in a voice channel first!";
|
2022-03-31 05:42:03 +00:00
|
|
|
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
|
|
|
|
if (this.connection.host !== this.author.id && this.author.id !== process.env.OWNER) return "Only the current voice session host can choose another host!";
|
2022-04-05 03:05:28 +00:00
|
|
|
const input = this.type === "classic" ? this.args.join(" ") : this.options.user;
|
|
|
|
if (!input || !input.trim()) return "You need to provide who you want the host to be!";
|
2022-01-18 19:05:39 +00:00
|
|
|
let user;
|
2022-04-05 03:05:28 +00:00
|
|
|
if (this.type === "classic") {
|
|
|
|
const getUser = this.message.mentions.length >= 1 ? this.message.mentions[0] : (await this.ipc.fetchUser(input));
|
|
|
|
if (getUser) {
|
|
|
|
user = getUser;
|
|
|
|
} else if (input.match(/^<?[@#]?[&!]?\d+>?$/) && input >= 21154535154122752n) {
|
|
|
|
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-01-18 19:05:39 +00:00
|
|
|
}
|
2022-04-05 03:05:28 +00:00
|
|
|
} else {
|
|
|
|
user = input;
|
2022-01-18 19:05:39 +00:00
|
|
|
}
|
|
|
|
if (!user) return "I can't find that user!";
|
|
|
|
if (user.bot) return "Setting a bot as the session host isn't a very good idea.";
|
2022-03-31 05:42:03 +00:00
|
|
|
const member = this.channel.guild ? this.channel.guild.members.get(user.id) : undefined;
|
2022-01-18 19:05:39 +00:00
|
|
|
if (!member) return "That user isn't in this server!";
|
|
|
|
const object = this.connection;
|
|
|
|
object.host = member.id;
|
2022-03-31 05:42:03 +00:00
|
|
|
players.set(this.channel.guild.id, object);
|
2022-01-18 19:05:39 +00:00
|
|
|
return `🔊 ${member.mention} is the new voice channel host.`;
|
|
|
|
}
|
|
|
|
|
2022-04-05 03:05:28 +00:00
|
|
|
static flags = [{
|
|
|
|
name: "user",
|
|
|
|
type: 6,
|
|
|
|
description: "The user you want the new host to be",
|
|
|
|
required: true
|
|
|
|
}];
|
2022-01-18 19:05:39 +00:00
|
|
|
static description = "Changes the host of the current voice session";
|
|
|
|
static aliases = ["sethost"];
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HostCommand;
|