From f22f4770cde5dcfc17802d6aaa0ace2c3cadb0b1 Mon Sep 17 00:00:00 2001 From: ipsum Date: Fri, 16 Apr 2010 17:55:02 -0400 Subject: [PATCH] added tf.py for counting hats in team fortress, blame gobiner --- plugins/tf.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 plugins/tf.py diff --git a/plugins/tf.py b/plugins/tf.py new file mode 100644 index 0000000..d05027e --- /dev/null +++ b/plugins/tf.py @@ -0,0 +1,47 @@ +''' +tf.py + +A skybot plugin for Team Fortress 2 +By Ipsum +''' + +import json +import urllib + +from util import hook + +@hook.command('hats') +@hook.command +def tf(inp): + '''.tf/.hats -- Displays the number of hats + and items waiting to be received by ''' + + if not inp: + return tf.__doc__ + + if inp.isdigit() : link = 'profiles' + else : link = 'id' + + url = 'http://steamcommunity.com/%s/%s/tfitems?json=1' % \ + (link,urllib.quote(inp, safe='')) + + raw_data = urllib.urlopen(url).read().decode('utf-8') + + try: + inv = json.JSONDecoder().decode(raw_data) + except ValueError: + return '%s is not a valid profile' % inp + + dropped,dhats,hats = 0,0,0 + for item in inv: + defindex = int(inv[item]['defindex']) + if inv[item]['inventory'] == 0: + if 47<=defindex<=55 or 94<=defindex<=126 or 134<=defindex<=152: + dhats += 1 + else: + dropped += 1 + else: + if 47<=defindex<=55 or 94<=defindex<=126 or 134<=defindex<=152: + hats += 1 + + return '%s has had %s items and %s hats drop (%s total hats)' % (inp,dropped,dhats,dhats+hats) \ No newline at end of file