Aggiornare 'inline.py'

This commit is contained in:
HonusBot 2020-03-09 00:18:09 +01:00
parent 70d8f4f918
commit db8bac435f

View File

@ -16,7 +16,7 @@ class InlineBot:
self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;" 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, r = requests.get(self.apiUrl,
headers={ headers={
"botid":password.BOT_ID, "botid":password.BOT_ID,
@ -32,13 +32,13 @@ class InlineBot:
if not r: if not r:
return self.errorText 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 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 self.errorText
return r.headers["imageurl"] return r.headers[requiredField]
def start(self): def start(self):
self.bot = Bot(token=password.BOT_TOKEN) self.bot = Bot(token=password.BOT_TOKEN)
@ -66,12 +66,28 @@ class InlineBot:
def commandStart(self, update, context): 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") 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): def makeResult(self, qTitle, qMode, qDesc, qValue):
if qMode == "text":
return InlineQueryResultArticle( return InlineQueryResultArticle(
id=uuid.uuid4().hex, id=uuid.uuid4().hex,
type="article", type="article",
title=qTitle, title=qTitle,
input_message_content=InputTextMessageContent("<a href=\"" + picUrl + "\">H0nusBot</a>", "HTML"), input_message_content=InputTextMessageContent("<a href=\"" + qValue + "\">HonusBot</a>", "HTML"),
description=qDesc
)
if qMode == "image":
return InlineQueryResultArticle(
id=uuid.uuid4().hex,
type="article",
title=qTitle,
input_message_content=InputTextMessageContent("<a href=\"" + qValue + "\">Scherzo del rasoio</a>", "HTML"),
description=qDesc
)
return InlineQueryResultArticle(
id=uuid.uuid4().hex,
type="article",
title=qTitle,
input_message_content=InputTextMessageContent("Unknown result type!", "HTML"),
description=qDesc description=qDesc
) )
@ -80,15 +96,15 @@ class InlineBot:
query = update.inline_query.query query = update.inline_query.query
results = list() results = list()
if not query: if not query:
results.append(self.makeResult("Pony", "yay, ponies!", self.callRequest("pony", senderid, query))) results.append(self.makeResult("Pony", "image", "yay, ponies!", self.callRequest("pony", "imageurl", senderid, query)))
results.append(self.makeResult("Clop", "NSFW ponies", self.callRequest("clop", senderid, query))) results.append(self.makeResult("Clop", "image", "NSFW ponies", self.callRequest("clop", "imageurl", senderid, query)))
results.append(self.makeResult("Furry", "Furries", self.callRequest("furry", senderid, query))) results.append(self.makeResult("Furry", "image", "Furries", self.callRequest("furry", "imageurl", senderid, query)))
results.append(self.makeResult("Loli", "Cute lolis", self.callRequest("loli", senderid, query))) results.append(self.makeResult("Loli", "image", "Cute lolis", self.callRequest("loli", "imageurl", senderid, query)))
results.append(self.makeResult("Yiff", "Yiff", self.callRequest("yiff", senderid, query))) results.append(self.makeResult("Yiff", "image", "Yiff", self.callRequest("yiff", "imageurl", senderid, query)))
results.append(self.makeResult("Lewd", "Say hi to the police", self.callRequest("lewd", senderid, query))) results.append(self.makeResult("Lewd", "image", "Say hi to the police", self.callRequest("lewd", "imageurl", senderid, query)))
results.append(self.makeResult("Rasoio", "Dai facciamogli lo scherzo del rasoio!1!!", self.callRequest("rasoio", senderid, query))) results.append(self.makeResult("Rasoio", "html", "Dai facciamogli lo scherzo del rasoio!1!!", self.callRequest("rasoio", "htmldescription", senderid, query)))
else: 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) context.bot.answer_inline_query(update.inline_query.id, results, 1, False)
InlineBot().start() InlineBot().start()