Load youmubot-cf

This commit is contained in:
Natsu Kagami 2020-02-06 14:15:06 -05:00
parent 3ad172a5b6
commit 7c77b7fd61
Signed by: nki
GPG key ID: 73376E117CD20735
3 changed files with 52 additions and 2 deletions

View file

@ -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(())
}

View file

@ -6,9 +6,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["core", "osu"]
default = ["core", "osu", "codeforces"]
core = []
osu = ["youmubot-osu"]
codeforces = ["youmubot-cf"]
[dependencies]
serenity = "0.8"
@ -17,4 +18,5 @@ youmubot-db = { path = "../youmubot-db" }
youmubot-prelude = { path = "../youmubot-prelude" }
youmubot-core = { path = "../youmubot-core" }
youmubot-osu = { path = "../youmubot-osu", optional = true }
youmubot-cf = { path = "../youmubot-cf", optional = true }

View file

@ -71,6 +71,8 @@ fn main() {
println!("Core enabled.");
#[cfg(feature = "osu")]
println!("osu! enabled.");
#[cfg(feature = "codeforces")]
println!("codeforces enabled.");
client.with_framework(fw);
@ -155,5 +157,7 @@ fn setup_framework(client: &Client) -> StandardFramework {
.group(&youmubot_core::COMMUNITY_GROUP);
#[cfg(feature = "osu")]
let fw = fw.group(&youmubot_osu::discord::OSU_GROUP);
#[cfg(feature = "codeforces")]
let fw = fw.group(&youmubot_cf::CODEFORCES_GROUP);
fw
}