-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ana-rchy/dev
add fact check command
- Loading branch information
Showing
8 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters