Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telegram import Bot, Poll
- from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackContext
- from credits import bot_token
- from PIL import Image, ImageFont, ImageDraw
- bot = Bot(token=bot_token)
- updater = Updater(token=bot_token)
- dispatcher = updater.dispatcher
- def set_meme_text(username, ts, bs):
- img = Image.open(f'{username}_photo.jpg')
- rgb_img = img.convert("RGB")
- title_font = ImageFont.truetype("Nautilus.otf", 60)
- width, height = rgb_img.size
- meme = ImageDraw.Draw(rgb_img)
- meme.text(((width / 2 - width / 4), height / 4), ts, (0, 0, 0), font=title_font)
- meme.text(((width / 2 - width / 4), height - height / 4), bs, (0, 0, 0), font=title_font)
- rgb_img.save(f"{username}_meme.jpg")
- PHOTO = 1
- TOP_STRING = 1
- BOT_STRING = 1
- VIDEO = 1
- ts = ''
- def start(update, context):
- update.message.reply_text('Добро пожаловать в генератор ботов!'
- ' Отправьте фото, чтобы начать с ним работать!')
- return PHOTO
- def photo(update, context):
- user = str(update.message.from_user['username'])
- photo_file = update.message.document.get_file()
- photo_file.download(f'{user}_photo.jpg')
- update.message.reply_text('Отлично! Теперь добавь верхнюю надпись'
- 'или отправь /skip если хочешь пропустить этот шаг')
- return TOP_STRING
- def top_string(update,context):
- global ts
- update.message.reply_text("Смешно =) А теперь вводи нижнюю надпись или отправь;"
- " /skip если хочешь пропустить этот шаг")
- ts = update.message.text
- return BOT_STRING
- def skip_top_string(update,context):
- update.message.reply_text('Тогда пиши что должно быть внизу или отправь'
- ' /skip если хочешь пропустить этот шаг')
- return BOT_STRING
- def bottom_string(update,context):
- user = str(update.message.from_user['username'])
- update.message.reply_text('Лови результат')
- bs = update.message.text
- set_meme_text(user, ts,bs)
- sending_img = open(user+ "_meme.jpg", 'rb')
- context.bot.send_document(update.effective_chat.id, sending_img)
- return ConversationHandler.END
- bottom_string_handler = MessageHandler(Filters.text & ~Filters.command,bottom_string)
- top_string_handler = MessageHandler(Filters.text & ~Filters.command,top_string)
- skip_top_string_handler = CommandHandler("skip", skip_top_string)
- start_handler = CommandHandler("start",start)
- photo_handler = MessageHandler(Filters.document.category("image"), photo)
- conv_handler = ConversationHandler(entry_points=start_handler,
- states={
- PHOTO: [photo_handler],
- TOP_STRING: [top_string_handler,skip_top_string_handler],
- BOT_STRING: [bottom_string_handler]
- },fallbacks=[bottom_string_handler])
- dispatcher.add_handler(start_handler)
- dispatcher.add_handler(conv_handler)
- dispatcher.add_handler(bottom_string_handler)
- dispatcher.add_handler(top_string_handler)
- dispatcher.add_handler(skip_top_string_handler)
- dispatcher.add_handler(photo_handler)
- updater.start_polling()
- updater.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement