自定义开播通知群

This commit is contained in:
2025-08-27 14:56:01 +08:00
parent b0f226fcef
commit 09a2d65a34
3 changed files with 24 additions and 4 deletions

5
db.py
View File

@@ -2,8 +2,9 @@
import mysql.connector import mysql.connector
import schedule import schedule
class Room: 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.room_id = room_id
self.liver_uid = liver_uid self.liver_uid = liver_uid
self.liver_name = liver_name self.liver_name = liver_name
@@ -27,7 +28,7 @@ def flush_room_info():
rooms[room_id] = Room(room_id, liver_uid, liver_name) 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))) return rooms.get(room_id, Room(room_id, 0, str(room_id)))

View File

@@ -11,6 +11,11 @@ import re
path = "logs" path = "logs"
room_id_re = re.compile(rf"{path}/(\d+).jsonl$") room_id_re = re.compile(rf"{path}/(\d+).jsonl$")
notify_qq_group = {
"12571885": ["831867573", "138981147"],
"147482": ["175545447"],
}
class Room: class Room:
position = 0 position = 0
@@ -18,7 +23,7 @@ class Room:
state = 0 state = 0
state_changed = False state_changed = False
def __init__(self, room_id) -> None: def __init__(self, room_id: str) -> None:
self.room_id = room_id self.room_id = room_id
self.db_room = db.get_room(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}) 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: elif room.state == 2:
msg = "\n".join([ msg = "\n".join([
f"{room.db_room.liver_name} 下锅了!", f"{room.db_room.liver_name} 下锅了!",
@@ -140,6 +148,16 @@ class MyHandler(FileSystemEventHandler):
]) ])
requests.post("http://turntf:18846/notify", json={"msg": msg}) 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(): def main():
for f in os.listdir(path): for f in os.listdir(path):

View File

@@ -5,5 +5,6 @@ redis
PyYAML PyYAML
watchdog watchdog
requests requests
mysql mysql-connector-python
schedule schedule
requests