32 Commits

Author SHA1 Message Date
jcreek fa1fada289 fix(*): Add log and try catch loop to prevent getting a user from a mention throwing uncleanly 2021-02-28 09:54:16 +00:00
jcreek eea9841481 feat(*): Clean up whitespace 2021-02-28 09:52:57 +00:00
jcreek 5f875bc91d feat(*): Replace some key messages with embed messages 2021-02-14 19:13:31 +00:00
jcreek dadc08d94c feat(*): Add helpers file with sendEmbedMessage function 2021-02-14 19:13:31 +00:00
jcreek 73906e1957 fix(*): Clear pokemon name and captain name when using the clear queue command 2021-02-14 19:13:31 +00:00
jcreek 84a8f2c22c fix(*): Clear pokemon name and captain ign when filling a queue 2021-02-14 19:13:31 +00:00
jcreek c6333e7d06 feat(*): Disable the automatic channel deletion 2021-02-14 19:13:31 +00:00
jcreek 36366499ed feat(*): Add manual update instructions to readme 2021-02-14 19:13:31 +00:00
jcreek 95e9003ce7 feat(*): Add future feature suggestions section to readme 2021-02-14 19:13:31 +00:00
jcreek 02dc03e5ef fix(*): Enable users with spaces in their username to delete their adventure channels
Why on earth does Discord even allow people to have spaces in their usernames?
2021-02-14 19:13:31 +00:00
jcreek d901ee4672 fix(*): Hand edge cases for the start command 2021-02-14 19:13:31 +00:00
jcreek 6865d021a3 fix(*): Use prefix rather than command text for help and adminhelp commands 2021-02-14 19:13:31 +00:00
jcreek c8dbcd9120 fix(*): Missed empty queue check for when a player leaves a queue they were the only one in 2021-02-14 19:13:31 +00:00
jcreek df6211d5e4 feat(*): Finish implementing start command 2021-02-14 19:13:31 +00:00
jcreek 17a8f98ca3 fix(*): Fix further missed lowercasing of channel names by Discord for text channels 2021-02-14 19:13:31 +00:00
Josh Creek 8d7df9d4ec feat(*): Remove potential feature from readme as it has been implemented 2021-02-14 19:13:31 +00:00
Josh Creek 2e5c468c8f feat(*): Add start command for voting to start the adventure before the queue is full 2021-02-14 19:13:31 +00:00
Josh Creek 3d51cc1551 feat(*): Update help commands to use the correct command symbol from the config file rather than hard-coding one 2021-02-14 19:13:31 +00:00
jcreek be885bc286 fix(*): Fix bug where text channel names are automatically lowercased by Discord so couldn't be deleted if the username had capital letters 2021-02-14 19:13:31 +00:00
jcreek f127e09858 fix(*): Fix broken channel deletion and add more helpful logs 2021-02-14 19:13:31 +00:00
jcreek 3191be31e1 feat(*): Add a dev token for debugging and testing in the dev discord 2021-02-14 19:13:31 +00:00
jcreek c48edec643 feat(*): Enable console logging even in production so Jord can see logs easily 2021-02-14 19:13:31 +00:00
jcreek c642d95335 feat(*): Improve logging and error handling 2021-02-14 19:13:31 +00:00
jcreek e08495bfc2 feat(*): Remove unused getCurrentDateAndTime function 2021-02-14 19:13:30 +00:00
jcreek 087fecf93a fix(*): Further fixes to elasticsearch logging to get the stacktrace coming through correctly 2021-02-14 19:13:30 +00:00
jcreek c3fcc15f06 fix(*): Make the elasticsearch logging render out log data correctly for filtering in kibana 2021-02-14 19:13:29 +00:00
jcreek 939a99b62d feat(*): Implement winston-elasticsearch for logging to Elasticsearch 2021-02-14 19:12:59 +00:00
jcreek 3aa3f7ac52 refactor(*): Move maxqueuesize to alphabetical order 2021-02-14 19:12:11 +00:00
jcreek 9459e2714c feat(*): Increase default channel delete time to 30 minutes 2021-02-14 19:11:53 +00:00
jcreek 6a3cec4a0e feat(*): Add config option to toggle auto deleting commands 2021-02-14 19:11:53 +00:00
jcreek be7ba9e28d feat(*): Add channel delete time to config file 2021-02-14 19:11:53 +00:00
jcreek c48c5f32a9 feat(*): Add config file content 2021-02-14 19:11:04 +00:00
3 changed files with 75 additions and 49 deletions
+3 -3
View File
@@ -3,10 +3,10 @@
"deletecommandstoggle": false,
"maxqueuesize": 4,
"elasticsearch" : {
"elasticsearch_address" : "http://jcreek.ddns.net:9200",
"elasticsearch_address" : "http://YOUR-ELASTICSEARCH-ADDRESS-GOES-HERE:9200",
"elasticsearch_index_pattern" : "[logs-denbot-]YYYY.MM.DD"
},
"prefix": "!",
"token-dev": "Nzc4MDI2MTE1NDkwOTA2MTYz.X7L_SA.bNzC1kQUpBSwEsjp_cDGwR62Soo",
"token": "NzcwMDQyMDEzMjY5NDkxNzUy.X5Xzgg.kcr_51g95iUvEcYCfbQvG1Sx8ao"
"token-dev": "YOUR-DEV-TOKEN-GOES-HERE",
"token": "YOUR-TOKEN-GOES-HERE"
}
+21
View File
@@ -0,0 +1,21 @@
const { loggers } = require("winston");
module.exports = {
sendEmbedMessage: function (logger, message, Discord, title, description, colour = '#F4B400') {
// For documentation see https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/first-bot/using-embeds-in-messages.md
try {
const embed = new Discord.MessageEmbed()
.setTitle(title)
.setColor(colour)
.setDescription(description)
.setFooter('This is a custom bot - if it goes down, tag Scruffy')
.setThumbnail('https://cdn.discordapp.com/icons/770039159506337802/a_510706276ebcf77e568900fa708e6c63.png?size=128')
.setTimestamp();
message.channel.send(embed);
} catch (error) {
logger.error('Failed to send embed message', error);
message.channel.send('There was a problem, sorry!');
}
},
};
+51 -46
View File
@@ -2,6 +2,7 @@ const Discord = require('discord.js');
const winston = require('winston');
const Elasticsearch = require('winston-elasticsearch');
const config = require('./config.json');
const {sendEmbedMessage} = require('./helpers.js');
const client = new Discord.Client();
const { format } = winston;
@@ -113,10 +114,10 @@ function generateRandomCode() {
function checkQueue(message) {
if (playerQueue.length === config.maxqueuesize || (playerQueue.length > 0 && playerQueue.length == playerVotes.length)) {
// Queue is full
logger.log('info', 'Queue is full');
logger.info('Queue is full');
// 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')}`);
sendEmbedMessage(logger, message, Discord, 'Queue full', `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}`;
@@ -131,32 +132,32 @@ function checkQueue(message) {
});
} catch (error) {
logger.error('Tried to DM users: ', error);
message.channel.send(`There was an error, please let an admin know!\n${error}`);
sendEmbedMessage(logger, message, Discord, 'An error occurred', `There was an error, please let an admin know!\n${error}`, '#DB4437');
}
makeTempChannel(message, adventureMessage);
// Clear the queue and votes
playerQueue = [];
logger.log('info', 'Emptied queue');
logger.info('Emptied queue');
playerVotes = [];
logger.log('info', 'Emptied votes');
logger.info('Emptied votes');
pokemonName = '';
captainInGameName = '';
logger.log('info', 'Emptied pokemon name and captain name');
logger.info('Emptied pokemon name and captain name');
}
else if (playerQueue.length === 0) {
message.channel.send('The queue is empty :(');
sendEmbedMessage(logger, message, Discord, 'Queue empty', 'The queue is empty :(');
pokemonName = '';
captainInGameName = '';
}
else {
// Show queue after adding
if (pokemonName === '' && captainInGameName === '') {
message.channel.send(`${generateQueueTitle()}\n${playerQueue.map((player, index) => `${index + 1} - ${player.username}`).join('\n')}`);
sendEmbedMessage(logger, message, Discord, generateQueueTitle(), `${playerQueue.map((player, index) => `${index + 1} - ${player.username}`).join('\n')}`);
}
else {
message.channel.send(`${generateQueueTitle()}\nPokemon: ${pokemonName}\nCaptain's IGN: ${captainInGameName}\n${playerQueue.map((player, index) => `${index + 1} - ${player.username}`).join('\n')}`);
sendEmbedMessage(logger, message, Discord, generateQueueTitle(), `**Pokemon**: ${pokemonName}\n**Captain's IGN**: ${captainInGameName}\n${playerQueue.map((player, index) => `${index + 1} - ${player.username}`).join('\n')}`);
}
}
}
@@ -259,8 +260,8 @@ client.on('message', function (message) {
logger.info(`${message.author.username} used command q in ${message.channel.name}`);
logger.log('info', `${message.author.username} joined the queue.`);
message.channel.send(`=====\n${message.author.username} joined the queue.`);
logger.info(`${message.author.username} joined the queue.`);
sendEmbedMessage(logger, message, Discord, 'Queue in progress', `${message.author.username} joined the queue.`);
playerQueue.push(message.author);
@@ -306,8 +307,8 @@ client.on('message', function (message) {
}
}
logger.log('info', `${message.author.username} left the queue.`);
message.channel.send(`${message.author.username} left the queue.`);
logger.info(`${message.author.username} left the queue.`);
sendEmbedMessage(logger, message, Discord, 'Queue in progress', `${message.author.username} left the queue.`);
checkQueue(message);
}
@@ -341,10 +342,10 @@ client.on('message', function (message) {
// First player to vote
playerVotes.push(message.author);
message.channel.send(`=====\n${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`);
sendEmbedMessage(logger, message, Discord, 'Voting to start early', `${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`);
}
else if (playerVotes.includes(message.author.username)) {
message.channel.send(`=====\n${message.author.username} has already voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`);
sendEmbedMessage(logger, message, Discord, 'Voting to start early', `${message.author.username} has already voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`);
}
else if (playerVotes.length < config.maxqueuesize) {
// Not the first player to vote
@@ -352,7 +353,7 @@ client.on('message', function (message) {
if (playerVotes.length < playerQueue.length) {
// Still not all players voted
message.channel.send(`=====\n${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`);
sendEmbedMessage(logger, message, Discord, 'Voting to start early', `${message.author.username} voted to start the adventure.\nAll other players in the queue must also vote to start the adventure for it to begin without ${config.maxqueuesize} players.`);
}
else {
// All players have voted, we can start the adventure early
@@ -384,55 +385,59 @@ client.on('message', function (message) {
if (playerQueue.length === 0) {
message.channel.send(`The queue is already empty...`);
logger.log('info', `${message.author.username} attempted to clear the queue but it was already empty.`);
logger.info( `${message.author.username} attempted to clear the queue but it was already empty.`);
}
else {
playerQueue = [];
playerVotes = [];
message.channel.send(`The queue has been cleared!`);
logger.log('info', `${message.author.username} cleared the queue and the votes.`);
logger.info( `${message.author.username} cleared the queue and the votes.`);
pokemonName = '';
captainInGameName = '';
logger.log('info', 'Emptied pokemon name and captain name');
logger.info('Emptied pokemon name and captain name');
}
}
// Remove a tagged user from the queue
if (command === 'ru' && args[0]) {
const user = getUserFromMention(args[0]);
// Delete the message with the bot command
if (config.deletecommandstoggle) {
message.delete();
}
if (config.deletecommandstoggle) {
message.delete();
}
logger.info(`${message.author.username} used command ru in ${message.channel.name}`);
logger.info(`${message.author.username} used command ru ${user} in ${message.channel.name}`);
if ((playerQueue.includes(user))) {
try {
const user = getUserFromMention(args[0]);
// Search for the user
for(var i = 0; i < playerQueue.length; i++){
if ((playerQueue[i].username === user.username)){
playerQueue.splice(i, 1);
if ((playerQueue.includes(user))) {
// Search for the user
for(var i = 0; i < playerQueue.length; i++){
if ((playerQueue[i].username === user.username)){
playerQueue.splice(i, 1);
i--;
}
}
for( var i = 0; i < playerVotes.length; i++){
if ( playerVotes[i].username === user.username) {
playerVotes.splice(i, 1);
i--;
}
}
for( var i = 0; i < playerVotes.length; i++){
if ( playerVotes[i].username === user.username) {
playerVotes.splice(i, 1);
i--;
}
}
message.channel.send(`${user.username} removed from queue.`);
logger.info( `${message.author.username} removed ${user.username} from queue.`);
message.channel.send(`${user.username} removed from queue.`);
logger.log('info', `${message.author.username} removed ${user.username} from queue.`);
checkQueue(message);
}
else if (!(playerQueue.includes(user))) {
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.`);
checkQueue(message);
}
else if (!(playerQueue.includes(user))) {
message.channel.send(`${user.username} is not in the queue.`);
logger.info( `${message.author.username} attempted to remove ${user.username} from queue but they weren't in it.`);
}
} catch (error) {
logger.error(`Tried to remove user ${args[0]} from queue but got an error: ${error}`);
message.channel.send(`Failed to remove ${args[0]} from the queue.`);
}
}
@@ -442,11 +447,11 @@ client.on('message', function (message) {
// 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.name)
logger.log('info', `${message.author.username} deleted their adventure channel.`);
logger.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.name} but it's not their adventure channel.`);
logger.info( `${message.author.username} attempted to delete channel ${message.channel.name} but it's not their adventure channel.`);
}
}