Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/nwplus/nwPlus_discord_bot
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
JPGarCar committed Feb 26, 2021
2 parents 7a4b978 + 6bfc174 commit 5202e6c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions classes/activity-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class ActivityManager {
const member = activity.generalText.guild.member(user);

if (!seenUsers.has(user.id)) {
if (role != undefined) this.parseRole(member, activity.name, botGuild);
this.parseRole(member, activity.name, botGuild);
seenUsers.set(user.id, user.username);
}
});
Expand Down Expand Up @@ -168,14 +168,14 @@ class ActivityManager {
discordServices.addRoleToMember(member, botGuild.stamps.stamp0thRoleId);
discordServices.sendMessageToMember(member, 'I did not find an existing stamp role for you so I gave you one for attending '
+ activityName + '. Please contact an admin if there was a problem.', true);
winston.loggers.get(botGuild._id).userStats(`Activity named ${activityName} tried to give a stamp to the user with id ${user.id} but he has no stamp, I gave them the first stamp!`, {event: "Activity Manager"});
winston.loggers.get(botGuild._id).userStats(`Activity named ${activityName} tried to give a stamp to the user with id ${member.id} but he has no stamp, I gave them the first stamp!`, {event: "Activity Manager"});
return;
}

let stampNumber = botGuild.stamps.stampRoleIDs.get(role.id);
if (stampNumber === botGuild.stamps.stampRoleIDs.size - 1) {
discordServices.sendMessageToMember(member, 'You already have the maximum allowed number of stamps!', true);
winston.loggers.get(botGuild._id).userStats(`Activity named ${activityName} tried to give a stamp to the user with id ${user.id} but he is already in the max stamp ${stampNumber}`, {event: "Activity Manager"});
winston.loggers.get(botGuild._id).userStats(`Activity named ${activityName} tried to give a stamp to the user with id ${member.id} but he is already in the max stamp ${stampNumber}`, {event: "Activity Manager"});
return;
}
let newRoleID;
Expand Down
6 changes: 3 additions & 3 deletions classes/cave.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class Cave {
/**
* Constructor to create a cave.
* @param {CaveOptions} caveOptions - the cave options
* @param {BotGuildModel} botGuild
*/
constructor(caveOptions) {
constructor(caveOptions, botGuild) {

/**
* The cave options.
Expand Down Expand Up @@ -128,7 +129,7 @@ class Cave {
/**
* @type {BotGuildModel}
*/
this.botGuild;
this.botGuild = botGuild;

winston.loggers.get(this.botGuild._id).event(`A cave named ${caveOptions.name} was created.`, {data: {caveOptions: caveOptions}, event: "Cave"});
}
Expand All @@ -140,7 +141,6 @@ class Cave {
* @async
*/
async init(guildChannelManager) {
this.botGuild = await BotGuild.findById(guildChannelManager.guild.id);
await this.initPrivate(guildChannelManager);
await this.initPublic(guildChannelManager);
winston.loggers.get(this.botGuild._id).event(`The cave named ${this.caveOptions.name} has been initialized!`, {event: "Cave"});
Expand Down
8 changes: 4 additions & 4 deletions classes/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Prompt {
*/
static async messagePrompt({prompt, channel, userId}, responseType, time = 0) {

winston.loggers.get(channel.guild.id).event(`The message prompt has been used in channel ${channel.name} for user ${userId}`, {event: "Prompt"});
winston.loggers.get(channel?.guild?.id || 'main').event(`The message prompt has been used in channel ${channel.name} for user ${userId}`, {event: "Prompt"});

let finalPrompt = '<@' + userId + '> ' + prompt + (responseType == 'number' ? ' Respond with a number only!' : responseType == 'boolean' ? ' (yes/no)' : responseType == 'mention' ? ' To make a mention use the @ or # for a user or channel respectively!' : '' +
(time === 0 ? '' : '\n* Respond within ' + time + ' seconds.') + '\n* Respond with cancel to cancel.');
Expand All @@ -39,7 +39,7 @@ class Prompt {
} catch (error) {
channel.send('<@' + userId + '> Time is up, please try again once you are ready, we recommend you write the text, then react, then send!').then(msg => msg.delete({timeout: 10000}));
discordServices.deleteMessage(promptMsg);
winston.loggers.get(channel.guild.id).verbose(`Prompt in ${channel.name} with id ${channel.id} for user ${userId} timed out!`, {event: "Prompt"});
winston.loggers.get(channel?.guild?.id || 'main').verbose(`Prompt in ${channel.name} with id ${channel.id} for user ${userId} timed out!`, {event: "Prompt"});
let timeoutError = new Error('Prompt timed out.');
timeoutError.name = 'Timeout'
throw timeoutError;
Expand All @@ -52,13 +52,13 @@ class Prompt {

// check if they responded with cancel
if (msg.content.toLowerCase() === 'cancel') {
winston.loggers.get(channel.guild.id).verbose(`Prompt in ${channel.name} with id ${channel.id} for user ${userId} was canceled!`, {event: "Prompt"});
winston.loggers.get(channel?.guild?.id || 'main').verbose(`Prompt in ${channel.name} with id ${channel.id} for user ${userId} was canceled!`, {event: "Prompt"});
let cancelError = new Error("The prompt has been canceled.");
cancelError.name = 'Cancel'
throw cancelError;
}

winston.loggers.get(channel.guild.id).verbose(`A prompt has been sent to ${channel.name} with id ${channel.id} for user ${userId} of type ${responseType}. Message: ${prompt}. The response was ${msg.cleanContent}.`, {event: "Prompt"});
winston.loggers.get(channel?.guild?.id || 'main').verbose(`A prompt has been sent to ${channel.name} with id ${channel.id} for user ${userId} of type ${responseType}. Message: ${prompt}. The response was ${msg.cleanContent}.`, {event: "Prompt"});

return msg;
}
Expand Down
7 changes: 4 additions & 3 deletions commands/a_activity/init-workshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ module.exports = class InitWorkshop extends ActivityCommand {
*/
async activityCommand(botGuild, message, activity) {
// prompt user for roles that will have access to the TA side of the workshop
let TARoles;
let TARoles = new Discord.Collection();
try {
if (await Prompt.yesNoPrompt({prompt: 'Aside from Staff, are there other roles you would like to allow access to the TA channels?',
channel: message.channel, userId: message.author.id})) {
TARoles = await Prompt.rolePrompt({prompt: 'Mention the role(s) here now!', channel: message.channel, userId: message.author.id});
};
} catch (error) {
TARoles = new Discord.Collection();
// do nothing
}
TARoles.each(role => {

TARoles.forEach(role => {
activity.generalText.updateOverwrite(role, {VIEW_CHANNEL: true});
activity.generalVoice.updateOverwrite(role, {VIEW_CHANNEL: true, SPEAK: true, MOVE_MEMBERS: true});
activity.category.updateOverwrite(role, {VIEW_CHANNEL: true});
Expand Down
7 changes: 5 additions & 2 deletions commands/a_start_commands/start-mentor-cave.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const discordServices = require('../../discord-services');
const Discord = require('discord.js');
const Cave = require('../../classes/cave');
const Prompt = require('../../classes/prompt');
const winston = require('winston');
const BotGuildModel = require('../../classes/bot-guild');

// Command export
module.exports = class StartMentors extends PermissionCommand {
Expand Down Expand Up @@ -90,7 +92,7 @@ module.exports = class StartMentors extends PermissionCommand {
reminderTime: (await Prompt.numberPrompt({prompt: 'How long, in minutes, shall a ticket go unaccepted before the bot sends a reminder to all mentors?',
channel, userId}))[0],
}
});
}, botGuild);


let adminConsole = message.guild.channels.resolve(botGuild.channelIDs.adminConsole);
Expand All @@ -110,7 +112,8 @@ module.exports = class StartMentors extends PermissionCommand {
cave.checkForExistingRoles(message.guild.roles, adminConsole, userId);

} catch (error) {
channel.send('Due to a prompt cancel, the mentor cave creation was unsuccessful.').then(msg => msg.delete({timeout: 5000}));
message.channel.send('Due to a prompt cancel, the mentor cave creation was unsuccessful.').then(msg => msg.delete({timeout: 5000}));
winston.loggers.get(message.guild.id).warning(`An error was found but it was handled by not setting up the mentor cave. Error: ${error}`, { event: "StartMentorCave Command" });
}
}

Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bot.on('error', (error) => {
* Runs when the bot runs into an error when running a command.
*/
bot.on('commandError', (command, error, message) => {
winston.loggers.get(message.guild.id).error(`Command Error: In command ${command.name} got uncaught rejection ${error.name} : ${error.message}`);
winston.loggers.get(channel?.guild?.id || 'main').error(`Command Error: In command ${command.name} got uncaught rejection ${error.name} : ${error.message}`);
mainLogger.error(`Command Error: In command ${command.name} got uncaught rejection ${error.name} : ${error.message}`, { event: "Error", data: error});
});

Expand Down Expand Up @@ -210,7 +210,7 @@ bot.on('commandRun', (command, promise, message, args) => {
/**
* Runs when an unknown command is triggered.
*/
bot.on('unknownCommand', (message) => winston.loggers.get(message.guild.id).command(`An unknown command has been triggered in the channel ${message.channel.name} with id ${message.channel.id}. The message had the content ${message.cleanContent}.`));
bot.on('unknownCommand', (message) => winston.loggers.get(message?.guild?.id || 'main').command(`An unknown command has been triggered in the channel ${message.channel.name} with id ${message.channel.id}. The message had the content ${message.cleanContent}.`));

/**
* Logs in the bot
Expand Down Expand Up @@ -339,7 +339,7 @@ async function greetNewMember(member, botGuild) {
}

try {
Verification.verify(member, email, member.guild, botGuild);
await Verification.verify(member, email, member.guild, botGuild);
} catch (error) {
discordServices.sendEmbedToMember(member, {
title: 'Verification Error',
Expand Down

0 comments on commit 5202e6c

Please sign in to comment.