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,7 +22,7 @@ const {userModel} = require('../../schemas/userSchema');
module.exports = class{
constructor(server){
this.server = server;
this.commandPreprocessor = new commandPreprocessor(server)
this.commandPreprocessor = new commandPreprocessor(server, this)
}
defineListeners(socket){
@ -89,8 +89,27 @@ module.exports = class{
this.server.io.emit("chatMessage", {user: "Server", flair: "", highLevel: 10, msg, type: "announcement"});
}
relayChannelAnnouncement(socket, msg){
//This codebase is always at a 10
this.server.io.in(socket.chan).emit("chatMessage", {user: "Channel", flair: "", highLevel: 10, msg, type: "announcement"});
relayChannelAnnouncement(chan, msg){
const activeChan = this.server.activeChannels.get(chan);
//If channel isn't null
if(activeChan != null){
//This codebase is always at a 10
this.server.io.in(chan).emit("chatMessage", {user: "Channel", flair: "", highLevel: 10, msg, type: "announcement"});
}
}
clearChat(chan, user){
const activeChan = this.server.activeChannels.get(chan);
//If channel isn't null
if(activeChan != null){
const target = activeChan.userList.get(user);
//If no user was entered OR the user was found
if(user == null || target != null){
this.server.io.in(chan).emit("clearChat", {user});
}
}
}
}

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]);
}
}
}

View file

@ -64,6 +64,12 @@ const channelPermissionSchema = new mongoose.Schema({
default: "admin",
required: true
},
clearChat: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,
default: "admin",
required: true
},
deleteChannel: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,

View file

@ -123,6 +123,12 @@ module.exports.channelPermissionValidator = {
options: module.exports.isRank
},
},
'channelPermissionsMap.clearChat': {
optional: true,
custom: {
options: module.exports.isRank
},
},
'channelPermissionsMap.deleteChannel': {
optional: true,
custom: {