From bdf9aa8a9e1ee176bc860043876f1d3f99381cd8 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 7 Aug 2015 17:19:03 +0200 Subject: [PATCH] Impedito un crash. --- royalbot.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/royalbot.py b/royalbot.py index 22e05e88..feff3c79 100644 --- a/royalbot.py +++ b/royalbot.py @@ -61,6 +61,7 @@ def getSteamStatus(steamid): } #Manda la richiesta ai server di Telegram e convertila in un dizionario r = requests.get("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/", params=parametri).json() + print(r) return r #Il loop del bot @@ -80,21 +81,22 @@ while(True): sendMessage("Specifica lo steamid della persona di cui vuoi specificare lo stato. Tag di telegram coming soon!", msg['chat']['id']) else: steam = getSteamStatus(msg['text'][7:]) - online = steam['response']['players'][0]['personastate'] - name = steam['response']['players'][0]['personaname'] - text = "" - if(online == 0): - text = "Offline" - elif(online == 1): - text = "Online" - elif(online == 2): - text = "Occupato" - elif(online == 3): - text = "Assente" - elif(online == 4): - text = "Inattivo" - elif(online == 5): - text = "Disponibile per scambiare" - elif(online == 6): - text = "Disponibile per giocare" - sendMessage(name + " e' " + text + ".", msg['chat']['id']) \ No newline at end of file + if(steam['response']['players']): + online = steam['response']['players'][0]['personastate'] + name = steam['response']['players'][0]['personaname'] + text = "" + if(online == 0): + text = "Offline" + elif(online == 1): + text = "Online" + elif(online == 2): + text = "Occupato" + elif(online == 3): + text = "Assente" + elif(online == 4): + text = "Inattivo" + elif(online == 5): + text = "Disponibile per scambiare" + elif(online == 6): + text = "Disponibile per giocare" + sendMessage(name + " รจ " + text + ".", msg['chat']['id']) \ No newline at end of file