feat(*): Add functionality to create temp text channel for completed queue members

This commit is contained in:
2020-10-26 08:55:32 +00:00
parent 11f55b7eb3
commit 4ab02a6dda
+27
View File
@@ -74,6 +74,8 @@ function checkQueue(message) {
message.channel.send(`There was an error, please let an admin know!\n${error}`); message.channel.send(`There was an error, please let an admin know!\n${error}`);
} }
makeTempChannel(message);
// Clear the queue // Clear the queue
playerQueue = []; playerQueue = [];
logger.log('info', 'Emptied queue'); 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) { 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;