refactor framework setup
This commit is contained in:
parent
3e992bf683
commit
885e28f98f
1 changed files with 22 additions and 13 deletions
35
src/main.rs
35
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use color_eyre::eyre::{eyre, Context as _, Report, Result};
|
||||
use color_eyre::eyre::{Context as _, Report, Result};
|
||||
use config::Config;
|
||||
use log::*;
|
||||
use poise::{
|
||||
|
@ -40,32 +40,50 @@ impl Data {
|
|||
}
|
||||
}
|
||||
|
||||
async fn setup(
|
||||
ctx: &serenity::Context,
|
||||
_ready: &serenity::Ready,
|
||||
framework: &Framework<Data, Report>,
|
||||
) -> Result<Data> {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
info!("Registered global commands!");
|
||||
|
||||
let data = Data::new()?;
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
dotenvy::dotenv().ok();
|
||||
color_eyre::install()?;
|
||||
env_logger::init();
|
||||
|
||||
let token =
|
||||
std::env::var("TOKEN").wrap_err_with(|| eyre!("Couldn't find token in environment!"))?;
|
||||
let token = std::env::var("DISCORD_BOT_TOKEN")
|
||||
.wrap_err_with(|| "Couldn't find bot token in environment!")?;
|
||||
|
||||
let intents =
|
||||
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
||||
|
||||
let options = FrameworkOptions {
|
||||
commands: commands::to_global_commands(),
|
||||
|
||||
on_error: |error| Box::pin(handlers::handle_error(error)),
|
||||
|
||||
command_check: Some(|ctx| {
|
||||
Box::pin(async move { Ok(ctx.author().id != ctx.framework().bot_id) })
|
||||
}),
|
||||
|
||||
event_handler: |ctx, event, framework, data| {
|
||||
Box::pin(handlers::handle_event(ctx, event, framework, data))
|
||||
},
|
||||
|
||||
prefix_options: PrefixFrameworkOptions {
|
||||
prefix: Some("r".into()),
|
||||
edit_tracker: Some(EditTracker::for_timespan(Duration::from_secs(3600))),
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
@ -73,16 +91,7 @@ async fn main() -> Result<()> {
|
|||
.token(token)
|
||||
.intents(intents)
|
||||
.options(options)
|
||||
.setup(|ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
info!("Registered global commands!");
|
||||
|
||||
let data = Data::new()?;
|
||||
|
||||
Ok(data)
|
||||
})
|
||||
});
|
||||
.setup(|ctx, ready, framework| Box::pin(setup(ctx, ready, framework)));
|
||||
|
||||
tokio::select! {
|
||||
result = framework.run() => { result.map_err(Report::from) },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue