Added !clear command

This commit is contained in:
rainbow napkin 2024-12-10 18:51:21 -05:00
parent df18b4d783
commit f8efe5b99e
6 changed files with 79 additions and 14 deletions

View file

@ -22,9 +22,10 @@ const permissionModel = require('../../schemas/permissionSchema');
const channelModel = require('../../schemas/channel/channelSchema');
module.exports = class commandPreprocessor{
constructor(server){
constructor(server, chatHandler){
this.server = server;
this.commandProcessor = new commandProcessor(server, this);
this.chatHandler = chatHandler;
this.commandProcessor = new commandProcessor(server, this, chatHandler);
}
async preprocess(socket, data){
@ -82,27 +83,30 @@ module.exports = class commandPreprocessor{
//If the send flag is true
if(this.sendFlag){
//FUCKIN' SEND IT!
this.server.chatHandler.relayChat(this.socket, this.commandArray.join('').trimStart());
this.chatHandler.relayChat(this.socket, this.commandArray.join('').trimStart());
}
}
}
class commandProcessor{
constructor(server, preprocessor){
constructor(server, preprocessor, chatHandler){
this.server = server;
this.preprocessor = preprocessor
this.chatHandler = chatHandler;
}
//Command keywords get run through .toLowerCase(), so we should use lowercase method names for command methods
whisper(){
//splice out our whisper
this.preprocessor.commandArray.splice(0,2);
//send it
this.server.chatHandler.relayChat(this.preprocessor.socket, this.preprocessor.commandArray.join(''), 'whisper');
this.chatHandler.relayChat(this.preprocessor.socket, this.preprocessor.commandArray.join(''), 'whisper');
return;
}
async announce(){
//Get the current channel from the database
const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan});
//Check if the user has permission, and publicly shame them if they don't (lmao)
@ -110,7 +114,7 @@ class commandProcessor{
//splice out our whisper
this.preprocessor.commandArray.splice(0,2);
//send it
this.server.chatHandler.relayChannelAnnouncement(this.preprocessor.socket, this.preprocessor.commandArray.join(''));
this.chatHandler.relayChannelAnnouncement(this.preprocessor.socket.chan, this.preprocessor.commandArray.join(''));
}
}
@ -120,7 +124,18 @@ class commandProcessor{
//splice out our whisper
this.preprocessor.commandArray.splice(0,2);
//send it
this.server.chatHandler.relayServerAnnouncement(this.preprocessor.commandArray.join(''));
this.chatHandler.relayServerAnnouncement(this.preprocessor.commandArray.join(''));
}
}
async clear(){
//Get the current channel from the database
const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan});
//Check if the user has permission, and publicly shame them if they don't (lmao)
if(!(this.preprocessor.sendFlag = !(await chanDB.permCheck(this.preprocessor.socket.user, 'clearChat')))){
//Send off the command
this.chatHandler.clearChat(this.preprocessor.socket.chan, this.preprocessor.argumentArray[1]);
}
}
}