Critical Hotfix for !announce and !serverannounce

This commit is contained in:
rainbow napkin 2025-04-26 09:48:02 -04:00
parent bddbb3a4a3
commit eadfa7c126

View file

@ -22,6 +22,7 @@ const tokebot = require('./tokebot');
const linkUtils = require('../../utils/linkUtils');
const permissionModel = require('../../schemas/permissionSchema');
const channelModel = require('../../schemas/channel/channelSchema');
const { command } = require('../../validators/tokebotValidator');
module.exports = class commandPreprocessor{
constructor(server, chatHandler){
@ -82,7 +83,7 @@ module.exports = class commandPreprocessor{
if(commandObj.argumentArray != null){
if(this.commandProcessor[commandObj.argumentArray[0].toLowerCase()] != null){
//Process the command and use the return value to set the sendflag (true if command valid)
commandObj.sendFlag = await this.commandProcessor[commandObj.argumentArray[0].toLowerCase()](commandObj);
commandObj.sendFlag = await this.commandProcessor[commandObj.argumentArray[0].toLowerCase()](commandObj, this);
}else{
//Process as toke command if we didnt get a match from the standard server-side command processor
commandObj.sendFlag = await this.tokebot.tokeProcessor(commandObj);
@ -123,75 +124,75 @@ class commandProcessor{
}
//Command keywords get run through .toLowerCase(), so we should use lowercase method names for command methods
whisper(preprocessor){
whisper(commandObj){
//splice out our command
preprocessor.commandArray.splice(0,2);
commandObj.commandArray.splice(0,2);
//Mark out the current message as a whisper
preprocessor.chatType = 'whisper';
commandObj.chatType = 'whisper';
//Make sure to throw the send flag
return true
}
spoiler(preprocessor){
spoiler(commandObj){
//splice out our command
preprocessor.commandArray.splice(0,2);
commandObj.commandArray.splice(0,2);
//Mark out the current message as a spoiler
preprocessor.chatType = 'spoiler';
commandObj.chatType = 'spoiler';
//Make sure to throw the send flag
return true
}
strikethrough(preprocessor){
strikethrough(commandObj){
//splice out our command
preprocessor.commandArray.splice(0,2);
commandObj.commandArray.splice(0,2);
//Mark out the current message as a spoiler
preprocessor.chatType = 'strikethrough';
commandObj.chatType = 'strikethrough';
//Make sure to throw the send flag
return true
}
bold(preprocessor){
bold(commandObj){
//splice out our command
preprocessor.commandArray.splice(0,2);
commandObj.commandArray.splice(0,2);
//Mark out the current message as a spoiler
preprocessor.chatType = 'bold';
commandObj.chatType = 'bold';
//Make sure to throw the send flag
return true
}
italics(preprocessor){
italics(commandObj){
//splice out our command
preprocessor.commandArray.splice(0,2);
commandObj.commandArray.splice(0,2);
//Mark out the current message as a spoiler
preprocessor.chatType = 'italics';
commandObj.chatType = 'italics';
//Make sure to throw the send flag
return true
}
async announce(preprocessor){
async announce(commandObj, preprocessor){
//Get the current channel from the database
const chanDB = await channelModel.findOne({name: preprocessor.socket.chan});
const chanDB = await channelModel.findOne({name: commandObj.socket.chan});
//Check if the user has permission, and publicly shame them if they don't (lmao)
if(chanDB != null && await chanDB.permCheck(preprocessor.socket.user, 'announce')){
if(chanDB != null && await chanDB.permCheck(commandObj.socket.user, 'announce')){
//splice out our command
preprocessor.commandArray.splice(0,2);
commandObj.commandArray.splice(0,2);
//Prep the message using pre-processor functions chat-handling
await preprocessor.prepMessage();
await preprocessor.prepMessage(commandObj);
//send it
this.chatHandler.relayChannelAnnouncement(preprocessor.socket.chan, preprocessor.message, preprocessor.links);
this.chatHandler.relayChannelAnnouncement(commandObj.socket.chan, commandObj.message, commandObj.links);
//throw send flag
return false;
@ -201,17 +202,17 @@ class commandProcessor{
return true;
}
async serverannounce(preprocessor){
async serverannounce(commandObj, preprocessor){
//Check if the user has permission, and publicly shame them if they don't (lmao)
if(await permissionModel.permCheck(preprocessor.socket.user, 'announce')){
if(await permissionModel.permCheck(commandObj.socket.user, 'announce')){
//splice out our command
preprocessor.commandArray.splice(0,2);
commandObj.commandArray.splice(0,2);
//Prep the message using pre-processor functions for chat-handling
await preprocessor.prepMessage();
await preprocessor.prepMessage(commandObj);
//send it
this.chatHandler.relayServerAnnouncement(preprocessor.message, preprocessor.links);
this.chatHandler.relayServerAnnouncement(commandObj.message, commandObj.links);
//throw send flag
return false;
@ -221,14 +222,14 @@ class commandProcessor{
return true;
}
async clear(preprocessor){
async clear(commandObj){
//Get the current channel from the database
const chanDB = await channelModel.findOne({name: preprocessor.socket.chan});
const chanDB = await channelModel.findOne({name: commandObj.socket.chan});
//Check if the user has permission, and publicly shame them if they don't (lmao)
if(await chanDB.permCheck(preprocessor.socket.user, 'clearChat')){
if(await chanDB.permCheck(commandObj.socket.user, 'clearChat')){
//Send off the command
this.chatHandler.clearChat(preprocessor.socket.chan, preprocessor.argumentArray[1]);
this.chatHandler.clearChat(commandObj.socket.chan, commandObj.argumentArray[1]);
//throw send flag
return false;
}
@ -237,24 +238,24 @@ class commandProcessor{
return true;
}
async kick(preprocessor){
async kick(commandObj){
//Get the current channel from the database
const chanDB = await channelModel.findOne({name: preprocessor.socket.chan});
const chanDB = await channelModel.findOne({name: commandObj.socket.chan});
//Check if the user has permission, and publicly shame them if they don't (lmao)
if(await chanDB.permCheck(preprocessor.socket.user, 'kickUser')){
if(await chanDB.permCheck(commandObj.socket.user, 'kickUser')){
//Get username from argument array
const username = preprocessor.argumentArray[1];
const username = commandObj.argumentArray[1];
//Get channel
const channel = this.server.activeChannels.get(preprocessor.socket.chan);
const channel = this.server.activeChannels.get(commandObj.socket.chan);
//get initiator and target user objects
const initiator = channel.userList.get(preprocessor.socket.user.user);
const initiator = channel.userList.get(commandObj.socket.user.user);
const target = channel.userList.get(username);
//get initiator and target override abilities
const override = await permissionModel.overrideCheck(preprocessor.socket.user, 'kickUser');
const override = await permissionModel.overrideCheck(commandObj.socket.user, 'kickUser');
const targetOverride = await permissionModel.overrideCheck(target, 'kickUser');
//If there is no user
@ -291,10 +292,10 @@ class commandProcessor{
//Splice out kick
preprocessor.commandArray.splice(0,4)
commandObj.commandArray.splice(0,4)
//Get collect reason
var reason = preprocessor.commandArray.join('');
var reason = commandObj.commandArray.join('');
//If no reason was given
if(reason == ''){