Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8780dfec6f | |||
| 490d807e7a | |||
| fa208199ab | |||
| 38a17f42a3 | |||
| 37179fc4d7 | |||
| 56e0aabbf3 |
22
.drone.yml
22
.drone.yml
@ -38,6 +38,17 @@ steps:
|
|||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
commands:
|
commands:
|
||||||
- docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python scripts/test_plugin_load.py
|
- docker run --rm gitea.service.jazzwhom.top/mttu-developers/konabot:nightly-${DRONE_COMMIT_SHA} python scripts/test_plugin_load.py
|
||||||
|
- name: 发送构建结果到 ntfy
|
||||||
|
image: parrazam/drone-ntfy
|
||||||
|
when:
|
||||||
|
status: [success, failure]
|
||||||
|
settings:
|
||||||
|
url: https://ntfy.service.jazzwhom.top
|
||||||
|
topic: drone_ci
|
||||||
|
tags:
|
||||||
|
- drone-ci
|
||||||
|
token:
|
||||||
|
from_secret: NTFY_TOKEN
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: docker-socket
|
- name: docker-socket
|
||||||
@ -74,6 +85,17 @@ steps:
|
|||||||
volumes:
|
volumes:
|
||||||
- name: docker-socket
|
- name: docker-socket
|
||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
|
- name: 发送构建结果到 ntfy
|
||||||
|
image: parrazam/drone-ntfy
|
||||||
|
when:
|
||||||
|
status: [success, failure]
|
||||||
|
settings:
|
||||||
|
url: https://ntfy.service.jazzwhom.top
|
||||||
|
topic: drone_ci
|
||||||
|
tags:
|
||||||
|
- drone-ci
|
||||||
|
token:
|
||||||
|
from_secret: NTFY_TOKEN
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: docker-socket
|
- name: docker-socket
|
||||||
|
|||||||
@ -2,7 +2,8 @@ from functools import reduce
|
|||||||
from math import ceil
|
from math import ceil
|
||||||
import re
|
import re
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from nonebot_plugin_alconna import Alconna, Args, UniMessage, on_alconna
|
from nonebot import on_message
|
||||||
|
from nonebot_plugin_alconna import Alconna, Args, UniMessage, UniMsg, on_alconna
|
||||||
from konabot.common.nb.qq_broadcast import qq_broadcast
|
from konabot.common.nb.qq_broadcast import qq_broadcast
|
||||||
from konabot.common.username import get_username
|
from konabot.common.username import get_username
|
||||||
from konabot.plugins.kona_ph.core.storage import get_today_date
|
from konabot.plugins.kona_ph.core.storage import get_today_date
|
||||||
@ -23,16 +24,29 @@ async def is_play_group(target: DepLongTaskTarget):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
cmd_submit = on_alconna(Alconna(
|
# cmd_submit = on_alconna(Alconna(
|
||||||
"re:提交(?:答案|题解|[fF]lag)",
|
# "re:提交(?:答案|题解|[fF]lag)",
|
||||||
Args["flag", str],
|
# Args["flag", str],
|
||||||
), rule=is_play_group)
|
# ), rule=is_play_group)
|
||||||
|
#
|
||||||
|
# @cmd_submit.handle()
|
||||||
|
# async def _(flag: str, target: DepLongTaskTarget):
|
||||||
|
# async with puzzle_manager() as manager:
|
||||||
|
# result = manager.submit(target.target_id, flag)
|
||||||
|
# await target.send_message(result.get_unimessage())
|
||||||
|
|
||||||
|
|
||||||
|
cmd_submit = on_message(rule=is_play_group)
|
||||||
|
|
||||||
|
|
||||||
@cmd_submit.handle()
|
@cmd_submit.handle()
|
||||||
async def _(flag: str, target: DepLongTaskTarget):
|
async def _(msg: UniMsg, target: DepLongTaskTarget):
|
||||||
async with puzzle_manager() as manager:
|
txt = msg.extract_plain_text().strip()
|
||||||
result = manager.submit(target.target_id, flag)
|
if match := re.match(r"^提交(?:答案|题解|[fF]lag)\s*(?P<submission>.+?)\s*$", txt):
|
||||||
await target.send_message(result.get_unimessage())
|
submission: str = match.group("submission")
|
||||||
|
async with puzzle_manager() as manager:
|
||||||
|
result = manager.submit(target.target_id, submission)
|
||||||
|
await target.send_message(result.get_unimessage())
|
||||||
|
|
||||||
|
|
||||||
cmd_query = on_alconna(Alconna(
|
cmd_query = on_alconna(Alconna(
|
||||||
@ -83,13 +97,13 @@ async def _(target: DepLongTaskTarget):
|
|||||||
uname = get_username(int(u), gid)
|
uname = get_username(int(u), gid)
|
||||||
t = d.strftime("%H:%M")
|
t = d.strftime("%H:%M")
|
||||||
tries = len(manager.submissions[p.raw_id][u])
|
tries = len(manager.submissions[p.raw_id][u])
|
||||||
msg = msg.text(f"\n- {uname} [Solved at {t} in {tries} times]")
|
msg = msg.text(f"\n- {uname} [🎉 {t} 完成 | {tries} 提交]")
|
||||||
for u in info.tried_users - set(info.success_users.keys()):
|
for u in info.tried_users - set(info.success_users.keys()):
|
||||||
uname = u
|
uname = u
|
||||||
if re.match(r"^\d+$", u):
|
if re.match(r"^\d+$", u):
|
||||||
uname = get_username(int(u), gid)
|
uname = get_username(int(u), gid)
|
||||||
tries = len(manager.submissions[p.raw_id][u])
|
tries = len(manager.submissions[p.raw_id][u])
|
||||||
msg = msg.text(f"\n- {uname} [Unsolved in {tries} times]")
|
msg = msg.text(f"\n- {uname} [💦 {tries} 提交]")
|
||||||
|
|
||||||
await target.send_message(msg)
|
await target.send_message(msg)
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ from pydantic import BaseModel
|
|||||||
from konabot.common.longtask import DepLongTaskTarget
|
from konabot.common.longtask import DepLongTaskTarget
|
||||||
from konabot.common.nb.extract_image import download_image_bytes
|
from konabot.common.nb.extract_image import download_image_bytes
|
||||||
from konabot.common.nb.qq_broadcast import qq_broadcast
|
from konabot.common.nb.qq_broadcast import qq_broadcast
|
||||||
|
from konabot.common.username import get_username
|
||||||
from konabot.plugins.kona_ph.core.storage import Puzzle, PuzzleManager, get_today_date, puzzle_manager
|
from konabot.plugins.kona_ph.core.storage import Puzzle, PuzzleManager, get_today_date, puzzle_manager
|
||||||
|
|
||||||
PUZZLE_PAGE_SIZE = 10
|
PUZZLE_PAGE_SIZE = 10
|
||||||
@ -41,11 +42,11 @@ def get_puzzle_info_message(manager: PuzzleManager, puzzle: Puzzle) -> UniMessag
|
|||||||
msg = UniMessage.text(
|
msg = UniMessage.text(
|
||||||
f"--- 谜题信息 ---\n"
|
f"--- 谜题信息 ---\n"
|
||||||
f"Raw ID: {puzzle.raw_id}\n"
|
f"Raw ID: {puzzle.raw_id}\n"
|
||||||
f"标题: {puzzle.title}\n"
|
f"出题者: {get_username(puzzle.author_id)} | {puzzle.author_id}\n"
|
||||||
f"出题者 ID: {puzzle.author_id}\n"
|
|
||||||
f"创建时间: {puzzle.created_at.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
f"创建时间: {puzzle.created_at.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
||||||
f"Flag: {puzzle.flag}\n"
|
|
||||||
f"状态: {status}{status_suffix}\n\n"
|
f"状态: {status}{status_suffix}\n\n"
|
||||||
|
f"标题: {puzzle.title}\n"
|
||||||
|
f"Flag: {puzzle.flag}\n\n"
|
||||||
f"{puzzle.content}"
|
f"{puzzle.content}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,6 +81,8 @@ def create_admin_commands():
|
|||||||
dest="modify",
|
dest="modify",
|
||||||
),
|
),
|
||||||
Subcommand("publish", Args["raw_id?", str], dest="publish"),
|
Subcommand("publish", Args["raw_id?", str], dest="publish"),
|
||||||
|
Subcommand("preview", Args["raw_id", str], dest="preview"),
|
||||||
|
Subcommand("get-submits", Args["raw_id", str], dest="get-submits")
|
||||||
),
|
),
|
||||||
rule=is_puzzle_manager,
|
rule=is_puzzle_manager,
|
||||||
)
|
)
|
||||||
@ -93,6 +96,8 @@ def create_admin_commands():
|
|||||||
msg = msg.text("konaph info <id> - 查看谜题\n")
|
msg = msg.text("konaph info <id> - 查看谜题\n")
|
||||||
msg = msg.text("konaph my <page?> - 查看我的谜题列表\n")
|
msg = msg.text("konaph my <page?> - 查看我的谜题列表\n")
|
||||||
msg = msg.text("konaph modify - 查看如何修改谜题信息\n")
|
msg = msg.text("konaph modify - 查看如何修改谜题信息\n")
|
||||||
|
msg = msg.text("konaph preview <id> - 预览一个题目的效果,不会展示答案\n")
|
||||||
|
msg = msg.text("konaph get-submits <id> - 获得题目的提交记录\n")
|
||||||
|
|
||||||
if is_puzzle_admin(target):
|
if is_puzzle_admin(target):
|
||||||
msg = msg.text("konaph all [--ready] <page?> - 查看所有谜题\n")
|
msg = msg.text("konaph all [--ready] <page?> - 查看所有谜题\n")
|
||||||
@ -196,7 +201,7 @@ def create_admin_commands():
|
|||||||
if manager.puzzle_pinned == p.raw_id:
|
if manager.puzzle_pinned == p.raw_id:
|
||||||
message = message.text("[📌]")
|
message = message.text("[📌]")
|
||||||
if manager.is_puzzle_published(p.raw_id):
|
if manager.is_puzzle_published(p.raw_id):
|
||||||
message = message.text(f"[#{p.index_id}] ")
|
message = message.text(f"[✨][#{p.index_id}] ")
|
||||||
elif p.ready:
|
elif p.ready:
|
||||||
message = message.text("[✅] ")
|
message = message.text("[✅] ")
|
||||||
else:
|
else:
|
||||||
@ -227,7 +232,7 @@ def create_admin_commands():
|
|||||||
if p.raw_id == manager.puzzle_pinned:
|
if p.raw_id == manager.puzzle_pinned:
|
||||||
message = message.text("[📌]")
|
message = message.text("[📌]")
|
||||||
if manager.is_puzzle_published(p.raw_id):
|
if manager.is_puzzle_published(p.raw_id):
|
||||||
message = message.text(f"[#{p.index_id}] ")
|
message = message.text(f"[✨][#{p.index_id}] ")
|
||||||
elif p.ready:
|
elif p.ready:
|
||||||
message = message.text("[✅] ")
|
message = message.text("[✅] ")
|
||||||
else:
|
else:
|
||||||
@ -284,7 +289,7 @@ def create_admin_commands():
|
|||||||
"支持的参数:\n"
|
"支持的参数:\n"
|
||||||
" --title <str> 标题\n"
|
" --title <str> 标题\n"
|
||||||
" --description <str> 题目详情描述(用直引号包裹以支持多行)\n"
|
" --description <str> 题目详情描述(用直引号包裹以支持多行)\n"
|
||||||
" --flag <str> flag\n"
|
" --flag <str> flag,也就是题目的答案\n"
|
||||||
" --image <图片> 图片\n"
|
" --image <图片> 图片\n"
|
||||||
" --remove-image 删除图片"
|
" --remove-image 删除图片"
|
||||||
)
|
)
|
||||||
@ -300,7 +305,11 @@ def create_admin_commands():
|
|||||||
if description is not None:
|
if description is not None:
|
||||||
p.content = description
|
p.content = description
|
||||||
if flag is not None:
|
if flag is not None:
|
||||||
p.flag = flag
|
p.flag = flag.strip()
|
||||||
|
if flag.strip() != flag:
|
||||||
|
await target.send_message(
|
||||||
|
"⚠️ 注意:你输入的 Flag 含有开头或结尾的空格,已经帮你去除"
|
||||||
|
)
|
||||||
if image is not None and image.url is not None:
|
if image is not None and image.url is not None:
|
||||||
b = await download_image_bytes(image.url)
|
b = await download_image_bytes(image.url)
|
||||||
p.add_image(b.unwrap())
|
p.add_image(b.unwrap())
|
||||||
@ -326,4 +335,31 @@ def create_admin_commands():
|
|||||||
await qq_broadcast(config.plugin_puzzle_playgroup, p.get_unimessage())
|
await qq_broadcast(config.plugin_puzzle_playgroup, p.get_unimessage())
|
||||||
return await target.send_message("Ok!")
|
return await target.send_message("Ok!")
|
||||||
|
|
||||||
|
@cmd_admin.assign("preview")
|
||||||
|
async def _(target: DepLongTaskTarget, raw_id: str):
|
||||||
|
async with puzzle_manager() as manager:
|
||||||
|
puzzle = manager.puzzle_data.get(raw_id)
|
||||||
|
if puzzle is None:
|
||||||
|
return await target.send_message("没有这个谜题")
|
||||||
|
if not is_puzzle_admin(target) and target.target_id != puzzle.author_id:
|
||||||
|
return await target.send_message("你没有权限预览这个谜题")
|
||||||
|
return await target.send_message(puzzle.get_unimessage())
|
||||||
|
|
||||||
|
@cmd_admin.assign("get-submits")
|
||||||
|
async def _(target: DepLongTaskTarget, raw_id: str):
|
||||||
|
async with puzzle_manager() as manager:
|
||||||
|
puzzle = manager.puzzle_data.get(raw_id)
|
||||||
|
if puzzle is None:
|
||||||
|
return await target.send_message("没有这个谜题")
|
||||||
|
if not is_puzzle_admin(target) and target.target_id != puzzle.author_id:
|
||||||
|
return await target.send_message("你没有权限预览这个谜题")
|
||||||
|
|
||||||
|
msg = UniMessage.text(f"==== {puzzle.title} 提交记录 ====\n\n")
|
||||||
|
submits = manager.submissions.get(raw_id, {})
|
||||||
|
for uid, ls in submits.items():
|
||||||
|
s = ', '.join((i.flag for i in ls))
|
||||||
|
msg = msg.text(f"- {get_username(uid)}:{s}\n")
|
||||||
|
return await target.send_message(msg)
|
||||||
|
|
||||||
|
|
||||||
return cmd_admin
|
return cmd_admin
|
||||||
|
|||||||
Reference in New Issue
Block a user