36 releases

0.1.36 Feb 1, 2021
0.1.35 Feb 1, 2021
0.1.34 Jan 29, 2021

#3 in #export-rust-log-info

Download history 71/week @ 2023-10-31 46/week @ 2023-11-07 8/week @ 2023-11-14 44/week @ 2023-11-21 116/week @ 2023-11-28 40/week @ 2023-12-05 44/week @ 2023-12-12 8/week @ 2023-12-19 78/week @ 2023-12-26 4/week @ 2024-01-02 44/week @ 2024-01-09 9/week @ 2024-01-16 40/week @ 2024-01-23 76/week @ 2024-01-30 7/week @ 2024-02-06 193/week @ 2024-02-13

318 downloads per month

MIT and AGPL-3.0-only

36KB
643 lines

lichessbot

documentation Crates.io Crates.io (recent)

Lichess bot. Under construction.

Usage

use log::{info, log_enabled, Level};

extern crate env_logger;

use dotenv::dotenv;

use lichessbot::lichessbot::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    dotenv().ok();
    env_logger::init();

    let bot = Box::leak(Box::new(
        LichessBot::new()
            .uci_opt("Move Overhead", 500)
            .uci_opt("Threads", 4)
            .uci_opt("Hash", 128)
            .uci_opt("Contempt", -25)
            .enable_classical(false)
            .enable_rapid(false)
            .disable_blitz(false)
            .disable_bullet(false)
            .enable_ultrabullet(false)
            .enable_casual(true)
            .disable_rated(false),
    ));

    if log_enabled!(Level::Info) {
        info!("starting bot stream");
    }

    let (tx, mut rxa) = bot.stream().await;

    tokio::time::sleep(tokio::time::Duration::from_millis(120000)).await;

    let _ = tx.send("stopped by user".to_string()).await;

    let result = rxa.recv().await;

    if log_enabled!(Level::Info) {
        info!("stop stream result {:?}", result);
    }

    Ok(())
}

Logging

export RUST_LOG=info
# or 
export RUST_LOG=debug

Config

Set environment as follows:

Token

RUST_BOT_TOKEN={lichess API token with bot scopes}

Bot name

RUST_BOT_NAME={bot lichess username}

example

RUST_BOT_NAME=chesshyperbot

Engine name ( optional )

RUST_BOT_ENGINE_NAME={engine executable name}

examples

Linux RUST_BOT_ENGINE_NAME=./stockfish12

Windows RUST_BOT_ENGINE_NAME=stockfish12.exe

If no engine name is provided, random moves will be played.

Dependencies

~13–28MB
~430K SLoC