Add setrole command
This commit is contained in:
parent
52916c4432
commit
735847bb63
4 changed files with 32 additions and 13 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import { MatrixClient } from "matrix-js-sdk";
|
||||
import type { ICallbackStore } from "../types.js";
|
||||
import { config } from "../../config.js";
|
||||
import { load, save } from "../../store/store.js";
|
||||
import { load, save, state } from "../../store/store.js";
|
||||
import type { TRole } from "../../store/types.js";
|
||||
|
||||
let client: MatrixClient;
|
||||
|
||||
|
|
@ -11,6 +12,11 @@ const registerModuleAdmin = (
|
|||
) => {
|
||||
client = matrixClient;
|
||||
|
||||
callbackStore.messageCallbacks.push({
|
||||
startConditions: [`${config.app.triggerPrefix}setrole`],
|
||||
allowedRoles: ["ADMIN"],
|
||||
callbackFunc: onSetRole,
|
||||
});
|
||||
callbackStore.messageCallbacks.push({
|
||||
startConditions: [`${config.app.triggerPrefix}shutdown`],
|
||||
allowedRoles: ["ADMIN"],
|
||||
|
|
@ -28,25 +34,38 @@ const registerModuleAdmin = (
|
|||
});
|
||||
};
|
||||
|
||||
const onShutdown = (text: string, roomId: string) => {
|
||||
const onSetRole = async (text: string, roomId: string) => {
|
||||
const words = text.split(" ");
|
||||
const userId = words[1];
|
||||
const role = words[2] as TRole;
|
||||
const user = state.users.find((user) => user.id === userId);
|
||||
|
||||
if (!user || !role) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.role = role;
|
||||
|
||||
client.sendTextMessage(roomId, `Role for ${user} has been set to ${role}`);
|
||||
};
|
||||
|
||||
const onShutdown = async (text: string, roomId: string) => {
|
||||
if (!text.includes("nosave")) {
|
||||
client.sendTextMessage(roomId, "Saving data...");
|
||||
await client.sendTextMessage(roomId, "Saving data...");
|
||||
save();
|
||||
}
|
||||
|
||||
const sendPromise = client.sendTextMessage(roomId, "Shutting down...");
|
||||
sendPromise.finally(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
await client.sendTextMessage(roomId, "Shutting down...");
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
const onLoadData = (_text: string, roomId: string) => {
|
||||
client.sendTextMessage(roomId, "Loading data...");
|
||||
const onLoadData = async (_text: string, roomId: string) => {
|
||||
await client.sendTextMessage(roomId, "Loading data...");
|
||||
load();
|
||||
};
|
||||
|
||||
const onSaveData = (_text: string, roomId: string) => {
|
||||
client.sendTextMessage(roomId, "Saving data...");
|
||||
const onSaveData = async (_text: string, roomId: string) => {
|
||||
await client.sendTextMessage(roomId, "Saving data...");
|
||||
save();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue