From 83fe9d658d2f5fdbd61f8889ddf69d44efbc44c9 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 23 Aug 2020 23:25:37 -0400 Subject: [PATCH] add option to turn off email notifications --- src/commands/page.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/commands/page.ts b/src/commands/page.ts index 4af6d41..7033147 100644 --- a/src/commands/page.ts +++ b/src/commands/page.ts @@ -11,7 +11,7 @@ export default class Page extends Command { super(client); this.name = 'page'; this.description = 'Pages the specified emergency number, department number, or individual number with the specified pager code.'; - this.usage = 'page [optional message]'; + this.usage = `${this.client.config.prefix}page [optional message]\n${this.client.config.prefix}page settings `; this.aliases = ['p']; this.permissions = 1; this.enabled = true; @@ -49,10 +49,31 @@ export default class Page extends Command { embed.setTimestamp(); 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(); const loading = await this.loading(message.channel, 'Paging...'); 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); if (page.status === true) { loading.delete(); @@ -134,6 +155,7 @@ export default class Page extends Command { for (const email of recipientEntry.emailAddresses) { const recipient = this.mainGuild.members.get(recipientEntry.individualAssignID); const sender = this.mainGuild.members.get(senderEntry.individualAssignID); + if (recipientEntry.receiveEmail === false) continue; if (!recipient || !sender) { this.logPage({ number: senderNumber, user: 'N/A' }, { number: recipientNumber, user: 'N/A' }, 'email', code); } else {