Created !ignore command to add users to blocklist, and supporting methods to get and set blocks (and their alts) from DB
This commit is contained in:
parent
286c08d231
commit
999fae91b7
2 changed files with 116 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
//Local Imports
|
//Local Imports
|
||||||
const permissionModel = require('../../schemas/permissionSchema');
|
const permissionModel = require('../../schemas/permissionSchema');
|
||||||
const channelModel = require('../../schemas/channel/channelSchema');
|
const channelModel = require('../../schemas/channel/channelSchema');
|
||||||
|
const {userModel} = require('../../schemas/user/userSchema');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing global server-side chat/command processing logic
|
* Class representing global server-side chat/command processing logic
|
||||||
|
|
@ -113,6 +114,28 @@ class commandProcessor{
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async ignore(commandObj){
|
||||||
|
//If we wherent given a user to ignore
|
||||||
|
if(commandObj.argumentArray[1] == null){
|
||||||
|
//Silently return
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Attempt to find user DB doc object
|
||||||
|
const userDB = await userModel.findOne({user: commandObj.socket.user.user});
|
||||||
|
|
||||||
|
//Prevent missing users
|
||||||
|
if(userDB == null){
|
||||||
|
throw loggerUtils.exceptionSmith("Called from invalid user", "validation");
|
||||||
|
}
|
||||||
|
|
||||||
|
//ignore user
|
||||||
|
await userDB.ignoreByUser(commandObj.argumentArray[1]);
|
||||||
|
|
||||||
|
//disable send flag
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command Processor method to handle the '!announce' command
|
* Command Processor method to handle the '!announce' command
|
||||||
* @param {Object} commandObj - Object representing a single given command/chat request
|
* @param {Object} commandObj - Object representing a single given command/chat request
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,10 @@ const userSchema = new mongoose.Schema({
|
||||||
type: mongoose.SchemaTypes.ObjectID,
|
type: mongoose.SchemaTypes.ObjectID,
|
||||||
ref: "user"
|
ref: "user"
|
||||||
}],
|
}],
|
||||||
|
ignored:[{
|
||||||
|
type: mongoose.SchemaTypes.ObjectID,
|
||||||
|
ref: "user",
|
||||||
|
}],
|
||||||
playlists: [playlistSchema]
|
playlists: [playlistSchema]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -662,6 +666,95 @@ userSchema.methods.deleteEmote = async function(name){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignores a given user by their username
|
||||||
|
* @param {Mongoose.Document} userDB - DB Document of user to ignore
|
||||||
|
*/
|
||||||
|
userSchema.methods.ignoreByUser = async function(user){
|
||||||
|
//Pull user doc from DB
|
||||||
|
const userDB = await this.constructor.findOne({user});
|
||||||
|
//Do a ignorem user by username
|
||||||
|
await this.ignoreByUserDoc(userDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignores a given user by their DB Document
|
||||||
|
* @param {Mongoose.Document} userDB - DB Document of user to ignore
|
||||||
|
*/
|
||||||
|
userSchema.methods.ignoreByUserDoc = async function(userDB){
|
||||||
|
//Prevent missing users
|
||||||
|
if(userDB == null){
|
||||||
|
throw loggerUtils.exceptionSmith("User not found", "validation");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.ignored.includes(userDB._id)){
|
||||||
|
throw loggerUtils.exceptionSmith("User already ignored", "validation");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Push user into ignored array
|
||||||
|
this.ignored.push(userDB._id);
|
||||||
|
|
||||||
|
//Save the DB document
|
||||||
|
await this.save();
|
||||||
|
|
||||||
|
console.log(await this.getIgnoredUsers());
|
||||||
|
}
|
||||||
|
|
||||||
|
userSchema.methods.getIgnoredUsers = async function(fetchAlts = true){
|
||||||
|
//Not me commiting ancient fucking sin
|
||||||
|
const _this = this;
|
||||||
|
|
||||||
|
//Populate all ignored users
|
||||||
|
await this.populate('ignored');
|
||||||
|
|
||||||
|
//If we're fetching alts
|
||||||
|
if(fetchAlts){
|
||||||
|
//Populate ignored users alts
|
||||||
|
await this.populate('ignored.alts');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create return object to hold list of DB ids and public user IDs/names
|
||||||
|
//Code using this method typically only need either/or, so seperating them from da get-go was the easiest option.
|
||||||
|
const ignored = {
|
||||||
|
_id: [],
|
||||||
|
user: []
|
||||||
|
}
|
||||||
|
|
||||||
|
//Iterate through all ignored users
|
||||||
|
for(const ignoredUser of this.ignored){
|
||||||
|
//Push user to ignored list
|
||||||
|
pushToList(ignoredUser);
|
||||||
|
|
||||||
|
//If we're fetching alts
|
||||||
|
if(fetchAlts){
|
||||||
|
//Iterate through ignored users alts
|
||||||
|
for(const ignoredAlt of ignoredUser.alts){
|
||||||
|
//Push alt to ignored list
|
||||||
|
pushToList(ignoredAlt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return list of ignored users
|
||||||
|
return ignored;
|
||||||
|
|
||||||
|
function pushToList(ignoredUser){
|
||||||
|
//If we haven't already added this user, and it isn't us
|
||||||
|
//ignoring our own alts seem silly at first, but remember 1 IP =/= one user.
|
||||||
|
//VPNs, CGNAT, and even household disagreements all happen in da real world.
|
||||||
|
if(!ignored._id.includes(ignoredUser._id) && !ignoredUser._id.equals(_this._id)){
|
||||||
|
//Push DB _id into list for server-side use
|
||||||
|
ignored._id.push(ignoredUser._id);
|
||||||
|
//Push ignored username/outward id combo for client usage
|
||||||
|
ignored.user.push({
|
||||||
|
user: ignoredUser.user,
|
||||||
|
id: ignoredUser.id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Salts, Hashes and Tattoo's IP address to user document in a privacy respecting manner
|
* Salts, Hashes and Tattoo's IP address to user document in a privacy respecting manner
|
||||||
* @param {String} ip - Plaintext IP Address to Salt, Hash and Tattoo
|
* @param {String} ip - Plaintext IP Address to Salt, Hash and Tattoo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue