-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.rs
65 lines (58 loc) · 2 KB
/
data.rs
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
use std::fmt::Display;
use std::fs;
use crossterm::style::Color as Colour;
use lazy_static::lazy_static;
use pathdiv::PathDiv;
use regex::Regex;
lazy_static! {
pub(crate) static ref DATA_DIR: PathDiv = {
let path = PathDiv::new()
/ dirs::home_dir().expect(concat!(
"Failed to determine home directory.",
" Please set the HOME environment variable.",
))
/ ".config"
/ "aoc_helper";
if !path.exists() {
fs::create_dir_all(&path).expect("Failed to create data directory.");
}
path
};
pub(crate) static ref PRACTICE_DATA_DIR: PathDiv = {
let path = PathDiv::new()
/ dirs::home_dir().expect(concat!(
"Failed to determine home directory.",
" Please set the HOME environment variable.",
))
/ ".config"
/ "aoc_helper"
/ "practice";
if !path.exists() {
fs::create_dir_all(&path).expect("Failed to create data directory.");
}
path
};
pub(crate) static ref TOKEN_FILE: PathDiv = &*DATA_DIR / "token.txt";
pub(crate) static ref WAIT_TIME: Regex =
Regex::new(r"You have (?:(\d+)m )?(\d+)s left to wait.").expect("Infallible");
pub(crate) static ref RANK: Regex =
Regex::new(r"You (?:got|achieved) rank (\d+) on this star's leaderboard.")
.expect("Infallible");
}
pub(crate) const USER_AGENT: &str = concat!(
"github.com/starwort/raoc v",
env!("CARGO_PKG_VERSION"),
" contact: Discord @starwort",
" Github https://github.com/Starwort/raoc/issues",
);
pub(crate) const GOLD: Colour = Colour::Rgb {
r: 255,
g: 215,
b: 135,
};
pub(crate) fn leaderboard_url(year: impl Display, day: impl Display) -> String {
format!("https://adventofcode.com/{year}/leaderboard/day/{day}")
}
pub(crate) fn base_url(year: impl Display, day: impl Display) -> String {
format!("https://adventofcode.com/{year}/day/{day}")
}