Add admin eval message (disabled by default)
This commit is contained in:
parent
08e0d55f60
commit
1cd456066f
|
@ -5,6 +5,7 @@ enableColorChanging: false
|
|||
enableCustomNoteData: true
|
||||
adminParticipant:
|
||||
_id: "0"
|
||||
name: "mpp"
|
||||
name: mpp
|
||||
color: "#fff"
|
||||
id: "0"
|
||||
enableAdminEval: false
|
||||
|
|
|
@ -284,6 +284,11 @@ declare interface ServerEvents {
|
|||
_id?: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
eval: {
|
||||
m: "eval";
|
||||
str: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare interface ClientEvents {
|
||||
|
|
|
@ -704,6 +704,15 @@ export class Socket extends EventEmitter {
|
|||
user.tag = JSON.stringify({ text, color });
|
||||
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>();
|
||||
|
|
|
@ -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");
|
||||
|
||||
import { color } from "./handlers/color";
|
||||
import { eval_msg } from "./handlers/eval";
|
||||
import { move } from "./handlers/move";
|
||||
import { name } from "./handlers/name";
|
||||
import { notification } from "./handlers/notification";
|
||||
|
@ -25,7 +26,8 @@ EVENT_GROUP_ADMIN.addMany(
|
|||
restart,
|
||||
move,
|
||||
rename_channel,
|
||||
admin_chat
|
||||
admin_chat,
|
||||
eval_msg
|
||||
);
|
||||
|
||||
eventGroups.push(EVENT_GROUP_ADMIN);
|
||||
|
|
|
@ -7,6 +7,7 @@ export interface UsersConfig {
|
|||
enableColorChanging: boolean;
|
||||
enableCustomNoteData: boolean;
|
||||
adminParticipant: Participant;
|
||||
enableAdminEval: boolean;
|
||||
}
|
||||
|
||||
export const usersConfigPath = "config/users.yml";
|
||||
|
@ -23,7 +24,8 @@ export const defaultUsersConfig: UsersConfig = {
|
|||
name: "mpp",
|
||||
color: "#fff",
|
||||
id: "0"
|
||||
}
|
||||
},
|
||||
enableAdminEval: false
|
||||
};
|
||||
|
||||
// Importing this elsewhere causes bun to segfault
|
||||
|
|
Loading…
Reference in New Issue