5 Commits

2 changed files with 22 additions and 10 deletions
+2
View File
@@ -51,4 +51,6 @@ To access the command line inside the docker container you can run:
`docker exec -it <container id> /bin/bash`
## Version 2.0 potential features
* Let three people agree to start early using a voting command, so they don't have to wait for a fourth person (all three must vote to start)
+20 -10
View File
@@ -5,7 +5,10 @@ const client = new Discord.Client();
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
defaultMeta: { service: 'user-service' },
transports: [
//
@@ -67,9 +70,10 @@ function checkQueue(message) {
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 baseMessage = `@${playerQueue[0].username} is making the lobby. Here is your link code ${randomCode}`;
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!`;
? `${generateQueueTitle()}\n${baseMessage}`
: `${generateQueueTitle()}\nPokemon: ${pokemonName}\nCaptain's IGN: ${captainInGameName}\n${baseMessage}`;
try {
// DM users
@@ -139,6 +143,7 @@ function makeTempChannel(message, adventureMessage) {
});
});
logger.info(`Making temp channel ${channelName}`)
message.guild.channels.create(channelName, {
type: 'text',
permissionOverwrites: permissionOverwrites,
@@ -151,14 +156,19 @@ function makeTempChannel(message, adventureMessage) {
.catch(logger.error);
// Delete the channel after the configured amount of minutes
setTimeout(function(){ deleteChannel(message, createdChannelId); }, (config.channeldeletetimeinminutes * 1000 * 60) );
setTimeout(function(){ deleteChannel(message, channelName); }, (config.channeldeletetimeinminutes * 1000 * 60) );
}
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);
fetchedChannel.delete();
function deleteChannel(message, channelName) {
try {
// Get a Channel by Name
const fetchedChannel = message.guild.channels.cache.find(channel => channel.name === channelName);
logger.info(`Deleting temp channel ${channelName}`)
fetchedChannel.delete();
} catch (error) {
logger.error(error);
}
}
client.on('message', function (message) {
@@ -286,7 +296,7 @@ client.on('message', function (message) {
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, message.channel.id)
deleteChannel(message, message.channel.name)
logger.log('info', `${message.author.username} deleted their adventure channel.`);
}
else {