diff --git a/euphoxide-bot/Cargo.toml b/euphoxide-bot/Cargo.toml index 988a1d7..c1f80c3 100644 --- a/euphoxide-bot/Cargo.toml +++ b/euphoxide-bot/Cargo.toml @@ -6,6 +6,7 @@ edition = { workspace = true } [dependencies] cookie = { workspace = true } euphoxide = { path = "../euphoxide" } +jiff = { workspace = true } log = { workspace = true } tokio = { workspace = true, features = ["rt"] } tokio-tungstenite = { workspace = true } diff --git a/euphoxide-bot/src/bot.rs b/euphoxide-bot/src/bot.rs new file mode 100644 index 0000000..0e24906 --- /dev/null +++ b/euphoxide-bot/src/bot.rs @@ -0,0 +1,64 @@ +use std::sync::Arc; + +use jiff::Timestamp; +use tokio::sync::mpsc; + +use crate::{ + instance::ServerConfig, + instances::{Event, Instances, InstancesConfig}, +}; + +#[derive(Debug, Clone)] +#[non_exhaustive] +pub struct BotConfig { + pub server: ServerConfig, + pub instances: InstancesConfig, + pub state: S, +} + +impl BotConfig { + pub fn with_state(self, state: S2) -> BotConfig { + BotConfig { + server: self.server, + instances: self.instances, + state, + } + } + + pub fn create(self, event_tx: mpsc::Sender) -> Bot { + Bot::new(self, event_tx) + } +} + +impl Default for BotConfig<()> { + fn default() -> Self { + Self { + server: ServerConfig::default(), + instances: InstancesConfig::default(), + state: (), + } + } +} + +#[derive(Clone)] +pub struct Bot { + pub server_config: ServerConfig, + pub state: Arc, + pub instances: Instances, + pub start_time: Timestamp, +} + +impl Bot { + pub fn new(config: BotConfig, event_tx: mpsc::Sender) -> Self { + Self { + server_config: config.server, + state: Arc::new(config.state), + instances: Instances::new(config.instances, event_tx), + start_time: Timestamp::now(), + } + } + + pub fn handle_event(&self, event: Event) { + todo!() + } +} diff --git a/euphoxide-bot/src/instances.rs b/euphoxide-bot/src/instances.rs index d9e5d2d..4d51526 100644 --- a/euphoxide-bot/src/instances.rs +++ b/euphoxide-bot/src/instances.rs @@ -134,6 +134,7 @@ impl InstancesTask { async fn on_cmd(&mut self, cmd: Command) { match cmd { Command::GetInstances(tx) => { + self.purge_instances(); // Not necessary for correctness let _ = tx.send(self.instances.values().cloned().collect()); } Command::AddInstance(config, tx) => { diff --git a/euphoxide-bot/src/lib.rs b/euphoxide-bot/src/lib.rs index d777157..4ecf479 100644 --- a/euphoxide-bot/src/lib.rs +++ b/euphoxide-bot/src/lib.rs @@ -1,2 +1,3 @@ +pub mod bot; pub mod instance; pub mod instances;