diff --git a/README.md b/README.md index f17ced9..90a8e26 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Commands: * sq - Show the queue * cq - Clear the queue (admin-only, not to be shared with normal users) * ru - Remove a tagged user from the queue (admin-only, not to be shared with normal users) +* dc - Delete an adventure channel (only the captain can use this) ## Dockerize the bot diff --git a/index.js b/index.js index 0fe29d4..d550d6a 100644 --- a/index.js +++ b/index.js @@ -46,6 +46,7 @@ client.once('ready', () =>{ * sq - Show the queue * cq - Clear the queue * ru - Remove a tagged user from the queue + * dc - Delete an adventure channel (only the captain can use this) */ function generateRandomCode() { @@ -136,6 +137,11 @@ function makeTempChannel(message) { setTimeout(function(){ deleteChannel(createdChannelId); }, 20000); } +function deleteChannel(channelId) { + const fetchedChannel = message.guild.channels.cache.get(channelId); + fetchedChannel.delete(); +} + client.on('message', function (message) { // Ignore messages from the bot and that don't begin with the prefix if (message.author.bot) return; @@ -241,5 +247,17 @@ client.on('message', function (message) { message.channel.send(`${user.username} is not in the queue.`); logger.log('info', `${message.author.username} attempted to remove ${user.username} from queue but they weren't in it.`); } - } + } + + if (command === 'dc') { + // todo - add logic here to determine if they can delete the channel (i.e. it's their temporary one) - compare the name + if (message.channel.name === getChannelName(message.author.username)) { + deleteChannel(message.channel.id) + logger.log('info', `${message.author.username} deleted their adventure channel.`); + } + else { + message.channel.send(`${message.author.username} is not allowed to delete this channel.`); + logger.log('info', `${message.author.username} attempted to delete channel ${message.channel.id} but it's not their adventure channel.`); + } + } });