Add coin leaderboard command
check / local-gate (push) Failing after 1m34s

This commit is contained in:
JWeBot Contributors
2026-10-15 19:00:29 +08:00
parent 148ae672f4
commit bf4f28f48e
26 changed files with 357 additions and 24 deletions
+4 -4
View File
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
[project]
name = "jwebot-kernel"
version = "0.6.10a0+1015"
version = "0.6.11a0+1015"
description = "Stable routing and extension authority for JWeBot"
requires-python = ">=3.9"
dependencies = [
"jwebot-config==0.6.10a0+1015",
"jwebot-sdk==0.6.10a0+1015",
"jwebot-official-extensions==0.6.10a0+1015",
"jwebot-config==0.6.11a0+1015",
"jwebot-sdk==0.6.11a0+1015",
"jwebot-official-extensions==0.6.11a0+1015",
"tomli>=2; python_version < '3.11'",
]
@@ -107,4 +107,4 @@ __all__ = [
"verify_installed_release_signature",
]
__version__ = "0.6.10a0+1015"
__version__ = "0.6.11a0+1015"
@@ -3665,6 +3665,114 @@ class Ledger:
"game_counts": dict(account["game_counts"]),
}
def player_coin_ranking(
self,
group: str,
*,
limit: int = 10,
) -> list[dict[str, Any]]:
group = bounded_text(group, limit=256)
self.seed_person_aliases(group)
with self.lock:
account_rows = [
dict(row)
for row in self.connection.execute(
"""
SELECT person_key, state_json, updated_at
FROM player_accounts
WHERE group_fingerprint = ?
""",
(group,),
).fetchall()
]
alias_rows = [
dict(row)
for row in self.connection.execute(
"""
SELECT DISTINCT canonical_name
FROM person_aliases
WHERE group_fingerprint = ?
""",
(group,),
).fetchall()
]
profile_rows = [
dict(row)
for row in self.connection.execute(
"""
SELECT person_key, display_name
FROM person_profiles
WHERE group_fingerprint = ?
""",
(group,),
).fetchall()
]
observation_rows = [
dict(row)
for row in self.connection.execute(
"""
SELECT person_key, display_name
FROM person_observations
WHERE group_fingerprint = ?
ORDER BY observed_at DESC, created_at DESC
""",
(group,),
).fetchall()
]
labels: dict[str, str] = {}
for row in alias_rows:
canonical = bounded_text(row["canonical_name"], limit=120)
if canonical:
labels[person_scope_key(group, canonical)] = person_display_label(
canonical
)
for row in profile_rows:
person_key = str(row["person_key"])
labels.setdefault(
person_key,
person_display_label(row["display_name"]),
)
for row in observation_rows:
person_key = str(row["person_key"])
labels.setdefault(
person_key,
person_display_label(row["display_name"]),
)
records: list[dict[str, Any]] = []
for row in account_rows:
person_key = str(row["person_key"])
try:
account = json.loads(str(row["state_json"]))
except json.JSONDecodeError as error:
raise LocalCommandError("金币账户状态无效") from error
if not isinstance(account, dict):
raise LocalCommandError("金币账户状态无效")
normalize_player_account(account)
loan = account.get("loan")
loan_principal = (
int(loan.get("principal", 0))
if isinstance(loan, dict)
else 0
)
records.append(
{
"display_name": labels.get(
person_key,
f"玩家 {person_key[:8]}",
),
"balance": int(account["balance"]),
"loan": loan_principal,
"updated_at": str(row["updated_at"]),
}
)
records.sort(
key=lambda item: (
-int(item["balance"]),
str(item["display_name"]).casefold(),
)
)
return records[: max(1, min(int(limit), 20))]
def transfer_player_coins(
self,
group: str,