diff --git a/.gitignore b/.gitignore index 64fb574..72ddabf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .idea -bot-store/ -config.yaml # ---> Python # Byte-compiled / optimized / DLL files diff --git a/README.md b/README.md index cf2104a..6a99073 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ _ChatGPT bot for Matrix._ +Uses code from [anoadragon453/nio-template](https://github.com/anoadragon453/nio-template). + ## Install ```bash diff --git a/matrix_gpt/bot/callbacks.py b/matrix_gpt/bot/callbacks.py index 6e879eb..04268d0 100644 --- a/matrix_gpt/bot/callbacks.py +++ b/matrix_gpt/bot/callbacks.py @@ -5,7 +5,7 @@ import time from nio import (AsyncClient, InviteMemberEvent, JoinError, MatrixRoom, MegolmEvent, RoomMessageText, UnknownEvent, ) from .bot_commands import Command -from .chat_functions import get_thread_content, is_thread, process_chat, react_to_event +from .chat_functions import check_authorized, get_thread_content, is_thread, process_chat, react_to_event # from .config import Config from .storage import Storage @@ -52,7 +52,7 @@ class Callbacks: if event.sender == self.client.user_id: return - if self.allowed_to_chat != 'all' and event.sender not in self.allowed_to_chat: + if not check_authorized(event.sender, self.allowed_to_chat): return if event.server_timestamp < self.startup_ts: @@ -98,10 +98,14 @@ class Callbacks: event: The invite event. """ - if event.sender not in self.allowed_to_invite: + if not check_authorized(event.sender, self.allowed_to_invite): logger.info(f"Got invite to {room.room_id} from {event.sender} but rejected.") return + # if event.sender not in self.allowed_to_invite: + # logger.info(f"Got invite to {room.room_id} from {event.sender} but rejected.") + # return + logger.debug(f"Got invite to {room.room_id} from {event.sender}.") # Attempt to join 3 times before giving up diff --git a/matrix_gpt/bot/chat_functions.py b/matrix_gpt/bot/chat_functions.py index 885613b..3e13c63 100644 --- a/matrix_gpt/bot/chat_functions.py +++ b/matrix_gpt/bot/chat_functions.py @@ -211,3 +211,16 @@ async def process_chat(client, room, event, command, store, openai, thread_root_ store.add_event_id(resp.event_id) # else: # logger.info(f'Not responding to seen event {event.event_id}') + + +def check_authorized(string, to_check): + if to_check != 'all': + if '@' not in to_check and ':' not in to_check: + # Homeserver + print(string.split(':')[-1], to_check) + if string.split(':')[-1] not in to_check: + return False + elif string not in to_check: + # By username + return False + return True diff --git a/matrixgpt.service b/matrixgpt.service new file mode 100644 index 0000000..cbb315e --- /dev/null +++ b/matrixgpt.service @@ -0,0 +1,14 @@ +[Unit] +Description=Icinga to Kuma converter. +After=network.target + +[Service] +User=flask +Environment="ICINGA2KUMA_ICINGA2_PW=[your icinga2 API password]" +WorkingDirectory=/opt/icinga2-checks +ExecStart=/opt/matrixgpt/venv/bin/python3 +Restart=always + +[Install] +WantedBy=multi-user.target + diff --git a/nio-template b/nio-template deleted file mode 160000 index 3d8fbf1..0000000 --- a/nio-template +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d8fbf142b71e5e9da3fbffb177fb44542de1200