diff --git a/inline.py b/inline.py index ecfe61a..caa2769 100644 --- a/inline.py +++ b/inline.py @@ -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("HonusBot", "HTML")