forked from mttu-developers/konabot
添加宾几人功能
This commit is contained in:
4
konabot/docs/sys/宾几人.txt
Normal file
4
konabot/docs/sys/宾几人.txt
Normal file
@ -0,0 +1,4 @@
|
||||
# 宾几人
|
||||
|
||||
查询 Bingo 有几个人。直接发送给 Bot 即可。
|
||||
|
||||
52
konabot/plugins/mc_count_player/__init__.py
Normal file
52
konabot/plugins/mc_count_player/__init__.py
Normal file
@ -0,0 +1,52 @@
|
||||
import asyncio
|
||||
import mcstatus
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters import Event
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
from konabot.common.nb.is_admin import is_admin
|
||||
from mcstatus.responses import JavaStatusResponse
|
||||
|
||||
|
||||
cmd = on_command("宾几人", aliases=set(("宾人数", "mcbingo")), rule=is_admin)
|
||||
|
||||
|
||||
def parse_status(motd: str) -> str:
|
||||
if "[PRE-GAME]" in motd:
|
||||
return "[✨ 空闲]"
|
||||
if "[IN-GAME]" in motd:
|
||||
return "[🕜 游戏中]"
|
||||
if "[POST-GAME]" in motd:
|
||||
return "[🕜 游戏中]"
|
||||
return "[✨ 开放]"
|
||||
|
||||
|
||||
def dump_server_status(name: str, status: JavaStatusResponse | BaseException) -> str:
|
||||
if isinstance(status, JavaStatusResponse):
|
||||
motd = status.motd.to_plain()
|
||||
# Bingo Status: [PRE-GAME], [IN-GAME], [POST-GAME]
|
||||
st = parse_status(motd)
|
||||
return f"{name}: {st} {status.players.online} 人在线"
|
||||
else:
|
||||
return f"{name}: 好像没开"
|
||||
|
||||
|
||||
@cmd.handle()
|
||||
async def _(evt: Event):
|
||||
servers = (
|
||||
(mcstatus.JavaServer("play.simpfun.cn", 11495), "小帕 Bingo"),
|
||||
(mcstatus.JavaServer("bingo.mujica.tech"), "坏枪 Bingo"),
|
||||
(mcstatus.JavaServer("mc.mujica.tech", 11456), "齿轮盛宴"),
|
||||
)
|
||||
|
||||
responses = await asyncio.gather(
|
||||
*map(lambda s: s[0].async_status(), servers),
|
||||
return_exceptions=True,
|
||||
)
|
||||
messages = "\n".join((
|
||||
dump_server_status(n, r)
|
||||
for n, r in zip(map(lambda s: s[1], servers), responses)
|
||||
))
|
||||
|
||||
await UniMessage.text(messages).finish(evt, at_sender=False)
|
||||
|
||||
66
poetry.lock
generated
66
poetry.lock
generated
@ -569,6 +569,23 @@ type = "legacy"
|
||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
reference = "mirrors"
|
||||
|
||||
[[package]]
|
||||
name = "asyncio-dgram"
|
||||
version = "3.0.0"
|
||||
description = "Higher level Datagram support for Asyncio"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "asyncio_dgram-3.0.0-py3-none-any.whl", hash = "sha256:a4113061e6a7fbeee928d49c56cb61b68ca4a2fbee37f7e97280bbc72323ba8e"},
|
||||
{file = "asyncio_dgram-3.0.0.tar.gz", hash = "sha256:bd0937807a44451d799573b32400702187fd0bba6136f7cf306e9327c0c20f3e"},
|
||||
]
|
||||
|
||||
[package.source]
|
||||
type = "legacy"
|
||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
reference = "mirrors"
|
||||
|
||||
[[package]]
|
||||
name = "attrs"
|
||||
version = "25.4.0"
|
||||
@ -1284,6 +1301,32 @@ type = "legacy"
|
||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
reference = "mirrors"
|
||||
|
||||
[[package]]
|
||||
name = "dnspython"
|
||||
version = "2.8.0"
|
||||
description = "DNS toolkit"
|
||||
optional = false
|
||||
python-versions = ">=3.10"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "dnspython-2.8.0-py3-none-any.whl", hash = "sha256:01d9bbc4a2d76bf0db7c1f729812ded6d912bd318d3b1cf81d30c0f845dbf3af"},
|
||||
{file = "dnspython-2.8.0.tar.gz", hash = "sha256:181d3c6996452cb1189c4046c61599b84a5a86e099562ffde77d26984ff26d0f"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
dev = ["black (>=25.1.0)", "coverage (>=7.0)", "flake8 (>=7)", "hypercorn (>=0.17.0)", "mypy (>=1.17)", "pylint (>=3)", "pytest (>=8.4)", "pytest-cov (>=6.2.0)", "quart-trio (>=0.12.0)", "sphinx (>=8.2.0)", "sphinx-rtd-theme (>=3.0.0)", "twine (>=6.1.0)", "wheel (>=0.45.0)"]
|
||||
dnssec = ["cryptography (>=45)"]
|
||||
doh = ["h2 (>=4.2.0)", "httpcore (>=1.0.0)", "httpx (>=0.28.0)"]
|
||||
doq = ["aioquic (>=1.2.0)"]
|
||||
idna = ["idna (>=3.10)"]
|
||||
trio = ["trio (>=0.30)"]
|
||||
wmi = ["wmi (>=1.5.1) ; platform_system == \"Windows\""]
|
||||
|
||||
[package.source]
|
||||
type = "legacy"
|
||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
reference = "mirrors"
|
||||
|
||||
[[package]]
|
||||
name = "exceptiongroup"
|
||||
version = "1.3.0"
|
||||
@ -2253,6 +2296,27 @@ type = "legacy"
|
||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
reference = "mirrors"
|
||||
|
||||
[[package]]
|
||||
name = "mcstatus"
|
||||
version = "12.2.1"
|
||||
description = "A library to query Minecraft Servers for their status and capabilities."
|
||||
optional = false
|
||||
python-versions = ">=3.10"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "mcstatus-12.2.1-py3-none-any.whl", hash = "sha256:9da6b8b6c1a43521f13cc50f312501091c1e7437c3ad2d65b9ccb534d70b1244"},
|
||||
{file = "mcstatus-12.2.1.tar.gz", hash = "sha256:0c6fb84c96685bb02189951ba895afbaca22b65bfe74e7fc55ef73a1c6e8a9ce"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
asyncio-dgram = ">=2.1.2"
|
||||
dnspython = ">=2.4.2"
|
||||
|
||||
[package.source]
|
||||
type = "legacy"
|
||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
reference = "mirrors"
|
||||
|
||||
[[package]]
|
||||
name = "mdit-py-plugins"
|
||||
version = "0.5.0"
|
||||
@ -5062,4 +5126,4 @@ reference = "mirrors"
|
||||
[metadata]
|
||||
lock-version = "2.1"
|
||||
python-versions = ">=3.12,<4.0"
|
||||
content-hash = "67585972f882646c3ee31bce98309a85aaee00fe015bfe14867781055e777ed2"
|
||||
content-hash = "4caff431bad39bc7fb0dd2685ed64394f2bf960660b017897b8d00a8137d32f5"
|
||||
|
||||
@ -32,6 +32,7 @@ dependencies = [
|
||||
"alibabacloud-green20220302 (>=3.0.1,<4.0.0)",
|
||||
"pypinyin (>=0.55.0,<0.56.0)",
|
||||
"shapely (>=2.1.2,<3.0.0)",
|
||||
"mcstatus (>=12.2.1,<13.0.0)",
|
||||
]
|
||||
|
||||
[tool.poetry]
|
||||
|
||||
Reference in New Issue
Block a user