add option to turn off email notifications

pull/29/head
Matthew 2020-08-23 23:25:37 -04:00
parent ca14936a8d
commit 83fe9d658d
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 24 additions and 2 deletions

View File

@ -11,7 +11,7 @@ export default class Page extends Command {
super(client); super(client);
this.name = 'page'; this.name = 'page';
this.description = 'Pages the specified emergency number, department number, or individual number with the specified pager code.'; this.description = 'Pages the specified emergency number, department number, or individual number with the specified pager code.';
this.usage = 'page <pager number> <pager code> [optional message]'; this.usage = `${this.client.config.prefix}page <pager number> <pager code> [optional message]\n${this.client.config.prefix}page settings <type: email> <options: [email: on/off]>`;
this.aliases = ['p']; this.aliases = ['p'];
this.permissions = 1; this.permissions = 1;
this.enabled = true; this.enabled = true;
@ -49,10 +49,31 @@ export default class Page extends Command {
embed.setTimestamp(); embed.setTimestamp();
return message.channel.createMessage({ embed }); return message.channel.createMessage({ embed });
} }
if (args[0] === 'settings') {
const pager = await this.client.db.PagerNumber.findOne({ individualAssignID: message.author.id });
if (!pager) return this.error(message.channel, 'You do not have a Pager Number.');
switch (args[1]) {
case 'email':
if (args[2] === 'off') {
if (pager.receiveEmail === false) return this.error(message.channel, 'You are already set to not receive email notifications.');
await pager.updateOne({ $set: { receiveEmail: false } });
return this.success(message.channel, 'You will no longer receive notifications by email for pages.');
}
if (args[2] === 'on') {
if (pager.receiveEmail === true) return this.error(message.channel, 'You are already set to receive email notifications.');
await pager.updateOne({ $set: { receiveEmail: true } });
return this.success(message.channel, 'You will now receive notifications by email for pages.');
}
break;
default:
this.error(message.channel, 'Invalid response provided.');
break;
}
}
message.delete(); message.delete();
const loading = await this.loading(message.channel, 'Paging...'); const loading = await this.loading(message.channel, 'Paging...');
const sender = await this.client.db.PagerNumber.findOne({ individualAssignID: message.author.id }); const sender = await this.client.db.PagerNumber.findOne({ individualAssignID: message.author.id });
if (!sender) return this.error(message.channel, 'You do not have a Pager Numer.'); if (!sender) return this.error(message.channel, 'You do not have a Pager Number.');
const page = await this.page(args[0], sender.num, args[1], message, args[2] ? args.slice(2).join(' ') : undefined); const page = await this.page(args[0], sender.num, args[1], message, args[2] ? args.slice(2).join(' ') : undefined);
if (page.status === true) { if (page.status === true) {
loading.delete(); loading.delete();
@ -134,6 +155,7 @@ export default class Page extends Command {
for (const email of recipientEntry.emailAddresses) { for (const email of recipientEntry.emailAddresses) {
const recipient = this.mainGuild.members.get(recipientEntry.individualAssignID); const recipient = this.mainGuild.members.get(recipientEntry.individualAssignID);
const sender = this.mainGuild.members.get(senderEntry.individualAssignID); const sender = this.mainGuild.members.get(senderEntry.individualAssignID);
if (recipientEntry.receiveEmail === false) continue;
if (!recipient || !sender) { if (!recipient || !sender) {
this.logPage({ number: senderNumber, user: 'N/A' }, { number: recipientNumber, user: 'N/A' }, 'email', code); this.logPage({ number: senderNumber, user: 'N/A' }, { number: recipientNumber, user: 'N/A' }, 'email', code);
} else { } else {