From 9210ada744feaac8459f8e3bd8271bfca514da63 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 18 May 2020 11:57:43 -0400 Subject: [PATCH] Only allow phone calls to one channel at a time --- commands/games-sp/blackjack.js | 2 +- commands/games-sp/hangman.js | 2 +- commands/phone/admin-phone.js | 3 +-- commands/phone/phone.js | 7 ++++--- package.json | 2 +- structures/Client.js | 4 ++++ 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/commands/games-sp/blackjack.js b/commands/games-sp/blackjack.js index ddfdbe3d..dea217de 100644 --- a/commands/games-sp/blackjack.js +++ b/commands/games-sp/blackjack.js @@ -27,7 +27,7 @@ module.exports = class BlackjackCommand extends Command { }); } - async run(msg, { deckCount }) { // eslint-disable-line complexity + async run(msg, { deckCount }) { const current = this.client.games.get(msg.channel.id); if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`); try { diff --git a/commands/games-sp/hangman.js b/commands/games-sp/hangman.js index 5cc8095f..45aebd3c 100644 --- a/commands/games-sp/hangman.js +++ b/commands/games-sp/hangman.js @@ -28,7 +28,7 @@ module.exports = class HangmanCommand extends Command { }); } - async run(msg) { // eslint-disable-line complexity + async run(msg) { const current = this.client.games.get(msg.channel.id); if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`); this.client.games.set(msg.channel.id, { name: this.name }); diff --git a/commands/phone/admin-phone.js b/commands/phone/admin-phone.js index fddf6e8a..7ebcb272 100644 --- a/commands/phone/admin-phone.js +++ b/commands/phone/admin-phone.js @@ -24,8 +24,7 @@ module.exports = class AdminPhoneCommand extends Command { } 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 (this.client.inPhoneCall(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 { diff --git a/commands/phone/phone.js b/commands/phone/phone.js index f1044747..fc809b56 100644 --- a/commands/phone/phone.js +++ b/commands/phone/phone.js @@ -41,14 +41,14 @@ module.exports = class PhoneCommand extends Command { if (channelID !== 'count' && (!msg.channel.topic || !msg.channel.topic.includes(''))) { return msg.say('You can only start a call in a channel with `` in the topic.'); } - const inCall = this.client.phone.some(call => [call.origin.id, call.recipient.id].includes(msg.channel.id)); - if (channelID !== 'count' && inCall) { + 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('') - && !msg.guild.channels.cache.has(channel.id)); + && !msg.guild.channels.cache.has(channel.id) + && (channelID ? true : !this.client.inPhoneCall(channel))); if (!channels.size) return msg.reply('No channels currently allow phone calls...'); let channel; if (channelID) { @@ -58,6 +58,7 @@ module.exports = class PhoneCommand extends Command { if (!channel.topic || !channel.topic.includes('')) { 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.'); } else { channel = channels.random(); } diff --git a/package.json b/package.json index 9c4a80fb..90361a19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "114.13.1", + "version": "114.13.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/Client.js b/structures/Client.js index acf9d44b..9669c298 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -33,4 +33,8 @@ module.exports = class XiaoClient extends CommandoClient { this.activities = activities; this.leaveMessages = leaveMsgs; } + + inPhoneCall(channel) { + return this.phone.some(call => call.origin.id === channel.id || call.recipient.id === channel.id); + } };