Files
xiao/commands/phone/phone.js
T
Dragon Fire 1407e9c4e1 Fix
2020-12-01 20:28:02 -05:00

86 lines
3.3 KiB
JavaScript

const Command = require('../../structures/Command');
const PhoneCall = require('../../structures/phone/PhoneCall');
module.exports = class PhoneCommand extends Command {
constructor(client) {
super(client, {
name: 'phone',
aliases: ['phone-call', 'call'],
group: 'phone',
memberName: 'phone',
description: 'Starts a phone call with a random server.',
throttling: {
usages: 1,
duration: 45
},
args: [
{
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(channelID);
},
parse: channelID => channelID.toLowerCase()
}
],
credit: [
{
name: 'Tatsumaki',
url: 'https://tatsumaki.xyz/',
reason: 'Concept'
}
]
});
}
async run(msg, { channelID }) {
if (channelID !== 'count' && (msg.guild && (!msg.channel.topic || !msg.channel.topic.includes('<xiao:phone>')))) {
return msg.say('You can only start a call in a channel with `<xiao:phone>` in the topic.');
}
if (channelID !== 'count' && this.client.inPhoneCall(msg.channel)) {
return msg.say('This channel is already in a phone call.');
}
const channels = this.client.channels.cache.filter(channel => channel.guild
&& channel.topic
&& channel.topic.includes('<xiao:phone>')
&& !channel.topic.includes('<xiao:phone:no-random>')
&& !channel.topic.includes(`<xiao:phone:block:${msg.guild ? msg.channel.id : msg.author.id}>`)
&& (msg.guild ? !channel.topic.includes(`<xiao:phone:block:${msg.guild.id}>`) : true)
&& (msg.guild ? msg.channel.topic && !msg.channel.topic.includes(`<xiao:phone:block:${channel.id}>`) : true)
&& (msg.guild ? msg.channel.topic && !msg.channel.topic.includes(`<xiao:phone:block:${channel.guild.id}>`) : true)
&& (msg.guild ? !msg.guild.channels.cache.has(channel.id) : true)
&& (channelID ? true : !this.client.inPhoneCall(channel)));
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);
if (!channel) return msg.reply('This channel does not exist.');
if (!channel.guild) return msg.reply('You cannot call DM channels.');
if (!channel.topic || !channel.topic.includes('<xiao:phone>')) {
return msg.reply('This channel does not allow phone calls.');
}
if (this.client.inPhoneCall(channel)) return msg.reply('This channel is already in a call.');
if (channel.topic.includes(`<xiao:phone:block:${msg.channel.id}>`)) {
return msg.reply('That channel has blocked this channel from calling them.');
}
if (msg.guild && channel.topic.includes(`<xiao:phone:block:${msg.guild.id}>`)) {
return msg.reply('That channel has blocked this server from calling them.');
}
} else {
channel = channels.random();
}
try {
const id = `${msg.channel.id}:${channel.id}`;
this.client.phone.set(id, new PhoneCall(this.client, msg.author, msg.channel, channel));
await this.client.phone.get(id).start();
return null;
} catch {
return msg.reply('Failed to start the call. Try again later!');
}
}
};