diff --git a/.full-env.example b/.full-env.example index 9a4378d..bd61619 100644 --- a/.full-env.example +++ b/.full-env.example @@ -3,7 +3,7 @@ USER_ID="@lullap:xxxxxxxxxxxxx.xxx" PASSWORD="xxxxxxxxxxxxxxx" ACCESS_TOKEN="xxxxxxxxxxx" DEVICE_ID="xxxxxxxxxxxxxx" -ROOM_ID="!FYCmBSkCRUXXXXXXXXX:matrix.XXX.XXX" +ROOM_ID="!aaaaaaa:XXX.XXX,!bbbbbb:XXX.XXX" IMPORT_KEYS_PATH="element-keys.txt" IMPORT_KEYS_PASSWORD="xxxxxxxxxxxx" OPENAI_API_KEY="xxxxxxxxxxxxxxxxx" diff --git a/CHANGELOG.md b/CHANGELOG.md index a8cc23f..2b7fbed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.8.0 - Support custom help message +- Support several whitelist room_id ## 1.7.2 - Refactor gpt vision trigger method diff --git a/custom_help_message.txt b/custom_help_message.txt index 51e96a0..cc9fedc 100644 --- a/custom_help_message.txt +++ b/custom_help_message.txt @@ -1,11 +1,11 @@ Hi there, welcome to our chat room! -Our bot is powered by opensource project [matrix_chatgpt_bot](https://github.com/hibobmaster/matrix_chatgpt_bot). Here are some commands you can use to interact with the bot. !gpt [prompt], generate a one time response without context conversation !chat [prompt], chat with context conversation !pic [prompt], Image generation by DALL-E-3 or LocalAI or stable-diffusion-webui !new + chat, start a new conversation -!lc [prompt], chat using langchain api quote a image and @bot with prompt, gpt vision function @bot with prompt, create a thread level chatting !help, help message + +Our bot is powered by opensource project [matrix_chatgpt_bot](https://github.com/hibobmaster/matrix_chatgpt_bot). diff --git a/full-config.json.example b/full-config.json.example index ba13950..1cb5931 100644 --- a/full-config.json.example +++ b/full-config.json.example @@ -4,7 +4,7 @@ "password": "xxxxxxxxxxxxxxxxxx", "access_token": "xxxxxxxxxxxxxx", "device_id": "MatrixChatGPTBot", - "room_id": "!xxxxxxxxxxxxxxxxxxxxxx:xxxxx.org", + "room_id": ["!xxxxxxxxxxxxxxxxxxxxxx:xxxxx.org"], "import_keys_path": "element-keys.txt", "import_keys_password": "xxxxxxxxxxxxxxxxxxxx", "openai_api_key": "xxxxxxxxxxxxxxxxxxxxxxxx", diff --git a/src/bot.py b/src/bot.py index d12c53b..75c08f9 100644 --- a/src/bot.py +++ b/src/bot.py @@ -56,7 +56,7 @@ class Bot: device_id: str, password: Union[str, None] = None, access_token: Union[str, None] = None, - room_id: Union[str, None] = None, + whitelist_room_id: Optional[list[str]] = None, import_keys_path: Optional[str] = None, import_keys_password: Optional[str] = None, openai_api_key: Union[str, None] = None, @@ -110,7 +110,6 @@ class Bot: self.password: str = password self.access_token: str = access_token self.device_id: str = device_id - self.room_id: str = room_id self.openai_api_key: str = openai_api_key self.gpt_api_endpoint: str = ( @@ -159,6 +158,14 @@ class Bot: self.base_path = Path(os.path.dirname(__file__)).parent + self.whitelist_room_id = whitelist_room_id + if whitelist_room_id is not None: + if isinstance(whitelist_room_id, str): + whitelist_room_id_list = list() + for room_id in whitelist_room_id.split(","): + whitelist_room_id_list.append(room_id.strip()) + self.whitelist_room_id = whitelist_room_id_list + if lc_admin is not None: if isinstance(lc_admin, str): lc_admin = list(filter(None, lc_admin.split(","))) @@ -243,13 +250,9 @@ class Bot: # message_callback RoomMessageText event async def message_callback(self, room: MatrixRoom, event: RoomMessageText) -> None: - if self.room_id is None: - room_id = room.room_id - else: - # if event room id does not match the room id in config, return - if room.room_id != self.room_id: - return - room_id = self.room_id + if room.room_id not in self.whitelist_room_id: + return + room_id = room.room_id # reply event_id reply_to_event_id = event.event_id diff --git a/src/main.py b/src/main.py index 1d40fed..8ed9df4 100644 --- a/src/main.py +++ b/src/main.py @@ -44,7 +44,7 @@ async def main(): password=config.get("password"), access_token=config.get("access_token"), device_id=config.get("device_id"), - room_id=config.get("room_id"), + whitelist_room_id=config.get("room_id"), import_keys_path=config.get("import_keys_path"), import_keys_password=config.get("import_keys_password"), openai_api_key=config.get("openai_api_key"), @@ -83,7 +83,7 @@ async def main(): password=os.environ.get("PASSWORD"), access_token=os.environ.get("ACCESS_TOKEN"), device_id=os.environ.get("DEVICE_ID"), - room_id=os.environ.get("ROOM_ID"), + whitelist_room_id=os.environ.get("ROOM_ID"), import_keys_path=os.environ.get("IMPORT_KEYS_PATH"), import_keys_password=os.environ.get("IMPORT_KEYS_PASSWORD"), openai_api_key=os.environ.get("OPENAI_API_KEY"),