mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 05:49:49 +02:00
Split Phone into it's own manager
This commit is contained in:
+2
-14
@@ -5,6 +5,7 @@ const winston = require('winston');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Redis = require('./Redis');
|
||||
const PhoneManager = require('./phone/PhoneManager');
|
||||
const TimerManager = require('./remind/TimerManager');
|
||||
const PokemonStore = require('./pokemon/PokemonStore');
|
||||
const MemePosterClient = require('./MemePoster');
|
||||
@@ -45,24 +46,11 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
}) : null;
|
||||
this.games = new Collection();
|
||||
this.dispatchers = new Map();
|
||||
this.phone = new Collection();
|
||||
this.phone = new PhoneManager(this);
|
||||
this.activities = activities;
|
||||
this.leaveMessages = leaveMsgs;
|
||||
}
|
||||
|
||||
inPhoneCall(channel) {
|
||||
return this.phone.some(call => call.origin.id === channel.id || call.recipient.id === channel.id);
|
||||
}
|
||||
|
||||
isBlockedFromPhone(origin, recipient, caller) {
|
||||
return (recipient.guild && recipient.topic.includes(`<xiao:phone:block:${origin.id}>`))
|
||||
|| (recipient.guild && recipient.topic.includes(`<xiao:phone:block:${caller.id}>`))
|
||||
|| (origin.guild && recipient.guild && recipient.topic.includes(`<xiao:phone:block:${origin.guild.id}>`))
|
||||
|| (origin.guild && origin.topic.includes(`<xiao:phone:block:${recipient.id}>`))
|
||||
|| (origin.guild && recipient.guild && origin.topic.includes(`<xiao:phone:block:${recipient.guild.id}>`))
|
||||
|| (origin.guild && origin.topic.includes(`<xiao:phone:block:${caller.id}>`));
|
||||
}
|
||||
|
||||
importBlacklist() {
|
||||
const read = fs.readFileSync(path.join(__dirname, '..', 'blacklist.json'), { encoding: 'utf8' });
|
||||
const file = JSON.parse(read);
|
||||
|
||||
@@ -118,7 +118,7 @@ module.exports = class PhoneCall {
|
||||
if (this.cooldown.has(msg.author.id) && !this.client.isOwner(msg.author)) {
|
||||
return otherChannel.send(`☎️ ${msg.author}, slow down! You're sending messages too fast!`);
|
||||
}
|
||||
if (this.client.isBlockedFromPhone(otherChannel, channel, msg.author)) {
|
||||
if (this.client.phone.isBlocked(otherChannel, channel, msg.author)) {
|
||||
return otherChannel.send(`☎️ ${msg.author}, you are blocked from sending messages to this channel!`);
|
||||
}
|
||||
this.setTimeout();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
const Collection = require('@discordjs/collection');
|
||||
|
||||
module.exports = class PhoneManager extends Collection {
|
||||
constructor(client, options) {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
super(options);
|
||||
}
|
||||
|
||||
inCall(channel) {
|
||||
return this.some(call => call.origin.id === channel.id || call.recipient.id === channel.id);
|
||||
}
|
||||
|
||||
isBlocked(origin, recipient, caller) {
|
||||
return (recipient.guild && recipient.topic.includes(`<xiao:phone:block:${origin.id}>`))
|
||||
|| (recipient.guild && recipient.topic.includes(`<xiao:phone:block:${caller.id}>`))
|
||||
|| (origin.guild && recipient.guild && recipient.topic.includes(`<xiao:phone:block:${origin.guild.id}>`))
|
||||
|| (origin.guild && origin.topic.includes(`<xiao:phone:block:${recipient.id}>`))
|
||||
|| (origin.guild && recipient.guild && origin.topic.includes(`<xiao:phone:block:${recipient.guild.id}>`))
|
||||
|| (origin.guild && origin.topic.includes(`<xiao:phone:block:${caller.id}>`));
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user