diff --git a/src/helpers.ts b/src/helpers.ts index d09d7f6..8724a8f 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -69,7 +69,11 @@ const getUserName = (user: IUser): string => { 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 match = mention .match(regex) diff --git a/src/modules/admin/admin.ts b/src/modules/admin/admin.ts index af3a673..2fefee4 100644 --- a/src/modules/admin/admin.ts +++ b/src/modules/admin/admin.ts @@ -3,6 +3,7 @@ import type { ICallbackStore } from "../types.js"; import { config } from "../../config.js"; import { load, save, state } from "../../store/store.js"; import type { TRole } from "../../store/types.js"; +import { getUserFromMention } from "../../helpers.js"; let client: MatrixClient; @@ -36,9 +37,9 @@ const registerModuleAdmin = ( const onSetRole = async (text: string, roomId: string) => { const words = text.split(" "); - const userId = words[1]; + const mention = words[1]; const role = words[2] as TRole; - const user = state.users.find((user) => user.id === userId); + const user = getUserFromMention(mention); if (!user || !role) { return; diff --git a/src/modules/ai/ai.ts b/src/modules/ai/ai.ts index 8668f49..d29ea41 100644 --- a/src/modules/ai/ai.ts +++ b/src/modules/ai/ai.ts @@ -41,7 +41,7 @@ const onAI = async (text: string, roomId: string, sender: string) => { alts: alts, } 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);