This commit is contained in:
Christian Rendina 2020-05-05 17:14:38 +02:00
parent f68e0234a7
commit 497cfe33b0
1 changed files with 10 additions and 10 deletions

View File

@ -115,6 +115,15 @@ class Config:
def getUserAgent(self): def getUserAgent(self):
return self.userAgent return self.userAgent
def jsonasResponse(dct):
print("LOG:::",str(dct))
if "imageUrl" in dct:
return JSONResponse(dct["authorized"], dct["success"], dct["imageUrl"], "")
elif "htmlDescription" in dct:
return JSONResponse(dct["authorized"], dct["success"], "", dct["htmlDescription"])
else:
raise Exception("Invalid JSON")
class InlineBot: class InlineBot:
def __init__(self): def __init__(self):
self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;" self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;"
@ -137,15 +146,6 @@ class InlineBot:
self.commands.append(Command("Lewd", "Say hi to the police", "imageurl", "imageUrl")) self.commands.append(Command("Lewd", "Say hi to the police", "imageurl", "imageUrl"))
self.commands.append(Command("Rasoio", "Dai facciamogli lo scherzo del rasoio!1!!", "genericurl", "htmlDescription")) self.commands.append(Command("Rasoio", "Dai facciamogli lo scherzo del rasoio!1!!", "genericurl", "htmlDescription"))
self.cancerCommand = Command("Cancer", "Search cancer", "imageurl", "imageurl") self.cancerCommand = Command("Cancer", "Search cancer", "imageurl", "imageurl")
def asResponse(self, dct):
print("LOG:::",str(dct))
if "imageUrl" in dct:
return JSONResponse(dct["authorized"], dct["success"], dct["imageUrl"], "")
elif "htmlDescription" in dct:
return JSONResponse(dct["authorized"], dct["success"], "", dct["htmlDescription"])
else:
raise Exception("Invalid JSON")
def callRequest(self, command, senderid, text = ""): def callRequest(self, command, senderid, text = ""):
if not command: if not command:
@ -163,7 +163,7 @@ class InlineBot:
resp = None resp = None
#try: #try:
resp = json.loads(r.text, object_hook = self.asResponse) resp = json.loads(r.text, object_hook = jsonasResponse)
#except: #except:
# self.logger.warning('JSON deserialization failed') # self.logger.warning('JSON deserialization failed')
# return None ## Invalid json # return None ## Invalid json