Added banner, added host

This commit is contained in:
Essem 2022-01-18 13:05:39 -06:00
parent 8b238a2316
commit 76fe5b6aa6
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
3 changed files with 81 additions and 6 deletions

View file

@ -0,0 +1,33 @@
import Command from "../../classes/command.js";
class BannerCommand extends Command {
async run() {
if (this.message.mentions[0]) {
return this.message.mentions[0].banner ? this.message.mentions[0].dynamicBannerURL(null, 1024) : "This user doesn't have a banner!";
} else if (await this.ipc.fetchUser(this.args[0])) {
const user = await this.ipc.fetchUser(this.args[0]);
return user.banner ? this.client._formatImage(`/banners/${user.id}/${user.banner}`, null, 1024) : "This user doesn't have a banner!";
} else if (this.args[0] && this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] >= 21154535154122752n) {
try {
const user = await this.client.getRESTUser(this.args[0]);
return user.banner ? this.client._formatImage(`/banners/${user.id}/${user.banner}`, null, 1024) : "This user doesn't have a banner!";
} catch {
return this.message.author.banner ? this.message.author.dynamicBannerURL(null, 1024) : "You don't have a banner!";
}
} else if (this.args.join(" ") !== "" && this.message.channel.guild) {
const userRegex = new RegExp(this.args.join("|"), "i");
const member = this.message.channel.guild.members.find(element => {
return userRegex.test(element.nick) ?? userRegex.test(element.username);
});
return member && member.user.banner ? member.user.dynamicBannerURL(null, 1024) : (this.message.author.banner ? this.message.author.dynamicBannerURL(null, 1024) : "This user doesn't have a banner!");
} else {
return this.message.author.banner ? this.message.author.dynamicBannerURL(null, 1024) : "You don't have a banner!";
}
}
static description = "Gets a user's banner";
static aliases = ["userbanner"];
static arguments = ["{mention/id}"];
}
export default BannerCommand;

42
commands/music/host.js Normal file
View file

@ -0,0 +1,42 @@
import { players } from "../../utils/soundplayer.js";
import MusicCommand from "../../classes/musicCommand.js";
class HostCommand extends MusicCommand {
async run() {
if (!this.message.channel.guild) return "This command only works in servers!";
if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!";
if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.message.author.id && this.message.author.id !== process.env.OWNER) return "Only the current voice session host can choose another host!";
if (this.args.length === 0) return "You need to provide who you want the host to be!";
const getUser = this.message.mentions.length >= 1 ? this.message.mentions[0] : (this.args.length !== 0 ? await this.ipc.fetchUser(this.args[0]) : null);
let user;
if (getUser) {
user = getUser;
} else if (this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] >= 21154535154122752n) {
try {
user = await this.client.getRESTUser(this.args[0]);
} catch {
// no-op
}
} else if (this.args.join(" ") !== "") {
const userRegex = new RegExp(this.args.join("|"), "i");
const member = this.client.users.find(element => {
return userRegex.test(element.username);
});
user = member;
}
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.";
const member = this.message.channel.guild ? this.message.channel.guild.members.get(user.id) : undefined;
if (!member) return "That user isn't in this server!";
const object = this.connection;
object.host = member.id;
players.set(this.message.channel.guild.id, object);
return `🔊 ${member.mention} is the new voice channel host.`;
}
static description = "Changes the host of the current voice session";
static aliases = ["sethost"];
}
export default HostCommand;

View file

@ -92,16 +92,16 @@ export async function play(client, sound, message, music = false) {
if (oldQueue && oldQueue.length !== 0 && music) {
return `Your ${playlistInfo.name ? "playlist" : "tune"} \`${playlistInfo.name ? playlistInfo.name.trim() : (tracks[0].info.title !== "" ? tracks[0].info.title.trim() : "(blank)")}\` has been added to the queue!`;
} else {
nextSong(client, message, connection, tracks[0].track, tracks[0].info, music, voiceChannel, player ? player.loop : false, player ? player.shuffle : false);
nextSong(client, message, connection, tracks[0].track, tracks[0].info, music, voiceChannel, player ? player.host : message.author.id, player ? player.loop : false, player ? player.shuffle : false);
return;
}
}
export async function nextSong(client, message, connection, track, info, music, voiceChannel, loop = false, shuffle = false, lastTrack = null) {
export async function nextSong(client, message, connection, track, info, music, voiceChannel, host, loop = false, shuffle = false, lastTrack = null) {
skipVotes.delete(voiceChannel.guild.id);
const parts = Math.floor((0 / info.length) * 10);
let playingMessage;
if (!music && players.get(voiceChannel.guild.id)) {
if (!music && players.has(voiceChannel.guild.id)) {
const playMessage = players.get(voiceChannel.guild.id).playMessage;
try {
players.delete(voiceChannel.guild.id);
@ -110,7 +110,7 @@ export async function nextSong(client, message, connection, track, info, music,
// no-op
}
}
if (music && lastTrack === track && players.get(voiceChannel.guild.id)) {
if (music && lastTrack === track && players.has(voiceChannel.guild.id)) {
playingMessage = players.get(voiceChannel.guild.id).playMessage;
} else {
try {
@ -147,7 +147,7 @@ export async function nextSong(client, message, connection, track, info, music,
connection.removeAllListeners("end");
await connection.play(track);
await connection.volume(75);
players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, shuffle: shuffle, playMessage: playingMessage });
players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: host, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, shuffle: shuffle, playMessage: playingMessage });
connection.once("error", async (error) => {
try {
if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();
@ -194,7 +194,7 @@ export async function nextSong(client, message, connection, track, info, music,
queues.set(voiceChannel.guild.id, newQueue);
if (newQueue.length !== 0) {
const newTrack = await Rest.decode(connection.node, newQueue[0]);
nextSong(client, message, connection, newQueue[0], newTrack, music, voiceChannel, player.loop, player.shuffle, track);
nextSong(client, message, connection, newQueue[0], newTrack, music, voiceChannel, host, player.loop, player.shuffle, track);
try {
if (newQueue[0] !== track && playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();
if (newQueue[0] !== track && player.playMessage.channel.messages.get(player.playMessage.id)) await player.playMessage.delete();