Skip to content

Commit

Permalink
fact check command added
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-rchy committed May 12, 2024
1 parent 032ea83 commit a70987a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 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.
30 changes: 27 additions & 3 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
use poise::serenity_prelude as serenity;
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<'_>, arg: String) -> Result<(), Error> {
ctx.say("asdasd").await?;
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()
}

0 comments on commit a70987a

Please sign in to comment.