diff --git a/db.py b/db.py index 9db4fff..e174195 100644 --- a/db.py +++ b/db.py @@ -2,8 +2,9 @@ import mysql.connector import schedule + class Room: - def __init__(self, room_id, liver_uid, liver_name): + def __init__(self, room_id: str, liver_uid, liver_name): self.room_id = room_id self.liver_uid = liver_uid self.liver_name = liver_name @@ -27,7 +28,7 @@ def flush_room_info(): rooms[room_id] = Room(room_id, liver_uid, liver_name) -def get_room(room_id) -> Room: +def get_room(room_id: str) -> Room: return rooms.get(room_id, Room(room_id, 0, str(room_id))) diff --git a/live_status_ntf.py b/live_status_ntf.py index 50dc0e8..3d5187b 100644 --- a/live_status_ntf.py +++ b/live_status_ntf.py @@ -11,6 +11,11 @@ import re path = "logs" room_id_re = re.compile(rf"{path}/(\d+).jsonl$") +notify_qq_group = { + "12571885": ["831867573", "138981147"], + "147482": ["175545447"], +} + class Room: position = 0 @@ -18,7 +23,7 @@ class Room: state = 0 state_changed = False - def __init__(self, room_id) -> None: + def __init__(self, room_id: str) -> None: self.room_id = room_id self.db_room = db.get_room(room_id) @@ -133,6 +138,9 @@ class MyHandler(FileSystemEventHandler): ]) requests.post("http://turntf:18846/notify", json={"msg": msg}) + for notify_group in notify_qq_group.get(room.room_id, []): + seng_qq_group_msg(notify_group, msg) + elif room.state == 2: msg = "\n".join([ f"{room.db_room.liver_name} 下锅了!", @@ -140,6 +148,16 @@ class MyHandler(FileSystemEventHandler): ]) requests.post("http://turntf:18846/notify", json={"msg": msg}) + for notify_group in notify_qq_group.get(room.room_id, []): + seng_qq_group_msg(notify_group, msg) + + +def seng_qq_group_msg(group_id: str, msg: str): + requests.post("http://napcat:3000/send_group_msg", json={ + "group_id": group_id, + "message": msg + }) + def main(): for f in os.listdir(path): diff --git a/requirements.txt b/requirements.txt index a170091..63efce7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,6 @@ redis PyYAML watchdog requests -mysql +mysql-connector-python schedule +requests