HonusBot/inline.py

101 lines
3.0 KiB
Python

# File: inline.py
# Description: 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;;"
self.commands = {
"Pony" : "yay, ponies!",
"Clop" : "NSFW ponies",
"Furry" : "Furries"
"Loli" : "Cute lolis",
"Yiff" : "Yiff",
"Lewd" : "Say hi to the police",
"Rasoio" : "Dai facciamogli lo scherzo del rasoio!1!!"
}
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:
for key in self.commands:
desc = self.commands[key]
results.append(self.makeResult(key, desc, self.callRequest(key.lower(), 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()