h/plugins/tf.py

41 lines
1.1 KiB
Python
Raw Normal View History

2010-04-18 17:24:17 +00:00
# tf.py: written by ipsum
#
2010-04-23 03:50:56 +00:00
# This skybot plugin retreives the number of items
2010-04-18 17:24:17 +00:00
# a given user has waiting from idling in Team Fortress 2.
from util import hook, http
2010-04-18 17:24:17 +00:00
@hook.command('hats')
@hook.command
def tf(inp):
2010-04-18 17:24:17 +00:00
""".tf/.hats <SteamID> -- Shows items waiting to be received in TF2."""
2010-04-23 03:50:56 +00:00
if inp.isdigit():
link = 'profiles'
2010-04-23 03:50:56 +00:00
else:
link = 'id'
url = 'http://steamcommunity.com/%s/%s/tfitems?json=1' % \
(link, http.quote(inp.encode('utf8'), safe=''))
try:
inv = http.get_json(url)
except ValueError:
return '%s is not a valid profile' % inp
2010-04-23 03:50:56 +00:00
dropped, dhats, hats = 0, 0, 0
2010-04-17 00:29:12 +00:00
for item, data in inv.iteritems():
ind = int(data['defindex'])
if data['inventory'] == 0:
2010-04-18 17:24:17 +00:00
if 47 <= ind <= 55 or 94 <= ind <= 126 or 134 <= ind <= 152:
dhats += 1
else:
2010-04-18 17:24:17 +00:00
dropped += 1
else:
2010-04-18 17:24:17 +00:00
if 47 <= ind <= 55 or 94 <= ind <= 126 or 134 <= ind <= 152:
hats += 1
2010-04-18 17:24:17 +00:00
return '%s has had %s items and %s hats drop (%s total hats)' % \
(inp, dropped, dhats, dhats + hats)