mirror of
https://github.com/jcreek/denBot.git
synced 2026-07-12 18:33:45 +00:00
feat(*): Add command to remove a tagged user from the queue
This commit is contained in:
@@ -17,6 +17,7 @@ client.once('ready', () =>{
|
||||
* lq - Leave the queue
|
||||
* sq - Show the queue
|
||||
* cq - Clear the queue
|
||||
* ru - Remove a user from the queue
|
||||
*/
|
||||
|
||||
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) {
|
||||
// Ignore messages from the bot and that don't begin with the prefix
|
||||
if (message.author.bot) return;
|
||||
@@ -130,4 +145,33 @@ client.on('message', function (message) {
|
||||
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.`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user