Set up simple command for osu

This commit is contained in:
Natsu Kagami 2024-12-31 01:18:22 +01:00 committed by Natsu Kagami
parent 125bad04da
commit 2cdff76837
5 changed files with 37 additions and 1 deletions

1
Cargo.lock generated
View file

@ -3382,6 +3382,7 @@ dependencies = [
"dashmap 5.5.3",
"futures-util",
"lazy_static",
"poise",
"rand",
"regex",
"reqwest",

View file

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

View file

@ -0,0 +1,16 @@
use super::*;
use youmubot_prelude::*;
/// osu!-related command group.
#[poise::command(slash_command, subcommands("top"))]
pub async fn osu<U: HasOsuEnv>(_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<U: HasOsuEnv>(ctx: CmdContext<'_, U>, username: Option<String>) -> Result<()> {
todo!()
}

View file

@ -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<T: AsRef<OsuEnv> + 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, "<osu::Env>")

View file

@ -61,6 +61,7 @@ impl AsRef<youmubot_prelude::Env> for Env {
}
}
#[cfg(feature = "osu")]
impl AsRef<youmubot_osu::discord::OsuEnv> 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();