Support all prefixes
This commit is contained in:
parent
35853b4237
commit
e7d1b9c380
@ -17,12 +17,12 @@ pub fn wc_guild(msg: &Message) -> Result<(), Error> {
|
||||
|
||||
let guild;
|
||||
if guild_name.len() <= 3 {
|
||||
if let Some(guild_) = wynncraft::guild_by_prefix(guild_name)? {
|
||||
if let Some(guild_) = wynncraft::guild(&guild_.name)? {
|
||||
if let Some(guild_) = guild_by_prefix(guild_name)? {
|
||||
if let Some(guild_) = wynncraft::guild(&guild_)? {
|
||||
guild = guild_;
|
||||
} else {
|
||||
// this shouldnt happen
|
||||
bail!(ResponseError::UnknownGuild { name: guild_.name });
|
||||
bail!(ResponseError::UnknownGuild { name: guild_ });
|
||||
}
|
||||
} else {
|
||||
bail!(ResponseError::UnknownGuildPrefix { name: guild_name.to_owned() });
|
||||
@ -90,6 +90,19 @@ pub fn wc_guild(msg: &Message) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn guild_by_prefix(prefix: &str) -> Result<Option<String>, Error> {
|
||||
let resp = reqwest::get("https://wynnapi.herokuapp.com/list")?.text().unwrap().replace(",]", "]");
|
||||
|
||||
let guilds: Value = serde_json::from_str(&resp)?;
|
||||
|
||||
for guild in guilds.get("guilds").unwrap().as_array().unwrap() {
|
||||
if guild.get("prefix").unwrap().as_str().unwrap().to_lowercase() == prefix.to_lowercase() {
|
||||
return Ok(Some(guild.get("name").unwrap().as_str().unwrap().to_owned()));
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn wc_topguilds(msg: &Message) -> Result<(), Error> {
|
||||
let limit: usize = msg.content[13..].parse().unwrap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user