Add admin eval message (disabled by default)
This commit is contained in:
parent
08e0d55f60
commit
1cd456066f
|
@ -5,6 +5,7 @@ enableColorChanging: false
|
||||||
enableCustomNoteData: true
|
enableCustomNoteData: true
|
||||||
adminParticipant:
|
adminParticipant:
|
||||||
_id: "0"
|
_id: "0"
|
||||||
name: "mpp"
|
name: mpp
|
||||||
color: "#fff"
|
color: "#fff"
|
||||||
id: "0"
|
id: "0"
|
||||||
|
enableAdminEval: false
|
||||||
|
|
|
@ -284,6 +284,11 @@ declare interface ServerEvents {
|
||||||
_id?: string;
|
_id?: string;
|
||||||
message: string;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eval: {
|
||||||
|
m: "eval";
|
||||||
|
str: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface ClientEvents {
|
declare interface ClientEvents {
|
||||||
|
|
|
@ -704,6 +704,15 @@ export class Socket extends EventEmitter {
|
||||||
user.tag = JSON.stringify({ text, color });
|
user.tag = JSON.stringify({ text, color });
|
||||||
updateUser(this.getUserID(), user);
|
updateUser(this.getUserID(), user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public eval(str: string) {
|
||||||
|
try {
|
||||||
|
const output = eval(str);
|
||||||
|
logger.info(output);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const socketsBySocketID = new Map<string, Socket>();
|
export const socketsBySocketID = new Map<string, Socket>();
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { ChannelList } from "../../../../channel/ChannelList";
|
||||||
|
import { readUser, updateUser } from "../../../../data/user";
|
||||||
|
import { ServerEventListener } from "../../../../util/types";
|
||||||
|
import { findSocketsByUserID } from "../../../Socket";
|
||||||
|
import { config } from "../../../usersConfig";
|
||||||
|
|
||||||
|
export const eval_msg: ServerEventListener<"eval"> = {
|
||||||
|
id: "eval",
|
||||||
|
callback: async (msg, socket) => {
|
||||||
|
// Evaluate a JavaScript expression
|
||||||
|
if (!config.enableAdminEval) return;
|
||||||
|
if (typeof msg.str !== "string") return;
|
||||||
|
socket.eval(msg.str);
|
||||||
|
}
|
||||||
|
};
|
|
@ -5,6 +5,7 @@ import { clear_chat } from "./handlers/clear_chat";
|
||||||
export const EVENT_GROUP_ADMIN = new EventGroup("admin");
|
export const EVENT_GROUP_ADMIN = new EventGroup("admin");
|
||||||
|
|
||||||
import { color } from "./handlers/color";
|
import { color } from "./handlers/color";
|
||||||
|
import { eval_msg } from "./handlers/eval";
|
||||||
import { move } from "./handlers/move";
|
import { move } from "./handlers/move";
|
||||||
import { name } from "./handlers/name";
|
import { name } from "./handlers/name";
|
||||||
import { notification } from "./handlers/notification";
|
import { notification } from "./handlers/notification";
|
||||||
|
@ -25,7 +26,8 @@ EVENT_GROUP_ADMIN.addMany(
|
||||||
restart,
|
restart,
|
||||||
move,
|
move,
|
||||||
rename_channel,
|
rename_channel,
|
||||||
admin_chat
|
admin_chat,
|
||||||
|
eval_msg
|
||||||
);
|
);
|
||||||
|
|
||||||
eventGroups.push(EVENT_GROUP_ADMIN);
|
eventGroups.push(EVENT_GROUP_ADMIN);
|
||||||
|
|
|
@ -7,6 +7,7 @@ export interface UsersConfig {
|
||||||
enableColorChanging: boolean;
|
enableColorChanging: boolean;
|
||||||
enableCustomNoteData: boolean;
|
enableCustomNoteData: boolean;
|
||||||
adminParticipant: Participant;
|
adminParticipant: Participant;
|
||||||
|
enableAdminEval: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const usersConfigPath = "config/users.yml";
|
export const usersConfigPath = "config/users.yml";
|
||||||
|
@ -23,7 +24,8 @@ export const defaultUsersConfig: UsersConfig = {
|
||||||
name: "mpp",
|
name: "mpp",
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
id: "0"
|
id: "0"
|
||||||
}
|
},
|
||||||
|
enableAdminEval: false
|
||||||
};
|
};
|
||||||
|
|
||||||
// Importing this elsewhere causes bun to segfault
|
// Importing this elsewhere causes bun to segfault
|
||||||
|
|
Loading…
Reference in New Issue