diff --git a/.env.example b/.env.example index c609549..58e3816 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ DISCORD_TOKEN= -PREFIX="-h " \ No newline at end of file +PREFIX="-h " +CHALLENGE_DIR=/path/to/challenge/content/folder \ No newline at end of file diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs new file mode 100644 index 0000000..6aa5dbf --- /dev/null +++ b/src/commands/challenge.rs @@ -0,0 +1,25 @@ +use serenity::framework::standard::{macros::command, Args, CommandResult}; +use serenity::model::prelude::*; +use serenity::prelude::*; + +use std::env; +use std::fs; + +#[command] +async fn challenge(ctx: &Context, msg: &Message) -> CommandResult { + println!("Command received"); + let challenge_dir = env::var("CHALLENGE_DIR").unwrap(); + let paths = fs::read_dir(challenge_dir).unwrap(); + let challenge = { + let mut max = 0; + for path in paths { + let number = path.unwrap().path().file_stem().unwrap().to_str().unwrap().parse::().unwrap(); + if number > max { + max = number; + } + } + max + }; + msg.reply(&ctx.http, format!("Tegaki Tuesday #{n}: https://tegakituesday.com/{n}", n = challenge)).await?; + Ok(()) +} \ No newline at end of file diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3158fa4..68d80c7 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,2 +1,3 @@ pub mod kanji; pub mod owner; +pub mod challenge; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b38a517..c8559b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ mod commands; use std::{collections::HashSet, env, sync::Arc}; -use commands::{kanji::*, owner::*}; +use commands::{kanji::*, owner::*, challenge::*}; use serenity::{ async_trait, client::bridge::gateway::ShardManager, @@ -43,7 +43,7 @@ impl EventHandler for Handler { } #[group] -#[commands(joyo, jinmeiyo, kyoiku, jlpt, hyogai, so, sleep)] +#[commands(joyo, jinmeiyo, kyoiku, jlpt, hyogai, so, challenge, sleep)] struct General; #[tokio::main]