Add HeXi bot codebase: custom plugins, web frontends, tests
- hexi core: message handling, rate limiting, cooldown, plugin manager - Custom plugins: BF stats, daily check-in, quotes, persona cards, etc. - Community plugins vendored under hexi/plugins with local fixes - Web admin frontends (learning-chat, persona-admin), unified hexi/web - Tests for rate_limit/cooldown/memes/persona; poetry.lock Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import random
|
||||
import re
|
||||
|
||||
from nonebot import on_regex, on_startswith, require
|
||||
from nonebot.adapters.onebot.v11 import MessageEvent
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.typing import T_State
|
||||
|
||||
require("nonebot_plugin_alconna")
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="掷骰子",
|
||||
description="掷骰子 / 结婚判定",
|
||||
usage=".r 掷骰子\n.r 3d12 掷3次12面骰子\n.r 2d3~6+1 掷2次3~6面骰子并加1\n.qj [名字] 与xxx结婚判定",
|
||||
type="application",
|
||||
)
|
||||
|
||||
dice = on_regex(
|
||||
re.compile(
|
||||
r"^\.r\s*(?:(?P<num>\d{0,2})d(?:(?P<min>\d{1,4})~)?(?P<max>\d{0,4})(?:(?P<opr>[+-])(?P<offset>\d{0,5}))?)?\b",
|
||||
re.I,
|
||||
)
|
||||
)
|
||||
marriage = on_startswith(".qj")
|
||||
|
||||
|
||||
async def do_dice(
|
||||
ev: MessageEvent,
|
||||
num: int,
|
||||
min_: int,
|
||||
max_: int,
|
||||
opr: int,
|
||||
offset: int,
|
||||
tip: str = "的掷骰结果是:",
|
||||
) -> None:
|
||||
if num == 0:
|
||||
await UniMessage.text("咦?我骰子呢?").send()
|
||||
return
|
||||
min_, max_ = min(min_, max_), max(min_, max_)
|
||||
rolls = [random.randint(min_, max_) for _ in range(num)]
|
||||
total = sum(rolls)
|
||||
rolls_str = "+".join(map(str, rolls))
|
||||
if len(rolls_str) > 100:
|
||||
rolls_str = str(total)
|
||||
res = total + opr * offset
|
||||
sign = " +-"[opr]
|
||||
msg = [
|
||||
f"{tip}\n",
|
||||
str(num) if num > 1 else "",
|
||||
"D",
|
||||
f"{min_}~" if min_ != 1 else "",
|
||||
str(max_),
|
||||
f"{sign}{offset}" if offset else "",
|
||||
f"={rolls_str}",
|
||||
f"{sign}{offset}" if offset else "",
|
||||
f"={res}" if offset or num > 1 else "",
|
||||
]
|
||||
await UniMessage.text("".join(msg)).send(at_sender=True)
|
||||
|
||||
|
||||
@dice.handle()
|
||||
async def dice_handle(ev: MessageEvent, state: T_State):
|
||||
num, min_, max_, opr, offset = 1, 1, 100, 1, 0
|
||||
matched = state.get("_matched_dict") or {}
|
||||
if s := matched.get("num"):
|
||||
num = int(s)
|
||||
if s := matched.get("min"):
|
||||
min_ = int(s)
|
||||
if s := matched.get("max"):
|
||||
max_ = int(s)
|
||||
if s := matched.get("opr"):
|
||||
opr = -1 if s == "-" else 1
|
||||
if s := matched.get("offset"):
|
||||
offset = int(s)
|
||||
await do_dice(ev, num, min_, max_, opr, offset)
|
||||
|
||||
|
||||
@marriage.handle()
|
||||
async def marriage_handle(ev: MessageEvent):
|
||||
text = ev.message.extract_plain_text().strip()
|
||||
wife = text[len(".qj") :].strip()
|
||||
tip = f"与{wife}的ケッコンカッコカリ结果是:" if wife else "的ケッコンカッコカリ结果是:"
|
||||
await do_dice(ev, 1, 3, 6, 1, 0, tip)
|
||||
Reference in New Issue
Block a user