2024-07-11 04:38:16 +00:00
|
|
|
use anyhow::Result;
|
2024-07-10 19:49:05 +00:00
|
|
|
use crate::telegram::DispatchWithResult;
|
2024-07-04 01:15:39 +00:00
|
|
|
|
2024-07-04 22:47:10 +00:00
|
|
|
pub(crate) mod database;
|
2024-07-11 05:53:51 +00:00
|
|
|
pub(crate) mod utils;
|
2024-07-04 01:15:39 +00:00
|
|
|
mod telegram;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
2024-07-04 22:47:10 +00:00
|
|
|
// Logging setup
|
2024-07-10 19:49:05 +00:00
|
|
|
pretty_env_logger::init();
|
|
|
|
log::debug!("Logging initialized successfully!");
|
|
|
|
|
2024-07-04 22:47:10 +00:00
|
|
|
// Telegram setup
|
2024-07-10 19:49:05 +00:00
|
|
|
log::trace!("Setting up Telegram bot dispatcher...");
|
|
|
|
let mut telegram_dispatcher = telegram::dispatcher();
|
|
|
|
let telegram_awaitable = telegram_dispatcher.dispatch_with_result();
|
|
|
|
|
|
|
|
// Run all services concurrently
|
|
|
|
log::info!("Starting services...");
|
2024-07-11 04:38:16 +00:00
|
|
|
let result = tokio::try_join![
|
2024-07-10 19:49:05 +00:00
|
|
|
telegram_awaitable,
|
|
|
|
];
|
2024-07-04 01:15:39 +00:00
|
|
|
|
2024-07-10 19:49:05 +00:00
|
|
|
// This should never happen, but just in case...
|
2024-07-11 04:38:16 +00:00
|
|
|
match result {
|
|
|
|
Err(error) => {
|
|
|
|
log::error!("A service has exited with an error, bailing out: {error:?}");
|
|
|
|
anyhow::bail!("A service has exited with an error.")
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
log::error!("All service have exited successfully, bailing out...");
|
|
|
|
anyhow::bail!("All service have exited successfully.")
|
|
|
|
}
|
|
|
|
}
|
2024-07-04 01:15:39 +00:00
|
|
|
}
|