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;;"
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("<a href=\"" + picUrl + "\">H0nusBot</a>", "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("<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
)
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()