From 095e69c61986d2f17a84347367f5419415c3f165 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 7 Jul 2020 11:02:35 -0400 Subject: [PATCH] Phone Info Command --- README.md | 3 ++- commands/phone/admin-phone.js | 2 +- commands/phone/phone-info.js | 36 +++++++++++++++++++++++++++++++++++ commands/phone/phone.js | 2 +- package.json | 2 +- structures/phone/PhoneCall.js | 5 ++++- 6 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 commands/phone/phone-info.js diff --git a/README.md b/README.md index 25c2cbd0..19228d60 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 529 +Total: 530 ### Utility: @@ -801,6 +801,7 @@ Total: 529 * **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-info:** Gives information on the current phone call. * **phone:** Starts a phone call with a random server. ### Other: diff --git a/commands/phone/admin-phone.js b/commands/phone/admin-phone.js index 7ebcb272..2fedf62a 100644 --- a/commands/phone/admin-phone.js +++ b/commands/phone/admin-phone.js @@ -29,7 +29,7 @@ module.exports = class AdminPhoneCommand extends Command { if (!channel || !channel.guild) return msg.reply('This channel does not exist.'); try { const id = `${msg.channel.id}:${channel.id}`; - this.client.phone.set(id, new PhoneCall(this.client, msg.channel, channel, true)); + this.client.phone.set(id, new PhoneCall(this.client, msg.author, msg.channel, channel, true)); await this.client.phone.get(id).start(); return null; } catch { diff --git a/commands/phone/phone-info.js b/commands/phone/phone-info.js new file mode 100644 index 00000000..fcb4859a --- /dev/null +++ b/commands/phone/phone-info.js @@ -0,0 +1,36 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const moment = require('moment'); +require('moment-duration-format'); + +module.exports = class PhoneInfoCommand extends Command { + constructor(client) { + super(client, { + name: 'phone-info', + aliases: ['call-info', 'phone-call-info'], + group: 'phone', + memberName: 'phone-info', + description: 'Gives information on the current phone call.', + guildOnly: true + }); + } + + async run(msg) { + const origin = this.client.phone.find(call => call.origin.id === msg.channel.id); + const recipient = this.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.'); + const otherChannel = msg.channel.id === call.origin.id ? call.recipient : call.origin; + 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 ID', otherChannel.id, true) + .addField('❯ Call Duration', moment.duration(Date.now() - call.timeStarted).format('d:hh:mm:ss'), true) + .addField('❯ Admin Call?', call.ownerOrigin ? 'Yes' : 'No', true) + .addField('❯ Started By', call.startUser.tag, true); + return msg.embed(embed); + } +}; diff --git a/commands/phone/phone.js b/commands/phone/phone.js index fc809b56..6dd868d9 100644 --- a/commands/phone/phone.js +++ b/commands/phone/phone.js @@ -64,7 +64,7 @@ module.exports = class PhoneCommand extends Command { } try { const id = `${msg.channel.id}:${channel.id}`; - this.client.phone.set(id, new PhoneCall(this.client, msg.channel, channel)); + this.client.phone.set(id, new PhoneCall(this.client, msg.author, msg.channel, channel)); await this.client.phone.get(id).start(); return null; } catch { diff --git a/package.json b/package.json index 0dfbb856..41f4133c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.10.2", + "version": "119.11.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/phone/PhoneCall.js b/structures/phone/PhoneCall.js index 0ac58adb..b5e1a01c 100644 --- a/structures/phone/PhoneCall.js +++ b/structures/phone/PhoneCall.js @@ -2,17 +2,19 @@ const { stripIndents } = require('common-tags'); const { shorten, stripInvites, verify } = require('../../util/Util'); module.exports = class PhoneCall { - constructor(client, origin, recipient, ownerOrigin) { + constructor(client, startUser, origin, recipient, ownerOrigin) { Object.defineProperty(this, 'client', { value: client }); this.id = `${origin.id}:${recipient.id}`; this.origin = origin; this.recipient = recipient; + this.startUser = startUser; this.active = false; this.timeout = null; this.ownerOrigin = ownerOrigin || false; this.cooldown = new Set(); this.ratelimitMeters = new Map(); + this.timeStarted = null; } async start() { @@ -34,6 +36,7 @@ module.exports = class PhoneCall { async accept() { this.active = true; + this.timeStarted = new Date(); this.setTimeout(); if (this.ownerOrigin) return this; await this.origin.send(`☎️ **${this.recipient.guild.name}** picked up! Type \`hang up\` to hang up.`);