|
| 1 | +# Ported by MVaL |
| 2 | + |
| 3 | +from telethon.errors.rpcerrorlist import YouBlockedUserError |
| 4 | +from telethon import events |
| 5 | +from io import BytesIO |
| 6 | +from PIL import Image |
| 7 | +import asyncio |
| 8 | +import time |
| 9 | +from datetime import datetime |
| 10 | +from hachoir.metadata import extractMetadata |
| 11 | +from hachoir.parser import createParser |
| 12 | +from pySmartDL import SmartDL |
| 13 | +from telethon.tl.types import DocumentAttributeVideo |
| 14 | +from userbot.modules.upload_download import progress, humanbytes, time_formatter |
| 15 | +from userbot import (TEMP_DOWNLOAD_DIRECTORY, CMD_HELP, bot) |
| 16 | +from userbot.events import register |
| 17 | +import datetime |
| 18 | +from collections import defaultdict |
| 19 | +import math |
| 20 | +import os |
| 21 | +import requests |
| 22 | +import zipfile |
| 23 | +from telethon.errors.rpcerrorlist import StickersetInvalidError |
| 24 | +from telethon.errors import MessageNotModifiedError |
| 25 | +from telethon.tl.functions.account import UpdateNotifySettingsRequest |
| 26 | +from telethon.tl.functions.messages import GetStickerSetRequest |
| 27 | +from telethon.tl.types import (DocumentAttributeFilename, DocumentAttributeSticker, |
| 28 | + InputMediaUploadedDocument, InputPeerNotifySettings, |
| 29 | + InputStickerSetID, InputStickerSetShortName, |
| 30 | + MessageMediaPhoto) |
| 31 | + |
| 32 | + |
| 33 | +THUMB_IMAGE_PATH = "./thumb_image.jpg" |
| 34 | + |
| 35 | + |
| 36 | +@register(outgoing=True, pattern="^.mmf(?: |$)(.*)") |
| 37 | +async def mim(event): |
| 38 | + if event.fwd_from: |
| 39 | + return |
| 40 | + if not event.reply_to_msg_id: |
| 41 | + await event.edit("`Syntax: reply to an image with .mms` 'text on top' ; 'text on bottom' ") |
| 42 | + return |
| 43 | + reply_message = await event.get_reply_message() |
| 44 | + if not reply_message.media: |
| 45 | + await event.edit("```reply to a image/sticker/gif```") |
| 46 | + return |
| 47 | + chat = "@MemeAutobot" |
| 48 | + sender = reply_message.sender |
| 49 | + file_ext_ns_ion = "@memetime.png" |
| 50 | + file = await bot.download_file(reply_message.media) |
| 51 | + uploaded_gif = None |
| 52 | + if reply_message.sender.bot: |
| 53 | + await event.edit("```Reply to actual users message.```") |
| 54 | + return |
| 55 | + else: |
| 56 | + await event.edit("```Transfiguration Time! Mwahaha Memifying this image! (」゚ロ゚)」 ```") |
| 57 | + await asyncio.sleep(5) |
| 58 | + |
| 59 | + async with bot.conversation("@MemeAutobot") as bot_conv: |
| 60 | + try: |
| 61 | + memeVar = event.pattern_match.group(1) |
| 62 | + await silently_send_message(bot_conv, "/start") |
| 63 | + await asyncio.sleep(1) |
| 64 | + await silently_send_message(bot_conv, memeVar) |
| 65 | + await bot.send_file(chat, reply_message.media) |
| 66 | + response = await bot_conv.get_response() |
| 67 | + except YouBlockedUserError: |
| 68 | + await event.reply("```Please unblock @MemeAutobot and try again```") |
| 69 | + return |
| 70 | + if response.text.startswith("Forward"): |
| 71 | + await event.edit("```can you kindly disable your forward privacy settings for good, Nibba?```") |
| 72 | + if "Okay..." in response.text: |
| 73 | + await event.edit("```🛑 🤨 NANI?! This is not an image! This will take sum tym to convert to image... UwU 🧐 🛑```") |
| 74 | + thumb = None |
| 75 | + if os.path.exists(THUMB_IMAGE_PATH): |
| 76 | + thumb = THUMB_IMAGE_PATH |
| 77 | + input_str = event.pattern_match.group(1) |
| 78 | + if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY): |
| 79 | + os.makedirs(TEMP_DOWNLOAD_DIRECTORY) |
| 80 | + if event.reply_to_msg_id: |
| 81 | + file_name = "meme.png" |
| 82 | + reply_message = await event.get_reply_message() |
| 83 | + to_download_directory = TEMP_DOWNLOAD_DIRECTORY |
| 84 | + downloaded_file_name = os.path.join(to_download_directory, file_name) |
| 85 | + downloaded_file_name = await bot.download_media( |
| 86 | + reply_message, |
| 87 | + downloaded_file_name, |
| 88 | + ) |
| 89 | + if os.path.exists(downloaded_file_name): |
| 90 | + await bot.send_file( |
| 91 | + chat, |
| 92 | + downloaded_file_name, |
| 93 | + force_document=False, |
| 94 | + supports_streaming=False, |
| 95 | + allow_cache=False, |
| 96 | + thumb=thumb, |
| 97 | + ) |
| 98 | + os.remove(downloaded_file_name) |
| 99 | + else: |
| 100 | + await event.edit("File Not Found {}".format(input_str)) |
| 101 | + response = await bot_conv.get_response() |
| 102 | + the_download_directory = TEMP_DOWNLOAD_DIRECTORY |
| 103 | + files_name = "memes.webp" |
| 104 | + download_file_name = os.path.join(the_download_directory, files_name) |
| 105 | + await bot.download_media( |
| 106 | + response.media, |
| 107 | + download_file_name, |
| 108 | + ) |
| 109 | + requires_file_name = TEMP_DOWNLOAD_DIRECTORY + "memes.webp" |
| 110 | + await bot.send_file( # pylint:disable=E0602 |
| 111 | + event.chat_id, |
| 112 | + requires_file_name, |
| 113 | + supports_streaming=False, |
| 114 | + caption="Memifyed", |
| 115 | + ) |
| 116 | + await event.delete() |
| 117 | + #await bot.send_message(event.chat_id, "`☠️☠️Ah Shit... Here we go Again!🔥🔥`") |
| 118 | + elif not is_message_image(reply_message): |
| 119 | + await event.edit("Invalid message type. Plz choose right message type u NIBBA.") |
| 120 | + return |
| 121 | + else: |
| 122 | + await bot.send_file(event.chat_id, response.media) |
| 123 | + |
| 124 | +def is_message_image(message): |
| 125 | + if message.media: |
| 126 | + if isinstance(message.media, MessageMediaPhoto): |
| 127 | + return True |
| 128 | + if message.media.document: |
| 129 | + if message.media.document.mime_type.split("/")[0] == "image": |
| 130 | + return True |
| 131 | + return False |
| 132 | + return False |
| 133 | + |
| 134 | +async def silently_send_message(conv, text): |
| 135 | + await conv.send_message(text) |
| 136 | + response = await conv.get_response() |
| 137 | + await conv.mark_read(message=response) |
| 138 | + return response |
| 139 | + |
| 140 | +CMD_HELP.update({ |
| 141 | + "memify": |
| 142 | + ".mmf texttop ; textbottom\ |
| 143 | + \nUsage: Reply a sticker/image/gif and send with cmd." |
| 144 | +}) |
0 commit comments