From 4ab02a6ddab21304fc72a0878a3d7b0e50fe0240 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Mon, 26 Oct 2020 08:55:32 +0000 Subject: [PATCH] feat(*): Add functionality to create temp text channel for completed queue members --- index.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/index.js b/index.js index 2420d74..0fe29d4 100644 --- a/index.js +++ b/index.js @@ -74,6 +74,8 @@ function checkQueue(message) { message.channel.send(`There was an error, please let an admin know!\n${error}`); } + makeTempChannel(message); + // Clear the queue playerQueue = []; logger.log('info', 'Emptied queue'); @@ -109,6 +111,31 @@ function getUserFromMention(mention) { } } +function getChannelName(username) { + return `${username}'s adventurers`; +} + +function makeTempChannel(message) { + const everyoneRole = message.guild.defaultRole; + let createdChannelId = ''; + + const channelName = getChannelName(message.author.username); + message.guild.createChannel(channelName, 'text') + .then(createdChannel => { + playerQueue.forEach(player => { + createdChannel.overwritePermissions(player.id, { VIEW_CHANNEL: true }); + }); + createdChannel.overwritePermissions(client.id, { VIEW_CHANNEL: true }); + createdChannel.overwritePermissions(everyoneRole, { VIEW_CHANNEL: false }); + + createdChannelId = createdChannel.id; + }) + .catch(logger.error); + + // Delete the channel after 20 minutes + setTimeout(function(){ deleteChannel(createdChannelId); }, 20000); +} + client.on('message', function (message) { // Ignore messages from the bot and that don't begin with the prefix if (message.author.bot) return;