Implement color admin message

This commit is contained in:
Hri7566 2024-01-26 05:02:32 -05:00
parent ee391cb250
commit 2b8ab0ddca
2 changed files with 25 additions and 3 deletions

View File

@ -335,11 +335,15 @@ export class Socket extends EventEmitter {
]); ]);
} }
public async userset(name?: string, color?: string) { public async userset(
name?: string,
color?: string,
admin: boolean = false
) {
let isColor = false; let isColor = false;
// Color changing // Color changing
if (color && config.enableColorChanging) { if (color && (config.enableColorChanging || admin)) {
isColor = isColor =
typeof color === "string" && !!color.match(/^#[0-9a-f]{6}$/i); typeof color === "string" && !!color.match(/^#[0-9a-f]{6}$/i);
} }

View File

@ -1,9 +1,27 @@
import { readUser, updateUser } from "../../../../data/user";
import { ServerEventListener } from "../../../../util/types"; import { ServerEventListener } from "../../../../util/types";
import { findSocketsByUserID } from "../../../Socket";
import { eventGroups } from "../../../events"; import { eventGroups } from "../../../events";
export const color: ServerEventListener<"color"> = { export const color: ServerEventListener<"color"> = {
id: "color", id: "color",
callback: (msg, socket) => { callback: async (msg, socket) => {
// TODO color // TODO color
const id = msg._id;
const color = msg.color;
if (typeof id !== "string") return;
if (typeof color !== "string") return;
const user = await readUser(msg._id);
if (!user) return;
user.color = color;
await updateUser(id, user);
const toUpdate = findSocketsByUserID(id);
toUpdate.forEach(s => {
s.userset(undefined, msg.color);
});
} }
}; };