Changed
This commit is contained in:
parent
93fe9610f4
commit
08e3cd3c13
1 changed files with 16 additions and 15 deletions
|
@ -1,55 +1,56 @@
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
from urllib import quote_plus
|
from urllib import quote_plus
|
||||||
|
|
||||||
api_url = "http://www.fishbans.com/api/stats/%s/force/"
|
api_url = "http://api.fishbans.com/stats/{}/"
|
||||||
|
|
||||||
|
|
||||||
@hook.command("bans")
|
@hook.command("bans")
|
||||||
@hook.command
|
@hook.command
|
||||||
def fishbans(inp):
|
def fishbans(inp):
|
||||||
"fishbans <user> -- Gets information on <user>s minecraft bans from fishbans"
|
"fishbans <user> -- Gets information on <user>s minecraft bans from fishbans"
|
||||||
user = inp
|
user = inp.strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = http.get_json(api_url % quote_plus(user))
|
request = http.get_json(api_url.format(quote_plus(user)))
|
||||||
except (http.HTTPError, http.URLError) as e:
|
except (http.HTTPError, http.URLError) as e:
|
||||||
return "Could not fetch ban data from the Fishbans API: {}".format(e)
|
return "Could not fetch ban data from the Fishbans API: {}".format(e)
|
||||||
|
|
||||||
if request["success"] == False:
|
if request["success"] == False:
|
||||||
return "Could not fetch ban data for %s." % user
|
return "Could not fetch ban data for {}.".format(user)
|
||||||
|
|
||||||
user_url = "http://fishbans.com/u/%s" % user
|
user_url = "http://fishbans.com/u/{}/".format(user)
|
||||||
ban_count = request["stats"]["totalbans"]
|
ban_count = request["stats"]["totalbans"]
|
||||||
|
|
||||||
return "The user \x02%s\x02 has \x02%s\x02 ban(s). See detailed info " \
|
return "The user \x02{}\x02 has \x02{}\x02 ban(s). See detailed info " \
|
||||||
"at %s" % (user, ban_count, user_url)
|
"at {}".format(user, ban_count, user_url)
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def bancount(inp):
|
def bancount(inp):
|
||||||
"bancount <user> -- Gets a count of <user>s minecraft bans from fishbans"
|
"bancount <user> -- Gets a count of <user>s minecraft bans from fishbans"
|
||||||
user = inp
|
user = inp.strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = http.get_json(api_url % quote_plus(user))
|
request = http.get_json(api_url.format(quote_plus(user)))
|
||||||
except (http.HTTPError, http.URLError) as e:
|
except (http.HTTPError, http.URLError) as e:
|
||||||
return "Could not fetch ban data from the Fishbans API: {}".format(e)
|
return "Could not fetch ban data from the Fishbans API: {}".format(e)
|
||||||
|
|
||||||
if request["success"] == False:
|
if request["success"] == False:
|
||||||
return "Could not fetch ban data for %s." % user
|
return "Could not fetch ban data for {}.".format(user)
|
||||||
|
|
||||||
user_url = "http://fishbans.com/u/%s" % user
|
user_url = "http://fishbans.com/u/{}/".format(user)
|
||||||
services = request["stats"]["service"]
|
services = request["stats"]["service"]
|
||||||
|
|
||||||
out = []
|
out = []
|
||||||
for service, ban_count in services.items():
|
for service, ban_count in services.items():
|
||||||
if ban_count != 0:
|
if ban_count != 0:
|
||||||
out.append("%s: \x02%s\x02" % (service, ban_count))
|
out.append("{}: \x02{}\x02".format(service, ban_count))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not out:
|
if not out:
|
||||||
return "The user \x02%s\x02 has no bans." % user
|
return "The user \x02{}\x02 has no bans.".format(user)
|
||||||
else:
|
else:
|
||||||
text = "Bans for \x02%s\x02: " % user
|
# dat string.
|
||||||
return text + ", ".join(out)
|
return "Bans for \x02{}\x02: ".format(user) + ", ".join(out) + ". More info " \
|
||||||
|
"at {}".format(user_url)
|
||||||
|
|
Reference in a new issue