diff --git a/bot.py b/bot.py index fbd595bb..46b86964 100644 --- a/bot.py +++ b/bot.py @@ -3,6 +3,8 @@ import telegram import steam import random import osu +import hearthstone +import sys # Playlist di /rage, si riempie quando รจ vuota rage = [] @@ -204,3 +206,45 @@ while True: elif cmd[0].startswith('/automah'): print(unm + ": /automah") telegram.sendmessage("Automaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", sby) + elif cmd[0].startswith('/hs'): + print(unm + ": /hs") + try: + r = hearthstone.card(cmd[1])[0] + except ValueError: + telegram.sendmessage(chr(9888) + "La carta specificata non esiste!", sby) + else: + # Si trova nelle bustine + if 'howToGet' not in r: + if 'cardSet' in r: + r['howToGet'] = "Trovala nelle bustine " + r['cardSet'] + "." + else: + r['howToGet'] = "Inottenibile." + # Nessuna classe + if 'playerClass' not in r: + r['playerClass'] = "Neutral" + # Testo principale + if r['type'] == "Spell": + text = str("[" + r['name'] + "](" + r['img'] + ") " + "(" + r['rarity'] + ")\n" + + r['playerClass'] + "\n" + + str(r['cost']) + " mana\n" + + r['text'] + "\n" + + r['howToGet'] + "\n\n_" + + r['flavor'] + "_\n") + elif r['type'] == "Minion": + text = str("[" + r['name'] + "](" + r['img'] + ") " + "(" + r['rarity'] + ")\n" + + r['playerClass'] + "\n" + + str(r['cost']) + " mana\n" + + str(r['attack']) + " attacco\n" + + str(r['health']) + " salute\n" + + r['text'] + "\n" + + r['howToGet'] + "\n\n_" + + r['flavor'] + "_\n") + telegram.sendmessage(text, sby) + elif cmd[0].startswith('/restart'): + if unm == "@Steffo": + telegram.sendmessage("Riavvio confermato.", sby) + sys.exit(0) + + diff --git a/hearthstone.py b/hearthstone.py index 969bedc5..dbbf2f74 100644 --- a/hearthstone.py +++ b/hearthstone.py @@ -4,3 +4,26 @@ import requests # Per far funzionare questa libreria serve un file "hearthstoneapi.txt" con l'API key ricevuta da mashape.com apikey = filemanager.readfile('hearthstoneapi.txt') + +def card(name): + headers = { + 'X-Mashape-Key': apikey + } + parametri = { + 'locale': 'itIT' + } + # TODO: Controllare che questo non sia exploitabile per un XSS o roba del genere. Anche se dubito. + r = requests.get("https://omgvamp-hearthstone-v1.p.mashape.com/cards/" + name, + params=parametri, headers=headers) + if r.status_code != 404: + return r.json() + else: + parametri = { + 'locale': 'enUS' + } + r = requests.get("https://omgvamp-hearthstone-v1.p.mashape.com/cards/search/" + name, + params=parametri, headers=headers) + if r.status_code != 404: + return r.json() + else: + raise ValueError("La carta non esiste!")