Added !clear command
This commit is contained in:
parent
df18b4d783
commit
f8efe5b99e
|
|
@ -22,7 +22,7 @@ const {userModel} = require('../../schemas/userSchema');
|
||||||
module.exports = class{
|
module.exports = class{
|
||||||
constructor(server){
|
constructor(server){
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.commandPreprocessor = new commandPreprocessor(server)
|
this.commandPreprocessor = new commandPreprocessor(server, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
defineListeners(socket){
|
defineListeners(socket){
|
||||||
|
|
@ -89,8 +89,27 @@ module.exports = class{
|
||||||
this.server.io.emit("chatMessage", {user: "Server", flair: "", highLevel: 10, msg, type: "announcement"});
|
this.server.io.emit("chatMessage", {user: "Server", flair: "", highLevel: 10, msg, type: "announcement"});
|
||||||
}
|
}
|
||||||
|
|
||||||
relayChannelAnnouncement(socket, msg){
|
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 codebase is always at a 10
|
||||||
this.server.io.in(socket.chan).emit("chatMessage", {user: "Channel", flair: "", highLevel: 10, msg, type: "announcement"});
|
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});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,9 +22,10 @@ const permissionModel = require('../../schemas/permissionSchema');
|
||||||
const channelModel = require('../../schemas/channel/channelSchema');
|
const channelModel = require('../../schemas/channel/channelSchema');
|
||||||
|
|
||||||
module.exports = class commandPreprocessor{
|
module.exports = class commandPreprocessor{
|
||||||
constructor(server){
|
constructor(server, chatHandler){
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.commandProcessor = new commandProcessor(server, this);
|
this.chatHandler = chatHandler;
|
||||||
|
this.commandProcessor = new commandProcessor(server, this, chatHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
async preprocess(socket, data){
|
async preprocess(socket, data){
|
||||||
|
|
@ -82,27 +83,30 @@ module.exports = class commandPreprocessor{
|
||||||
//If the send flag is true
|
//If the send flag is true
|
||||||
if(this.sendFlag){
|
if(this.sendFlag){
|
||||||
//FUCKIN' SEND IT!
|
//FUCKIN' SEND IT!
|
||||||
this.server.chatHandler.relayChat(this.socket, this.commandArray.join('').trimStart());
|
this.chatHandler.relayChat(this.socket, this.commandArray.join('').trimStart());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class commandProcessor{
|
class commandProcessor{
|
||||||
constructor(server, preprocessor){
|
constructor(server, preprocessor, chatHandler){
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.preprocessor = preprocessor
|
this.preprocessor = preprocessor
|
||||||
|
this.chatHandler = chatHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Command keywords get run through .toLowerCase(), so we should use lowercase method names for command methods
|
||||||
whisper(){
|
whisper(){
|
||||||
//splice out our whisper
|
//splice out our whisper
|
||||||
this.preprocessor.commandArray.splice(0,2);
|
this.preprocessor.commandArray.splice(0,2);
|
||||||
//send it
|
//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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async announce(){
|
async announce(){
|
||||||
|
//Get the current channel from the database
|
||||||
const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan});
|
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)
|
//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
|
//splice out our whisper
|
||||||
this.preprocessor.commandArray.splice(0,2);
|
this.preprocessor.commandArray.splice(0,2);
|
||||||
//send it
|
//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
|
//splice out our whisper
|
||||||
this.preprocessor.commandArray.splice(0,2);
|
this.preprocessor.commandArray.splice(0,2);
|
||||||
//send it
|
//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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,6 +64,12 @@ const channelPermissionSchema = new mongoose.Schema({
|
||||||
default: "admin",
|
default: "admin",
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
clearChat: {
|
||||||
|
type: mongoose.SchemaTypes.String,
|
||||||
|
enum: rankEnum,
|
||||||
|
default: "admin",
|
||||||
|
required: true
|
||||||
|
},
|
||||||
deleteChannel: {
|
deleteChannel: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: mongoose.SchemaTypes.String,
|
||||||
enum: rankEnum,
|
enum: rankEnum,
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,12 @@ module.exports.channelPermissionValidator = {
|
||||||
options: module.exports.isRank
|
options: module.exports.isRank
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'channelPermissionsMap.clearChat': {
|
||||||
|
optional: true,
|
||||||
|
custom: {
|
||||||
|
options: module.exports.isRank
|
||||||
|
},
|
||||||
|
},
|
||||||
'channelPermissionsMap.deleteChannel': {
|
'channelPermissionsMap.deleteChannel': {
|
||||||
optional: true,
|
optional: true,
|
||||||
custom: {
|
custom: {
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,16 @@ a{
|
||||||
color: var(--accent0);
|
color: var(--accent0);
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover{
|
a:hover, i:hover{
|
||||||
color: var(--focus0-alt0);
|
color: var(--focus0-alt0);
|
||||||
text-shadow: var(--focus-glow0);
|
text-shadow: var(--focus-glow0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a:active, i:active{
|
||||||
|
color: var(--focus0-alt1);
|
||||||
|
box-shadow: var(--focus-glow0-alt0);
|
||||||
|
}
|
||||||
|
|
||||||
select{
|
select{
|
||||||
background-color: var(--bg2);
|
background-color: var(--bg2);
|
||||||
border-radius: 0.5em;
|
border-radius: 0.5em;
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,22 @@ class chatBox{
|
||||||
}
|
}
|
||||||
|
|
||||||
defineListeners(){
|
defineListeners(){
|
||||||
this.client.socket.on("chatMessage", (data) => {
|
this.client.socket.on("chatMessage", this.displayChat.bind(this));
|
||||||
this.displayChat(data);
|
this.client.socket.on("clearChat", this.clearChat.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
clearChat(data){
|
||||||
|
//If we where passed a user to check
|
||||||
|
if(data.user != null){
|
||||||
|
var clearedChats = document.querySelectorAll(`.chat-entry-${data.user}`);
|
||||||
|
}else{
|
||||||
|
var clearedChats = document.querySelectorAll('.chat-entry');
|
||||||
|
}
|
||||||
|
|
||||||
|
//For each chat found
|
||||||
|
clearedChats.forEach((chat) => {
|
||||||
|
//fuckin' nukem!
|
||||||
|
chat.remove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue