Fix ghost guild members erroring

This commit is contained in:
Sakuhl 2018-01-02 00:11:47 +01:00
parent 37c369cfcb
commit 2a2697b13f
2 changed files with 22 additions and 25 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#5ea547e2298f51bef4ac45759b56801696a795fc"
source = "git+https://gitlab.com/Sakuhl/wynncraft#b73034104c1bc02ec3bde74c6a1042943a61bab1"
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

@ -1,5 +1,4 @@
extern crate wynncraft;
use wynncraft::{Guild, Player};
extern crate serenity;
use serenity::prelude::*;
@ -46,39 +45,37 @@ impl EventHandler for Handler {
fn wc_guild(msg: Message) {
let guild = &msg.content[9..];
if let Ok(guild) = wynncraft::guild(guild) {
let guild: Guild = guild;
let guild = wynncraft::guild(guild).unwrap();
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=territoryList").unwrap();
assert!(resp.status().is_success());
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=territoryList").unwrap();
assert!(resp.status().is_success());
let territories: Value = serde_json::from_reader(resp).unwrap();
let territories: Value = serde_json::from_reader(resp).unwrap();
let mut message = String::new();
for value in territories.get("territories").unwrap().as_object().unwrap().values() {
if value.get("guild").unwrap().as_str().unwrap() == guild.name {
message.push_str(&format!("
let mut message = String::new();
for value in territories.get("territories").unwrap().as_object().unwrap().values() {
if value.get("guild").unwrap().as_str().unwrap() == guild.name {
message.push_str(&format!("
**Territory**: {}",
value.get("territory").unwrap().as_str().unwrap()
))
}
value.get("territory").unwrap().as_str().unwrap()
))
}
}
msg.channel_id.say(
format!(
msg.channel_id.say(
format!(
"**Guild**: {}
**prefix**: {}
**Created**: {}
**Level**: {}
**Members**: {}",
guild.name,
guild.prefix,
guild.created_friendly,
guild.level,
guild.members.len()
) + &message
).unwrap();
}
guild.name,
guild.prefix,
guild.created_friendly,
guild.level,
guild.members.len()
) + &message
).unwrap();
}
fn wc_status(msg: Message) {
@ -124,7 +121,7 @@ fn wc_territory(msg: Message) {
fn wc_player(msg: Message) {
let player = &msg.content[10..];
let player: Player = wynncraft::player(player).unwrap();
let player = wynncraft::player(player).unwrap();
let current_server_msg = if player.current_server != "null" {
format!("\n**Currently online on**: {}", player.current_server)