diff --git a/assets/fact_check/american.webp b/assets/fact_check/american.webp new file mode 100644 index 0000000..76d1938 Binary files /dev/null and b/assets/fact_check/american.webp differ diff --git a/assets/fact_check/batman.gif b/assets/fact_check/batman.gif new file mode 100644 index 0000000..cce750c Binary files /dev/null and b/assets/fact_check/batman.gif differ diff --git a/assets/fact_check/star_wars_imperial.gif b/assets/fact_check/star_wars_imperial.gif new file mode 100644 index 0000000..56a2a7d Binary files /dev/null and b/assets/fact_check/star_wars_imperial.gif differ diff --git a/assets/fact_check/trump_false.gif b/assets/fact_check/trump_false.gif new file mode 100644 index 0000000..4444383 Binary files /dev/null and b/assets/fact_check/trump_false.gif differ diff --git a/assets/fact_check/unsc.gif b/assets/fact_check/unsc.gif new file mode 100644 index 0000000..fbca159 Binary files /dev/null and b/assets/fact_check/unsc.gif differ diff --git a/src/commands.rs b/src/commands.rs new file mode 100644 index 0000000..0c8efa8 --- /dev/null +++ b/src/commands.rs @@ -0,0 +1,36 @@ +use poise::{serenity_prelude::CreateAttachment, reply::CreateReply}; +use tokio::fs::File; + +type Data = (); +type Error = Box; +type Context<'a> = poise::Context<'a, Data, Error>; + +#[poise::command(prefix_command, slash_command)] +pub async fn fact_check(ctx: Context<'_>) -> Result<(), Error> { + let image = get_fact_check_image().await; + let attachment = CreateAttachment + ::file(&image, "fact_check.png").await.unwrap(); + + let reply = CreateReply { + attachments: vec![attachment], + ..Default::default() + }; + + ctx.send(reply).await?; + + Ok(()) +} + + +async fn get_fact_check_image() -> File { + let paths = std::fs::read_dir("assets/fact_check/").unwrap(); + let mut images: Vec = vec![]; + for path in paths { + images.push(path.unwrap().path().display().to_string()); + } + + let rand_index = rand::random::() % images.len(); + let image = &images[rand_index]; + + File::open(image).await.unwrap() +} diff --git a/src/lib.rs b/src/lib.rs index 5c031ed..c4713ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod jobs; pub mod motd; pub mod web; +pub mod commands; diff --git a/src/main.rs b/src/main.rs index affbf95..28ab183 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use eveningbot::jobs; +use eveningbot::{commands, jobs}; use poise::serenity_prelude::{self as serenity}; use std::sync::Arc; use tokio_cron_scheduler::JobScheduler; @@ -24,7 +24,11 @@ pub async fn poise_setup() -> serenity::Client { let framework = poise::Framework::<(), Error>::builder() .options(poise::FrameworkOptions { - commands: vec![], + commands: vec![commands::fact_check()], + prefix_options: poise::PrefixFrameworkOptions { + prefix: Some("!".into()), + ..Default::default() + }, ..Default::default() }) .setup(|ctx, _ready, framework| {