mirror of
https://github.com/supleed2/nanobot.git
synced 2024-12-22 22:25:51 +00:00
Add service module
To multiplex discord bot and http server in shuttle
This commit is contained in:
parent
d62fabb048
commit
1b8914cf67
20
src/service.rs
Normal file
20
src/service.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use crate::{Data, Error};
|
||||||
|
|
||||||
|
pub(crate) struct NanoBot {
|
||||||
|
pub discord: poise::FrameworkBuilder<Data, Error>,
|
||||||
|
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(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue