From b8e3fc819a1e252448568f33165c3711e6530342 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 1 Dec 2020 20:09:24 -0500 Subject: [PATCH] DM Phone Calls --- Xiao.js | 2 +- commands/phone/admin-phone.js | 1 - commands/phone/phone-book.js | 1 - commands/phone/phone-info.js | 9 +++++---- commands/phone/phone.js | 5 ++--- package.json | 2 +- structures/phone/PhoneCall.js | 27 ++++++++++++++++++++++----- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Xiao.js b/Xiao.js index 4d545ed5..287e5d80 100644 --- a/Xiao.js +++ b/Xiao.js @@ -110,7 +110,7 @@ client.on('message', async msg => { const recipient = client.phone.find(call => call.recipient.id === msg.channel.id); if (!origin && !recipient) return; const call = origin || recipient; - if (!call.adminCall && (!msg.channel.topic || !msg.channel.topic.includes(''))) return; + if (!call.adminCall && (msg.guild && (!msg.channel.topic || !msg.channel.topic.includes('')))) return; if (!call.active) return; if (call.adminCall && msg.guild.id === call.origin.guild.id && !client.isOwner(msg.author)) return; try { diff --git a/commands/phone/admin-phone.js b/commands/phone/admin-phone.js index 2fedf62a..e18a31c3 100644 --- a/commands/phone/admin-phone.js +++ b/commands/phone/admin-phone.js @@ -9,7 +9,6 @@ module.exports = class AdminPhoneCommand extends Command { group: 'phone', memberName: 'admin-phone', description: 'Starts an admin phone call with a server.', - guildOnly: true, ownerOnly: true, args: [ { diff --git a/commands/phone/phone-book.js b/commands/phone/phone-book.js index 6e49807f..84aca566 100644 --- a/commands/phone/phone-book.js +++ b/commands/phone/phone-book.js @@ -8,7 +8,6 @@ module.exports = class PhoneBookCommand extends Command { group: 'phone', memberName: 'phone-book', description: 'Looks up phone-enabled servers.', - guildOnly: true, args: [ { key: 'query', diff --git a/commands/phone/phone-info.js b/commands/phone/phone-info.js index a3c5a341..8c12dfe9 100644 --- a/commands/phone/phone-info.js +++ b/commands/phone/phone-info.js @@ -8,8 +8,7 @@ module.exports = class PhoneInfoCommand extends Command { aliases: ['call-info', 'phone-call-info'], group: 'phone', memberName: 'phone-info', - description: 'Gives information on the current phone call.', - guildOnly: true + description: 'Gives information on the current phone call.' }); } @@ -20,11 +19,13 @@ module.exports = class PhoneInfoCommand extends Command { const call = origin || recipient; if (!call.active) return msg.reply('☎️ This call is not currently active.'); const otherChannel = msg.channel.id === call.origin.id ? call.recipient : call.origin; + const otherChannelDM = msg.channel.id === call.origin.id ? false : Boolean(call.origin.guild); const embed = new MessageEmbed() .setColor(0x00AE86) .setThumbnail(otherChannel.guild.iconURL({ format: 'png' })) - .addField('❯ Recipient Channel', `#${otherChannel.name}`, true) - .addField('❯ Recipient Server', otherChannel.guild.name, true) + .addField('❯ Recipient Channel', + otherChannelDM ? `@${call.origin.startUser.tag}` : `#${otherChannel.name}`, true) + .addField('❯ Recipient Server', otherChannelDM ? 'DM' : otherChannel.guild.name, true) .addField('❯ Recipient ID', otherChannel.id, true) .addField('❯ Call Duration', call.durationDisplay, true) .addField('❯ Admin Call?', call.adminCall ? 'Yes' : 'No', true) diff --git a/commands/phone/phone.js b/commands/phone/phone.js index f61166f6..36851fd0 100644 --- a/commands/phone/phone.js +++ b/commands/phone/phone.js @@ -9,7 +9,6 @@ module.exports = class PhoneCommand extends Command { group: 'phone', memberName: 'phone', description: 'Starts a phone call with a random server.', - guildOnly: true, throttling: { usages: 1, duration: 45 @@ -38,7 +37,7 @@ module.exports = class PhoneCommand extends Command { } async run(msg, { channelID }) { - if (channelID !== 'count' && (!msg.channel.topic || !msg.channel.topic.includes(''))) { + if (channelID !== 'count' && (msg.guild && (!msg.channel.topic || !msg.channel.topic.includes('')))) { return msg.say('You can only start a call in a channel with `` in the topic.'); } if (channelID !== 'count' && this.client.inPhoneCall(msg.channel)) { @@ -68,7 +67,7 @@ module.exports = class PhoneCommand extends Command { return msg.reply('That channel has blocked this channel from calling them.'); } if (channel.topic.includes(``)) { - return msg.replY('That channel has blocked this server from calling them.'); + return msg.reply('That channel has blocked this server from calling them.'); } } else { channel = channels.random(); diff --git a/package.json b/package.json index 52d435b8..b0ac8c52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "123.0.4", + "version": "123.0.5", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/phone/PhoneCall.js b/structures/phone/PhoneCall.js index 495d972e..36327e99 100644 --- a/structures/phone/PhoneCall.js +++ b/structures/phone/PhoneCall.js @@ -9,6 +9,7 @@ module.exports = class PhoneCall { this.id = `${origin.id}:${recipient.id}`; this.origin = origin; + this.originDM = !Boolean(origin.guild); this.recipient = recipient; this.startUser = startUser; this.active = false; @@ -22,10 +23,18 @@ module.exports = class PhoneCall { async start() { if (this.adminCall) { await this.origin.send(`☎️ Admin call started with **${this.recipient.guild.name}**.`); - await this.recipient.send(`☎️ An **ADMIN** call from **${this.origin.guild.name}** has begun.`); + if (this.originDM) { + await this.recipient.send(`☎️ An **ADMIN** call from **${this.startUser.tag}'s DMs** has begun.`); + } else { + await this.recipient.send(`☎️ An **ADMIN** call from **${this.origin.guild.name}** has begun.`); + } } else { await this.origin.send(`☎️ Calling **${this.recipient.guild.name} (${this.recipient.id})**...`); - await this.recipient.send(`☎️ Incoming call from **${this.origin.guild.name} (${this.origin.id})**. Pick up?`); + if (this.originDM) { + await this.recipient.send(`☎️ Incoming call from **${this.startUser.tag}'s DM (${this.origin.id})**. Pick up?`); + } else { + await this.recipient.send(`☎️ Incoming call from **${this.origin.guild.name} (${this.origin.id})**. Pick up?`); + } const validation = await verify(this.recipient, null); if (!validation) { await this.hangup('declined', validation); @@ -43,7 +52,11 @@ module.exports = class PhoneCall { if (this.adminCall) return this; const usage = this.client.registry.commands.get('hang-up').usage(); await this.origin.send(`☎️ **${this.recipient.guild.name}** picked up! Use ${usage} to hang up.`); - await this.recipient.send(`☎️ Accepted call from **${this.origin.guild.name}**. Use ${usage} to hang up.`); + if (this.originDM) { + await this.recipient.send(`☎️ Accepted call from **${this.startUser.tag}'s DM**. Use ${usage} to hang up.`); + } else { + await this.recipient.send(`☎️ Accepted call from **${this.origin.guild.name}**. Use ${usage} to hang up.`); + } return this; } @@ -84,7 +97,11 @@ module.exports = class PhoneCall { } } else { const quitter = nonQuitter.id === this.origin.id ? this.recipient : this.origin; - await nonQuitter.send(`☎️ **${quitter.guild.name}** hung up. _(Lasted ${this.durationDisplay})_`); + if (quitter.guild) { + await nonQuitter.send(`☎️ **${quitter.guild.name}** hung up. _(Lasted ${this.durationDisplay})_`); + } else { + await nonQuitter.send(`☎️ **${this.startUser.tag}** hung up. _(Lasted ${this.durationDisplay})_`); + } await quitter.send(`☎️ Hung up. _(Lasted ${this.durationDisplay})_`); } this.client.phone.delete(this.id); @@ -121,7 +138,7 @@ module.exports = class PhoneCall { sendVoicemail(channel, msg) { return channel.send(stripIndents` - ☎️ New Voicemail from **${msg.guild.name}:** + ☎️ New Voicemail from **${this.originDM ? `${this.startUser.tag}'s DMs` : this.origin.guild.name}:** **${msg.author.tag}:** ${stripInvites(msg.content)} `); }