1
0
forked from sass/tipibot

Some bug updates

This commit is contained in:
Rene Arumetsa
2026-05-03 14:45:42 +03:00
parent 58684d5f34
commit d65173fbe9
2 changed files with 18 additions and 11 deletions

View File

@@ -690,18 +690,19 @@ async def do_season_reset(top_n: int = 10) -> list[tuple[str, int, int]]:
# Internal write helper # Internal write helper
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
async def _commit(user_id: int, user: UserData) -> None: async def _commit(user_id: int, user: UserData) -> None:
record_id = user.get("_pb_id") # type: ignore[typeddict-item]
clean = {k: v for k, v in user.items() if k != "_pb_id"}
clean["user_id"] = str(user_id)
try: try:
record_id = user.get("_pb_id") # type: ignore[typeddict-item]
clean = {k: v for k, v in user.items() if k != "_pb_id"}
clean["user_id"] = str(user_id)
if record_id: if record_id:
await pb_client.update_record(record_id, clean) await pb_client.update_record(record_id, clean)
else: else:
_log.warning("_commit for user %s had no _pb_id; creating new record", user_id) _log.warning("_commit for user %s had no _pb_id; creating new record", user_id)
created = await pb_client.create_record(clean) created = await pb_client.create_record(clean)
user["_pb_id"] = created["id"] # type: ignore[typeddict-unknown-key] user["_pb_id"] = created["id"] # type: ignore[typeddict-unknown-key]
except Exception as exc: except (aiohttp.ClientError, asyncio.TimeoutError, RuntimeError) as exc:
_log.error("_commit failed for user %s: %s", user_id, exc) _log.error("_commit failed for user %s: %s", user_id, exc)
raise DatabaseError(f"Failed to persist user {user_id}: {exc}") from exc
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -952,9 +953,13 @@ async def do_fish_sell(user_id: int, indices: list[int] | None = None) -> dict:
to_sell = inv to_sell = inv
remaining = [] remaining = []
else: else:
valid_indices = [i if i >= 0 else len(inv) + i for i in indices] sell_idx = {
to_sell = [inv[i] for i in sorted(set(valid_indices)) if 0 <= i < len(inv)] (i if i >= 0 else len(inv) + i)
keep_idx = set(range(len(inv))) - set(indices) for i in indices
}
sell_idx = {i for i in sell_idx if 0 <= i < len(inv)}
to_sell = [inv[i] for i in sorted(sell_idx)]
keep_idx = set(range(len(inv))) - sell_idx
remaining = [inv[i] for i in sorted(keep_idx)] remaining = [inv[i] for i in sorted(keep_idx)]
if not to_sell: if not to_sell:

View File

@@ -1,8 +1,10 @@
# TipiBOTi muudatuste logi # TipiBOT changelog
Siit leiad ülevaate TipiBOTi uuendustest. Uusimad muudatused on üleval. Here you'll find an overview of TipiBOT updates. Latest changes are at the top.
Vorminda iga versioon `## ` peakirjaga (nt `## v0.1.0 — 2026-05-03`). Format each version with a `## ` header (e.g. `## v0.1.0 — 2026-05-03`).
## v0.1.0 — 2026-05-03 ## v0.1.0 — 2026-05-03
- Lisatud `/patchnotes` - Added `/patchnotes`
- Fixed silent swallowing of database write errors — failed saves now show the user an error instead of appearing to succeed
- Fixed fish-sell bug that let the last fish be duplicated (sold and kept in inventory)