forked from mttu-developers/konabot
宾几人功能调整;bilibili fetch 调整
This commit is contained in:
@ -1,18 +1,29 @@
|
||||
import re
|
||||
|
||||
from nonebot import on_message
|
||||
from nonebot import get_plugin_config, on_message
|
||||
from nonebot_plugin_alconna import Reference, Reply, UniMsg
|
||||
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.adapters.onebot.v11.event import GroupMessageEvent as OB11GroupEvent
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
bilifetch_enabled_groups: list[int] = []
|
||||
|
||||
|
||||
config = get_plugin_config(Config)
|
||||
pattern = (
|
||||
r"^(?:(?:av|cv)\d+|BV[a-zA-Z0-9]{10})|"
|
||||
r"(?:b23\.tv|bili(?:22|23|33|2233)\.cn|\.bilibili\.com|QQ小程序(?:]|]|\])哔哩哔哩).{0,500}"
|
||||
)
|
||||
|
||||
|
||||
def _rule(msg: UniMsg):
|
||||
def _rule(msg: UniMsg, evt: Event) -> bool:
|
||||
if isinstance(evt, OB11GroupEvent):
|
||||
if evt.group_id not in config.bilifetch_enabled_groups:
|
||||
return False
|
||||
|
||||
to_search = msg.exclude(Reply, Reference).dump(json=True)
|
||||
to_search2 = msg.exclude(Reply, Reference).extract_plain_text()
|
||||
if not re.search(pattern, to_search) and not re.search(pattern, to_search2):
|
||||
|
||||
@ -26,7 +26,12 @@ def dump_server_status(name: str, status: JavaStatusResponse | BaseException) ->
|
||||
motd = status.motd.to_plain()
|
||||
# Bingo Status: [PRE-GAME], [IN-GAME], [POST-GAME]
|
||||
st = parse_status(motd)
|
||||
return f"{name}: {st} {status.players.online} 人在线"
|
||||
players_sample = status.players.sample or []
|
||||
players_sample_suffix = ""
|
||||
if len(players_sample) > 0:
|
||||
player_list = [s.name for s in players_sample]
|
||||
players_sample_suffix = " (" + ", ".join(player_list) + ")"
|
||||
return f"{name}: {st} {status.players.online} 人在线{players_sample_suffix}"
|
||||
else:
|
||||
return f"{name}: 好像没开"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user