8 Commits

3 changed files with 51 additions and 15 deletions
+2
View File
@@ -15,6 +15,8 @@ Commands:
* cq - Clear the queue (admin-only, not to be shared with normal users) * 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) * 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) * dc - Delete an adventure channel (only the captain can use this)
* help - Show all user commands
* adminhelp - Show all admin commands
## Installing Docker ## Installing Docker
+2 -2
View File
@@ -1,7 +1,7 @@
{ {
"maxqueuesize": 4, "channeldeletetimeinminutes": 30,
"channeldeletetimeinminutes": 20,
"deletecommandstoggle": false, "deletecommandstoggle": false,
"maxqueuesize": 4,
"prefix": "!", "prefix": "!",
"token": "NzcwMDQyMDEzMjY5NDkxNzUy.X5Xzgg.kcr_51g95iUvEcYCfbQvG1Sx8ao" "token": "NzcwMDQyMDEzMjY5NDkxNzUy.X5Xzgg.kcr_51g95iUvEcYCfbQvG1Sx8ao"
} }
+47 -13
View File
@@ -66,23 +66,22 @@ function checkQueue(message) {
// Post a message to say the queue is complete // Post a message to say the queue is complete
message.channel.send(`The adventure is beginning - players should check their DMs\n${playerQueue.map((player, index) => `${index + 1} - ${player.username}`).join('\n')}`); message.channel.send(`The adventure is beginning - players should check their DMs\n${playerQueue.map((player, index) => `${index + 1} - ${player.username}`).join('\n')}`);
const randomCode = generateRandomCode();
const adventureMessage = (pokemonName === '' && captainInGameName === '')
? `${generateQueueTitle()}\nHere is your link code ${randomCode} - @${playerQueue[0].username} is making the lobby, have fun!`
: `${generateQueueTitle()}\nPokemon: ${pokemonName}\nCaptain's IGN: ${captainInGameName}\nHere is your link code ${randomCode} - @${playerQueue[0].username} is making the lobby, have fun!`;
try { try {
// DM users // DM users
const randomCode = generateRandomCode();
playerQueue.forEach(player => { playerQueue.forEach(player => {
if (pokemonName === '' && captainInGameName === '') { client.users.cache.get(player.id).send(adventureMessage);
client.users.cache.get(player.id).send(`${generateQueueTitle()}\nHere is your link code ${randomCode} - @${playerQueue[0].username} is making the lobby, have fun!`);
}
else {
client.users.cache.get(player.id).send(`${generateQueueTitle()}\nPokemon: ${pokemonName}\nCaptain's IGN: ${captainInGameName}\nHere is your link code ${randomCode} - @${playerQueue[0].username} is making the lobby, have fun!`);
}
}); });
} catch (error) { } catch (error) {
logger.log('error', error); logger.log('error', error);
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); makeTempChannel(message, adventureMessage);
// Clear the queue // Clear the queue
playerQueue = []; playerQueue = [];
@@ -122,8 +121,8 @@ function getChannelName(username) {
return `${username}s-adventurers`; return `${username}s-adventurers`;
} }
function makeTempChannel(message) { function makeTempChannel(message, adventureMessage) {
const channelName = getChannelName(message.author.username); const channelName = getChannelName(playerQueue[0].username);
let createdChannelId = ''; let createdChannelId = '';
let everyoneRole = message.guild.roles.cache.find(r => r.name === '@everyone'); let everyoneRole = message.guild.roles.cache.find(r => r.name === '@everyone');
@@ -143,14 +142,21 @@ function makeTempChannel(message) {
message.guild.channels.create(channelName, { message.guild.channels.create(channelName, {
type: 'text', type: 'text',
permissionOverwrites: permissionOverwrites, permissionOverwrites: permissionOverwrites,
}).then(createdChannel => { createdChannelId = createdChannel.id; }) }).then(createdChannel => {
createdChannelId = createdChannel.id;
// Post in the channel
createdChannel.send(adventureMessage);
})
.catch(logger.error); .catch(logger.error);
// Delete the channel after 20 seconds // Delete the channel after the configured amount of minutes
setTimeout(function(){ deleteChannel(message, createdChannelId); }, (config.channeldeletetimeinminutes * 1000 * 60) ); setTimeout(function(){ deleteChannel(message, createdChannelId); }, (config.channeldeletetimeinminutes * 1000 * 60) );
} }
function deleteChannel(message, channelId) { function deleteChannel(message, channelId) {
// For some reason this errors without the console.log loading the cache first - not sure why
console.log(message.guild.channels.cache);
const fetchedChannel = message.guild.channels.cache.get(channelId); const fetchedChannel = message.guild.channels.cache.get(channelId);
fetchedChannel.delete(); fetchedChannel.delete();
} }
@@ -280,7 +286,7 @@ client.on('message', function (message) {
if (command === 'dc') { 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 // 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)) { if (message.channel.name === getChannelName(message.author.username)) {
deleteChannel(message.channel.id) deleteChannel(message, message.channel.id)
logger.log('info', `${message.author.username} deleted their adventure channel.`); logger.log('info', `${message.author.username} deleted their adventure channel.`);
} }
else { else {
@@ -288,4 +294,32 @@ client.on('message', function (message) {
logger.log('info', `${message.author.username} attempted to delete channel ${message.channel.id} but it's not their adventure channel.`); logger.log('info', `${message.author.username} attempted to delete channel ${message.channel.id} but it's not their adventure channel.`);
} }
} }
if (command === 'help') {
let msg = `
The commands available to you are:
- !q - Join the queue
- !q <pokemon> <ign> - Join the queue (first player can set the pokemon and their in-game name)
- !lq - Leave the queue
- !sq - Show the queue
- !dc - Delete an adventure channel (only the captain can use this)
`;
message.channel.send(msg);
}
if (command === 'adminhelp') {
let msg = `
The commands available to you are:
- !q - Join the queue
- !q <pokemon> <ign> - Join the queue (first player can set the pokemon and their in-game name)
- !lq - Leave the queue
- !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)
`;
message.channel.send(msg);
}
}); });