Files
p4bl0t/src/discord/mod.rs
Lucien Cartier-Tilet 60a81f66a8
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 8m1s
feat: Enable Docker deployment and CD
Closes #8, partially addresses #6
2023-11-26 04:22:56 +01:00

50 lines
1.5 KiB
Rust

mod commands;
pub mod error;
mod events;
pub mod utils;
use poise::FrameworkBuilder;
use tracing::info;
use utils::serenity;
use commands::logging;
use utils::{BotData, Context, Error};
use self::events::event_handler;
pub type Result = ::std::result::Result<(), Error>;
/// Bootstraps the Discord bot.
///
/// # Panics
///
/// Panics if the environment `DISCORD_TOKEN` is unavailable.
pub fn make_bot() -> FrameworkBuilder<BotData, Error> {
match std::env::var("DISCORD_TOKEN") {
Ok(token) => {
info!("Launching bot with token {token}");
poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![logging()],
event_handler: |ctx, event, framework, data| {
Box::pin(event_handler(ctx, event, framework, data))
},
..Default::default()
})
.token(token)
.intents(serenity::GatewayIntents::non_privileged())
.setup(|ctx, _ready, framework| {
Box::pin(async move {
poise::builtins::register_globally(
ctx,
&framework.options().commands,
)
.await?;
Ok(BotData::new().await?)
})
})
}
Err(_) => panic!("DISCORD_TOKEN environment variable is missing."),
}
}