This commit is contained in:
@@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "jwebot-official-extensions"
|
||||
version = "0.6.10a0+1015"
|
||||
version = "0.6.11a0+1015"
|
||||
description = "Reviewed local command adapters and broker implementation for JWeBot"
|
||||
requires-python = ">=3.9"
|
||||
dependencies = [
|
||||
"jwebot-sdk==0.6.10a0+1015",
|
||||
"jwebot-sdk==0.6.11a0+1015",
|
||||
]
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
|
||||
@@ -90,4 +90,4 @@ __all__ = [
|
||||
"render_feature_list",
|
||||
]
|
||||
|
||||
__version__ = "0.6.10a0+1015"
|
||||
__version__ = "0.6.11a0+1015"
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"""Generated reviewed adapter for coin-ranking."""
|
||||
|
||||
from jwebot_sdk import Event, ExtensionResult, ReplyPlan, SingleGroupContext
|
||||
|
||||
|
||||
PROFILE = 'coin-ranking'
|
||||
AUTHOR = 'jwebot'
|
||||
DESCRIPTION = '富榜'
|
||||
HELP_ENTRIES = ('/大富翁榜',)
|
||||
COMMANDS = ('/金币排行', '/金币排行榜', '/大富翁榜', '/richlist')
|
||||
|
||||
|
||||
def _handler(context: SingleGroupContext, command: str):
|
||||
def handle(event: Event, arguments: str) -> ExtensionResult:
|
||||
response = context.services.call(
|
||||
PROFILE,
|
||||
operation="execute",
|
||||
payload={
|
||||
"command": command,
|
||||
"arguments": arguments,
|
||||
"event": event.to_mapping(),
|
||||
},
|
||||
)
|
||||
texts = response.get("texts")
|
||||
if isinstance(texts, list) and texts and all(
|
||||
isinstance(item, str) and item.strip() for item in texts
|
||||
):
|
||||
return ExtensionResult(
|
||||
reply=ReplyPlan.multi_text(texts),
|
||||
metadata={"local_extension": PROFILE, "author": AUTHOR},
|
||||
)
|
||||
text = response.get("text")
|
||||
if not isinstance(text, str) or not text.strip():
|
||||
raise ValueError("local service returned invalid text")
|
||||
return ExtensionResult(
|
||||
reply=ReplyPlan.text(text),
|
||||
metadata={"local_extension": PROFILE, "author": AUTHOR},
|
||||
)
|
||||
|
||||
return handle
|
||||
|
||||
|
||||
def plugin(context: SingleGroupContext) -> None:
|
||||
for command in COMMANDS:
|
||||
context.commands.register(command, _handler(context, command))
|
||||
@@ -42,6 +42,10 @@ LOCAL_COMMAND_ALIASES = {
|
||||
"context": "context_summary",
|
||||
"金币": "wallet",
|
||||
"wallet": "wallet",
|
||||
"金币排行": "coin_ranking",
|
||||
"金币排行榜": "coin_ranking",
|
||||
"大富翁榜": "coin_ranking",
|
||||
"richlist": "coin_ranking",
|
||||
"转账": "transfer",
|
||||
"transfer": "transfer",
|
||||
"贷款": "loan",
|
||||
@@ -171,6 +175,13 @@ LOCAL_EXTENSIONS = (
|
||||
help_entries=("/转账 对方 金额;/transfer",),
|
||||
command_kinds=("transfer",),
|
||||
),
|
||||
LocalExtensionDescriptor(
|
||||
extension_id="coin-ranking",
|
||||
author=JWEBOT_AUTHOR,
|
||||
description="富榜",
|
||||
help_entries=("/大富翁榜",),
|
||||
command_kinds=("coin_ranking",),
|
||||
),
|
||||
LocalExtensionDescriptor(
|
||||
extension_id="coin-loan",
|
||||
author=JWEBOT_AUTHOR,
|
||||
|
||||
@@ -154,6 +154,7 @@ class LocalCommandEngine:
|
||||
return self.reply_cleaner(self.person_index(row, kind, arguments))
|
||||
if kind in {
|
||||
"wallet",
|
||||
"coin_ranking",
|
||||
"transfer",
|
||||
"loan",
|
||||
"repay",
|
||||
|
||||
@@ -175,6 +175,8 @@ class PlayerGames:
|
||||
return self.game_history(row, arguments)
|
||||
if kind == "lottery":
|
||||
return self.group_lottery(row, arguments)
|
||||
if kind == "coin_ranking":
|
||||
return self.coin_ranking(row, arguments)
|
||||
if kind == "transfer":
|
||||
return self.transfer(row, arguments)
|
||||
if kind in {"loan", "repay"}:
|
||||
@@ -316,6 +318,29 @@ class PlayerGames:
|
||||
str(row["group_fingerprint"]), str(row["sender"]),
|
||||
str(row["event_id"]), kind + ":" + arguments, execute)
|
||||
|
||||
def coin_ranking(self, row: dict[str, Any], arguments: str) -> str:
|
||||
value = arguments.strip()
|
||||
if value and not re.fullmatch(r"\d{1,2}", value):
|
||||
return "用法:/大富翁榜 或 /金币排行 [人数]"
|
||||
limit = int(value or 10)
|
||||
if not 1 <= limit <= 20:
|
||||
return "金币排行人数必须为 1~20"
|
||||
records = self.ledger.player_coin_ranking(
|
||||
str(row["group_fingerprint"]),
|
||||
limit=limit,
|
||||
)
|
||||
if not records:
|
||||
return "当前群还没有金币账户;发送 /金币 初始化"
|
||||
lines = ["大富翁榜:"]
|
||||
for index, record in enumerate(records, start=1):
|
||||
loan = int(record.get("loan", 0))
|
||||
loan_text = f"(未还贷款 {loan})" if loan else ""
|
||||
lines.append(
|
||||
f"{index}. {record['display_name']} {record['balance']} 金币"
|
||||
f"{loan_text}"
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
@staticmethod
|
||||
def parse_transfer(
|
||||
arguments: str,
|
||||
|
||||
Reference in New Issue
Block a user