From 0c04ae9013511c15f543dc16a8cfc9f40c2d692b Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 19 May 2020 14:01:26 -0400 Subject: [PATCH] Voicemail System --- README.md | 1 + commands/util/options.js | 1 + package.json | 2 +- structures/phone/PhoneCall.js | 35 ++++++++++++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ed365160..9b9c8be8 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ in the appropriate channel's topic to use it. * `` Disables leave messages (Place in the channel you recieve welcome messages in). * `` Allows a channel to recieve phone calls from the `phone` command. +* `` Prevents this channel from recieving voicemails for missed calls. * `` Hides a channel from the `phone-book` command. * `` Allows a channel to recieve portal messages from the `portal-send` command. diff --git a/commands/util/options.js b/commands/util/options.js index 8b092b6e..d22b2d07 100644 --- a/commands/util/options.js +++ b/commands/util/options.js @@ -20,6 +20,7 @@ module.exports = class OptionsCommand extends Command { \`\` Disables leave messages (System Channel). \`\` Allows this channel to recieve phone calls. + \`\` Prevents this channel from recieving voicemails for missed calls. \`\` Hides this channel from \`phone-book\`. \`\` Marks the channel as a portal channel for \`portal-send\`. `); diff --git a/package.json b/package.json index 97a7886d..46cddfee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "114.16.2", + "version": "114.16.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/phone/PhoneCall.js b/structures/phone/PhoneCall.js index db905274..18645d46 100644 --- a/structures/phone/PhoneCall.js +++ b/structures/phone/PhoneCall.js @@ -47,10 +47,31 @@ module.exports = class PhoneCall { await this.origin.send('☎️ Call ended due to inactivity.'); await this.recipient.send('☎️ Call ended due to inactivity.'); } else if (nonQuitter === 'declined') { - const originMsg = validation === 0 ? 'didn\'t answer...' : 'declined the call...'; - const recipientMsg = validation === 0 ? 'Sent to voicemail (not really).' : 'Declined the call.'; - await this.origin.send(`☎️ **${this.recipient.guild.name}** ${originMsg}`); + const recipientMsg = validation === 0 ? 'Sent to voicemail.' : 'Declined the call.'; await this.recipient.send(`☎️ ${recipientMsg}`); + if (validation === 0 && channel.topic && !channel.topic.includes('')) { + await this.origin.send(`☎️ **${this.recipient.guild.name}** didn't answer... Leave a voicemail?`); + const voicemailValidation = await verify(this.origin, null); + if (!voicemailValidation) { + await this.origin.send('☎️ No voicemail will be left.'); + } else { + await this.origin.send('☎️ Please leave your message (max 280 characters) after the beep. _Beep_.'); + const voicemail = await this.origin.awaitMessages(res => res.content && res.content.length >= 280, { + time: 30000, + max: 1 + }); + if (!voicemail.size) { + await this.origin.send('☎️ No voicemail will be left.'); + } else { + const voicemailMsg = voicemail.first(); + await this.sendVoicemail(this.recipient, voicemailMsg.author, voicemailMsg.content); + await this.origin.send('☎️ Your voicemail has been left.'); + } + } + } else { + let originMsg = validation === 0 ? 'didn\'t answer...' : 'declined the call...'; + await this.origin.send(`☎️ **${this.recipient.guild.name}** ${originMsg}`); + } } else { const quitter = nonQuitter.id === this.origin.id ? this.recipient : this.origin; await nonQuitter.send(`☎️ **${quitter.guild.name}** hung up.`); @@ -83,6 +104,14 @@ module.exports = class PhoneCall { return channel.send(`☎️ **${msg.author.tag}:** ${content}\n${attachments || ''}`.trim()); } + sendVoicemail(channel, author, message) { + if (!channel.topic || channel.topic.includes('')) return null; + return channel.send(stripInvites` + ☎️ New Voicemail from **${channel.guild.name}**: + **${author.tag}:** ${message} + `); + } + setTimeout() { if (this.timeout) clearTimeout(this.timeout); this.timeout = setTimeout(() => this.hangup('time'), 60000);