Admin call system

This commit is contained in:
Dragon Fire
2020-05-13 18:35:36 -04:00
parent 40a28a46f0
commit 577a665dc4
7 changed files with 70 additions and 12 deletions
+41
View File
@@ -0,0 +1,41 @@
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.',
guildOnly: true,
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 }) {
const inCall = this.client.phone.some(call => [call.origin.id, call.recipient.id].includes(msg.channel.id));
if (inCall) return msg.say('This channel is already in a phone call.');
if (channelID === 'count') return msg.say(`☎️ **${channels.size}** currently open lines.`);
const channel = this.client.channels.cache.get(channelID);
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));
await this.client.phone.get(id).start();
return null;
} catch {
return msg.reply('Failed to start the call. Try again later!');
}
}
};
+37
View File
@@ -0,0 +1,37 @@
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.',
guildOnly: true,
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('<xiao:phone>')
&& !channel.topic.includes('<xiao:phone-book:hide>')
&& (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.map(c => `**${c.id}** (#${c.name}: ${c.guild.name})`).slice(0, 10).join('\n')}
`);
}
};
+73
View File
@@ -0,0 +1,73 @@
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.',
guildOnly: true,
throttling: {
usages: 1,
duration: 60
},
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.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.');
}
const inCall = this.client.phone.some(call => [call.origin.id, call.recipient.id].includes(msg.channel.id));
if (channelID !== 'count' && inCall) {
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>')
&& !msg.guild.channels.cache.has(channel.id));
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 || !channel.guild) return msg.reply('This channel does not exist.');
if (!channel.topic || !channel.topic.includes('<xiao:phone>')) {
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));
await this.client.phone.get(id).start();
return null;
} catch {
return msg.reply('Failed to start the call. Try again later!');
}
}
};