feat: event_manager

This commit is contained in:
skkeye
2024-02-22 19:50:00 -05:00
parent 318bc500c8
commit 84b2a8b659
3 changed files with 48 additions and 11 deletions

View File

@@ -1,29 +1,37 @@
use poise::serenity_prelude as serenity;
struct Data {} // User data, which is stored and accessible in all command invocations
pub struct Data {} // User data, which is stored and accessible in all command invocations
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
/// Displays your or another user's account creation date
pub mod event_handlers;
/// Ping command with latency measurement
#[poise::command(slash_command, prefix_command)]
async fn age(
ctx: Context<'_>,
#[description = "Selected user"] user: Option<serenity::User>,
) -> Result<(), Error> {
let u = user.as_ref().unwrap_or_else(|| ctx.author());
let response = format!("{}'s account was created at {}", u.name, u.created_at());
ctx.say(response).await?;
async fn ping(ctx: Context<'_>) -> Result<(), Error> {
let original_msg_timestamp = ctx.created_at();
let msg = ctx.say("Pong!").await?.into_message().await?;
let latency = msg.timestamp.timestamp_millis() - original_msg_timestamp.timestamp_millis();
ctx.say(format!("Latency: {}ms", latency)).await?;
Ok(())
}
#[tokio::main]
async fn main() {
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
let intents = serenity::GatewayIntents::non_privileged();
let intents =
serenity::GatewayIntents::non_privileged().union(serenity::GatewayIntents::MESSAGE_CONTENT);
let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![age()],
prefix_options: poise::PrefixFrameworkOptions {
prefix: Some(String::from("!")),
..Default::default()
},
commands: vec![ping()],
event_handler: |ctx, event, framework, data| {
Box::pin(event_handlers::sc_event_handler(ctx, event, framework, data))
},
..Default::default()
})
.setup(|ctx, _ready, framework| {