2012-08-28 07:53:49 +12:00
from urllib import quote_plus
2014-02-14 16:36:57 +13:00
from util import hook , http
2013-02-13 17:37:57 +13:00
api_url = " http://api.fishbans.com/stats/ {} / "
2012-08-28 07:53:49 +12:00
@hook.command ( " bans " )
@hook.command
def fishbans ( inp ) :
2013-09-04 18:30:04 +08:00
""" fishbans <user> -- Gets information on <user>s minecraft bans from fishbans """
2013-02-13 17:37:57 +13:00
user = inp . strip ( )
2012-10-18 10:10:08 +13:00
try :
2013-02-13 17:37:57 +13:00
request = http . get_json ( api_url . format ( quote_plus ( user ) ) )
2012-10-18 10:10:08 +13:00
except ( http . HTTPError , http . URLError ) as e :
return " Could not fetch ban data from the Fishbans API: {} " . format ( e )
2012-08-28 07:53:49 +12:00
2013-09-04 18:30:04 +08:00
if not request [ " success " ] :
2013-02-13 17:37:57 +13:00
return " Could not fetch ban data for {} . " . format ( user )
2012-08-28 07:53:49 +12:00
2013-02-13 17:37:57 +13:00
user_url = " http://fishbans.com/u/ {} / " . format ( user )
2012-08-28 07:53:49 +12:00
ban_count = request [ " stats " ] [ " totalbans " ]
2013-02-13 17:37:57 +13:00
return " The user \x02 {} \x02 has \x02 {} \x02 ban(s). See detailed info " \
" at {} " . format ( user , ban_count , user_url )
2012-08-28 07:53:49 +12:00
@hook.command
def bancount ( inp ) :
2013-09-04 18:30:04 +08:00
""" bancount <user> -- Gets a count of <user>s minecraft bans from fishbans """
2013-02-13 17:37:57 +13:00
user = inp . strip ( )
2012-10-18 10:10:08 +13:00
try :
2013-02-13 17:37:57 +13:00
request = http . get_json ( api_url . format ( quote_plus ( user ) ) )
2012-10-18 10:10:08 +13:00
except ( http . HTTPError , http . URLError ) as e :
return " Could not fetch ban data from the Fishbans API: {} " . format ( e )
2012-08-28 07:53:49 +12:00
2013-09-04 18:30:04 +08:00
if not request [ " success " ] :
2013-02-13 17:37:57 +13:00
return " Could not fetch ban data for {} . " . format ( user )
2012-08-28 07:53:49 +12:00
2013-02-13 17:37:57 +13:00
user_url = " http://fishbans.com/u/ {} / " . format ( user )
2012-08-28 07:53:49 +12:00
services = request [ " stats " ] [ " service " ]
out = [ ]
for service , ban_count in services . items ( ) :
if ban_count != 0 :
2013-02-13 17:37:57 +13:00
out . append ( " {} : \x02 {} \x02 " . format ( service , ban_count ) )
2012-08-28 07:53:49 +12:00
else :
pass
if not out :
2013-02-13 17:37:57 +13:00
return " The user \x02 {} \x02 has no bans. " . format ( user )
2012-08-28 07:53:49 +12:00
else :
2013-02-13 17:37:57 +13:00
return " Bans for \x02 {} \x02 : " . format ( user ) + " , " . join ( out ) + " . More info " \
" at {} " . format ( user_url )