From 453456a4c8a5c0d55c868e49ef782f596f808158 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 19 Mar 2020 12:48:17 -0400 Subject: [PATCH] Allow phone calls with a specific channel ID --- commands/other/phone.js | 27 ++++++++++++++++++++------- package.json | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/commands/other/phone.js b/commands/other/phone.js index 62bd6291..4ede35a9 100644 --- a/commands/other/phone.js +++ b/commands/other/phone.js @@ -12,10 +12,14 @@ module.exports = class PhoneCommand extends Command { guildOnly: true, args: [ { - key: 'count', - prompt: 'Would you like to get the count of channels?', - type: 'boolean', - default: false + key: 'channelID', + prompt: 'What channel would you like to start a call with?', + type: 'string', + default: '', + validate: channelID => { + if (channelID.toLowerCase() === 'count') return true; + return !/^[0-9]+$/.test(val); + } } ], credit: [ @@ -28,7 +32,7 @@ module.exports = class PhoneCommand extends Command { }); } - async run(msg, { count }) { + async run(msg, { channelID }) { if (!msg.channel.topic || !msg.channel.topic.includes('')) { return msg.say('You can only start a call in a channel with `` in the topic.'); } @@ -39,9 +43,18 @@ module.exports = class PhoneCommand extends Command { && channel.topic && channel.topic.includes('') && !msg.guild.channels.cache.has(channel.id)); - if (count) return msg.say(`☎️ **${channels.size}** currently open lines.`); if (!channels.size) return msg.reply('No channels currently allow phone calls...'); - const channel = channels.random(); + let channel; + if (channelID) { + if (channelID.toLowerCase() === 'count') return msg.say(`☎️ **${channels.size}** currently open lines.`); + channel = this.client.channels.cache.get(channelID); + if (!channel || channel.type !== 'text') return msg.reply('This channel does not exist.'); + if (!channel.topic || !channel.topic.includes('')) { + return msg.reply('This channel does not allow phone calls.'); + } + } else { + channel = channels.random(); + } try { const id = `${msg.channel.id}:${channel.id}`; this.client.phone.set(id, new PhoneCall(this.client, msg.channel, channel)); diff --git a/package.json b/package.json index b24981ad..c9532c70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.10.0", + "version": "112.10.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {