add desc
This commit is contained in:
@@ -17,6 +17,8 @@ driver = nonebot.get_driver()
|
|||||||
def startup():
|
def startup():
|
||||||
if pconfig.proxy:
|
if pconfig.proxy:
|
||||||
rlib.set_proxy(pconfig.proxy)
|
rlib.set_proxy(pconfig.proxy)
|
||||||
|
if pconfig.pjsk_proxy:
|
||||||
|
rlib.set_pjsk_proxy(pconfig.pjsk_proxy)
|
||||||
if pconfig.github_token:
|
if pconfig.github_token:
|
||||||
rlib.set_ghp(pconfig.github_token)
|
rlib.set_ghp(pconfig.github_token)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ except:
|
|||||||
class Config(BaseModel):
|
class Config(BaseModel):
|
||||||
assets_studio_path: str
|
assets_studio_path: str
|
||||||
github_token: str | None = None
|
github_token: str | None = None
|
||||||
|
pjsk_proxy: str | None = None
|
||||||
@property
|
@property
|
||||||
def proxy(self) -> str | None:
|
def proxy(self) -> str | None:
|
||||||
return _proxy
|
return _proxy
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import ctypes
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from dataclasses import field, dataclass
|
||||||
from typing import Optional, Dict, Any, List
|
from typing import Optional, Dict, Any, List
|
||||||
|
|
||||||
|
|
||||||
@@ -14,16 +15,33 @@ def get_lib_filename(base_name):
|
|||||||
return f"lib{base_name}.so"
|
return f"lib{base_name}.so"
|
||||||
|
|
||||||
|
|
||||||
class FetchData:
|
@dataclass
|
||||||
event_id: int
|
class FetchResultCard:
|
||||||
card_paths: List[str]
|
text: str = ""
|
||||||
|
path: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: Dict[str, Any]) -> 'FetchData':
|
def from_dict(cls, data: Dict[str, Any]) -> 'FetchResultCard':
|
||||||
instance = cls()
|
return cls(
|
||||||
instance.event_id = data.get("event_id", 0)
|
text=data.get("text", ""),
|
||||||
instance.card_paths = data.get("card_paths", [])
|
path=data.get("path", []),
|
||||||
return instance
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class FetchResult:
|
||||||
|
event_id: int = 0
|
||||||
|
cards: List[FetchResultCard] = field(default_factory=list)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data: Dict[str, Any]) -> 'FetchResult':
|
||||||
|
return cls(
|
||||||
|
event_id=data.get("event_id", 0),
|
||||||
|
cards=[
|
||||||
|
FetchResultCard.from_dict(card)
|
||||||
|
for card in data.get("cards", [])
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SekaiSyncLib:
|
class SekaiSyncLib:
|
||||||
@@ -36,6 +54,10 @@ class SekaiSyncLib:
|
|||||||
self.lib.proxy.argtypes = [ctypes.c_char_p]
|
self.lib.proxy.argtypes = [ctypes.c_char_p]
|
||||||
self.lib.proxy.restype = None
|
self.lib.proxy.restype = None
|
||||||
|
|
||||||
|
# pjsk_proxy(x: *const c_char)
|
||||||
|
self.lib.pjsk_proxy.argtypes = [ctypes.c_char_p]
|
||||||
|
self.lib.pjsk_proxy.restype = None
|
||||||
|
|
||||||
# ghp(x: *const c_char)
|
# ghp(x: *const c_char)
|
||||||
self.lib.ghp.argtypes = [ctypes.c_char_p]
|
self.lib.ghp.argtypes = [ctypes.c_char_p]
|
||||||
self.lib.ghp.restype = None
|
self.lib.ghp.restype = None
|
||||||
@@ -72,6 +94,10 @@ class SekaiSyncLib:
|
|||||||
"""设置代理,传 None 或空字符串可清除"""
|
"""设置代理,传 None 或空字符串可清除"""
|
||||||
self.lib.proxy(self._str_to_bytes(proxy_url))
|
self.lib.proxy(self._str_to_bytes(proxy_url))
|
||||||
|
|
||||||
|
def set_pjsk_proxy(self, proxy_url: Optional[str]):
|
||||||
|
"""设置 pjsk_proxy,传 None 或空字符串可清除"""
|
||||||
|
self.lib.pjsk_proxy(self._str_to_bytes(proxy_url))
|
||||||
|
|
||||||
def set_ghp(self, token: Optional[str]):
|
def set_ghp(self, token: Optional[str]):
|
||||||
"""设置 GitHub Token,传 None 或空字符串可清除"""
|
"""设置 GitHub Token,传 None 或空字符串可清除"""
|
||||||
self.lib.ghp(self._str_to_bytes(token))
|
self.lib.ghp(self._str_to_bytes(token))
|
||||||
@@ -96,7 +122,7 @@ class SekaiSyncLib:
|
|||||||
"""
|
"""
|
||||||
return self.lib.stop()
|
return self.lib.stop()
|
||||||
|
|
||||||
def fetch_data(self) -> Optional[FetchData]:
|
def fetch_data(self) -> Optional[FetchResult]:
|
||||||
# 1. 获取裸指针
|
# 1. 获取裸指针
|
||||||
ptr = self.lib.fetch_data()
|
ptr = self.lib.fetch_data()
|
||||||
|
|
||||||
@@ -112,7 +138,7 @@ class SekaiSyncLib:
|
|||||||
|
|
||||||
# 3. 解码并反序列化 JSON
|
# 3. 解码并反序列化 JSON
|
||||||
json_str = json_bytes.decode('utf-8')
|
json_str = json_bytes.decode('utf-8')
|
||||||
return FetchData.from_dict(json.loads(json_str))
|
return FetchResult.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# 4. 无论是否发生 JSON 解析异常,绝对保证释放 Rust 内存!
|
# 4. 无论是否发生 JSON 解析异常,绝对保证释放 Rust 内存!
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ async def sync():
|
|||||||
return
|
return
|
||||||
message = Message()
|
message = Message()
|
||||||
inner = [MessageSegment.text(f"活动 {data.event_id} 的卡牌更新了!")]
|
inner = [MessageSegment.text(f"活动 {data.event_id} 的卡牌更新了!")]
|
||||||
for item in data.card_paths:
|
for card in data.cards:
|
||||||
|
inner.append(MessageSegment.text(card.text))
|
||||||
|
for item in card.path:
|
||||||
p = Path(item)
|
p = Path(item)
|
||||||
n = MessageSegment.image(file=item)
|
n = MessageSegment.image(file=item)
|
||||||
n.data["summary"] = f"[{p.name}]"
|
n.data["summary"] = f"[{p.name}]"
|
||||||
@@ -54,7 +56,8 @@ async def sync():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"发送消息到群组 {group} 失败: {e}")
|
logger.error(f"发送消息到群组 {group} 失败: {e}")
|
||||||
|
|
||||||
for path in data.card_paths:
|
for card in data.cards:
|
||||||
|
for path in card.path:
|
||||||
try:
|
try:
|
||||||
Path(path).unlink()
|
Path(path).unlink()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user