From cd3ca222c8a572e5614a3f82dad14bad897f4589 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 16 May 2020 10:25:34 -0400 Subject: [PATCH] Add hang up as a command --- README.md | 3 ++- commands/phone/hang-up.js | 27 +++++++++++++++++++++++++++ package.json | 2 +- structures/phone/PhoneCall.js | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 commands/phone/hang-up.js diff --git a/README.md b/README.md index 731882c1..c87b5a12 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 417 +Total: 419 ### Utility: @@ -582,6 +582,7 @@ Total: 417 ### Phone: * **admin-phone:** Starts an admin phone call with a server. (Owner-Only) +* **hang-up:** Hangs up the current phone call. * **phone-book:** Looks up phone-enabled servers. * **phone:** Starts a phone call with a random server. diff --git a/commands/phone/hang-up.js b/commands/phone/hang-up.js new file mode 100644 index 00000000..fc527a99 --- /dev/null +++ b/commands/phone/hang-up.js @@ -0,0 +1,27 @@ +const Command = require('../../structures/Command'); + +module.exports = class HangUpCommand extends Command { + constructor(client) { + super(client, { + name: 'hang-up', + group: 'phone', + memberName: 'hang-up', + description: 'Hangs up the current phone call.', + guildOnly: true + }); + } + + async run(msg) { + const origin = client.phone.find(call => call.origin.id === msg.channel.id); + const recipient = client.phone.find(call => call.recipient.id === msg.channel.id); + if (!origin && !recipient) return msg.reply('☎️ This channel is not in a phone call.'); + const call = origin || recipient; + if (!call.active) return msg.reply('☎️ This call is not currently active.'); + if (call.ownerOrigin && !this.client.isOwner(msg.author)) { + return msg.reply('☎️ You cannot hang up in an admin call.'); + } + const nonQuitter = msg.channel.id === call.origin.id ? call.recipient : call.origin; + await call.hangup(nonQuitter); + return null; + } +}; diff --git a/package.json b/package.json index 9ac57141..fcf12596 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "114.10.3", + "version": "114.11.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/phone/PhoneCall.js b/structures/phone/PhoneCall.js index 4d440355..db905274 100644 --- a/structures/phone/PhoneCall.js +++ b/structures/phone/PhoneCall.js @@ -61,7 +61,7 @@ module.exports = class PhoneCall { send(channel, msg, hasText, hasImage, hasEmbed) { if (msg.content && msg.content.toLowerCase() === 'hang up') { - if (this.ownerOrigin && channel.id === this.origin.id) { + if (this.ownerOrigin && channel.id === this.origin.id && !this.client.isOwner(msg.author)) { return this.recipient.send('☎️ You cannot hang up in an admin call.'); } return this.hangup(channel);