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
use anyhow::Result;
use irc::client::prelude::*;
use serde::Deserialize;
use tokio::fs;
const URL: &str = "https://meta.wikimedia.org/wiki/IRC/Bots/ircservserv";
const GIT_VERSION: &str = git_version::git_version!();
#[derive(Deserialize, Default)]
pub struct BotConfig {
#[serde(default)]
password_file: Option<String>,
pub channel_config: String,
#[serde(default)]
pub owners: Vec<String>,
#[serde(default)]
pub trusted: Vec<String>,
pub irc: Config,
}
pub enum TrustLevel {
Owner,
Trusted,
}
impl BotConfig {
pub async fn load(path: &str) -> Result<Self> {
let mut botconfig: BotConfig =
toml::from_str(&fs::read_to_string(path).await?)?;
if let Some(password_file) = &botconfig.password_file {
botconfig.irc.password = Some(
fs::read_to_string(password_file).await?.trim().to_string(),
);
}
botconfig.irc.version = Some(format!("{}, git: {}", URL, GIT_VERSION));
Ok(botconfig)
}
}