shuttle_serenity/
lib.rs

1#![doc = include_str!("../README.md")]
2use shuttle_runtime::{CustomError, Error};
3use std::net::SocketAddr;
4
5#[cfg(feature = "serenity")]
6use serenity::Client;
7#[cfg(feature = "serenity-0-11")]
8use serenity_0_11::Client;
9
10#[cfg(feature = "serenity")]
11pub use serenity;
12#[cfg(feature = "serenity-0-11")]
13pub use serenity_0_11 as serenity;
14
15/// A wrapper type for [serenity::Client] so we can implement [shuttle_runtime::Service] for it.
16pub struct SerenityService(pub Client);
17
18#[shuttle_runtime::async_trait]
19impl shuttle_runtime::Service for SerenityService {
20    /// Takes the client that is returned by the user in their [shuttle_runtime::main] function
21    /// and starts it.
22    async fn bind(mut self, _addr: SocketAddr) -> Result<(), Error> {
23        self.0.start_autosharded().await.map_err(CustomError::new)?;
24
25        Ok(())
26    }
27}
28
29impl From<Client> for SerenityService {
30    fn from(router: Client) -> Self {
31        Self(router)
32    }
33}
34
35#[doc = include_str!("../README.md")]
36pub type ShuttleSerenity = Result<SerenityService, Error>;