Latest dev sync
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
/**
|
||||
* @author Marzavec ( https://github.com/marzavec )
|
||||
* @summary Channel helper
|
||||
* @version 1.0.0
|
||||
* @description Functions to assist with channel manipulation
|
||||
* @module Channels
|
||||
*/
|
||||
|
||||
import {
|
||||
Errors,
|
||||
} from './_Constants';
|
||||
} from './_Constants.js';
|
||||
|
||||
/**
|
||||
* Checks if a client can join `channel`, returns numeric error code or true if
|
||||
@@ -10,12 +18,13 @@ import {
|
||||
* @param {object} socket Target client to evaluate
|
||||
* @return {boolean||error id}
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export function canJoinChannel(channel, socket) {
|
||||
if (typeof channel !== 'string') return Errors.Channel.INVALID_NAME;
|
||||
if (channel === '') return Errors.Channel.INVALID_NAME;
|
||||
if (channel.length > 120) return Errors.Channel.INVALID_LENGTH;
|
||||
|
||||
if (typeof socket.banned !== 'undefined' && socket.banned) return Errors.Channel.DEY_BANNED;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,9 +37,9 @@ export function canJoinChannel(channel, socket) {
|
||||
* @return {object}
|
||||
*/
|
||||
export function getChannelSettings(config, channel) {
|
||||
if (typeof config.channels !== 'undefined') {
|
||||
if (typeof config.channels[channel] !== 'undefined') {
|
||||
return config.channels[channel];
|
||||
if (typeof config.permissions !== 'undefined') {
|
||||
if (typeof config.permissions[channel] !== 'undefined') {
|
||||
return config.permissions[channel];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,3 +92,17 @@ export function findUsers(server, payload, limit = 0) {
|
||||
export function findUser(server, payload) {
|
||||
return findUsers(server, payload, 1)[0] || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the target socket's userid is already in target channel
|
||||
* @param {MainServer} server Main server reference
|
||||
* @param {string} channel Target channel
|
||||
* @param {object} socket Target client to evaluate
|
||||
* @return {boolean||object}
|
||||
*/
|
||||
export function socketInChannel(server, channel, socket) {
|
||||
return findUser(server, {
|
||||
channel,
|
||||
userid: socket.userid,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user