mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
added socket.flare
Each of the top level are given their own flair emoji which is applied to the socket on join or other events. May also add a module allowing users to set their own utf emoji, such as: /flair 🍆
This commit is contained in:
parent
4c1708b2d2
commit
dc841cb25e
|
@ -566,8 +566,8 @@ function pushMessage(args) {
|
|||
if (args.trip) {
|
||||
var tripEl = document.createElement('span');
|
||||
|
||||
if (args.mod) {
|
||||
tripEl.textContent = String.fromCodePoint(11088) + " " + args.trip + " ";
|
||||
if (args.flair) {
|
||||
tripEl.textContent = args.flair + " " + args.trip + " ";
|
||||
} else {
|
||||
tripEl.textContent = args.trip + " ";
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
isModerator,
|
||||
getUserDetails,
|
||||
levels,
|
||||
getAppearance,
|
||||
} from '../utility/_UAC.js';
|
||||
import {
|
||||
Errors,
|
||||
|
@ -140,6 +141,9 @@ export function chatHook({
|
|||
channel: socket.channel,
|
||||
}, { channel: socket.channel });
|
||||
|
||||
const { color, flair } = getAppearance(levels.channelOwner);
|
||||
socket.color = color;
|
||||
socket.flair = flair;
|
||||
socket.level = levels.channelOwner;
|
||||
|
||||
const updateNotice = {
|
||||
|
|
|
@ -87,7 +87,11 @@ export async function run({
|
|||
trip: payload.trip,
|
||||
});
|
||||
|
||||
const { color, flair } = getAppearance(newLevel);
|
||||
|
||||
for (let i = 0, j = targetClients.length; i < j; i += 1) {
|
||||
targetClients[i].color = color;
|
||||
targetClients[i].flair = flair;
|
||||
targetClients[i].level = newLevel;
|
||||
|
||||
server.broadcast({
|
||||
|
|
|
@ -121,6 +121,7 @@ export async function run({
|
|||
channel: socket.channel,
|
||||
text,
|
||||
level: socket.level,
|
||||
flair: socket.flair,
|
||||
customId,
|
||||
};
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import {
|
|||
getUserPerms,
|
||||
getUserDetails,
|
||||
isModerator,
|
||||
getAppearance,
|
||||
} from '../utility/_UAC.js';
|
||||
|
||||
/**
|
||||
|
@ -106,6 +107,10 @@ export async function run({
|
|||
}, socket);
|
||||
}
|
||||
|
||||
const { color, flair } = getAppearance(level);
|
||||
socket.color = color;
|
||||
socket.flair = flair;
|
||||
|
||||
// store the user values
|
||||
const userInfo = {
|
||||
nick,
|
||||
|
@ -115,7 +120,8 @@ export async function run({
|
|||
level,
|
||||
userid: socket.userid,
|
||||
isBot: socket.isBot,
|
||||
color: socket.color,
|
||||
color,
|
||||
flair,
|
||||
channel,
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,26 @@ import {
|
|||
getChannelSettings,
|
||||
} from './_Channels.js';
|
||||
|
||||
/**
|
||||
* Returns random rgb code
|
||||
* @return {string}
|
||||
*/
|
||||
const randomRGB = () => {
|
||||
const saturation = 0.80;
|
||||
const lightness = 0.65;
|
||||
const hue = Math.floor(Math.random() * 360);
|
||||
|
||||
const k = (n) => (n + hue / 30) % 12;
|
||||
const a = saturation * Math.min(lightness, 1 - lightness);
|
||||
const f = (n) => lightness - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
||||
|
||||
const r = `${Math.floor(255 * f(0)).toString(16)}`;
|
||||
const g = `${Math.floor(255 * f(8)).toString(16)}`;
|
||||
const b = `${Math.floor(255 * f(4)).toString(16)}`;
|
||||
|
||||
return `${r}${g}${b}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Object defining labels for default permission ranges
|
||||
* @typedef {Object} levels
|
||||
|
@ -37,6 +57,35 @@ export const levels = {
|
|||
|
||||
trustedUser: 500,
|
||||
default: 100,
|
||||
bot: 99,
|
||||
};
|
||||
|
||||
/**
|
||||
* Object defining labels for default permission ranges
|
||||
* @typedef {Object} levelAppearance
|
||||
* @property {number} admin Global administrator range
|
||||
*/
|
||||
export const levelAppearance = {
|
||||
[levels.admin]: {
|
||||
color: 'd73737',
|
||||
flair: String.fromCodePoint(127775), // 🌟
|
||||
},
|
||||
[levels.moderator]: {
|
||||
color: '1fad83',
|
||||
flair: String.fromCodePoint(11088), // ⭐
|
||||
},
|
||||
[levels.channelOwner]: {
|
||||
color: 'dd8800',
|
||||
flair: String.fromCodePoint(128081), // 👑
|
||||
},
|
||||
[levels.channelModerator]: {
|
||||
color: '2fa1ee',
|
||||
flair: String.fromCodePoint(128171), // 💫
|
||||
},
|
||||
[levels.bot]: {
|
||||
color: '2fa1ee',
|
||||
flair: String.fromCodePoint(129302), // 🤖
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -115,6 +164,7 @@ export function getUserDetails(socket) {
|
|||
userid: socket.userid,
|
||||
isBot: socket.isBot,
|
||||
color: socket.color,
|
||||
flair: socket.flair,
|
||||
online: true,
|
||||
};
|
||||
}
|
||||
|
@ -131,6 +181,24 @@ export function verifyNickname(nick) {
|
|||
return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with 'color' and 'flair' properties
|
||||
* associated by level
|
||||
* @public
|
||||
* @param {number} level Provided level
|
||||
* @return {object}
|
||||
*/
|
||||
export function getAppearance(level) {
|
||||
if (typeof levelAppearance[level] !== 'undefined') {
|
||||
return levelAppearance[level];
|
||||
}
|
||||
|
||||
return {
|
||||
color: randomRGB(),
|
||||
flair: false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes a user's password, returning a trip code
|
||||
* or a blank string
|
||||
|
|
Loading…
Reference in New Issue
Block a user