HonusBot/inline.py

94 lines
3.2 KiB
Python

# 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, 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:
return self.errorText
if r.headers["authorized"] != "true" or r.headers["success"] != "true" or r.headers["imageurl"] == "":
return self.errorText
return r.headers["imageurl"]
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, 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 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!", self.callRequest("pony", senderid, query)))
results.append(self.makeResult("Clop", "clopclop", self.callRequest("clop", senderid, query)))
results.append(self.makeResult("Furry", "DON'T!", self.callRequest("furry", senderid, query)))
results.append(self.makeResult("Loli", "say hi to the police!", self.callRequest("loli", senderid, query)))
results.append(self.makeResult("Yiff", "yiff", self.callRequest("yiff", senderid, query)))
results.append(self.makeResult("Lewd", "lolies", self.callRequest("lolies", senderid, query)))
else:
results.append(self.makeResult("Cancer", "Search cancer about " + query, self.callRequest("cancer", senderid, query)))
context.bot.answer_inline_query(update.inline_query.id, results, 1, False)
InlineBot().start()