testsAndMisc-archive/python_pkg/lichess_bot
Krzysztof kuhy Rudnicki 8f2fbd2311 refactor: enforce 500-line limit on all Python source files
Split 18+ Python files that exceeded 500 lines into smaller modules
with helper files (prefixed with _). All functions are re-exported
from the original modules to maintain backward compatibility with
test patches and external imports.

Files split:
- moviepy_showcase.py (1212 -> 302 + 3 helpers)
- anki_generator.py (1174 -> 473 + 4 helpers)
- test_analyze_chess_game.py (1152 -> 361 + 2 parts)
- poker_modifier_app.py (1024 -> 263 + 2 helpers)
- transcribe_fw.py (1007 -> 342 + 3 helpers)
- music_generator.py (1002 -> 319 + 2 helpers)
- translator.py (951 -> 442 + 2 helpers)
- cinema_planner.py (893 -> 369 + 2 helpers)
- lichess_bot/main.py (757 -> 495 + _game_logic.py)
- test_translator.py (725 -> 289 + part2 + conftest)
- test_lichess_api.py (680 -> 475 + part2)
- learning_pipe.py (668 -> 375 + 2 helpers)
- cache.py (655 -> 360 + _cache_decks.py)
- analyze_chess_game.py (632 -> 463 + _move_analysis.py)
- visualize_q02.py (609 -> 371 + helper)
- repo_explorer.py (602 -> 347 + 2 helpers)
- keyboard_coop/main.py (515 -> 416 + _dictionary.py)
- scanning.py (501 -> 314 + _enforce_loop.py)

All tests pass: 144 lichess_bot (100% branch coverage), 243 others.
No new lint errors introduced.
2026-03-17 22:47:42 +01:00
..
tests refactor: enforce 500-line limit on all Python source files 2026-03-17 22:47:42 +01:00
tools fix: resolve remaining ruff violations (FURB110, PLC0207) 2026-03-14 17:51:55 +01:00
__init__.py refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00
_game_logic.py refactor: enforce 500-line limit on all Python source files 2026-03-17 22:47:42 +01:00
.bot_version refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00
engine.py fix: address all pylint warnings 2025-12-01 16:11:15 +01:00
lichess_api.py feat(tests): add comprehensive tests for lichess_bot engine and API 2025-12-01 20:41:51 +01:00
main.py refactor: enforce 500-line limit on all Python source files 2026-03-17 22:47:42 +01:00
README.md refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00
requirements.txt refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00
run_tests.sh refactor: rename folders to fix N999, INP001, S311 linting rules 2025-11-30 21:20:17 +01:00
run.sh feat: added run sh and makefile scripts 2026-02-22 22:00:50 +01:00
utils.py fix: remove all pylint disable comments and enable all meta checks 2025-12-01 16:22:03 +01:00

Lichess Bot (minimal)

A small Lichess BOT that accepts standard challenges and plays quick random legal moves using python-chess. It demonstrates the Lichess Board API basics with a simple, readable implementation.

Features

  • Connects to Lichess Board API via streaming NDJSON
  • Accepts only standard chess challenges (bullet/blitz/rapid/classical)
  • Spawns a thread per active game
  • Plays random legal moves (swap in a stronger engine later)
  • Simple logging and basic retries on transient network errors

Requirements

  • Python 3.9+
  • A Lichess account that is activated as a BOT
  • A Lichess API access token with at least the scopes:
    • bot:play
    • challenge:read
    • challenge:write

Install dependencies:

pip install -r PYTHON/lichess_bot/requirements.txt

Activate BOT and get a token

  1. Create or use an existing Lichess account for your bot.
  2. Activate it as a BOT (one-time): https://lichess.org/api#tag/Bot
    • If not already BOT, you need to convert the account; follow Lichess docs.
  3. Create a personal API token: https://lichess.org/account/oauth/token/create
    • Grant scopes: bot:play, challenge:read, challenge:write

Export the token in your shell (recommended):

export LICHESS_TOKEN="your_bot_token_here"

Run

From the repo root:

python -m PYTHON.lichess_bot.main

Optional flags:

  • --log-level INFO|DEBUG|WARNING|ERROR (default: INFO)
  • --decline-correspondence (declines correspondence challenges)

You can also use the helper script:

bash PYTHON/lichess_bot/run.sh

Notes

  • The engine is intentionally weak (random moves). Swap it with a UCI engine or implement a better search in engine.py.
  • Network calls hit real Lichess endpoints. Keep the bot polite; respect rate limits.

Development

  • Small unit tests are in tests/ and only cover local helpers (no network). Run:
python -m pytest PYTHON/lichess_bot/tests -q

If you add tests requiring third-party packages, install them in your environment first.