Skip to content

Commit

Permalink
Merge pull request #4 from ana-rchy/dev
Browse files Browse the repository at this point in the history
add fact check command
  • Loading branch information
ana-rchy authored May 12, 2024
2 parents ef1361f + a70987a commit 86c9427
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
Binary file added assets/fact_check/american.webp
Binary file not shown.
Binary file added assets/fact_check/batman.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fact_check/star_wars_imperial.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fact_check/trump_false.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fact_check/unsc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use poise::{serenity_prelude::CreateAttachment, reply::CreateReply};
use tokio::fs::File;

type Data = ();
type Error = Box<dyn std::error::Error + Send + Sync>;
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<String> = vec![];
for path in paths {
images.push(path.unwrap().path().display().to_string());
}

let rand_index = rand::random::<usize>() % images.len();
let image = &images[rand_index];

File::open(image).await.unwrap()
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod jobs;
pub mod motd;
pub mod web;
pub mod commands;
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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| {
Expand Down

0 comments on commit 86c9427

Please sign in to comment.