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 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 config::Config;
|
||||||
use log::*;
|
use log::*;
|
||||||
use poise::{
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
dotenvy::dotenv().ok();
|
dotenvy::dotenv().ok();
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let token =
|
let token = std::env::var("DISCORD_BOT_TOKEN")
|
||||||
std::env::var("TOKEN").wrap_err_with(|| eyre!("Couldn't find token in environment!"))?;
|
.wrap_err_with(|| "Couldn't find bot token in environment!")?;
|
||||||
|
|
||||||
let intents =
|
let intents =
|
||||||
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
||||||
|
|
||||||
let options = FrameworkOptions {
|
let options = FrameworkOptions {
|
||||||
commands: commands::to_global_commands(),
|
commands: commands::to_global_commands(),
|
||||||
|
|
||||||
on_error: |error| Box::pin(handlers::handle_error(error)),
|
on_error: |error| Box::pin(handlers::handle_error(error)),
|
||||||
|
|
||||||
command_check: Some(|ctx| {
|
command_check: Some(|ctx| {
|
||||||
Box::pin(async move { Ok(ctx.author().id != ctx.framework().bot_id) })
|
Box::pin(async move { Ok(ctx.author().id != ctx.framework().bot_id) })
|
||||||
}),
|
}),
|
||||||
|
|
||||||
event_handler: |ctx, event, framework, data| {
|
event_handler: |ctx, event, framework, data| {
|
||||||
Box::pin(handlers::handle_event(ctx, event, framework, data))
|
Box::pin(handlers::handle_event(ctx, event, framework, data))
|
||||||
},
|
},
|
||||||
|
|
||||||
prefix_options: PrefixFrameworkOptions {
|
prefix_options: PrefixFrameworkOptions {
|
||||||
prefix: Some("r".into()),
|
prefix: Some("r".into()),
|
||||||
edit_tracker: Some(EditTracker::for_timespan(Duration::from_secs(3600))),
|
edit_tracker: Some(EditTracker::for_timespan(Duration::from_secs(3600))),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,16 +91,7 @@ async fn main() -> Result<()> {
|
||||||
.token(token)
|
.token(token)
|
||||||
.intents(intents)
|
.intents(intents)
|
||||||
.options(options)
|
.options(options)
|
||||||
.setup(|ctx, _ready, framework| {
|
.setup(|ctx, ready, framework| Box::pin(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)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
result = framework.run() => { result.map_err(Report::from) },
|
result = framework.run() => { result.map_err(Report::from) },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue