|
1 | 1 | import ChatGPTClient from '@waylaidwanderer/chatgpt-api';
|
2 | 2 | import { LogService, MatrixClient, UserID } from "matrix-bot-sdk";
|
3 |
| -import { CHATGPT_CONTEXT, CHATGPT_TIMEOUT, CHATGPT_IGNORE_MEDIA, MATRIX_DEFAULT_PREFIX_REPLY, MATRIX_DEFAULT_PREFIX, MATRIX_BLACKLIST, MATRIX_WHITELIST, MATRIX_RICH_TEXT, MATRIX_PREFIX_DM, MATRIX_THREADS } from "./env.js"; |
| 3 | +import { CHATGPT_CONTEXT, CHATGPT_TIMEOUT, CHATGPT_IGNORE_MEDIA, MATRIX_DEFAULT_PREFIX_REPLY, MATRIX_DEFAULT_PREFIX, MATRIX_BLACKLIST, MATRIX_WHITELIST, MATRIX_RICH_TEXT, MATRIX_PREFIX_DM, MATRIX_THREADS, MATRIX_ROOM_BLACKLIST, MATRIX_ROOM_WHITELIST } from "./env.js"; |
4 | 4 | import { RelatesTo, MessageEvent, StoredConversation, StoredConversationConfig } from "./interfaces.js";
|
5 | 5 | import { sendChatGPTMessage, sendError, sendReply } from "./utils.js";
|
6 | 6 |
|
@@ -29,13 +29,15 @@ export default class CommandHandler {
|
29 | 29 | }
|
30 | 30 | }
|
31 | 31 |
|
32 |
| - private shouldIgnore(event: MessageEvent): boolean { |
33 |
| - if (event.sender === this.userId) return true; // Ignore ourselves |
34 |
| - if (MATRIX_BLACKLIST && MATRIX_BLACKLIST.split(" ").find(b => event.sender.endsWith(b))) return true; // Ignore if on blacklist if set |
35 |
| - if (MATRIX_WHITELIST && !MATRIX_WHITELIST.split(" ").find(w => event.sender.endsWith(w))) return true; // Ignore if not on whitelist if set |
36 |
| - if (Date.now() - event.origin_server_ts > 10000) return true; // Ignore old messages |
37 |
| - if (event.content["m.relates_to"]?.["rel_type"] === "m.replace") return true; // Ignore edits |
38 |
| - if (CHATGPT_IGNORE_MEDIA && event.content.msgtype !== "m.text") return true; // Ignore everything which is not text if set |
| 32 | + private shouldIgnore(event: MessageEvent, roomId: string): boolean { |
| 33 | + if (event.sender === this.userId) return true; // Ignore ourselves |
| 34 | + if (MATRIX_BLACKLIST && MATRIX_BLACKLIST.split(" ").find(b => event.sender.endsWith(b))) return true; // Ignore if on blacklist if set |
| 35 | + if (MATRIX_WHITELIST && !MATRIX_WHITELIST.split(" ").find(w => event.sender.endsWith(w))) return true; // Ignore if not on whitelist if set |
| 36 | + if (MATRIX_ROOM_BLACKLIST && MATRIX_ROOM_BLACKLIST.split(" ").find(b => roomId.endsWith(b))) return true; // Ignore if on room blacklist if set |
| 37 | + if (MATRIX_ROOM_WHITELIST && !MATRIX_ROOM_WHITELIST.split(" ").find(w => roomId.endsWith(w))) return true; // Ignore if not on room whitelist if set |
| 38 | + if (Date.now() - event.origin_server_ts > 10000) return true; // Ignore old messages |
| 39 | + if (event.content["m.relates_to"]?.["rel_type"] === "m.replace") return true; // Ignore edits |
| 40 | + if (CHATGPT_IGNORE_MEDIA && event.content.msgtype !== "m.text") return true; // Ignore everything which is not text if set |
39 | 41 | return false;
|
40 | 42 | }
|
41 | 43 |
|
@@ -102,7 +104,7 @@ export default class CommandHandler {
|
102 | 104 | */
|
103 | 105 | private async onMessage(roomId: string, event: MessageEvent) {
|
104 | 106 | try {
|
105 |
| - if (this.shouldIgnore(event)) return; |
| 107 | + if (this.shouldIgnore(event, roomId)) return; |
106 | 108 |
|
107 | 109 | const storageKey = this.getStorageKey(event, roomId);
|
108 | 110 | const storedConversation = await this.getStoredConversation(storageKey, roomId);
|
|
0 commit comments