music: add queue removal

This commit is contained in:
Cynthia Foxwell 2022-04-24 12:56:53 -06:00
parent 306ad496fa
commit 902b3f77f9

View file

@ -308,7 +308,7 @@ async function enqueue(
return;
}
await connection.play(media, {inlineVolume: true, voiceDataTimeout: -1});
await connection.play(media, {voiceDataTimeout: -1});
textChannel.createMessage({
embeds: [
@ -398,8 +398,8 @@ command.callback = async function (msg, line) {
case "p":
if (msg.member?.voiceState?.channelID) {
if (voiceStorage.has(msg.guildID)) {
const conn = voiceStorage.get(msg.guildID);
if (conn.channelID != msg.member.voiceState.channelID) {
const connection = voiceStorage.get(msg.guildID);
if (connection.channelID != msg.member.voiceState.channelID) {
return "You are in a different voice channel than the bot.";
}
}
@ -520,7 +520,7 @@ command.callback = async function (msg, line) {
}
} else {
const url = await youtubeSearch(msg, argStr);
if (url != "Canceled" && url != "Request timed out") {
if (url.startsWith("https://youtu.be/")) {
await enqueue(
msg.guildID,
msg.member.voiceState.channelID,
@ -653,17 +653,64 @@ command.callback = async function (msg, line) {
return {
embed: {
title: "Currently Queued",
title: ":inbox_tray: Currently Queued",
color: 0x0088cc,
fields,
footer: {
text: queue.length > 9 ? `Showing 9/${queue.length}` : "",
text: queue.length > 9 ? `Showing 9/${queue.length} items` : "",
},
},
};
}
case "remove":
case "qr":
if (msg.member?.voiceState?.channelID) {
const connection = voiceStorage.get(msg.guildID);
if (voiceStorage.has(msg.guildID)) {
if (connection.channelID != msg.member.voiceState.channelID) {
return "You are in a different voice channel than the bot.";
}
}
let queue = connection._music_queue;
if (queue.length === 0) return "Nothing else is currently queued";
const hasManageMessages = msg.member.permissions.has("manageMessages");
if (!hasManageMessages)
queue = queue.filter((item) => item.addedBy == msg.member.id);
if (queue.length === 0) return "You currently have nothing queued";
const toRemove = await selectionMessage(
msg,
"Choose items to remove",
queue.slice(0, 25).map((item) => {
const user = hf.bot.users.get(item.addedBy);
return {
key: item.url,
display: (item.title ?? item.url).substr(0, 100),
description:
hasManageMessages &&
`Added by: ${user.username}#${user.discriminator}`,
};
}),
30000,
25
);
if (Array.isArray(toRemove)) {
for (const removedItem of toRemove) {
connection._music_queue = connection._music_queue.filter(
(item) => item.url !== removedItem
);
}
return `Removed ${toRemove.length} item(s).`;
} else {
return toRemove;
}
} else {
return "You are not in a voice channel";
}
case "lock":
case "unlock":
return "TODO";