From 1b8914cf6786a20e918971d848679c04195515bf Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Sat, 23 Sep 2023 23:14:26 +0100 Subject: [PATCH] Add service module To multiplex discord bot and http server in shuttle --- src/service.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/service.rs diff --git a/src/service.rs b/src/service.rs new file mode 100644 index 0000000..aaafff1 --- /dev/null +++ b/src/service.rs @@ -0,0 +1,20 @@ +use crate::{Data, Error}; + +pub(crate) struct NanoBot { + pub discord: poise::FrameworkBuilder, + pub router: axum::Router, +} + +#[shuttle_runtime::async_trait] +impl shuttle_runtime::Service for NanoBot { + async fn bind(mut self, addr: std::net::SocketAddr) -> Result<(), shuttle_runtime::Error> { + let serve = axum::Server::bind(&addr).serve(self.router.into_make_service()); + + tokio::select! { + _ = self.discord.run_autosharded() => {}, + _ = serve => {}, + }; + + Ok(()) + } +}