更新config文件

This commit is contained in:
San Liy 2023-12-19 01:05:14 +08:00
parent 5813255b8e
commit 81d57bf5da
2 changed files with 14 additions and 14 deletions

View File

@ -2,6 +2,7 @@ from dataclasses import dataclass
from typing import Optional, List, Union, Literal from typing import Optional, List, Union, Literal
from lib_not_dr.types import Options from lib_not_dr.types import Options
from pydantic import BaseModel
from socketio import AsyncClient from socketio import AsyncClient
@ -50,11 +51,15 @@ class Message(Options):
} }
@dataclass class SioConfig(BaseModel):
class SioConfig: host: str
HOST: str key: str
KEY: str self_id: str
SELF_ID: str admin: List[int]
validate_http: str
client_id: str
client_secret: str
@dataclass @dataclass

View File

@ -18,7 +18,7 @@ app = Sanic('GiteaPush', ctx=Ctx)
def get_config() -> SioConfig: def get_config() -> SioConfig:
with open('config.toml', 'rb') as f: with open('config.toml', 'rb') as f:
config = tomllib.load(f) config = tomllib.load(f)
return SioConfig(config['host'], config['private_key'], config['self_id']) return SioConfig(**config)
@app.before_server_start @app.before_server_start
@ -28,7 +28,7 @@ async def setup_before_start(_app):
start_sio_listener() start_sio_listener()
await _app.ctx.sio.connect(_app.ctx.sio_config.HOST) await _app.ctx.sio.connect(_app.ctx.sio_config.host)
@app.post('/receive') @app.post('/receive')
@ -85,7 +85,7 @@ def start_sio_listener():
logger.info( logger.info(
f"{Colors.BLUE}versions: {Colors.PURPLE}{versions} {Colors.BLUE}with type {type(salt)}|{salt=}{Colors.END}") f"{Colors.BLUE}versions: {Colors.PURPLE}{versions} {Colors.BLUE}with type {type(salt)}|{salt=}{Colors.END}")
# 准备数据 # 准备数据
sign = SigningKey(bytes.fromhex(app.ctx.sio_config.KEY)) sign = SigningKey(bytes.fromhex(app.ctx.sio_config.key))
signature = sign.sign(bytes.fromhex(salt)) signature = sign.sign(bytes.fromhex(salt))
# 发送数据 # 发送数据
@ -154,13 +154,8 @@ def start_sio_listener():
logger.debug(sio_log_format('add_message:', data)) logger.debug(sio_log_format('add_message:', data))
sender_id = data['message']['senderId'] sender_id = data['message']['senderId']
is_self = (sender_id == app.ctx.sio_config.SELF_ID)
sender_name = data['message']['username'] if sender_id != app.ctx.sio_config.self_id:
content = data['message']['content']
room_id = data['roomId']
if not is_self:
msg = command_convert(data) msg = command_convert(data)
if msg is not None: if msg is not None:
await app.ctx.sio.emit('sendMessage', msg.to_json()) await app.ctx.sio.emit('sendMessage', msg.to_json())