osu check works

This commit is contained in:
Natsu Kagami 2024-02-27 02:18:40 +01:00
parent bcd59c673c
commit 34b0d58966
Signed by: nki
GPG key ID: 55A032EB38B49ADB
6 changed files with 34 additions and 14 deletions

View file

@ -1,6 +1,5 @@
use poise::CreateReply;
use serde::Deserialize;
use serenity::builder::EditMessage;
use serenity::framework::standard::CommandError as Error;
use serenity::{
framework::standard::{

View file

@ -1,21 +1,33 @@
use serenity::all::Member;
use serenity::{all::Member, framework::standard::CommandResult};
use youmubot_prelude::*;
use crate::{discord::args::ScoreDisplay, models::Mods};
#[poise::command(slash_command, subcommands("check"))]
pub async fn osu<T: AsRef<crate::Env> + Sync>(_ctx: CmdContext<'_, T>) -> Result<(), Error> {
pub async fn osu<T: AsRef<crate::discord::Env> + Sync>(_ctx: CmdContext<'_, T>) -> CommandResult {
Ok(())
}
#[poise::command(slash_command)]
/// Check your/someone's score on the last beatmap in the channel
async fn check<T: AsRef<crate::Env> + Sync>(
async fn check<T: AsRef<crate::discord::Env> + Sync>(
ctx: CmdContext<'_, T>,
#[description = "Pass an osu! username to check for scores"] osu_id: Option<String>,
#[description = "Pass a member of the guild to check for scores"] member: Option<Member>,
#[description = "Filter mods that should appear in the scores returned"] mods: Option<Mods>,
#[description = "Score display style"] style: Option<ScoreDisplay>,
) -> Result<()> {
todo!()
) -> CommandResult {
Ok(crate::discord::check_impl(
ctx.data().as_ref(),
ctx.serenity_context(),
ctx.clone(),
ctx.channel_id(),
ctx.author(),
None,
osu_id,
member,
mods,
style,
)
.await?)
}

View file

@ -8,7 +8,7 @@ use crate::{
};
use rand::seq::IteratorRandom;
use serenity::{
all::{ChannelId, Member},
all::{ChannelId, Member, Mention},
builder::{CreateMessage, EditMessage},
collector,
framework::standard::{
@ -329,7 +329,14 @@ pub async fn save(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
pub async fn forcesave(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let data = ctx.data.read().await;
let osu = data.get::<OsuClient>().unwrap();
let target = args.single::<serenity::model::id::UserId>()?;
let target = match args.single::<Mention>()? {
Mention::User(id) => id,
m => {
msg.reply(&ctx, format!("Expected user_id, got {}", m))
.await?;
return Ok(());
}
};
let username = args.quoted().trimmed().single::<String>()?;
let user: Option<User> = osu

View file

@ -89,7 +89,7 @@ pub async fn server_rank(ctx: &Context, m: &Message, mut args: Args) -> CommandR
let users = std::sync::Arc::new(users);
let last_update = last_update.unwrap();
paginate_reply_fn(
move |page: u8, ctx: &Context| {
move |page: u8, _| {
const ITEMS_PER_PAGE: usize = 10;
let users = users.clone();
Box::pin(async move {

View file

@ -1,3 +1,4 @@
use serenity::framework::standard::CommandError;
/// Module `prelude` provides a sane set of default imports that can be used inside
/// a Youmubot source file.
pub use serenity::prelude::*;
@ -40,7 +41,7 @@ pub type AppData = Arc<RwLock<TypeMap>>;
pub struct HTTPClient;
/// The global context type for app commands
pub type CmdContext<'a, Env> = poise::Context<'a, Env, anyhow::Error>;
pub type CmdContext<'a, Env> = poise::Context<'a, Env, CommandError>;
/// The created base environment.
#[derive(Debug, Clone)]

View file

@ -2,7 +2,8 @@ use compose_framework::ComposedFramework;
use dotenv::var;
use serenity::{
framework::standard::{
macros::hook, BucketBuilder, CommandResult, Configuration, DispatchError, StandardFramework,
macros::hook, BucketBuilder, CommandError, CommandResult, Configuration, DispatchError,
StandardFramework,
},
model::{
channel::{Channel, Message},
@ -181,7 +182,7 @@ async fn main() {
// Poise for application commands
let poise_fw = poise::Framework::builder()
.setup(|_, _, _| Box::pin(async { Ok(env) as Result<_> }))
.setup(|_, _, _| Box::pin(async { Ok(env) as Result<_, CommandError> }))
.options(poise::FrameworkOptions {
prefix_options: poise::PrefixFrameworkOptions {
prefix: None,
@ -207,7 +208,7 @@ async fn main() {
}
})
},
commands: vec![poise_register()],
commands: vec![poise_register(), youmubot_osu::discord::app_commands::osu()],
..Default::default()
})
.build();
@ -312,7 +313,7 @@ async fn setup_framework(token: &str) -> StandardFramework {
rename = "register",
required_permissions = "MANAGE_GUILD"
)]
async fn poise_register(ctx: CmdContext<'_, Env>) -> Result<()> {
async fn poise_register(ctx: CmdContext<'_, Env>) -> CommandResult {
// TODO: make this work for guild owners too
poise::builtins::register_application_commands_buttons(ctx).await?;
Ok(())