feat(events/mod): adding the database to events
This commit is contained in:
parent
452fa0edd8
commit
6c858abb0a
1 changed files with 4 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ pub mod bot;
|
||||||
|
|
||||||
use crate::commands::SlashCommand;
|
use crate::commands::SlashCommand;
|
||||||
use serenity::all::*;
|
use serenity::all::*;
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
#[serenity::async_trait]
|
#[serenity::async_trait]
|
||||||
pub trait BotEvent: Send + Sync {
|
pub trait BotEvent: Send + Sync {
|
||||||
|
|
@ -13,6 +14,7 @@ pub trait BotEvent: Send + Sync {
|
||||||
_ctx: &Context,
|
_ctx: &Context,
|
||||||
_interaction: &Interaction,
|
_interaction: &Interaction,
|
||||||
_commands: &[Box<dyn SlashCommand>],
|
_commands: &[Box<dyn SlashCommand>],
|
||||||
|
_db: &PgPool,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
async fn on_message(&self, _ctx: &Context, _msg: &Message) {}
|
async fn on_message(&self, _ctx: &Context, _msg: &Message) {}
|
||||||
|
|
@ -34,6 +36,7 @@ pub fn import() -> Vec<Box<dyn BotEvent>> {
|
||||||
pub struct Bot {
|
pub struct Bot {
|
||||||
pub commands: Vec<Box<dyn SlashCommand>>,
|
pub commands: Vec<Box<dyn SlashCommand>>,
|
||||||
pub events: Vec<Box<dyn BotEvent>>,
|
pub events: Vec<Box<dyn BotEvent>>,
|
||||||
|
pub database: PgPool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serenity::async_trait]
|
#[serenity::async_trait]
|
||||||
|
|
@ -51,7 +54,7 @@ impl EventHandler for Bot {
|
||||||
.filter(|e| e.event_type() == "interaction_create")
|
.filter(|e| e.event_type() == "interaction_create")
|
||||||
{
|
{
|
||||||
event
|
event
|
||||||
.on_interaction_create(&ctx, &interaction, &self.commands)
|
.on_interaction_create(&ctx, &interaction, &self.commands, &self.database)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue