From d9c184084a0306770ef0311d4b1dfa77fa0c8895 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 29 Apr 2021 17:17:41 -0400 Subject: [PATCH] No direct calling --- commands/phone/admin-phone.js | 40 ----------------------------- commands/phone/phone-block.js | 22 ++++++++-------- commands/phone/phone-book.js | 36 -------------------------- commands/phone/phone.js | 38 +++++++-------------------- structures/phone/PhoneCall.js | 48 +++++++++++++++-------------------- 5 files changed, 40 insertions(+), 144 deletions(-) delete mode 100644 commands/phone/admin-phone.js delete mode 100644 commands/phone/phone-book.js diff --git a/commands/phone/admin-phone.js b/commands/phone/admin-phone.js deleted file mode 100644 index 7236944a..00000000 --- a/commands/phone/admin-phone.js +++ /dev/null @@ -1,40 +0,0 @@ -const Command = require('../../structures/Command'); -const PhoneCall = require('../../structures/phone/PhoneCall'); - -module.exports = class AdminPhoneCommand extends Command { - constructor(client) { - super(client, { - name: 'admin-phone', - aliases: ['admin-phone-call', 'admin-call', 'a-phone', 'a-phone-call', 'a-call'], - group: 'phone', - memberName: 'admin-phone', - description: 'Starts an admin phone call with a server.', - ownerOnly: true, - args: [ - { - key: 'channelID', - prompt: 'What channel would you like to start a call with?', - type: 'string', - validate: channelID => /^[0-9]+$/.test(channelID), - parse: channelID => channelID.toLowerCase() - } - ] - }); - } - - async run(msg, { channelID }) { - if (this.client.phone.inCall(msg.channel)) return msg.say('This channel is already in a phone call.'); - const channel = this.client.channels.cache.get(channelID); - if (!channel || !channel.guild) return msg.reply('This channel does not exist.'); - try { - const id = `${msg.guild ? msg.channel.id : msg.author.id}:${channel.id}`; - 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 { - const id = `${msg.guild ? msg.channel.id : msg.author.id}:${channel.id}`; - this.client.phone.delete(id); - return msg.reply('Failed to start the call. Try again later!'); - } - } -}; diff --git a/commands/phone/phone-block.js b/commands/phone/phone-block.js index 515f8ed1..e76497f3 100644 --- a/commands/phone/phone-block.js +++ b/commands/phone/phone-block.js @@ -12,22 +12,24 @@ module.exports = class PhoneBlockCommand extends Command { guildOnly: true, args: [ { - key: 'query', - prompt: 'What channel would you like to search for?', + key: 'id', + prompt: 'What is the ID of the channel or user you would like to block?', type: 'string' } ] }); } - async run(msg, { query }) { - const channels = this.client.channels.cache.filter(channel => { - const search = query.toLowerCase(); - return channel.guild && (channel.name.includes(search) || channel.id === search); - }); + async run(msg, { id }) { + let channel; + try { + channel = await this.client.channels.fetch(id); + } catch { + channel = null; + } let user; try { - user = await this.client.users.fetch(query); + user = await this.client.users.fetch(id); } catch { user = null; } @@ -37,9 +39,7 @@ module.exports = class PhoneBlockCommand extends Command { Place \`\` in this channel's topic `); } - if (!channels.size) return msg.reply('Could not find any results.'); - if (channels.size > 1) return msg.reply(`Found ${channels.size} channels, please be more specific (or use ID).`); - const channel = channels.first(); + if (!channel) return msg.reply('Could not find any results.'); return msg.say(stripIndents` __To block **#${channel.name} (${channel.id})**:__ Just the channel: Place \`\` in this channel's topic diff --git a/commands/phone/phone-book.js b/commands/phone/phone-book.js deleted file mode 100644 index e5119ad4..00000000 --- a/commands/phone/phone-book.js +++ /dev/null @@ -1,36 +0,0 @@ -const Command = require('../../structures/Command'); -const { stripIndents } = require('common-tags'); - -module.exports = class PhoneBookCommand extends Command { - constructor(client) { - super(client, { - name: 'phone-book', - group: 'phone', - memberName: 'phone-book', - description: 'Looks up phone-enabled servers.', - args: [ - { - key: 'query', - prompt: 'What server would you like to search for?', - type: 'string' - } - ] - }); - } - - run(msg, { query }) { - const channels = this.client.channels.cache.filter(channel => { - const search = query.toLowerCase(); - return channel.guild - && channel.topic - && channel.topic.includes('') - && channel.topic.includes('') - && (channel.guild.name.toLowerCase().includes(search) || channel.name.includes(search)); - }); - if (!channels.size) return msg.reply('Could not find any results.'); - return msg.say(stripIndents` - __**Results:**__ _(${channels.size} Results${channels.size > 10 ? ', Showing 10' : ''})_ - ${channels.map(c => `**${c.id}** (#${c.name}: ${c.guild.name})`).slice(0, 10).join('\n')} - `); - } -}; diff --git a/commands/phone/phone.js b/commands/phone/phone.js index f0be657c..411257bb 100644 --- a/commands/phone/phone.js +++ b/commands/phone/phone.js @@ -15,15 +15,11 @@ module.exports = class PhoneCommand extends Command { }, args: [ { - key: 'channelID', - prompt: 'What channel would you like to start a call with?', + key: 'count', + prompt: 'Do you want to get the count of phone servers?', type: 'string', default: '', - validate: channelID => { - if (channelID.toLowerCase() === 'count') return true; - return /^[0-9]+$/.test(channelID); - }, - parse: channelID => channelID.toLowerCase() + parse: count => count.toLowerCase() } ], credit: [ @@ -36,11 +32,11 @@ module.exports = class PhoneCommand extends Command { }); } - async run(msg, { channelID }) { - if (channelID !== 'count' && (msg.guild && (!msg.channel.topic || !msg.channel.topic.includes('')))) { + async run(msg, { count }) { + if (count !== '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.phone.inCall(msg.channel)) { + if (count !== 'count' && this.client.phone.inCall(msg.channel)) { return msg.say('This channel is already in a phone call.'); } const channels = this.client.channels.cache.filter(channel => channel.guild @@ -49,26 +45,10 @@ module.exports = class PhoneCommand extends Command { && !channel.topic.includes('') && !this.client.phone.isBlocked(msg.channel, channel, msg.author) && (msg.guild ? !msg.guild.channels.cache.has(channel.id) : true) - && (channelID ? true : !this.client.phone.inCall(channel))); + && !this.client.phone.inCall(channel)); + if (count === 'count') return msg.say(`☎️ **${channels.size}** currently open lines.`); if (!channels.size) return msg.reply('No channels currently allow phone calls...'); - let channel; - if (channelID) { - if (channelID === 'count') return msg.say(`☎️ **${channels.size}** currently open lines.`); - channel = this.client.channels.cache.get(channelID); - const user = this.client.users.cache.get(channelID); - if (user) return msg.reply('You cannot call DM channels.'); - if (!channel || !channel.guild) return msg.reply('That channel does not exist.'); - if (!channel.topic || !channel.topic.includes('')) { - return msg.reply('That channel does not allow phone calls.'); - } - if (msg.channel.id === channel.id) return msg.reply('You are literally in that channel right now.'); - if (this.client.phone.inCall(channel)) return msg.reply('That channel is already in a call.'); - if (this.client.phone.isBlocked(msg.channel, channel, msg.author)) { - return msg.reply('That channel has blocked this channel from calling them.'); - } - } else { - channel = channels.random(); - } + const channel = channels.random(); try { const id = `${msg.guild ? msg.channel.id : msg.author.id}:${channel.id}`; this.client.phone.set(id, new PhoneCall(this.client, msg.author, msg.channel, channel)); diff --git a/structures/phone/PhoneCall.js b/structures/phone/PhoneCall.js index 67144f2a..1c286bab 100644 --- a/structures/phone/PhoneCall.js +++ b/structures/phone/PhoneCall.js @@ -4,48 +4,41 @@ require('moment-duration-format'); const { shorten, stripInvites, preventURLEmbeds, stripNSFWURLs, verify } = require('../../util/Util'); module.exports = class PhoneCall { - constructor(client, startUser, origin, recipient, adminCall) { + constructor(client, startUser, origin, recipient) { Object.defineProperty(this, 'client', { value: client }); this.id = `${origin.guild ? origin.id : startUser.id}:${recipient.id}`; this.origin = origin; - this.originDM = !origin.guild; this.recipient = recipient; this.startUser = startUser; this.active = false; this.timeout = null; - this.adminCall = adminCall || false; this.cooldown = new Set(); this.ratelimitMeters = new Map(); this.timeStarted = null; } + get originDM() { + return !this.origin.guild; + } + async start() { - if (this.adminCall) { - await this.origin.send(`☎️ Admin call started with **${this.recipient.guild.name}**.`); - 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.`); - } + await this.origin.send(`☎️ Calling **${this.recipient.guild.name} (${this.recipient.id})**...`); + if (this.recipient.topic && this.recipient.topic.includes('')) { + await this.accept(); + return this; + } + if (this.originDM) { + await this.recipient.send( + `☎️ Incoming call from **${this.startUser.tag}'s DM (${this.startUser.id})**. Pick up?` + ); } else { - await this.origin.send(`☎️ Calling **${this.recipient.guild.name} (${this.recipient.id})**...`); - if (this.recipient.topic && this.recipient.topic.includes('')) { - await this.accept(); - return this; - } - if (this.originDM) { - await this.recipient.send( - `☎️ Incoming call from **${this.startUser.tag}'s DM (${this.startUser.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); - return this; - } + 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); + return this; } await this.accept(); return this; @@ -55,7 +48,6 @@ module.exports = class PhoneCall { this.active = true; this.timeStarted = new Date(); this.setTimeout(); - if (this.adminCall) return this; const usage = this.client.registry.commands.get('hang-up').usage(); if (this.originDM || (this.origin.topic && !this.origin.topic.includes(''))) { await this.sendNotice(this.origin, this.originDM);