feat(*): Add command to remove a tagged user from the queue

This commit is contained in:
2020-10-25 23:40:33 +00:00
parent a8c058f096
commit e5f9056c5e
+44
View File
@@ -17,6 +17,7 @@ client.once('ready', () =>{
* lq - Leave the queue * lq - Leave the queue
* sq - Show the queue * sq - Show the queue
* cq - Clear the queue * cq - Clear the queue
* ru - Remove a user from the queue
*/ */
function generateRandomCode() { function generateRandomCode() {
@@ -58,6 +59,20 @@ function checkQueue(message) {
} }
} }
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.cache.get(mention);
}
}
client.on('message', function (message) { client.on('message', function (message) {
// Ignore messages from the bot and that don't begin with the prefix // Ignore messages from the bot and that don't begin with the prefix
if (message.author.bot) return; if (message.author.bot) return;
@@ -130,4 +145,33 @@ client.on('message', function (message) {
console.log(`${message.author.username} cleared the queue.`); console.log(`${message.author.username} cleared the queue.`);
} }
} }
// Remove someone else from queue
if (command === 'ru' && args[0]) {
const user = getUserFromMention(args[0]);
// Delete the message with the bot command
message.delete();
if ((playerQueue.includes(user))) {
// Search for the user
for(var i = 0; i < playerQueue.length; i++){
console.log(i + ' ' + playerQueue[i].username);
if ((playerQueue[i].username === user.username)){
playerQueue.splice(i, 1);
i--;
}
}
message.channel.send(`${user.username} removed from queue.`);
console.log(`${message.author.username} removed ${user.username} from queue.`);
checkQueue(message);
}
else if (!(playerQueue.includes(user))) {
message.channel.send(`${user.username} is not in the queue.`);
console.log(`${message.author.username} attempted to remove ${user.username} from queue but they weren't in it.`);
}
}
}); });