use crate::serenity_prelude as serenity;
use crate::BoxFuture;
pub struct FrameworkBuilder<U, E> {
setup: Option<
Box<
dyn Send
+ Sync
+ for<'a> FnOnce(
&'a serenity::Context,
&'a serenity::Ready,
&'a crate::Framework<U, E>,
) -> BoxFuture<'a, Result<U, E>>,
>,
>,
options: Option<crate::FrameworkOptions<U, E>>,
commands: Vec<crate::Command<U, E>>,
initialize_owners: bool,
}
impl<U, E> Default for FrameworkBuilder<U, E> {
fn default() -> Self {
Self {
setup: Default::default(),
options: Default::default(),
commands: Default::default(),
initialize_owners: true,
}
}
}
impl<U, E> FrameworkBuilder<U, E> {
#[must_use]
pub fn setup<F>(mut self, setup: F) -> Self
where
F: Send
+ Sync
+ 'static
+ for<'a> FnOnce(
&'a serenity::Context,
&'a serenity::Ready,
&'a crate::Framework<U, E>,
) -> BoxFuture<'a, Result<U, E>>,
{
self.setup = Some(Box::new(setup) as _);
self
}
#[must_use]
pub fn options(mut self, options: crate::FrameworkOptions<U, E>) -> Self {
self.options = Some(options);
self
}
pub fn initialize_owners(mut self, initialize_owners: bool) -> Self {
self.initialize_owners = initialize_owners;
self
}
pub fn build(self) -> crate::Framework<U, E>
where
U: Send + Sync + 'static,
E: Send + 'static,
{
let setup = self
.setup
.expect("No user data setup function was provided to the framework");
let mut options = self.options.expect("No framework options provided");
options.commands.extend(self.commands);
options.initialize_owners = self.initialize_owners;
crate::Framework::new(options, setup)
}
}