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;; "
2020-03-09 00:18:09 +01:00
def callRequest ( self , command , requiredField , senderid , text ) :
2019-12-28 21:57:04 +01:00
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
2020-03-09 00:18:09 +01:00
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 :
2019-12-28 21:57:04 +01:00
return self . errorText
2020-03-09 00:18:09 +01:00
if r . headers [ " authorized " ] != " true " or r . headers [ " success " ] != " true " or r . headers [ requiredField ] == " " :
2019-12-28 21:57:04 +01:00
return self . errorText
2020-03-09 00:18:09 +01:00
return r . headers [ requiredField ]
2019-12-28 21:57:04 +01:00
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 " )
2020-03-09 00:18:09 +01:00
def makeResult ( self , qTitle , qMode , qDesc , qValue ) :
if qMode == " text " :
2020-03-09 00:19:42 +01:00
return InlineQueryResultArticle (
id = uuid . uuid4 ( ) . hex ,
type = " article " ,
title = qTitle ,
input_message_content = InputTextMessageContent ( " <a href= \" " + qValue + " \" >HonusBot</a> " , " HTML " ) ,
description = qDesc
)
2020-03-09 00:18:09 +01:00
if qMode == " image " :
2020-03-09 00:19:42 +01:00
return InlineQueryResultArticle (
id = uuid . uuid4 ( ) . hex ,
type = " article " ,
title = qTitle ,
input_message_content = InputTextMessageContent ( " <a href= \" " + qValue + " \" >Scherzo del rasoio</a> " , " HTML " ) ,
description = qDesc
)
2020-03-09 00:18:09 +01:00
return InlineQueryResultArticle (
2020-03-09 00:19:42 +01:00
id = uuid . uuid4 ( ) . hex ,
type = " article " ,
title = qTitle ,
input_message_content = InputTextMessageContent ( " Unknown result type! " , " HTML " ) ,
description = qDesc
2020-03-09 00:18:09 +01:00
)
2019-12-28 21:57:04 +01:00
def inlineQuery ( self , update , context ) :
senderid = str ( update . inline_query . from_user . id )
query = update . inline_query . query
results = list ( )
if not query :
2020-03-09 00:18:09 +01:00
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 ) ) )
2019-12-28 21:57:04 +01:00
else :
2020-03-09 00:18:09 +01:00
results . append ( self . makeResult ( " Cancer " , " image " , " Search cancer about " + query , self . callRequest ( " cancer " , " imageurl " , senderid , query ) ) )
2019-12-28 21:57:04 +01:00
context . bot . answer_inline_query ( update . inline_query . id , results , 1 , False )
InlineBot ( ) . start ( )