aoc_leaderbot_lib 2.0.0

Support library for aoc_leaderbot, an Advent of Code leaderboard-watching bot
docs.rs failed to build aoc_leaderbot_lib-2.0.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: aoc_leaderbot_lib-0.2.0

aoc_leaderbot_lib

CI codecov Security audit crates.io Crates.io MSRV downloads docs.rs Contributor Covenant

Library implementing the core functionalities of aoc_leaderbot, a bot that can watch an Advent of Code private leaderboard for changes and report them to various channels like Slack.

Installing

Add aoc_leaderbot_lib to your dependencies:

[dependencies]
aoc_leaderbot_lib = "2.0.0"

or by running:

cargo add aoc_leaderbot_lib

Usage

The bot's body is implemented via the run_bot function. This function will fetch the current version of the AoC leaderboard, then check if we had a previous version (from an earlier run). If no previous version exists, the bot reports the first run, saves the current version and exists. Otherwise, the bot compare the current leaderboard data with the previous one. If there are new members or if existing members got new stars, it reports changes and saves the current version as the last one seen.

In order to function, the bot needs three things, which are passed using traits.

Config

This trait is used by the bot to fetch information about what AoC leaderboard to watch. It is a read-only trait providing three pieces of information: the leaderboard ID, the AoC credentials and the year. The latter defaults to the current year.

Storage

This trait abstracts the bot's storage facility. It is used to load leaderboard data from a previous run and to save any new leaderboard data, as well as store information about errors that might be seen during bot execution.

Reporter

This trait abstracts the bot's capability to report leaderboard changes when it finds some. Its main purpose is to implement the report_changes method to report changes to the user. This could be via a Slack post, a Discord message, etc.

The reporter can also be used to report any error occurring during bot execution (ex: expired AoC session token, etc.) via its report_error method, as well as report the first bot run via its report_first_run method.

Concrete implementations

Although this library includes the bot's core function, it does not provide all possible implementations of the traits it needs for operations. This library includes two implementations of Config, one implementation of Storage and no implementation of Reporter. Users will thus need to implement a Reporter at a minimum.

For other trait implementations, you can look at related crates like aoc_leaderbot_slack_lib.

MemoryConfig

Required feature: config-mem (enabled by default)

This implementation of Config simply stores its values in memory. The most basic implementation, but it works.

get_env_config

Required feature: config-env (enabled by default)

This function returns an opaque Config implementation fetching the parameters from environment variables. This is possibly the most flexible way of providing the bot its config, which is why it is enabled by default.

MemoryStorage

Required feature: storage-mem

This implementation of Storage simply stores its data in memory. Although this means that it would technically lose its data upon program exit, the whole storage can be persisted using serde, which means it's a possibly-decent implementation.

Minimum Rust version

aoc_leaderbot_lib currently builds on Rust 1.88 or newer.

Contributing / Local development

For information about contributing to this project, see CONTRIBUTING. For information regarding local development, see DEVELOPMENT.