initial commit

This commit is contained in:
Pierre de Lacroix 2026-06-22 16:49:17 +02:00
commit f83fded289
Signed by: lateralus23
GPG key ID: 53E0CEC29C24EF39
15 changed files with 6084 additions and 0 deletions

84
src/main.rs Normal file
View file

@ -0,0 +1,84 @@
/*
Copyright © 2026 Anzenlang
Licensed under the PolyForm Noncommercial License 1.0.0
https://polyformproject.org/licenses/noncommercial/
SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
SPDX-AI-Restriction: No training allowed. See NOTICE file.
See LICENSE file for complete terms.
WARNING: The contents of this file may NOT be used to train AI/LLM models. See NOTICE for legal
details.
*/
use clap::{Parser};
use shift_bot::*;
prelude! {}
/// Runs the shift bot.
#[derive(Parser, Debug)]
#[command(version, about)]
struct Clap {
/// Verbosity level.
#[arg(short, long, value_name = "NATURAL", default_value_t = 2)]
verb: usize,
/// Wipe the static data directory before doing anything.
#[arg(short, long)]
wipe: bool,
/// Identifier of the element bot account to run.
#[arg(
short,
long,
value_name = "MATRIX_USERNAME",
default_value = "shift_bot_dev"
)]
username: String,
/// Homeserver.
#[arg(
short = 's',
long,
value_name = "MATRIX_HOMESERVER",
default_value = "matrix.org"
)]
homeserver: String,
/// Password of the element bot account.
#[arg(short, long, value_name = "PASSWORD")]
password: String,
}
impl Clap {
/// Retrieves the `log::Level` from CLA-s.
fn verb_level(&self) -> log::Level {
match self.verb {
// in quiet mode, only show errors
0 => log::Level::Error,
1 => log::Level::Warn,
2 => log::Level::Info,
3 => log::Level::Debug,
_ => log::Level::Trace,
}
}
/// Sets the main configuration.
async fn run(self) -> Res<()> {
simple_logger::init_with_level(self.verb_level())
.context("something when wrong while initializing logger")?;
conf::set(conf::Main::new());
warmup(self.wipe)?;
let bot = MatrixId::new(self.username, self.homeserver);
let conf = conf::Serve::new(bot, self.password);
serve_bot(conf).await
}
}
#[tokio::main]
async fn main() -> Res<()> {
let clap = Clap::parse();
clap.run().await
}