Add leaderboard

This commit is contained in:
Sakuhl 2018-01-02 00:47:50 +01:00
parent 2b441f42c5
commit a7290926db
2 changed files with 17 additions and 1 deletions

2
Cargo.lock generated
View File

@ -1066,7 +1066,7 @@ dependencies = [
[[package]]
name = "wynncraft"
version = "0.1.0"
source = "git+https://gitlab.com/Sakuhl/wynncraft#2a9a7d55e9b4d311b121f2ca330cc0fb9de7c723"
source = "git+https://gitlab.com/Sakuhl/wynncraft#97d6bb6a0741edb4f925e4487e6c6d52f90136d0"
dependencies = [
"reqwest 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -22,6 +22,8 @@ impl EventHandler for Handler {
fn on_message(&self, _: Context, msg: Message) {
if msg.content.starts_with("wc!guild ") {
wc_guild(msg);
} else if msg.content.starts_with("wc!topguilds ") {
wc_topguilds(msg);
} else if msg.content.starts_with("wc!territory ") {
wc_territory(msg);
} else if msg.content.starts_with("wc!status") {
@ -84,6 +86,20 @@ fn wc_guild(msg: Message) {
).unwrap();
}
fn wc_topguilds(msg: Message) {
let limit: usize = msg.content[13..].parse().unwrap();
let leaderboard = wynncraft::guild_leaderboard().unwrap();
let mut text = "```".to_owned();
for guild in leaderboard.data[..limit].into_iter() {
text += &format!("#{:02}: {:18} [{:3}] - {:2} territories\n", guild.num, guild.name, guild.prefix, guild.territories)
}
text += "```";
msg.channel_id.say(text).unwrap();
}
fn wc_status(msg: Message) {
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=onlinePlayersSum").unwrap();