1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

/hs coming soon

This commit is contained in:
Steffo 2015-12-20 20:05:13 +01:00
parent f6eb26e07b
commit 4fe42836ae
2 changed files with 67 additions and 0 deletions

44
bot.py
View file

@ -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)

View file

@ -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!")