mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 09:10:49 +00:00
Load youmubot-cf
This commit is contained in:
parent
3ad172a5b6
commit
7c77b7fd61
3 changed files with 52 additions and 2 deletions
|
@ -1 +1,45 @@
|
|||
pub mod embed;
|
||||
use serenity::{
|
||||
framework::standard::{
|
||||
macros::{command, group},
|
||||
Args, CommandResult,
|
||||
},
|
||||
model::{channel::Message, id::UserId},
|
||||
};
|
||||
use youmubot_prelude::*;
|
||||
|
||||
mod embed;
|
||||
|
||||
#[group]
|
||||
#[prefix = "cf"]
|
||||
#[description = "Codeforces-related commands"]
|
||||
#[commands(profile)]
|
||||
#[default_command(profile)]
|
||||
pub struct Codeforces;
|
||||
|
||||
#[command]
|
||||
#[aliases("p", "show", "u", "user", "get")]
|
||||
#[description = "Get an user's profile"]
|
||||
#[usage = "[handle or tag = yourself]"]
|
||||
#[example = "natsukagami"]
|
||||
#[num_args(1)]
|
||||
pub fn profile(ctx: &mut Context, m: &Message, mut args: Args) -> CommandResult {
|
||||
let handle = args.single::<String>()?;
|
||||
let http = ctx.data.get_cloned::<HTTPClient>();
|
||||
|
||||
let account = codeforces::User::info(&http, &[&handle[..]])?
|
||||
.into_iter()
|
||||
.next();
|
||||
|
||||
match account {
|
||||
Some(v) => m.channel_id.send_message(&ctx, |send| {
|
||||
send.content(format!(
|
||||
"{}: Here is the user that you requested",
|
||||
m.author.mention()
|
||||
))
|
||||
.embed(|e| embed::user_embed(&v, e))
|
||||
}),
|
||||
None => m.reply(&ctx, "User not found"),
|
||||
}?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue