Improve error handling and maybe fix war feed

This commit is contained in:
Sakuhl 2018-02-15 13:02:02 +01:00
parent ef74def35d
commit 4c6ee35ac7
7 changed files with 21 additions and 11 deletions

2
Cargo.lock generated
View File

@ -1206,7 +1206,7 @@ dependencies = [
[[package]] [[package]]
name = "wynnrobot" name = "wynnrobot"
version = "0.11.0" version = "0.11.1"
dependencies = [ dependencies = [
"configure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "configure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,7 +1,7 @@
[package] [package]
authors = ["Sakuhl <2012collector@gmail.com>"] authors = ["Sakuhl <2012collector@gmail.com>"]
name = "wynnrobot" name = "wynnrobot"
version = "0.11.0" version = "0.11.1"
[dependencies] [dependencies]
configure = "0.1.1" configure = "0.1.1"

View File

@ -65,7 +65,7 @@ pub fn war_livefeed() {
let mut players: Value = serde_json::from_reader(resp).unwrap(); let mut players: Value = serde_json::from_reader(resp).unwrap();
loop { loop {
thread::sleep_ms(50_000); // 50 seconds thread::sleep_ms(30_000); // 30 seconds
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=onlinePlayers").unwrap(); let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=onlinePlayers").unwrap();
let new_players: Value = serde_json::from_reader(resp).unwrap(); let new_players: Value = serde_json::from_reader(resp).unwrap();

View File

@ -13,6 +13,9 @@ use failure::Error;
use ::ResponseError; use ::ResponseError;
pub fn wc_guild(command: &str, msg: &Message) -> Result<(), Error> { pub fn wc_guild(command: &str, msg: &Message) -> Result<(), Error> {
if command.len() <= 6 {
bail!("no guild specified");
}
let guild_name = &command[6..]; let guild_name = &command[6..];
let guild; let guild;

View File

@ -65,6 +65,10 @@ pub fn wc_status(msg: &Message) -> Result<(), Error> {
} }
pub fn wc_territory(command: &str, msg: &Message) -> Result<(), Error> { pub fn wc_territory(command: &str, msg: &Message) -> Result<(), Error> {
if command.len() <= 10 {
bail!("no territory specified");
}
let territory = &command[10..]; let territory = &command[10..];
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=territoryList")?.text().unwrap(); let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=territoryList")?.text().unwrap();

View File

@ -5,6 +5,9 @@ use serenity::model::*;
use failure::Error; use failure::Error;
pub fn wc_player(command: &str, msg: &Message) -> Result<(), Error> { pub fn wc_player(command: &str, msg: &Message) -> Result<(), Error> {
if command.len() <= 7 {
bail!("no player specified");
}
let player = &command[7..]; let player = &command[7..];
let player = wynncraft::player(player)?; let player = wynncraft::player(player)?;

View File

@ -153,9 +153,9 @@ impl Handler {
wc_status(msg)?; wc_status(msg)?;
} else if command.starts_with("player") { } else if command.starts_with("player") {
wc_player(command, msg)?; wc_player(command, msg)?;
} else if command == "livefeed" { } else if command.starts_with("livefeed") {
wc_livefeed(msg)?; wc_livefeed(msg)?;
} else if command == "unlivefeed" { } else if command.starts_with("unlivefeed") {
wc_unlivefeed(msg)?; wc_unlivefeed(msg)?;
} else if command == "info" || command == "" { } else if command == "info" || command == "" {
wc_info(msg)?; wc_info(msg)?;
@ -165,9 +165,9 @@ impl Handler {
wc_crop(command, msg)?; wc_crop(command, msg)?;
} else if command == "crop" { } else if command == "crop" {
wc_crop_discord_upload(msg)?; wc_crop_discord_upload(msg)?;
} else if command == "warfeed" { } else if command.starts_with("warfeed") {
wc_warfeed(msg)?; wc_warfeed(msg)?;
} else if command == "unwarfeed" { } else if command.starts_with("unwarfeed") {
wc_unwarfeed(msg)?; wc_unwarfeed(msg)?;
} else if command.starts_with("shout") { } else if command.starts_with("shout") {
if msg.author.name == "Wurst" && msg.author.discriminator == 1783 { if msg.author.name == "Wurst" && msg.author.discriminator == 1783 {