49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use std::sync::atomic::AtomicBool;
|
|
|
|
use serenity::async_trait;
|
|
use serenity::model::{
|
|
gateway::Ready,
|
|
id::ChannelId,
|
|
};
|
|
use serenity::prelude::{Context, EventHandler};
|
|
use crate::config::{Config, ManifoldConfig};
|
|
|
|
use crate::responses::Responses;
|
|
|
|
pub struct Handler {
|
|
pub timer_running: AtomicBool,
|
|
}
|
|
|
|
impl Handler {
|
|
pub fn new() -> Self {
|
|
Handler {
|
|
timer_running: AtomicBool::from(false)
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl EventHandler for Handler {
|
|
async fn ready(&self, ctx: Context, _data_about_bot: Ready) {
|
|
let data = ctx.data.read().await;
|
|
let config = match data.get::<ManifoldConfig>() {
|
|
Some(c) => c.lock().await,
|
|
None => return
|
|
};
|
|
|
|
let responses = match data.get::<Responses>() {
|
|
Some(r) => r.lock().await,
|
|
None => return
|
|
};
|
|
|
|
let greeting = match responses.get_response(&"bot startup".to_string()) {
|
|
Some(g) => g.replace("{NAME}", &*ctx.cache.current_user().await.name).replace("{COFFEE_TYPE}", "espresso").to_string(),
|
|
None => "Manifold bot connected to discord and ready to begin broadcast operations.".to_string(),
|
|
};
|
|
|
|
let channel: ChannelId = config.get_channel(&"Log".to_string());
|
|
|
|
channel.say(&ctx, greeting).await.expect("Couldn't message log channel!");
|
|
}
|
|
}
|