HonusBot/inline.py

95 lines
3.4 KiB
Python
Raw Normal View History

2019-12-28 21:57:04 +01:00
# 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:
2019-12-29 01:25:09 +01:00
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)))
2020-03-08 21:26:51 +01:00
results.append(self.makeResult("Rasoio", "Dai facciamogli lo scherzo del rasoio!1!!", "https://www.youtube.com/watch?v=sj8kNDOpvWI"))
2019-12-28 21:57:04 +01:00
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()