mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 16:58:55 +00:00
osu check works
This commit is contained in:
parent
bcd59c673c
commit
34b0d58966
6 changed files with 34 additions and 14 deletions
|
@ -1,6 +1,5 @@
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serenity::builder::EditMessage;
|
|
||||||
use serenity::framework::standard::CommandError as Error;
|
use serenity::framework::standard::CommandError as Error;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
framework::standard::{
|
framework::standard::{
|
||||||
|
|
|
@ -1,21 +1,33 @@
|
||||||
use serenity::all::Member;
|
use serenity::{all::Member, framework::standard::CommandResult};
|
||||||
use youmubot_prelude::*;
|
use youmubot_prelude::*;
|
||||||
|
|
||||||
use crate::{discord::args::ScoreDisplay, models::Mods};
|
use crate::{discord::args::ScoreDisplay, models::Mods};
|
||||||
|
|
||||||
#[poise::command(slash_command, subcommands("check"))]
|
#[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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command)]
|
||||||
/// Check your/someone's score on the last beatmap in the channel
|
/// 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>,
|
ctx: CmdContext<'_, T>,
|
||||||
#[description = "Pass an osu! username to check for scores"] osu_id: Option<String>,
|
#[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 = "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 = "Filter mods that should appear in the scores returned"] mods: Option<Mods>,
|
||||||
#[description = "Score display style"] style: Option<ScoreDisplay>,
|
#[description = "Score display style"] style: Option<ScoreDisplay>,
|
||||||
) -> Result<()> {
|
) -> CommandResult {
|
||||||
todo!()
|
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?)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use rand::seq::IteratorRandom;
|
use rand::seq::IteratorRandom;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
all::{ChannelId, Member},
|
all::{ChannelId, Member, Mention},
|
||||||
builder::{CreateMessage, EditMessage},
|
builder::{CreateMessage, EditMessage},
|
||||||
collector,
|
collector,
|
||||||
framework::standard::{
|
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 {
|
pub async fn forcesave(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
let osu = data.get::<OsuClient>().unwrap();
|
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 username = args.quoted().trimmed().single::<String>()?;
|
||||||
let user: Option<User> = osu
|
let user: Option<User> = osu
|
||||||
|
|
|
@ -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 users = std::sync::Arc::new(users);
|
||||||
let last_update = last_update.unwrap();
|
let last_update = last_update.unwrap();
|
||||||
paginate_reply_fn(
|
paginate_reply_fn(
|
||||||
move |page: u8, ctx: &Context| {
|
move |page: u8, _| {
|
||||||
const ITEMS_PER_PAGE: usize = 10;
|
const ITEMS_PER_PAGE: usize = 10;
|
||||||
let users = users.clone();
|
let users = users.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use serenity::framework::standard::CommandError;
|
||||||
/// Module `prelude` provides a sane set of default imports that can be used inside
|
/// Module `prelude` provides a sane set of default imports that can be used inside
|
||||||
/// a Youmubot source file.
|
/// a Youmubot source file.
|
||||||
pub use serenity::prelude::*;
|
pub use serenity::prelude::*;
|
||||||
|
@ -40,7 +41,7 @@ pub type AppData = Arc<RwLock<TypeMap>>;
|
||||||
pub struct HTTPClient;
|
pub struct HTTPClient;
|
||||||
|
|
||||||
/// The global context type for app commands
|
/// 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.
|
/// The created base environment.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
@ -2,7 +2,8 @@ use compose_framework::ComposedFramework;
|
||||||
use dotenv::var;
|
use dotenv::var;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
framework::standard::{
|
framework::standard::{
|
||||||
macros::hook, BucketBuilder, CommandResult, Configuration, DispatchError, StandardFramework,
|
macros::hook, BucketBuilder, CommandError, CommandResult, Configuration, DispatchError,
|
||||||
|
StandardFramework,
|
||||||
},
|
},
|
||||||
model::{
|
model::{
|
||||||
channel::{Channel, Message},
|
channel::{Channel, Message},
|
||||||
|
@ -181,7 +182,7 @@ async fn main() {
|
||||||
|
|
||||||
// Poise for application commands
|
// Poise for application commands
|
||||||
let poise_fw = poise::Framework::builder()
|
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 {
|
.options(poise::FrameworkOptions {
|
||||||
prefix_options: poise::PrefixFrameworkOptions {
|
prefix_options: poise::PrefixFrameworkOptions {
|
||||||
prefix: None,
|
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()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
@ -312,7 +313,7 @@ async fn setup_framework(token: &str) -> StandardFramework {
|
||||||
rename = "register",
|
rename = "register",
|
||||||
required_permissions = "MANAGE_GUILD"
|
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
|
// TODO: make this work for guild owners too
|
||||||
poise::builtins::register_application_commands_buttons(ctx).await?;
|
poise::builtins::register_application_commands_buttons(ctx).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue