mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-27 14:18:36 +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,
|
guildOnly: true,
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'query',
|
key: 'id',
|
||||||
prompt: 'What channel would you like to search for?',
|
prompt: 'What is the ID of the channel or user you would like to block?',
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { query }) {
|
async run(msg, { id }) {
|
||||||
const channels = this.client.channels.cache.filter(channel => {
|
let channel;
|
||||||
const search = query.toLowerCase();
|
try {
|
||||||
return channel.guild && (channel.name.includes(search) || channel.id === search);
|
channel = await this.client.channels.fetch(id);
|
||||||
});
|
} catch {
|
||||||
|
channel = null;
|
||||||
|
}
|
||||||
let user;
|
let user;
|
||||||
try {
|
try {
|
||||||
user = await this.client.users.fetch(query);
|
user = await this.client.users.fetch(id);
|
||||||
} catch {
|
} catch {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
@@ -37,9 +39,7 @@ module.exports = class PhoneBlockCommand extends Command {
|
|||||||
Place \`<xiao:phone:block:${user.id}>\` in this channel's topic
|
Place \`<xiao:phone:block:${user.id}>\` in this channel's topic
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
if (!channels.size) return msg.reply('Could not find any results.');
|
if (!channel) 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();
|
|
||||||
return msg.say(stripIndents`
|
return msg.say(stripIndents`
|
||||||
__To block **#${channel.name} (${channel.id})**:__
|
__To block **#${channel.name} (${channel.id})**:__
|
||||||
Just the channel: Place \`<xiao:phone:block:${channel.id}>\` in this channel's topic
|
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: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'channelID',
|
key: 'count',
|
||||||
prompt: 'What channel would you like to start a call with?',
|
prompt: 'Do you want to get the count of phone servers?',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
validate: channelID => {
|
parse: count => count.toLowerCase()
|
||||||
if (channelID.toLowerCase() === 'count') return true;
|
|
||||||
return /^[0-9]+$/.test(channelID);
|
|
||||||
},
|
|
||||||
parse: channelID => channelID.toLowerCase()
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
credit: [
|
credit: [
|
||||||
@@ -36,11 +32,11 @@ module.exports = class PhoneCommand extends Command {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { channelID }) {
|
async run(msg, { count }) {
|
||||||
if (channelID !== 'count' && (msg.guild && (!msg.channel.topic || !msg.channel.topic.includes('<xiao:phone>')))) {
|
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.');
|
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.');
|
return msg.say('This channel is already in a phone call.');
|
||||||
}
|
}
|
||||||
const channels = this.client.channels.cache.filter(channel => channel.guild
|
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>')
|
&& !channel.topic.includes('<xiao:phone:no-random>')
|
||||||
&& !this.client.phone.isBlocked(msg.channel, channel, msg.author)
|
&& !this.client.phone.isBlocked(msg.channel, channel, msg.author)
|
||||||
&& (msg.guild ? !msg.guild.channels.cache.has(channel.id) : true)
|
&& (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...');
|
if (!channels.size) return msg.reply('No channels currently allow phone calls...');
|
||||||
let channel;
|
const channel = channels.random();
|
||||||
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();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const id = `${msg.guild ? msg.channel.id : msg.author.id}:${channel.id}`;
|
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));
|
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');
|
const { shorten, stripInvites, preventURLEmbeds, stripNSFWURLs, verify } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class PhoneCall {
|
module.exports = class PhoneCall {
|
||||||
constructor(client, startUser, origin, recipient, adminCall) {
|
constructor(client, startUser, origin, recipient) {
|
||||||
Object.defineProperty(this, 'client', { value: client });
|
Object.defineProperty(this, 'client', { value: client });
|
||||||
|
|
||||||
this.id = `${origin.guild ? origin.id : startUser.id}:${recipient.id}`;
|
this.id = `${origin.guild ? origin.id : startUser.id}:${recipient.id}`;
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.originDM = !origin.guild;
|
|
||||||
this.recipient = recipient;
|
this.recipient = recipient;
|
||||||
this.startUser = startUser;
|
this.startUser = startUser;
|
||||||
this.active = false;
|
this.active = false;
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
this.adminCall = adminCall || false;
|
|
||||||
this.cooldown = new Set();
|
this.cooldown = new Set();
|
||||||
this.ratelimitMeters = new Map();
|
this.ratelimitMeters = new Map();
|
||||||
this.timeStarted = null;
|
this.timeStarted = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get originDM() {
|
||||||
|
return !this.origin.guild;
|
||||||
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
if (this.adminCall) {
|
await this.origin.send(`☎️ Calling **${this.recipient.guild.name} (${this.recipient.id})**...`);
|
||||||
await this.origin.send(`☎️ Admin call started with **${this.recipient.guild.name}**.`);
|
if (this.recipient.topic && this.recipient.topic.includes('<xiao:phone:auto-accept>')) {
|
||||||
if (this.originDM) {
|
await this.accept();
|
||||||
await this.recipient.send(`☎️ An **ADMIN** call from **${this.startUser.tag}'s DMs** has begun.`);
|
return this;
|
||||||
} else {
|
}
|
||||||
await this.recipient.send(`☎️ An **ADMIN** call from **${this.origin.guild.name}** has begun.`);
|
if (this.originDM) {
|
||||||
}
|
await this.recipient.send(
|
||||||
|
`☎️ Incoming call from **${this.startUser.tag}'s DM (${this.startUser.id})**. Pick up?`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await this.origin.send(`☎️ Calling **${this.recipient.guild.name} (${this.recipient.id})**...`);
|
await this.recipient.send(`☎️ Incoming call from **${this.origin.guild.name} (${this.origin.id})**. Pick up?`);
|
||||||
if (this.recipient.topic && this.recipient.topic.includes('<xiao:phone:auto-accept>')) {
|
}
|
||||||
await this.accept();
|
const validation = await verify(this.recipient, null);
|
||||||
return this;
|
if (!validation) {
|
||||||
}
|
await this.hangup('declined', validation);
|
||||||
if (this.originDM) {
|
return this;
|
||||||
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.accept();
|
await this.accept();
|
||||||
return this;
|
return this;
|
||||||
@@ -55,7 +48,6 @@ module.exports = class PhoneCall {
|
|||||||
this.active = true;
|
this.active = true;
|
||||||
this.timeStarted = new Date();
|
this.timeStarted = new Date();
|
||||||
this.setTimeout();
|
this.setTimeout();
|
||||||
if (this.adminCall) return this;
|
|
||||||
const usage = this.client.registry.commands.get('hang-up').usage();
|
const usage = this.client.registry.commands.get('hang-up').usage();
|
||||||
if (this.originDM || (this.origin.topic && !this.origin.topic.includes('<xiao:phone:no-notice>'))) {
|
if (this.originDM || (this.origin.topic && !this.origin.topic.includes('<xiao:phone:no-notice>'))) {
|
||||||
await this.sendNotice(this.origin, this.originDM);
|
await this.sendNotice(this.origin, this.originDM);
|
||||||
|
|||||||
Reference in New Issue
Block a user