mirror of
https://github.com/jcreek/denBot.git
synced 2026-07-13 02:43:46 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 421858938c | |||
| 10536a87f1 | |||
| 482af77249 | |||
| 67566a6fea | |||
| 628c063c15 | |||
| 6cef805649 | |||
| 4133eae25d | |||
| e752d3ce80 | |||
| 400b34b9e4 | |||
| 7bf9ae00ee |
@@ -35,12 +35,24 @@ For a sanity check, you can run `docker images` and it should be displayed in th
|
||||
|
||||
## Running the Docker container
|
||||
|
||||
Running the bot with -d runs the container in detatched mode (as in it runs in the background). If you want to see what is happening, remove that option.
|
||||
Running the bot with --detach runs the container in detatched mode (as in it runs in the background). If you want to see what is happening, remove that option.
|
||||
|
||||
`docker run -d denbot`
|
||||
`docker run --detach --name denbot denbot`
|
||||
|
||||
You can use CTRL+C to exit out of this command window. If you're using Windows, Docker Desktop will now show your bot under 'Containers/Apps', from where you can easily stop and start it using the GUI.
|
||||
|
||||
## Updating
|
||||
|
||||
If doing it manually, in the folder with all the files run:
|
||||
|
||||
```
|
||||
docker stop denbot
|
||||
docker rm denbot
|
||||
docker image rm denbot
|
||||
docker build -t denbot .
|
||||
docker run --detach --name denbot denbot
|
||||
```
|
||||
|
||||
### More information
|
||||
|
||||
If you want more of a sanity check here are some following commands you can run the following commands:
|
||||
@@ -51,3 +63,7 @@ If you want more of a sanity check here are some following commands you can run
|
||||
To access the command line inside the docker container you can run:
|
||||
|
||||
`docker exec -it <container id> /bin/bash`
|
||||
|
||||
## Future feature suggestions
|
||||
|
||||
* If the party want to continue with the same people and the same link code they can do !again (only in the private chat) to run again and get the party for 30 more mins (denBot would also post the link code again so people can see it without scrolling) - using something like https://stackoverflow.com/questions/36563749/how-i-extend-settimeout-on-nodejs and an array of all the queues, removing those and their deletion functions each time an adventure channel is deleted
|
||||
|
||||
+21
@@ -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!');
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -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,27 +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
|
||||
// Clear the queue and votes
|
||||
playerQueue = [];
|
||||
logger.log('info', 'Emptied queue');
|
||||
logger.info('Emptied queue');
|
||||
playerVotes = [];
|
||||
logger.info('Emptied votes');
|
||||
pokemonName = '';
|
||||
captainInGameName = '';
|
||||
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')}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,7 +181,7 @@ function getUserFromMention(mention) {
|
||||
}
|
||||
|
||||
function getChannelName(username) {
|
||||
return `${username.toLowerCase()}s-adventurers`;
|
||||
return `${username.toLowerCase().replace(' ', '-')}s-adventurers`;
|
||||
}
|
||||
|
||||
function makeTempChannel(message, adventureMessage) {
|
||||
@@ -205,15 +211,16 @@ function makeTempChannel(message, adventureMessage) {
|
||||
|
||||
// Post in the channel
|
||||
createdChannel.send(adventureMessage);
|
||||
createdChannel.send(`Please delete this channel when you're finished with it using the ${config.prefix}dc command`);
|
||||
})
|
||||
.catch(logger.error);
|
||||
|
||||
try {
|
||||
// Delete the channel after the configured amount of minutes
|
||||
setTimeout(function(){ deleteChannel(message, channelName); }, (config.channeldeletetimeinminutes * 1000 * 60) );
|
||||
} catch (error) {
|
||||
logger.error(`Tried to delete channel ${channelName} after timeout: `, error);
|
||||
}
|
||||
// try {
|
||||
// // Delete the channel after the configured amount of minutes
|
||||
// setTimeout(function(){ deleteChannel(message, channelName); }, (config.channeldeletetimeinminutes * 1000 * 60) );
|
||||
// } catch (error) {
|
||||
// logger.error(`Tried to delete channel ${channelName} after timeout: `, error);
|
||||
// }
|
||||
}
|
||||
|
||||
function deleteChannel(message, channelName) {
|
||||
@@ -253,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);
|
||||
|
||||
@@ -300,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);
|
||||
}
|
||||
@@ -328,14 +335,17 @@ client.on('message', function (message) {
|
||||
if(playerQueue.length == 0) {
|
||||
message.channel.send(`You can only vote to start an adventure early if there is a queue. You can start a queue by using the command ${config.prefix}help`);
|
||||
}
|
||||
else if (!playerQueue.includes(message.author)) {
|
||||
message.channel.send(`You can only vote to start an adventure early if you are in the queue. You can join the queue by using the command ${config.prefix}q`);
|
||||
}
|
||||
else if(playerVotes.length == 0) {
|
||||
// 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
|
||||
@@ -343,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
|
||||
@@ -375,12 +385,16 @@ 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 {
|
||||
else {
|
||||
playerQueue = [];
|
||||
playerVotes = [];
|
||||
message.channel.send(`The queue has been cleared!`);
|
||||
logger.log('info', `${message.author.username} cleared the queue.`);
|
||||
logger.info( `${message.author.username} cleared the queue and the votes.`);
|
||||
pokemonName = '';
|
||||
captainInGameName = '';
|
||||
logger.info('Emptied pokemon name and captain name');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,13 +427,13 @@ client.on('message', function (message) {
|
||||
}
|
||||
|
||||
message.channel.send(`${user.username} removed from queue.`);
|
||||
logger.log('info', `${message.author.username} removed ${user.username} from queue.`);
|
||||
logger.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.`);
|
||||
logger.info( `${message.author.username} attempted to remove ${user.username} from queue but they weren't in it.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,23 +443,23 @@ 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.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (command === 'help') {
|
||||
let msg = `
|
||||
The commands available to you are:
|
||||
- ${command}q - Join the queue
|
||||
- ${command}q <pokemon> <ign> - Join the queue (first player can set the pokemon and their in-game name)
|
||||
- ${command}lq - Leave the queue
|
||||
- ${command}sq - Show the queue
|
||||
- ${command}start - Vote to start the adventure early, without the full number of players (all players in the queue must use this to start early)
|
||||
- ${command}dc - Delete an adventure channel (only the captain can use this)
|
||||
- ${config.prefix}q - Join the queue
|
||||
- ${config.prefix}q <pokemon> <ign> - Join the queue (first player can set the pokemon and their in-game name)
|
||||
- ${config.prefix}lq - Leave the queue
|
||||
- ${config.prefix}sq - Show the queue
|
||||
- ${config.prefix}start - Vote to start the adventure early, without the full number of players (all players in the queue must use this to start early)
|
||||
- ${config.prefix}dc - Delete an adventure channel (only the captain can use this)
|
||||
`;
|
||||
|
||||
message.channel.send(msg);
|
||||
@@ -454,14 +468,14 @@ The commands available to you are:
|
||||
if (command === 'adminhelp') {
|
||||
let msg = `
|
||||
The commands available to you are:
|
||||
- ${command}q - Join the queue
|
||||
- ${command}q <pokemon> <ign> - Join the queue (first player can set the pokemon and their in-game name)
|
||||
- ${command}lq - Leave the queue
|
||||
- ${command}sq - Show the queue
|
||||
- ${command}start - Vote to start the adventure early, without the full number of players (all players in the queue must use this to start early)
|
||||
- ${command}cq - Clear the queue (admin-only, not to be shared with normal users)
|
||||
- ${command}ru - Remove a tagged user from the queue (admin-only, not to be shared with normal users)
|
||||
- ${command}dc - Delete an adventure channel (only the captain can use this)
|
||||
- ${config.prefix}q - Join the queue
|
||||
- ${config.prefix}q <pokemon> <ign> - Join the queue (first player can set the pokemon and their in-game name)
|
||||
- ${config.prefix}lq - Leave the queue
|
||||
- ${config.prefix}sq - Show the queue
|
||||
- ${config.prefix}start - Vote to start the adventure early, without the full number of players (all players in the queue must use this to start early)
|
||||
- ${config.prefix}cq - Clear the queue (admin-only, not to be shared with normal users)
|
||||
- ${config.prefix}ru - Remove a tagged user from the queue (admin-only, not to be shared with normal users)
|
||||
- ${config.prefix}dc - Delete an adventure channel (only the captain can use this)
|
||||
`;
|
||||
|
||||
message.channel.send(msg);
|
||||
|
||||
Reference in New Issue
Block a user