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
+18 -7
View File
@@ -1,7 +1,7 @@
const { shorten, stripInvites, verify } = require('../../util/Util');
module.exports = class PhoneCall {
constructor(client, origin, recipient) {
constructor(client, origin, recipient, ownerOrigin) {
Object.defineProperty(this, 'client', { value: client });
this.id = `${origin.id}:${recipient.id}`;
@@ -9,15 +9,20 @@ module.exports = class PhoneCall {
this.recipient = recipient;
this.active = false;
this.timeout = null;
this.ownerOrigin = ownerOrigin || false;
}
async start() {
await this.origin.send(`☎️ Calling **${this.recipient.guild.name}**...`);
await this.recipient.send(`☎️ Incoming call from **${this.origin.guild.name}**. Pick up?`);
const validation = await verify(this.recipient, null);
if (!validation) {
await this.hangup('declined', validation);
return this;
if (this.ownerOrigin) {
await this.recipient.send(`☎️ Incoming **ADMIN** call from **${this.origin.guild.name}**...`);
} else {
await this.recipient.send(`☎️ Incoming call from **${this.origin.guild.name}**. Pick up?`);
const validation = await verify(this.recipient, null);
if (!validation) {
await this.hangup('declined', validation);
return this;
}
}
await this.accept();
return this;
@@ -26,6 +31,7 @@ module.exports = class PhoneCall {
async accept() {
this.active = true;
this.setTimeout();
if (this.ownerOrigin) return this;
await this.origin.send(`☎️ **${this.recipient.guild.name}** picked up! Type \`hang up\` to hang up.`);
await this.recipient.send(`☎️ Accepted call from **${this.origin.guild.name}**. Type \`hang up\` to hang up.`);
return this;
@@ -52,7 +58,12 @@ module.exports = class PhoneCall {
}
send(channel, msg, hasText, hasImage, hasEmbed) {
if (msg.content && msg.content.toLowerCase() === 'hang up') return this.hangup(channel);
if (msg.content && msg.content.toLowerCase() === 'hang up') {
if (this.ownerOrigin && channel.id !== this.origin.id) {
return this.recipient.send('☎️ You cannot hang up in an admin call.');
}
return this.hangup(channel);
}
this.setTimeout();
const attachments = hasImage ? msg.attachments.map(a => a.url).join('\n') : null;
if (!hasText && hasImage) return channel.send(`☎️ **${msg.author.tag}:**\n${attachments}`);