Added channel-wide !announce command
This commit is contained in:
parent
0182c6927e
commit
375cdfb3d8
10 changed files with 78 additions and 17 deletions
|
|
@ -83,4 +83,9 @@ module.exports = class{
|
|||
const user = this.server.getSocketInfo(socket);
|
||||
this.server.io.in(socket.chan).emit("chatMessage", {user: user.user, flair: user.flair, highLevel: user.highLevel, msg, type});
|
||||
}
|
||||
|
||||
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"});
|
||||
}
|
||||
}
|
||||
|
|
@ -16,13 +16,17 @@ 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
|
||||
const channelModel = require('../../schemas/channel/channelSchema');
|
||||
|
||||
module.exports = class commandPreprocessor{
|
||||
constructor(server){
|
||||
this.server = server;
|
||||
this.commandProcessor = new commandProcessor(server, this);
|
||||
}
|
||||
|
||||
preprocess(socket, data){
|
||||
async preprocess(socket, data){
|
||||
//Set socket, data, and sendFlag
|
||||
this.socket = socket;
|
||||
this.sendFlag = true;
|
||||
|
|
@ -36,7 +40,7 @@ module.exports = class commandPreprocessor{
|
|||
//split the command
|
||||
this.splitCommand();
|
||||
//Process the command
|
||||
this.processServerCommand();
|
||||
await this.processServerCommand();
|
||||
//Send it as chat (assuming the flag isn't false)
|
||||
this.sendChat();
|
||||
}
|
||||
|
|
@ -60,15 +64,15 @@ module.exports = class commandPreprocessor{
|
|||
this.argumentArray = this.command.match(/\b\w+\b/g);//Match by words surrounded by borders
|
||||
}
|
||||
|
||||
processServerCommand(){
|
||||
//If the first word is '!'
|
||||
if(this.commandArray[0] == '!'){
|
||||
async processServerCommand(){
|
||||
//If the raw message starts with '!' (skip commands that start with whitespace so people can send example commands in chat)
|
||||
if(this.rawData.msg[0] == '!'){
|
||||
//if it isn't just an exclimation point, and we have a real command
|
||||
if(this.argumentArray != null && this.commandProcessor[this.argumentArray[0]] != null){
|
||||
if(this.argumentArray != null && this.commandProcessor[this.argumentArray[0].toLowerCase()] != null){
|
||||
//disable chat
|
||||
this.sendFlag = false;
|
||||
//Process the command
|
||||
this.commandProcessor[this.argumentArray[0]]();
|
||||
await this.commandProcessor[this.argumentArray[0].toLowerCase()]();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -89,12 +93,23 @@ class commandProcessor{
|
|||
}
|
||||
|
||||
whisper(){
|
||||
//Ensure we don't double dip
|
||||
this.sendFlag = false;
|
||||
|
||||
//splice out our whisper
|
||||
this.preprocessor.commandArray.splice(0,2);
|
||||
//send it
|
||||
this.server.chatHandler.relayChat(this.preprocessor.socket, this.preprocessor.commandArray.join(''), 'whisper');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async announce(){
|
||||
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, 'announce')))){
|
||||
//splice out our whisper
|
||||
this.preprocessor.commandArray.splice(0,2);
|
||||
//send it
|
||||
this.server.chatHandler.relayChannelAnnouncement(this.preprocessor.socket, this.preprocessor.commandArray.join(''));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue