mirror of
https://github.com/jcreek/denBot.git
synced 2026-07-13 19:03:45 +00:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fa1fada289 | |||
| eea9841481 | |||
| 5f875bc91d | |||
| dadc08d94c | |||
| 73906e1957 | |||
| 84a8f2c22c | |||
| c6333e7d06 | |||
| 36366499ed | |||
| 95e9003ce7 | |||
| 02dc03e5ef | |||
| d901ee4672 | |||
| 6865d021a3 | |||
| c8dbcd9120 | |||
| df6211d5e4 | |||
| 17a8f98ca3 | |||
| 8d7df9d4ec | |||
| 2e5c468c8f | |||
| 3d51cc1551 | |||
| be885bc286 | |||
| f127e09858 | |||
| 3191be31e1 | |||
| c48edec643 | |||
| c642d95335 | |||
| e08495bfc2 | |||
| 087fecf93a | |||
| c3fcc15f06 | |||
| 939a99b62d | |||
| 3aa3f7ac52 | |||
| 9459e2714c | |||
| 6a3cec4a0e | |||
| be7ba9e28d | |||
| c48c5f32a9 |
+3
-3
@@ -3,10 +3,10 @@
|
|||||||
"deletecommandstoggle": false,
|
"deletecommandstoggle": false,
|
||||||
"maxqueuesize": 4,
|
"maxqueuesize": 4,
|
||||||
"elasticsearch" : {
|
"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"
|
"elasticsearch_index_pattern" : "[logs-denbot-]YYYY.MM.DD"
|
||||||
},
|
},
|
||||||
"prefix": "!",
|
"prefix": "!",
|
||||||
"token-dev": "Nzc4MDI2MTE1NDkwOTA2MTYz.X7L_SA.bNzC1kQUpBSwEsjp_cDGwR62Soo",
|
"token-dev": "YOUR-DEV-TOKEN-GOES-HERE",
|
||||||
"token": "NzcwMDQyMDEzMjY5NDkxNzUy.X5Xzgg.kcr_51g95iUvEcYCfbQvG1Sx8ao"
|
"token": "YOUR-TOKEN-GOES-HERE"
|
||||||
}
|
}
|
||||||
|
|||||||
+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 winston = require('winston');
|
||||||
const Elasticsearch = require('winston-elasticsearch');
|
const Elasticsearch = require('winston-elasticsearch');
|
||||||
const config = require('./config.json');
|
const config = require('./config.json');
|
||||||
|
const {sendEmbedMessage} = require('./helpers.js');
|
||||||
const client = new Discord.Client();
|
const client = new Discord.Client();
|
||||||
|
|
||||||
const { format } = winston;
|
const { format } = winston;
|
||||||
@@ -113,10 +114,10 @@ function generateRandomCode() {
|
|||||||
function checkQueue(message) {
|
function checkQueue(message) {
|
||||||
if (playerQueue.length === config.maxqueuesize || (playerQueue.length > 0 && playerQueue.length == playerVotes.length)) {
|
if (playerQueue.length === config.maxqueuesize || (playerQueue.length > 0 && playerQueue.length == playerVotes.length)) {
|
||||||
// Queue is full
|
// Queue is full
|
||||||
logger.log('info', 'Queue is full');
|
logger.info('Queue is full');
|
||||||
|
|
||||||
// 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')}`);
|
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 randomCode = generateRandomCode();
|
||||||
const baseMessage = `@${playerQueue[0].username} is making the lobby. Here is your link code ${randomCode}`;
|
const baseMessage = `@${playerQueue[0].username} is making the lobby. Here is your link code ${randomCode}`;
|
||||||
@@ -131,32 +132,32 @@ function checkQueue(message) {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Tried to DM users: ', 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);
|
makeTempChannel(message, adventureMessage);
|
||||||
|
|
||||||
// Clear the queue and votes
|
// Clear the queue and votes
|
||||||
playerQueue = [];
|
playerQueue = [];
|
||||||
logger.log('info', 'Emptied queue');
|
logger.info('Emptied queue');
|
||||||
playerVotes = [];
|
playerVotes = [];
|
||||||
logger.log('info', 'Emptied votes');
|
logger.info('Emptied votes');
|
||||||
pokemonName = '';
|
pokemonName = '';
|
||||||
captainInGameName = '';
|
captainInGameName = '';
|
||||||
logger.log('info', 'Emptied pokemon name and captain name');
|
logger.info('Emptied pokemon name and captain name');
|
||||||
}
|
}
|
||||||
else if (playerQueue.length === 0) {
|
else if (playerQueue.length === 0) {
|
||||||
message.channel.send('The queue is empty :(');
|
sendEmbedMessage(logger, message, Discord, 'Queue empty', 'The queue is empty :(');
|
||||||
pokemonName = '';
|
pokemonName = '';
|
||||||
captainInGameName = '';
|
captainInGameName = '';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Show queue after adding
|
// Show queue after adding
|
||||||
if (pokemonName === '' && captainInGameName === '') {
|
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 {
|
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.info(`${message.author.username} used command q in ${message.channel.name}`);
|
||||||
|
|
||||||
logger.log('info', `${message.author.username} joined the queue.`);
|
logger.info(`${message.author.username} joined the queue.`);
|
||||||
message.channel.send(`=====\n${message.author.username} joined the queue.`);
|
sendEmbedMessage(logger, message, Discord, 'Queue in progress', `${message.author.username} joined the queue.`);
|
||||||
|
|
||||||
playerQueue.push(message.author);
|
playerQueue.push(message.author);
|
||||||
|
|
||||||
@@ -306,8 +307,8 @@ client.on('message', function (message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log('info', `${message.author.username} left the queue.`);
|
logger.info(`${message.author.username} left the queue.`);
|
||||||
message.channel.send(`${message.author.username} left the queue.`);
|
sendEmbedMessage(logger, message, Discord, 'Queue in progress', `${message.author.username} left the queue.`);
|
||||||
|
|
||||||
checkQueue(message);
|
checkQueue(message);
|
||||||
}
|
}
|
||||||
@@ -341,10 +342,10 @@ client.on('message', function (message) {
|
|||||||
// First player to vote
|
// First player to vote
|
||||||
playerVotes.push(message.author);
|
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)) {
|
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) {
|
else if (playerVotes.length < config.maxqueuesize) {
|
||||||
// Not the first player to vote
|
// Not the first player to vote
|
||||||
@@ -352,7 +353,7 @@ client.on('message', function (message) {
|
|||||||
|
|
||||||
if (playerVotes.length < playerQueue.length) {
|
if (playerVotes.length < playerQueue.length) {
|
||||||
// Still not all players voted
|
// 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 {
|
else {
|
||||||
// All players have voted, we can start the adventure early
|
// All players have voted, we can start the adventure early
|
||||||
@@ -384,52 +385,59 @@ client.on('message', function (message) {
|
|||||||
|
|
||||||
if (playerQueue.length === 0) {
|
if (playerQueue.length === 0) {
|
||||||
message.channel.send(`The queue is already empty...`);
|
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 = [];
|
playerQueue = [];
|
||||||
playerVotes = [];
|
playerVotes = [];
|
||||||
message.channel.send(`The queue has been cleared!`);
|
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.info('Emptied pokemon name and captain name');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a tagged user from the queue
|
// Remove a tagged user from the queue
|
||||||
if (command === 'ru' && args[0]) {
|
if (command === 'ru' && args[0]) {
|
||||||
const user = getUserFromMention(args[0]);
|
|
||||||
|
|
||||||
// Delete the message with the bot command
|
// Delete the message with the bot command
|
||||||
if (config.deletecommandstoggle) {
|
if (config.deletecommandstoggle) {
|
||||||
message.delete();
|
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
|
if ((playerQueue.includes(user))) {
|
||||||
for(var i = 0; i < playerQueue.length; i++){
|
// Search for the user
|
||||||
if ((playerQueue[i].username === user.username)){
|
for(var i = 0; i < playerQueue.length; i++){
|
||||||
playerQueue.splice(i, 1);
|
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--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( var i = 0; i < playerVotes.length; i++){
|
message.channel.send(`${user.username} removed from queue.`);
|
||||||
if ( playerVotes[i].username === user.username) {
|
logger.info( `${message.author.username} removed ${user.username} from queue.`);
|
||||||
playerVotes.splice(i, 1);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
message.channel.send(`${user.username} removed from queue.`);
|
checkQueue(message);
|
||||||
logger.log('info', `${message.author.username} removed ${user.username} from queue.`);
|
}
|
||||||
|
else if (!(playerQueue.includes(user))) {
|
||||||
checkQueue(message);
|
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.`);
|
||||||
else if (!(playerQueue.includes(user))) {
|
}
|
||||||
message.channel.send(`${user.username} is not in the queue.`);
|
} catch (error) {
|
||||||
logger.log('info', `${message.author.username} attempted to remove ${user.username} from queue but they weren't in it.`);
|
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.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,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
|
// 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, message.channel.name)
|
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 {
|
else {
|
||||||
message.channel.send(`${message.author.username} is not allowed to delete this channel.`);
|
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.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user