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]]
name = "wynnrobot"
version = "0.11.0"
version = "0.11.1"
dependencies = [
"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)",

View File

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

View File

@ -65,7 +65,7 @@ pub fn war_livefeed() {
let mut players: Value = serde_json::from_reader(resp).unwrap();
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 new_players: Value = serde_json::from_reader(resp).unwrap();

View File

@ -13,6 +13,9 @@ use failure::Error;
use ::ResponseError;
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;

View File

@ -65,6 +65,10 @@ pub fn wc_status(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 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;
pub fn wc_player(command: &str, msg: &Message) -> Result<(), Error> {
if command.len() <= 7 {
bail!("no player specified");
}
let player = &command[7..];
let player = wynncraft::player(player)?;

View File

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