testsAndMisc/PYTHON/lichess_bot
Krzysztof kuhy Rudnicki 4da77b6cfe fix(lint): remove FBT001/FBT002/FBT003 and ARG001/ARG002 from global ignores
FBT001/FBT002 fixes:
- Make boolean params keyword-only with *, syntax in:
  - stockfish_analysis/analyze_chess_game.py: pov_white
  - lichess_bot/main.py: decline_correspondence
  - screen_locker/screen_lock.py: demo_mode
- Update call sites to use keyword arguments

ARG001/ARG002 fixes:
- Prefix unused params with underscore:
  - extractLinks/main.py: tag -> _tag
  - lichess_bot/lichess_api.py: game_id -> _game_id
  - lichess_bot/tests/conftest.py: config -> _config

FBT003 per-file ignores (external API calls):
- PYTHON/keyboardCoop/main.py: pygame.font.render
- PYTHON/screen_locker/screen_lock.py: tkinter API
- poker-modifier-app/poker_modifier_app.py: tkinter API
2025-11-30 16:23:16 +01:00
..
tests fix(lint): remove FBT001/FBT002/FBT003 and ARG001/ARG002 from global ignores 2025-11-30 16:23:16 +01:00
tools fix: replace asserts with combined None checks for ruff S101 2025-11-30 16:03:14 +01:00
__init__.py fix: correct shebang and executable permissions 2025-11-30 13:42:16 +01:00
.bot_version fix: correct shebang and executable permissions 2025-11-30 13:42:16 +01:00
engine.py fix: correct mypy ignore comment for attr-defined error 2025-11-30 15:49:40 +01:00
lichess_api.py fix(lint): remove FBT001/FBT002/FBT003 and ARG001/ARG002 from global ignores 2025-11-30 16:23:16 +01:00
main.py fix(lint): remove FBT001/FBT002/FBT003 and ARG001/ARG002 from global ignores 2025-11-30 16:23:16 +01:00
README.md fix: correct shebang and executable permissions 2025-11-30 13:42:16 +01:00
requirements.txt fix: correct shebang and executable permissions 2025-11-30 13:42:16 +01:00
run_tests.sh feat: added tests for lichess bot 2025-08-23 15:16:26 +02:00
run.sh fix: not able to start game as white 2025-08-22 17:04:42 +02:00
utils.py Enable D100-D107 docstring rules: add docstrings to all modules, classes, methods, and functions 2025-11-30 14:45:55 +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.