More work decoupling chatPreprocessor from src/app/channel.
This commit is contained in:
parent
23ad679473
commit
0ed1c0dd89
|
|
@ -18,7 +18,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const validator = require('validator')
|
const validator = require('validator')
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const commandPreprocessor = require('./commandPreprocessor');
|
const chatPreprocessor = require('../chatPreprocessor');
|
||||||
|
const commandProcessor = require('./commandProcessor');
|
||||||
|
const tokebot = require('./tokebot');
|
||||||
const loggerUtils = require('../../utils/loggerUtils');
|
const loggerUtils = require('../../utils/loggerUtils');
|
||||||
const linkUtils = require('../../utils/linkUtils');
|
const linkUtils = require('../../utils/linkUtils');
|
||||||
const emoteValidator = require('../../validators/emoteValidator');
|
const emoteValidator = require('../../validators/emoteValidator');
|
||||||
|
|
@ -42,7 +44,11 @@ class chatHandler{
|
||||||
/**
|
/**
|
||||||
* Child Command Pre-Processor Object
|
* Child Command Pre-Processor Object
|
||||||
*/
|
*/
|
||||||
this.commandPreprocessor = new commandPreprocessor(server, this)
|
this.chatPreprocessor = new chatPreprocessor(
|
||||||
|
server,
|
||||||
|
new commandProcessor(server, this),
|
||||||
|
new tokebot(server, this)
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Max chat buffer message count
|
* Max chat buffer message count
|
||||||
|
|
@ -67,8 +73,15 @@ class chatHandler{
|
||||||
* @param {Socket} socket - Socket we're receiving the request from
|
* @param {Socket} socket - Socket we're receiving the request from
|
||||||
* @param {Object} data - Event payload
|
* @param {Object} data - Event payload
|
||||||
*/
|
*/
|
||||||
handleChat(socket, data){
|
async handleChat(socket, data){
|
||||||
this.commandPreprocessor.preprocess(socket, data);
|
//Preprocess chat data
|
||||||
|
const preprocessedChat = await this.chatPreprocessor.preprocess(socket, data);
|
||||||
|
|
||||||
|
//If send flag wasn't set to false
|
||||||
|
if(preprocessedChat != false){
|
||||||
|
//Send that shit!
|
||||||
|
this.relayUserChat(socket, preprocessedChat.message, preprocessedChat.chatType, preprocessedChat.links);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,36 +14,10 @@ GNU Affero General Public License for more details.
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//NPM Imports
|
|
||||||
const validator = require('validator');//No express here, so regular validator it is!
|
|
||||||
|
|
||||||
//Local Imports
|
//Local Imports
|
||||||
const chatPreprocessor = require('../chatPreprocessor');
|
|
||||||
const tokebot = require('./tokebot');
|
|
||||||
const linkUtils = require('../../utils/linkUtils');
|
|
||||||
const permissionModel = require('../../schemas/permissionSchema');
|
const permissionModel = require('../../schemas/permissionSchema');
|
||||||
const channelModel = require('../../schemas/channel/channelSchema');
|
const channelModel = require('../../schemas/channel/channelSchema');
|
||||||
|
|
||||||
/**
|
|
||||||
* Class containing global server-side chat/command pre-processing logic
|
|
||||||
*/
|
|
||||||
class commandPreprocessor extends chatPreprocessor{
|
|
||||||
/**
|
|
||||||
* Instantiates a commandPreprocessor object
|
|
||||||
* @param {channelManager} server - Parent Server Object
|
|
||||||
* @param {chatHandler} chatHandler - Parent Chat Handler Object
|
|
||||||
*/
|
|
||||||
constructor(server, chatHandler){
|
|
||||||
//Call derived constructor
|
|
||||||
super(
|
|
||||||
server,
|
|
||||||
chatHandler,
|
|
||||||
new commandProcessor(server, chatHandler),
|
|
||||||
new tokebot(server, chatHandler)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing global server-side chat/command processing logic
|
* Class representing global server-side chat/command processing logic
|
||||||
*/
|
*/
|
||||||
|
|
@ -317,4 +291,4 @@ class commandProcessor{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = commandPreprocessor;
|
module.exports = commandProcessor;
|
||||||
|
|
@ -27,19 +27,13 @@ class chatPreprocessor{
|
||||||
/**
|
/**
|
||||||
* Instantiates a commandPreprocessor object
|
* Instantiates a commandPreprocessor object
|
||||||
* @param {channelManager} server - Parent Server Object
|
* @param {channelManager} server - Parent Server Object
|
||||||
* @param {chatHandler} chatHandler - Parent Chat Handler Object
|
|
||||||
*/
|
*/
|
||||||
constructor(server, chatHandler, commandProcessor, tokebot){
|
constructor(server, commandProcessor, tokebot){
|
||||||
/**
|
/**
|
||||||
* Parent Server Object
|
* Parent Server Object
|
||||||
*/
|
*/
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
/**
|
|
||||||
* Parent Chat Handler Object
|
|
||||||
*/
|
|
||||||
this.chatHandler = chatHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child Command Processor Object. Contains functions named after commands.
|
* Child Command Processor Object. Contains functions named after commands.
|
||||||
*/
|
*/
|
||||||
|
|
@ -82,8 +76,10 @@ class chatPreprocessor{
|
||||||
await this.prepMessage(commandObj);
|
await this.prepMessage(commandObj);
|
||||||
|
|
||||||
//Send the chat
|
//Send the chat
|
||||||
this.sendChat(commandObj);
|
return commandObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -157,15 +153,6 @@ class chatPreprocessor{
|
||||||
//Validate links and mark them by embed type
|
//Validate links and mark them by embed type
|
||||||
await this.markLinks(commandObj);
|
await this.markLinks(commandObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Relays chat to channel via parent Chat Handler object
|
|
||||||
* @param {Object} commandObj - Object representing a single given command/chat request
|
|
||||||
*/
|
|
||||||
sendChat(commandObj){
|
|
||||||
//FUCKIN' SEND IT!
|
|
||||||
this.chatHandler.relayUserChat(commandObj.socket, commandObj.message, commandObj.chatType, commandObj.links);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = chatPreprocessor;
|
module.exports = chatPreprocessor;
|
||||||
|
|
@ -39,7 +39,7 @@ tokeCommandSchema.pre('save', async function (next){
|
||||||
//if the command was changed
|
//if the command was changed
|
||||||
if(this.isModified("command")){
|
if(this.isModified("command")){
|
||||||
//Get server tokebot object
|
//Get server tokebot object
|
||||||
const tokebot = server.channelManager.chatHandler.commandPreprocessor.tokebot;
|
const tokebot = server.channelManager.chatHandler.chatPreprocessor.tokebot;
|
||||||
|
|
||||||
//If tokebot is up and running
|
//If tokebot is up and running
|
||||||
if(tokebot != null && tokebot.tokeCommands != null){
|
if(tokebot != null && tokebot.tokeCommands != null){
|
||||||
|
|
@ -58,7 +58,7 @@ tokeCommandSchema.pre('save', async function (next){
|
||||||
*/
|
*/
|
||||||
tokeCommandSchema.pre('deleteOne', {document: true}, async function (next){
|
tokeCommandSchema.pre('deleteOne', {document: true}, async function (next){
|
||||||
//Get server tokebot object (isn't this a fun dot crawler? Why hasn't anyone asked me to stop writing software yet?)
|
//Get server tokebot object (isn't this a fun dot crawler? Why hasn't anyone asked me to stop writing software yet?)
|
||||||
const tokebot = server.channelManager.chatHandler.commandPreprocessor.tokebot;
|
const tokebot = server.channelManager.chatHandler.chatPreprocessor.tokebot;
|
||||||
|
|
||||||
//Get the index of the command within tokeCommand and splice it out
|
//Get the index of the command within tokeCommand and splice it out
|
||||||
tokebot.tokeCommands.splice(tokebot.tokeCommands.indexOf(this.command),1);
|
tokebot.tokeCommands.splice(tokebot.tokeCommands.indexOf(this.command),1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue