Add restart message
This commit is contained in:
parent
52efc7a746
commit
c287a232ea
|
@ -92,7 +92,7 @@ export class Channel extends EventEmitter {
|
||||||
if (this.alreadyBound) return;
|
if (this.alreadyBound) return;
|
||||||
this.alreadyBound = true;
|
this.alreadyBound = true;
|
||||||
this.loadChatHistory();
|
this.loadChatHistory();
|
||||||
this.logger.info("Loaded Chat History.");
|
this.logger.info("Loaded chat history");
|
||||||
|
|
||||||
this.on("update", () => {
|
this.on("update", () => {
|
||||||
//this.logger.debug("-------- UPDATE START --------");
|
//this.logger.debug("-------- UPDATE START --------");
|
||||||
|
|
|
@ -240,6 +240,10 @@ declare interface ServerEvents {
|
||||||
targetChannel?: string;
|
targetChannel?: string;
|
||||||
targetUser?: string;
|
targetUser?: string;
|
||||||
} & Notification;
|
} & Notification;
|
||||||
|
|
||||||
|
restart: {
|
||||||
|
m: "restart"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface ClientEvents {
|
declare interface ClientEvents {
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
import { readUser, updateUser } from "../../../../data/user";
|
|
||||||
import { ServerEventListener } from "../../../../util/types";
|
|
||||||
import { findSocketsByUserID } from "../../../Socket";
|
|
||||||
|
|
||||||
export const name: ServerEventListener<"name"> = {
|
|
||||||
id: "name",
|
|
||||||
callback: async (msg, socket) => {
|
|
||||||
// Change someone else's name but it's an annoying admin feature
|
|
||||||
const id = msg._id;
|
|
||||||
const name = msg.name;
|
|
||||||
|
|
||||||
if (typeof id !== "string") return;
|
|
||||||
if (typeof name !== "string") return;
|
|
||||||
|
|
||||||
const user = await readUser(msg._id);
|
|
||||||
if (!user) return;
|
|
||||||
|
|
||||||
user.name = name;
|
|
||||||
await updateUser(id, user);
|
|
||||||
|
|
||||||
const toUpdate = findSocketsByUserID(id);
|
|
||||||
toUpdate.forEach(s => {
|
|
||||||
s.userset(msg.name, undefined, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { readUser, updateUser } from "../../../../data/user";
|
||||||
|
import { ServerEventListener } from "../../../../util/types";
|
||||||
|
import { findSocketsByUserID, socketsBySocketID } from "../../../Socket";
|
||||||
|
|
||||||
|
let timeout: Timer;
|
||||||
|
|
||||||
|
export const restart: ServerEventListener<"restart"> = {
|
||||||
|
id: "restart",
|
||||||
|
callback: async (msg, socket) => {
|
||||||
|
// Restart server
|
||||||
|
if (typeof timeout !== "undefined") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let everyone know
|
||||||
|
for (const sock of socketsBySocketID.values()) {
|
||||||
|
sock.sendNotification({
|
||||||
|
id: "server-restart",
|
||||||
|
target: "#piano",
|
||||||
|
duration: 20000,
|
||||||
|
class: "classic",
|
||||||
|
title: "Server Restart",
|
||||||
|
text: "The server is restarting soon."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
// Stop the program
|
||||||
|
process.exit();
|
||||||
|
}, 20000);
|
||||||
|
}
|
||||||
|
};
|
|
@ -6,12 +6,13 @@ export const EVENT_GROUP_ADMIN = new EventGroup("admin");
|
||||||
import { color } from "./handlers/color";
|
import { color } from "./handlers/color";
|
||||||
import { name } from "./handlers/name";
|
import { name } from "./handlers/name";
|
||||||
import { notification } from "./handlers/notification";
|
import { notification } from "./handlers/notification";
|
||||||
|
import { restart } from "./handlers/restart";
|
||||||
import { user_flag } from "./handlers/user_flag";
|
import { user_flag } from "./handlers/user_flag";
|
||||||
|
|
||||||
// EVENT_GROUP_ADMIN.add(color);
|
// EVENT_GROUP_ADMIN.add(color);
|
||||||
// EVENT_GROUP_ADMIN.add(name);
|
// EVENT_GROUP_ADMIN.add(name);
|
||||||
// EVENT_GROUP_ADMIN.add(user_flag);
|
// EVENT_GROUP_ADMIN.add(user_flag);
|
||||||
|
|
||||||
EVENT_GROUP_ADMIN.addMany(color, name, user_flag, clear_chat, notification);
|
EVENT_GROUP_ADMIN.addMany(color, name, user_flag, clear_chat, notification, restart);
|
||||||
|
|
||||||
eventGroups.push(EVENT_GROUP_ADMIN);
|
eventGroups.push(EVENT_GROUP_ADMIN);
|
||||||
|
|
Loading…
Reference in New Issue