owlrandomshitbot/bot.py

94 lines
2.9 KiB
Python
Raw Normal View History

2025-01-04 17:00:42 +00:00
from telegram import Update
2025-01-23 20:54:34 +00:00
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters, InlineQueryHandler, \
CallbackContext, CallbackQueryHandler
2024-10-25 16:45:07 +00:00
import logging
2025-01-04 17:00:42 +00:00
from tgbot.config import TOKEN
2025-01-23 20:54:34 +00:00
from tgbot.shit.handlers import handle_xitter, handle_red_ebalo, handle_hentai, handle_cute_button
2025-01-04 17:00:42 +00:00
from tgbot.shit.render import render_text_on_image, image_to_string
from io import BytesIO
2024-10-25 16:45:07 +00:00
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
2025-01-23 20:54:34 +00:00
2024-10-25 16:45:07 +00:00
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
2025-01-04 17:00:42 +00:00
await context.bot.send_message(chat_id=update.effective_chat.id,
text='WE ARE A PARTY OF UTTER MADNESS, '
'AND I AM A PERSON OF COMPLETE AND TOTAL DELUSION!')
2024-10-25 16:45:07 +00:00
async def respond_with_picture(update: Update, context: ContextTypes.DEFAULT_TYPE):
2025-01-04 17:00:42 +00:00
file = render_text_on_image("tgbot/assets/red_ebalo.png", update.message.text)
2024-10-25 16:45:07 +00:00
await context.bot.send_sticker(chat_id=update.effective_chat.id, sticker=file)
2025-01-04 17:00:42 +00:00
2024-12-08 19:32:46 +00:00
async def image2string(update: Update, context: ContextTypes.DEFAULT_TYPE):
2025-01-04 17:00:42 +00:00
photo = update.message.photo[-1]
2024-12-08 19:32:46 +00:00
2025-01-04 17:00:42 +00:00
file = await photo.get_file()
bio = BytesIO()
await file.download_to_memory(out=bio)
2024-12-08 19:32:46 +00:00
bio.seek(0)
s = image_to_string(bio)
await update.message.reply_text(s)
2024-10-25 16:45:07 +00:00
2025-01-23 20:54:34 +00:00
async def callback_query_handler(update: Update, context: CallbackContext):
query = update.callback_query
if query.data == "show_cute_popup":
await context.bot.answer_callback_query(
callback_query_id=query.id,
text="Hey! This button is for you! Thank you for clicking it, you are awesome!",
show_alert=True
)
else:
await query.answer()
2025-01-04 17:00:42 +00:00
async def handle_inline(update: Update, context: ContextTypes.DEFAULT_TYPE):
2024-10-25 16:45:07 +00:00
query = update.inline_query.query
if not query:
return
2024-11-30 22:42:27 +00:00
2025-01-04 17:00:42 +00:00
if "https://x.com" in query:
await handle_xitter(update, context)
2024-11-30 22:42:27 +00:00
return
2024-10-25 16:45:07 +00:00
2025-01-04 17:00:42 +00:00
if query.startswith("hentai"):
await handle_hentai(update, context)
return
2024-10-25 16:45:07 +00:00
2025-01-23 20:54:34 +00:00
if query.startswith("button!"):
await handle_cute_button(update, context)
return
2025-01-04 17:00:42 +00:00
await handle_red_ebalo(update, context)
2024-10-25 16:45:07 +00:00
def main():
application = ApplicationBuilder().token(TOKEN).build()
start_handler = CommandHandler('start', start)
picture_handler = MessageHandler(filters.TEXT & ~filters.COMMAND, respond_with_picture)
application.add_handler(start_handler)
2024-12-08 19:32:46 +00:00
application.add_handler(MessageHandler(filters.PHOTO, image2string))
2024-10-25 16:45:07 +00:00
application.add_handler(picture_handler)
2025-01-04 17:00:42 +00:00
application.add_handler(InlineQueryHandler(handle_inline))
2025-01-23 20:54:34 +00:00
application.add_handler(CallbackQueryHandler(callback_query_handler))
2024-10-25 16:45:07 +00:00
application.run_polling()
2025-01-04 17:00:42 +00:00
2024-10-25 16:45:07 +00:00
if __name__ == '__main__':
main()