forked from HonusBot/HonusBot
Ok callRequest > 0 now
This commit is contained in:
parent
aef4e6fda4
commit
e8e3ed7d79
23
inline.py
23
inline.py
|
@ -148,29 +148,29 @@ class InlineBot:
|
||||||
|
|
||||||
def callRequest(self, command, senderid, text = ""):
|
def callRequest(self, command, senderid, text = ""):
|
||||||
if not command:
|
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__))
|
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:
|
if not r:
|
||||||
return self.errorText
|
return None
|
||||||
|
|
||||||
if len(r.text) < 1:
|
if len(r.text) < 1:
|
||||||
return self.errorText
|
return None
|
||||||
|
|
||||||
resp = None
|
resp = None
|
||||||
try:
|
try:
|
||||||
resp = json.loads(r.text, object_hook = asResponse)
|
resp = json.loads(r.text, object_hook = asResponse)
|
||||||
except:
|
except:
|
||||||
return self.errorText ## Invalid json
|
return None ## Invalid json
|
||||||
|
|
||||||
if not resp.isAuthorized() or not resp.succeeded():
|
if not resp.isAuthorized() or not resp.succeeded():
|
||||||
return self.errorText
|
return None
|
||||||
|
|
||||||
txt = r.headers[command.getHeaderField()]
|
txt = r.headers[command.getHeaderField()]
|
||||||
|
|
||||||
if len(txt) < 1:
|
if len(txt) < 1:
|
||||||
return self.errorText ## Wrong api?
|
return None ## Wrong api?
|
||||||
|
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
@ -215,6 +215,15 @@ class InlineBot:
|
||||||
|
|
||||||
qValue = self.callRequest(command, senderid, querySearch)
|
qValue = self.callRequest(command, senderid, querySearch)
|
||||||
contentText = ""
|
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":
|
if command.getMode() == "imageurl":
|
||||||
contentText = InputTextMessageContent("<a href=\"" + qValue + "\">HonusBot</a>", "HTML")
|
contentText = InputTextMessageContent("<a href=\"" + qValue + "\">HonusBot</a>", "HTML")
|
||||||
|
|
Loading…
Reference in New Issue