Initial commit
This commit is contained in:
commit
c826b8a819
15 changed files with 4417 additions and 0 deletions
11
bot/Cargo.toml
Normal file
11
bot/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "bot"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
eva = { workspace = true, features = ["tokio"] }
|
||||
viendesu.workspace = true
|
||||
|
||||
eyre.workspace = true
|
||||
teloxide = { version = "0.17.0", default-features = false, features = ["macros", "rustls", "cache-me"] }
|
7
bot/src/config.rs
Normal file
7
bot/src/config.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use eva::{data, utils::SecretString};
|
||||
|
||||
#[data]
|
||||
pub struct Config {
|
||||
pub token: SecretString,
|
||||
pub endpoint: Option<String>,
|
||||
}
|
29
bot/src/lib.rs
Normal file
29
bot/src/lib.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use eva::{component_configs::ComponentConfig, supervisor::SlaveRx, trait_set};
|
||||
|
||||
use eyre::Context;
|
||||
use teloxide::Bot;
|
||||
|
||||
use viendesu::service::Service;
|
||||
|
||||
pub use self::config::Config;
|
||||
|
||||
pub mod config;
|
||||
|
||||
trait_set! {
|
||||
pub trait Api = Service + Clone;
|
||||
}
|
||||
|
||||
pub async fn run<A: Api>(api: A, rx: SlaveRx, config: ComponentConfig<Config>) -> eyre::Result<()> {
|
||||
_ = rx;
|
||||
|
||||
let mut bot = Bot::new(config.token.read().wrap_err("failed to read bot token")?);
|
||||
if let Some(api_endpoint) = &config.endpoint {
|
||||
bot = bot.set_api_url(
|
||||
api_endpoint
|
||||
.parse()
|
||||
.wrap_err("failed to parse bot api endpoint")?,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue