Ok callRequest > 0 now

This commit is contained in:
Christian Rendina 2020-05-05 12:34:22 +02:00
parent aef4e6fda4
commit e8e3ed7d79
1 changed files with 16 additions and 7 deletions

View File

@ -148,29 +148,29 @@ class InlineBot:
def callRequest(self, command, senderid, text = ""):
if not command:
return self.errorText
return None
r = requests.post(self.config.getApiUrl(), headers = { "Content-Type" : "application/json", "User-Agent" : self.config.getUserAgent() }, data = json.JSONEncoder().encode(JSONRequest(self.config, command.getName(), senderid, text).__dict__))
#if not r:
return self.errorText
if not r:
return None
if len(r.text) < 1:
return self.errorText
return None
resp = None
try:
resp = json.loads(r.text, object_hook = asResponse)
except:
return self.errorText ## Invalid json
return None ## Invalid json
if not resp.isAuthorized() or not resp.succeeded():
return self.errorText
return None
txt = r.headers[command.getHeaderField()]
if len(txt) < 1:
return self.errorText ## Wrong api?
return None ## Wrong api?
return txt
@ -215,6 +215,15 @@ class InlineBot:
qValue = self.callRequest(command, senderid, querySearch)
contentText = ""
if qValue == None:
return InlineQueryResultArticle(
id=uuid.uuid4().hex,
type="article",
title="Error",
input_message_content=InputTextMessageContent("Error", "HTML"),
description=self.errorText
)
if command.getMode() == "imageurl":
contentText = InputTextMessageContent("<a href=\"" + qValue + "\">HonusBot</a>", "HTML")