From db8bac435fb887db3d33bec264161e61bce32b6c Mon Sep 17 00:00:00 2001 From: HonusBot Date: Mon, 9 Mar 2020 00:18:09 +0100 Subject: [PATCH] Aggiornare 'inline.py' --- inline.py | 56 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/inline.py b/inline.py index dcfca7f..8acfdc3 100644 --- a/inline.py +++ b/inline.py @@ -16,7 +16,7 @@ class InlineBot: self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;" - def callRequest(self, command, senderid, text): + def callRequest(self, command, requiredField, senderid, text): r = requests.get(self.apiUrl, headers={ "botid":password.BOT_ID, @@ -32,13 +32,13 @@ class InlineBot: if not r: return self.errorText - if not "authorized" in r.headers or not "success" in r.headers or not "htmldescription" in r.headers or not "imageurl" in r.headers: + if not "authorized" in r.headers or not "success" in r.headers or not "htmldescription" in r.headers or not "imageurl" in r.headers or not requiredField in r.headers: return self.errorText - if r.headers["authorized"] != "true" or r.headers["success"] != "true" or r.headers["imageurl"] == "": + if r.headers["authorized"] != "true" or r.headers["success"] != "true" or r.headers[requiredField] == "": return self.errorText - return r.headers["imageurl"] + return r.headers[requiredField] def start(self): self.bot = Bot(token=password.BOT_TOKEN) @@ -66,29 +66,45 @@ class InlineBot: def commandStart(self, update, context): context.bot.send_message(chat_id=update.effective_chat.id, text="Inline cancer, clop, furry spammer (h0nus)",parse_mode="HTML") - def makeResult(self, qTitle, qDesc, picUrl): - return InlineQueryResultArticle( - id=uuid.uuid4().hex, - type="article", - title=qTitle, - input_message_content=InputTextMessageContent("H0nusBot", "HTML"), - description=qDesc - ) + def makeResult(self, qTitle, qMode, qDesc, qValue): + if qMode == "text": + return InlineQueryResultArticle( + id=uuid.uuid4().hex, + type="article", + title=qTitle, + input_message_content=InputTextMessageContent("HonusBot", "HTML"), + description=qDesc + ) + if qMode == "image": + return InlineQueryResultArticle( + id=uuid.uuid4().hex, + type="article", + title=qTitle, + input_message_content=InputTextMessageContent("Scherzo del rasoio", "HTML"), + description=qDesc + ) + return InlineQueryResultArticle( + id=uuid.uuid4().hex, + type="article", + title=qTitle, + input_message_content=InputTextMessageContent("Unknown result type!", "HTML"), + description=qDesc + ) def inlineQuery(self, update, context): senderid = str(update.inline_query.from_user.id) query = update.inline_query.query results = list() if not query: - results.append(self.makeResult("Pony", "yay, ponies!", self.callRequest("pony", senderid, query))) - results.append(self.makeResult("Clop", "NSFW ponies", self.callRequest("clop", senderid, query))) - results.append(self.makeResult("Furry", "Furries", self.callRequest("furry", senderid, query))) - results.append(self.makeResult("Loli", "Cute lolis", self.callRequest("loli", senderid, query))) - results.append(self.makeResult("Yiff", "Yiff", self.callRequest("yiff", senderid, query))) - results.append(self.makeResult("Lewd", "Say hi to the police", self.callRequest("lewd", senderid, query))) - results.append(self.makeResult("Rasoio", "Dai facciamogli lo scherzo del rasoio!1!!", self.callRequest("rasoio", senderid, query))) + results.append(self.makeResult("Pony", "image", "yay, ponies!", self.callRequest("pony", "imageurl", senderid, query))) + results.append(self.makeResult("Clop", "image", "NSFW ponies", self.callRequest("clop", "imageurl", senderid, query))) + results.append(self.makeResult("Furry", "image", "Furries", self.callRequest("furry", "imageurl", senderid, query))) + results.append(self.makeResult("Loli", "image", "Cute lolis", self.callRequest("loli", "imageurl", senderid, query))) + results.append(self.makeResult("Yiff", "image", "Yiff", self.callRequest("yiff", "imageurl", senderid, query))) + results.append(self.makeResult("Lewd", "image", "Say hi to the police", self.callRequest("lewd", "imageurl", senderid, query))) + results.append(self.makeResult("Rasoio", "html", "Dai facciamogli lo scherzo del rasoio!1!!", self.callRequest("rasoio", "htmldescription", senderid, query))) else: - results.append(self.makeResult("Cancer", "Search cancer about " + query, self.callRequest("cancer", senderid, query))) + results.append(self.makeResult("Cancer", "image", "Search cancer about " + query, self.callRequest("cancer", "imageurl", senderid, query))) context.bot.answer_inline_query(update.inline_query.id, results, 1, False) InlineBot().start()