minor improvements

This commit is contained in:
Cyberes 2023-03-18 02:30:12 -06:00
parent 9579c5261d
commit c90ecf3fcd
6 changed files with 36 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,6 +1,4 @@
.idea
bot-store/
config.yaml
# ---> Python
# Byte-compiled / optimized / DLL files

View File

@ -2,6 +2,8 @@
_ChatGPT bot for Matrix._
Uses code from [anoadragon453/nio-template](https://github.com/anoadragon453/nio-template).
## Install
```bash

View File

@ -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

View File

@ -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

14
matrixgpt.service Normal file
View File

@ -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

@ -1 +0,0 @@
Subproject commit 3d8fbf142b71e5e9da3fbffb177fb44542de1200