45 lines
1.0 KiB
Rust
45 lines
1.0 KiB
Rust
//! Event handling for the gateway sub-module.
|
|
|
|
use std::sync::Arc;
|
|
|
|
use async_trait::async_trait;
|
|
use twilight_model::gateway::payload::incoming::Ready;
|
|
|
|
use crate::{
|
|
framework::{
|
|
events::traits::{EventResult, OnReadyHandler, OnReconnectHandler},
|
|
runtime::Runtime,
|
|
},
|
|
state::State,
|
|
};
|
|
|
|
/// Logs a ready message when the bot is ready.
|
|
#[derive(Debug)]
|
|
pub struct ReadyHandler;
|
|
|
|
#[async_trait]
|
|
impl OnReadyHandler<State> for ReadyHandler {
|
|
async fn on_ready(&self, event: &Ready, _: Arc<Runtime<State>>) -> EventResult {
|
|
log::info!(
|
|
"Ready! Logged in as {}#{:>04}",
|
|
event.user.name,
|
|
event.user.discriminator
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// Logs a reconnection message when the gateway asks for a reconnection.
|
|
#[derive(Debug)]
|
|
pub struct ReconnectHandler;
|
|
|
|
#[async_trait]
|
|
impl OnReconnectHandler<State> for ReconnectHandler {
|
|
async fn on_reconnect(&self, _: Arc<Runtime<State>>) -> EventResult {
|
|
log::info!("The gateway asked for a reconnection");
|
|
|
|
Ok(())
|
|
}
|
|
}
|