This commit is contained in:
Aslan 2025-12-28 18:06:07 +01:00
parent 05875413f9
commit 00211a604f
3 changed files with 9 additions and 4 deletions

View file

@ -69,7 +69,11 @@ const getUserName = (user: IUser): string => {
return match.replaceAll("@", ""); return match.replaceAll("@", "");
}; };
const getUserFromMention = (mention: string): IUser | undefined => { const getUserFromMention = (mention: string | undefined): IUser | undefined => {
if (!mention) {
return undefined;
}
const regex = /\[\@\S*:aslan2142.space\]/; const regex = /\[\@\S*:aslan2142.space\]/;
const match = mention const match = mention
.match(regex) .match(regex)

View file

@ -3,6 +3,7 @@ import type { ICallbackStore } from "../types.js";
import { config } from "../../config.js"; import { config } from "../../config.js";
import { load, save, state } from "../../store/store.js"; import { load, save, state } from "../../store/store.js";
import type { TRole } from "../../store/types.js"; import type { TRole } from "../../store/types.js";
import { getUserFromMention } from "../../helpers.js";
let client: MatrixClient; let client: MatrixClient;
@ -36,9 +37,9 @@ const registerModuleAdmin = (
const onSetRole = async (text: string, roomId: string) => { const onSetRole = async (text: string, roomId: string) => {
const words = text.split(" "); const words = text.split(" ");
const userId = words[1]; const mention = words[1];
const role = words[2] as TRole; const role = words[2] as TRole;
const user = state.users.find((user) => user.id === userId); const user = getUserFromMention(mention);
if (!user || !role) { if (!user || !role) {
return; return;

View file

@ -41,7 +41,7 @@ const onAI = async (text: string, roomId: string, sender: string) => {
alts: alts, alts: alts,
} as IAdminInstructions; } as IAdminInstructions;
textMod = `Admin Instructions:\n${instructions}\nPrompt:\n${textMod}`; textMod = `Admin Instructions:\n${JSON.stringify(instructions)}\nPrompt:\n${textMod}`;
const responseAI = await getTextGemini(textMod); const responseAI = await getTextGemini(textMod);