diff --git a/Cargo.lock b/Cargo.lock index 7ba7b5c..34e90d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3382,6 +3382,7 @@ dependencies = [ "dashmap 5.5.3", "futures-util", "lazy_static", + "poise", "rand", "regex", "reqwest", diff --git a/youmubot-osu/Cargo.toml b/youmubot-osu/Cargo.toml index 0d34085..c738006 100644 --- a/youmubot-osu/Cargo.toml +++ b/youmubot-osu/Cargo.toml @@ -20,6 +20,7 @@ rosu-map = "0.1" time = "0.3" serde = { version = "1.0.137", features = ["derive"] } serenity = "0.12" +poise = "0.6" zip = "0.6.2" rand = "0.8" futures-util = "0.3.30" diff --git a/youmubot-osu/src/discord/commands.rs b/youmubot-osu/src/discord/commands.rs new file mode 100644 index 0000000..ce46b88 --- /dev/null +++ b/youmubot-osu/src/discord/commands.rs @@ -0,0 +1,16 @@ +use super::*; +use youmubot_prelude::*; + +/// osu!-related command group. +#[poise::command(slash_command, subcommands("top"))] +pub async fn osu(_ctx: CmdContext<'_, U>) -> Result<()> { + Ok(()) +} + +/// Returns top plays for a given player. +/// +/// If no osu! username is given, defaults to the currently registered user. +#[poise::command(slash_command)] +async fn top(ctx: CmdContext<'_, U>, username: Option) -> Result<()> { + todo!() +} diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index 0dc3827..d0a1884 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -15,6 +15,7 @@ use serenity::{ utils::MessageBuilder, }; +pub use commands::osu as osu_command; use db::{OsuLastBeatmap, OsuSavedUsers, OsuUser, OsuUserMode}; use embeds::{beatmap_embed, score_embed, user_embed}; pub use hook::{dot_osu_hook, hook, score_hook}; @@ -38,6 +39,7 @@ use crate::{ mod announcer; pub(crate) mod beatmap_cache; mod cache; +mod commands; mod db; pub(crate) mod display; pub(crate) mod embeds; @@ -67,6 +69,17 @@ pub struct OsuEnv { pub(crate) beatmaps: BeatmapMetaCache, } +/// Gets an [OsuEnv] from the current environment. +pub trait HasOsuEnv: Send + Sync { + fn osu_env(&self) -> &OsuEnv; +} + +impl + Send + Sync> HasOsuEnv for T { + fn osu_env(&self) -> &OsuEnv { + self.as_ref() + } +} + impl std::fmt::Debug for OsuEnv { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "") diff --git a/youmubot/src/main.rs b/youmubot/src/main.rs index 24e8093..af3e658 100644 --- a/youmubot/src/main.rs +++ b/youmubot/src/main.rs @@ -61,6 +61,7 @@ impl AsRef for Env { } } +#[cfg(feature = "osu")] impl AsRef for Env { fn as_ref(&self) -> &youmubot_osu::discord::OsuEnv { &self.osu @@ -275,7 +276,11 @@ async fn main() { } }) }, - commands: vec![poise_register()], + commands: vec![ + poise_register(), + #[cfg(feature = "osu")] + youmubot_osu::discord::osu_command(), + ], ..Default::default() }) .build();