From ebabd3ec75b5b7661bbbbdd7165359ebc5052945 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 3 Dec 2020 15:00:33 -0500 Subject: [PATCH] Add blocking of users fully from phone --- commands/phone/phone-block.js | 12 ++++++++++++ commands/phone/phone.js | 10 ++-------- package.json | 2 +- structures/Client.js | 9 +++++++++ structures/phone/PhoneCall.js | 7 +++++-- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/commands/phone/phone-block.js b/commands/phone/phone-block.js index 7822ddbe..b5f1fbc7 100644 --- a/commands/phone/phone-block.js +++ b/commands/phone/phone-block.js @@ -25,6 +25,18 @@ module.exports = class PhoneBlockCommand extends Command { const search = query.toLowerCase(); return channel.guild && (channel.name.includes(search) || channel.id === search); }); + let user; + try { + user = await this.client.users.fetch(query); + } catch { + user = null; + } + if (user) { + return msg.say(stripIndents` + __To block **${user.tag} (${user.id})** from DM calling and messages:__ + Place \`\` 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(); diff --git a/commands/phone/phone.js b/commands/phone/phone.js index 3c39fa3a..9153ce5b 100644 --- a/commands/phone/phone.js +++ b/commands/phone/phone.js @@ -47,10 +47,7 @@ module.exports = class PhoneCommand extends Command { && channel.topic && channel.topic.includes('') && !channel.topic.includes('') - && !channel.topic.includes(``) - && (msg.guild ? !channel.topic.includes(``) : true) - && (msg.guild ? msg.channel.topic && !msg.channel.topic.includes(``) : true) - && (msg.guild ? msg.channel.topic && !msg.channel.topic.includes(``) : true) + && !this.client.phone.isBlockedFromPhone(msg.channel, channel, msg.author) && (msg.guild ? !msg.guild.channels.cache.has(channel.id) : true) && (channelID ? true : !this.client.inPhoneCall(channel))); if (!channels.size) return msg.reply('No channels currently allow phone calls...'); @@ -65,12 +62,9 @@ module.exports = class PhoneCommand extends Command { 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.'); - if (channel.topic.includes(``)) { + if (this.client.isBlockedFromPhone(msg.channel, channel, msg.author)) { return msg.reply('That channel has blocked this channel from calling them.'); } - if (msg.guild && channel.topic.includes(``)) { - return msg.reply('That channel has blocked this server from calling them.'); - } } else { channel = channels.random(); } diff --git a/package.json b/package.json index 48583f8f..8f091220 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "123.3.0", + "version": "123.3.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/Client.js b/structures/Client.js index e3e37c2d..35f6fb5d 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -52,6 +52,15 @@ module.exports = class XiaoClient extends CommandoClient { return this.phone.some(call => call.origin.id === channel.id || call.recipient.id === channel.id); } + isBlockedFromPhone(origin, recipient, caller) { + return !recipient.topic.includes(``) + && !recipient.topic.includes(``) + && (origin.guild ? !recipient.topic.includes(``) : true) + && (origin.guild ? !origin.topic.includes(``) : true) + && (origin.guild ? !origin.topic.includes(``) : true) + && (origin.guild ? !origin.topic.includes(``) : true); + } + importCommandLeaderboard() { const read = fs.readFileSync(path.join(__dirname, '..', 'command-leaderboard.json'), { encoding: 'utf8' diff --git a/structures/phone/PhoneCall.js b/structures/phone/PhoneCall.js index 519671b0..787e0abb 100644 --- a/structures/phone/PhoneCall.js +++ b/structures/phone/PhoneCall.js @@ -111,9 +111,12 @@ module.exports = class PhoneCall { } send(channel, msg, hasText, hasImage, hasEmbed) { + const otherChannel = channel.id === this.origin.id ? this.recipient : this.origin; if (this.cooldown.has(msg.author.id) && !this.client.isOwner(msg.author)) { - const badChannel = channel.id === this.origin.id ? this.recipient : this.origin; - return badChannel.send(`☎️ ${msg.author}, slow down! You're sending messages too fast!`); + return otherChannel.send(`☎️ ${msg.author}, slow down! You're sending messages too fast!`); + } + if (this.client.isBlockedFromPhone(otherChannel, channel, msg.author)) { + return otherChannel.send(`☎️ ${msg.author}, you are blocked from sending messages to this channel!`); } this.setTimeout(); if (!this.client.isOwner(msg.author)) {