Add leaderboard
This commit is contained in:
parent
2b441f42c5
commit
a7290926db
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -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)",
|
||||
|
16
src/main.rs
16
src/main.rs
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user