mirror of
https://github.com/jcreek/denBot.git
synced 2026-07-13 19:03:45 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e752d3ce80 | |||
| 400b34b9e4 | |||
| 7bf9ae00ee | |||
| 4429e02b22 | |||
| 49cd612f51 | |||
| f6af7b4327 | |||
| 01768c5567 | |||
| 9700808773 | |||
| 857ee29e10 |
@@ -12,6 +12,7 @@ Commands:
|
||||
* 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
|
||||
* start - Vote to start the adventure early, without the full number of players (all players in the queue must use this to start early)
|
||||
* 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)
|
||||
@@ -50,7 +51,3 @@ 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`
|
||||
|
||||
## 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)
|
||||
|
||||
@@ -78,6 +78,7 @@ const logger = winston.createLogger({
|
||||
//}
|
||||
|
||||
let playerQueue = [];
|
||||
let playerVotes = [];
|
||||
let pokemonName = '';
|
||||
let captainInGameName = '';
|
||||
|
||||
@@ -110,7 +111,7 @@ function generateRandomCode() {
|
||||
}
|
||||
|
||||
function checkQueue(message) {
|
||||
if (playerQueue.length === config.maxqueuesize) {
|
||||
if (playerQueue.length === config.maxqueuesize || (playerQueue.length > 0 && playerQueue.length == playerVotes.length)) {
|
||||
// Queue is full
|
||||
logger.log('info', 'Queue is full');
|
||||
|
||||
@@ -135,9 +136,11 @@ function checkQueue(message) {
|
||||
|
||||
makeTempChannel(message, adventureMessage);
|
||||
|
||||
// Clear the queue
|
||||
// Clear the queue and votes
|
||||
playerQueue = [];
|
||||
logger.log('info', 'Emptied queue');
|
||||
playerVotes = [];
|
||||
logger.log('info', 'Emptied votes');
|
||||
}
|
||||
else if (playerQueue.length === 0) {
|
||||
message.channel.send('The queue is empty :(');
|
||||
@@ -174,7 +177,7 @@ function getUserFromMention(mention) {
|
||||
}
|
||||
|
||||
function getChannelName(username) {
|
||||
return `${username}s-adventurers`;
|
||||
return `${username.toLowerCase().replace(' ', '-')}s-adventurers`;
|
||||
}
|
||||
|
||||
function makeTempChannel(message, adventureMessage) {
|
||||
@@ -285,15 +288,22 @@ client.on('message', function (message) {
|
||||
|
||||
logger.info(`${message.author.username} used command lq in ${message.channel.name}`);
|
||||
|
||||
logger.log('info', `${message.author.username} left the queue.`);
|
||||
message.channel.send(`${message.author.username} left the queue.`);
|
||||
|
||||
for( var i = 0; i < playerQueue.length; i++){
|
||||
if ( playerQueue[i] === message.author) {
|
||||
playerQueue.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( var i = 0; i < playerVotes.length; i++){
|
||||
if ( playerVotes[i] === message.author) {
|
||||
playerVotes.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
logger.log('info', `${message.author.username} left the queue.`);
|
||||
message.channel.send(`${message.author.username} left the queue.`);
|
||||
|
||||
checkQueue(message);
|
||||
}
|
||||
@@ -308,6 +318,45 @@ client.on('message', function (message) {
|
||||
message.channel.send(`${message.author.username} you can't leave the queue before you've joined it!`);
|
||||
}
|
||||
|
||||
// Vote to start early with only the users currently in the queue
|
||||
if(command === 'start') {
|
||||
// Delete the message with the bot command
|
||||
if (config.deletecommandstoggle) {
|
||||
message.delete();
|
||||
}
|
||||
|
||||
logger.info(`${message.author.username} used command ${command} in ${message.channel.name}`);
|
||||
|
||||
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.`);
|
||||
}
|
||||
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.`);
|
||||
}
|
||||
else if (playerVotes.length < config.maxqueuesize) {
|
||||
// Not the first player to vote
|
||||
playerVotes.push(message.author);
|
||||
|
||||
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.`);
|
||||
}
|
||||
else {
|
||||
// All players have voted, we can start the adventure early
|
||||
checkQueue(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show the queue
|
||||
if(command === 'sq') {
|
||||
// Delete the message with the bot command
|
||||
@@ -333,10 +382,11 @@ client.on('message', function (message) {
|
||||
message.channel.send(`The queue is already empty...`);
|
||||
logger.log('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.log('info', `${message.author.username} cleared the queue and the votes.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +411,13 @@ client.on('message', function (message) {
|
||||
}
|
||||
}
|
||||
|
||||
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.log('info', `${message.author.username} removed ${user.username} from queue.`);
|
||||
|
||||
@@ -389,11 +446,12 @@ client.on('message', function (message) {
|
||||
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)
|
||||
- ${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);
|
||||
@@ -402,13 +460,14 @@ The commands available to you are:
|
||||
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)
|
||||
- ${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