mirror of
https://github.com/matrixgpt/matrix-chatgpt-bot.git
synced 2024-09-30 04:55:44 +00:00
Fix MATRIX_PREFIX_REPLY
This commit is contained in:
parent
8115dd4779
commit
f7f55412a6
@ -17,11 +17,9 @@ export async function handleRoomEvent(client: MatrixClient, chatGPT: ChatGPTAPIB
|
|||||||
const rootEventId: string = (relatesTo !== undefined && relatesTo.event_id !== undefined) ? relatesTo.event_id : event.event_id;
|
const rootEventId: string = (relatesTo !== undefined && relatesTo.event_id !== undefined) ? relatesTo.event_id : event.event_id;
|
||||||
const storedValue: string = await client.storageProvider.readValue('gpt-' + rootEventId)
|
const storedValue: string = await client.storageProvider.readValue('gpt-' + rootEventId)
|
||||||
const storedConversation: StoredConversation = (storedValue !== undefined) ? JSON.parse(storedValue) : undefined;
|
const storedConversation: StoredConversation = (storedValue !== undefined) ? JSON.parse(storedValue) : undefined;
|
||||||
const config = (storedConversation !== undefined && storedConversation.config !== undefined) ? storedConversation.config : undefined;
|
const config = (storedConversation !== undefined && storedConversation.config !== undefined) ? storedConversation.config : {};
|
||||||
|
const MATRIX_PREFIX_REPLY = (config.MATRIX_PREFIX_REPLY === undefined) ? MATRIX_DEFAULT_PREFIX_REPLY : config.MATRIX_PREFIX_REPLY
|
||||||
const MATRIX_PREFIX_REPLY = (config === undefined) ? MATRIX_DEFAULT_PREFIX_REPLY : config.MATRIX_PREFIX_REPLY
|
const shouldBePrefixed: boolean = ((MATRIX_DEFAULT_PREFIX) && (relatesTo === undefined)) || (MATRIX_PREFIX_REPLY && (relatesTo !== undefined));
|
||||||
const shouldBePrefixed: boolean = ((Boolean(MATRIX_DEFAULT_PREFIX)) && (MATRIX_PREFIX_REPLY || (relatesTo === undefined)));
|
|
||||||
|
|
||||||
if (event.sender === MATRIX_BOT_USERNAME) return; // Don't reply to ourself
|
if (event.sender === MATRIX_BOT_USERNAME) return; // Don't reply to ourself
|
||||||
if (Date.now() - event.origin_server_ts > 10000) return; // Don't reply to old messages
|
if (Date.now() - event.origin_server_ts > 10000) return; // Don't reply to old messages
|
||||||
if (shouldBePrefixed && !event.content.body.startsWith(MATRIX_DEFAULT_PREFIX)) return; // Don't reply without prefix if prefixed
|
if (shouldBePrefixed && !event.content.body.startsWith(MATRIX_DEFAULT_PREFIX)) return; // Don't reply without prefix if prefixed
|
||||||
|
Loading…
Reference in New Issue
Block a user