Add challenge command

late-submissions
Elnu 3 years ago
parent 810e3f09c4
commit 66b52c491d

@ -1,2 +1,3 @@
DISCORD_TOKEN=
PREFIX="-h "
CHALLENGE_DIR=/path/to/challenge/content/folder

@ -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::<i32>().unwrap();
if number > max {
max = number;
}
}
max
};
msg.reply(&ctx.http, format!("Tegaki Tuesday #{n}: https://tegakituesday.com/{n}", n = challenge)).await?;
Ok(())
}

@ -1,2 +1,3 @@
pub mod kanji;
pub mod owner;
pub mod challenge;

@ -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]

Loading…
Cancel
Save