1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! 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.
//!
//! ## 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 of the leaderboard 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.
//!
//! [`aoc_leaderbot`]: https://github.com/clechasseur/aoc_leaderbot
//! [Advent of Code]: https://adventofcode.com/
//! [`run_bot`]: leaderbot::run_bot
//! [`Config`]: leaderbot::Config
//! [leaderboard ID]: leaderbot::Config::leaderboard_id
//! [AoC credentials]: leaderbot::Config::credentials
//! [year]: leaderbot::Config::year
//! [`Storage`]: leaderbot::Storage
//! [`Reporter`]: leaderbot::Reporter
//! [`report_changes`]: leaderbot::Reporter::report_changes
//! [`report_error`]: leaderbot::Reporter::report_error
//! [`report_first_run`]: leaderbot::Reporter::report_first_run
//! [`aoc_leaderbot_slack_lib`]: https://crates.io/crates/aoc_leaderbot_slack_lib
//! [`MemoryConfig`]: leaderbot::config::mem::MemoryConfig
//! [`get_env_config`]: leaderbot::config::env::get_env_config
//! [`MemoryStorage`]: leaderbot::storage::mem::MemoryStorage
//! [`serde`]: https://serde.rs/
pub
pub use Error;
pub use ErrorKind;
pub use Result;