Skip to content

fix(admin,db): fix /kill and /unban crashes, persist bans, harden add_user - #119

Merged
d-Rickyy-b merged 1 commit into
masterfrom
claude/project-thread-gbpez2-admin-db
Oct 8, 2026
Merged

d-Rickyy-b merged 1 commit into
masterfrom
claude/project-thread-gbpez2-admin-db

Conversation

@d-Rickyy-b

Copy link
Copy Markdown
Owner

Requested by Rico · project thread

Before:

  • /kill without a chat id replied "Please provide a chat_id!" and then crashed with an IndexError.
  • /unban <id> for a user who wasn't banned crashed with a KeyError.
  • /ban <id> for someone who never used the bot only worked until the next restart.
  • A user without a Telegram language_code, or one who had used /language before /start, hit an IntegrityError in add_user. The error was swallowed and left a half-written user in the open transaction, which the next unrelated commit then committed.

After: /kill just shows the usage hint. Unbanning a user who isn't banned is a no-op. Bans of unknown users are stored in the database. New users are always stored with a valid chat row.

How:

  • kill_game_cmd now returns after the usage hint.
  • unban_user uses set.discard instead of set.remove.
  • ban_user runs INSERT OR IGNORE for the users row before setting banned=1.
  • _add_user defaults the language to "en", uses INSERT OR IGNORE for the chats row (an existing language choice is kept), and rolls back on any remaining IntegrityError.

New tests are in database/tests/database_test.py. They use random user ids and clean up after themselves. Three of them fail on master and all four pass with this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KouGQtM6VBedfBdNr8WFX5


Generated by Claude Code

@d-Rickyy-b d-Rickyy-b self-assigned this Oct 8, 2026
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 69.363% (+1.4%) from 67.99% — claude/project-thread-gbpez2-admin-db into master

@coveralls

coveralls commented Oct 8, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 69.363% (+1.4%) from 67.99% — claude/project-thread-gbpez2-admin-db into master

…_user

- /kill without a chat_id replied with a usage hint and then crashed
  with an IndexError, because it didn't return.
- /unban for a user who wasn't banned raised a KeyError. Use
  set.discard instead of set.remove.
- Banning a user who has no row in the users table only added them to
  the in-memory set, so the ban was lost on restart. Insert a users row
  first if it doesn't exist.
- add_user swallowed IntegrityErrors without rolling back, leaving a
  half written user in the open transaction. Users without a Telegram
  language_code violated the NOT NULL constraint of chats.lang_id, and
  users whose chat row already existed (after /language) hit the
  primary key. Default the language to "en", ignore an existing chat
  row and roll back on remaining errors.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KouGQtM6VBedfBdNr8WFX5
@d-Rickyy-b
d-Rickyy-b force-pushed the claude/project-thread-gbpez2-admin-db branch from 22aa4ae to 5479be6 Compare October 8, 2026 21:32
@d-Rickyy-b
d-Rickyy-b merged commit ced54b0 into master Oct 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants