mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
No direct calling
This commit is contained in:
@@ -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!');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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 \`<xiao:phone:block:${user.id}>\` 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 \`<xiao:phone:block:${channel.id}>\` in this channel's topic
|
||||
|
||||
@@ -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('<xiao:phone>')
|
||||
&& channel.topic.includes('<xiao:phone-book>')
|
||||
&& (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')}
|
||||
`);
|
||||
}
|
||||
};
|
||||
+9
-29
@@ -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('<xiao:phone>')))) {
|
||||
async run(msg, { count }) {
|
||||
if (count !== '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.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('<xiao:phone:no-random>')
|
||||
&& !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('<xiao:phone>')) {
|
||||
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));
|
||||
|
||||
@@ -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('<xiao:phone:auto-accept>')) {
|
||||
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('<xiao:phone:auto-accept>')) {
|
||||
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('<xiao:phone:no-notice>'))) {
|
||||
await this.sendNotice(this.origin, this.originDM);
|
||||
|
||||
Reference in New Issue
Block a user