# File: MammottoInline.py
# Description: MammotroBot inline wrapper
# Author: Arvs100
# Date: 25-12-2019 ~ 28-12-2019
from telegram.ext import Updater, InlineQueryHandler, CommandHandler
import logging
from telegram import InlineQueryResultArticle, InputTextMessageContent, Bot
import uuid
import requests
import password
class InlineBot:
def __init__(self):
self.apiUrl = password.API_URL
self.errorText = "Sowwy mawster, an ewror occuwed. ;;w;;"
def callRequest(self, command, requiredField, senderid, text):
r = requests.get(self.apiUrl,
headers={
"botid":password.BOT_ID,
"botpassword":password.BOT_PASSWORD,
"command":command,
"replytouserid":"0",
"senderuserid":senderid,
"receiverchatid":"0",
"querytext":text
}
)
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 or not requiredField in r.headers:
return self.errorText
if r.headers["authorized"] != "true" or r.headers["success"] != "true" or r.headers[requiredField] == "":
return self.errorText
return r.headers[requiredField]
def start(self):
self.bot = Bot(token=password.BOT_TOKEN)
self.updater = Updater(bot=self.bot,use_context=True)
print("h0nus bot\n");
self.dispatcher = self.updater.dispatcher
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
self.logger = logging.getLogger(__name__)
self.dispatcher.add_error_handler(self.errorHandler)
inline_caps_handler = InlineQueryHandler(self.inlineQuery)
self.dispatcher.add_handler(inline_caps_handler)
print("Started!")
self.updater.start_polling()
self.updater.idle()
def errorHandler(self, update, context):
"""Log Errors caused by Updates."""
self.logger.warning('Update "%s" caused error "%s"', update, context.error)
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, 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", "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", "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()