99 lines
3.1 KiB
Python
Raw Normal View History

2025-01-05 00:00:42 +07:00
from telegram import Update
2025-01-24 03:54:34 +07:00
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters, InlineQueryHandler, \
CallbackContext, CallbackQueryHandler
2024-10-25 23:45:07 +07:00
import logging
2025-03-05 15:43:03 +07:00
from tgbot.config import TOKEN, PROMPTING_USERS
2025-01-24 03:54:34 +07:00
from tgbot.shit.handlers import handle_xitter, handle_red_ebalo, handle_hentai, handle_cute_button
2025-03-03 04:10:37 +07:00
from tgbot.shit.prompting import gen_image
2025-01-05 00:00:42 +07:00
from tgbot.shit.render import render_text_on_image, image_to_string
from io import BytesIO
2024-10-25 23:45:07 +07:00
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
2025-01-24 03:54:34 +07:00
2024-10-25 23:45:07 +07:00
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
2025-01-05 00:00:42 +07: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 23:45:07 +07:00
2025-03-03 04:10:37 +07:00
async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
2025-03-05 15:43:03 +07:00
if not update.message.text.startswith("prompting") or update.message.from_user["username"] not in PROMPTING_USERS:
2025-03-03 04:10:37 +07:00
file = render_text_on_image("tgbot/assets/red_ebalo.png", update.message.text)
await context.bot.send_sticker(chat_id=update.effective_chat.id, sticker=file)
else:
await gen_image(update, context)
2024-10-25 23:45:07 +07:00
2025-01-05 00:00:42 +07:00
2024-12-09 02:32:46 +07:00
async def image2string(update: Update, context: ContextTypes.DEFAULT_TYPE):
2025-01-05 00:00:42 +07:00
photo = update.message.photo[-1]
2024-12-09 02:32:46 +07:00
2025-01-05 00:00:42 +07:00
file = await photo.get_file()
bio = BytesIO()
await file.download_to_memory(out=bio)
2024-12-09 02:32:46 +07:00
bio.seek(0)
s = image_to_string(bio)
await update.message.reply_text(s)
2024-10-25 23:45:07 +07:00
2025-01-24 03:54:34 +07: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-03-05 15:43:03 +07:00
2025-01-05 00:00:42 +07:00
async def handle_inline(update: Update, context: ContextTypes.DEFAULT_TYPE):
2024-10-25 23:45:07 +07:00
query = update.inline_query.query
if not query:
return
2024-12-01 05:42:27 +07:00
2025-01-05 00:00:42 +07:00
if "https://x.com" in query:
await handle_xitter(update, context)
2024-12-01 05:42:27 +07:00
return
2024-10-25 23:45:07 +07:00
2025-01-05 00:00:42 +07:00
if query.startswith("hentai"):
await handle_hentai(update, context)
return
2024-10-25 23:45:07 +07:00
2025-01-24 03:54:34 +07:00
if query.startswith("button!"):
await handle_cute_button(update, context)
return
2025-01-05 00:00:42 +07:00
await handle_red_ebalo(update, context)
2024-10-25 23:45:07 +07:00
2025-03-05 15:43:03 +07:00
2024-10-25 23:45:07 +07:00
def main():
application = ApplicationBuilder().token(TOKEN).build()
start_handler = CommandHandler('start', start)
2025-03-03 04:10:37 +07:00
text_handler = MessageHandler(filters.TEXT & ~filters.COMMAND, handle_text)
2024-10-25 23:45:07 +07:00
application.add_handler(start_handler)
2024-12-09 02:32:46 +07:00
application.add_handler(MessageHandler(filters.PHOTO, image2string))
2025-03-03 04:10:37 +07:00
application.add_handler(text_handler)
2025-01-05 00:00:42 +07:00
application.add_handler(InlineQueryHandler(handle_inline))
2025-01-24 03:54:34 +07:00
application.add_handler(CallbackQueryHandler(callback_query_handler))
2024-10-25 23:45:07 +07:00
application.run_polling()
2025-01-05 00:00:42 +07:00
2024-10-25 23:45:07 +07:00
if __name__ == '__main__':
main()