From 7c77b7fd61c032c17d4d79805057ba0fa862f06b Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Thu, 6 Feb 2020 14:15:06 -0500 Subject: [PATCH] Load youmubot-cf --- youmubot-cf/src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++++- youmubot/Cargo.toml | 4 +++- youmubot/src/main.rs | 4 ++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/youmubot-cf/src/lib.rs b/youmubot-cf/src/lib.rs index 057a3a2..dcab2a9 100644 --- a/youmubot-cf/src/lib.rs +++ b/youmubot-cf/src/lib.rs @@ -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::()?; + let http = ctx.data.get_cloned::(); + + 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(()) +} diff --git a/youmubot/Cargo.toml b/youmubot/Cargo.toml index 5d5469a..c20d200 100644 --- a/youmubot/Cargo.toml +++ b/youmubot/Cargo.toml @@ -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 } diff --git a/youmubot/src/main.rs b/youmubot/src/main.rs index 54e765b..a7e0526 100644 --- a/youmubot/src/main.rs +++ b/youmubot/src/main.rs @@ -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 }