|
14 | 14 | import re |
15 | 15 | from asyncio.exceptions import TimeoutError |
16 | 16 |
|
17 | | -from PIL import Image, ImageEnhance, ImageOps, ImageFont, ImageDraw |
18 | | -from telethon import events |
| 17 | +from glitch_this import ImageGlitcher |
| 18 | +from PIL import Image, ImageDraw, ImageEnhance, ImageFont, ImageOps |
| 19 | +from telethon import events, functions, types |
19 | 20 | from telethon.errors.rpcerrorlist import YouBlockedUserError |
20 | 21 | from telethon.tl.types import DocumentAttributeFilename |
21 | 22 |
|
22 | 23 | from userbot import CMD_HELP, TEMP_DOWNLOAD_DIRECTORY, bot |
23 | 24 | from userbot.events import register |
24 | 25 |
|
| 26 | +Glitched = TEMP_DOWNLOAD_DIRECTORY + "glitch.gif" |
| 27 | + |
25 | 28 | EMOJI_PATTERN = re.compile( |
26 | 29 | "[" |
27 | 30 | "\U0001F1E0-\U0001F1FF" # flags (iOS) |
|
39 | 42 | ) |
40 | 43 |
|
41 | 44 |
|
42 | | -@register(outgoing=True, pattern="^.mmf(?: |$)(.*)") |
| 45 | +@register(outgoing=True, pattern=r"^\.glitch(?: |$)(.*)") |
| 46 | +async def glitch(event): |
| 47 | + if not event.reply_to_msg_id: |
| 48 | + await event.edit("`I Wont Glitch A Ghost!`") |
| 49 | + return |
| 50 | + reply_message = await event.get_reply_message() |
| 51 | + if not reply_message.media: |
| 52 | + await event.edit("`reply to a image/sticker`") |
| 53 | + return |
| 54 | + await bot.download_file(reply_message.media) |
| 55 | + await event.edit("`Downloading Media..`") |
| 56 | + if event.is_reply: |
| 57 | + data = await check_media(reply_message) |
| 58 | + if isinstance(data, bool): |
| 59 | + await event.edit("`Unsupported Files...`") |
| 60 | + return |
| 61 | + else: |
| 62 | + await event.edit("`Reply to Any Media Sur`") |
| 63 | + return |
| 64 | + |
| 65 | + try: |
| 66 | + value = int(event.pattern_match.group(1)) |
| 67 | + if value > 8: |
| 68 | + raise ValueError |
| 69 | + except ValueError: |
| 70 | + value = 2 |
| 71 | + await event.edit("```Glitching This Media```") |
| 72 | + await asyncio.sleep(2) |
| 73 | + file_name = "glitch.png" |
| 74 | + to_download_directory = TEMP_DOWNLOAD_DIRECTORY |
| 75 | + downloaded_file_name = os.path.join(to_download_directory, file_name) |
| 76 | + downloaded_file_name = await bot.download_media( |
| 77 | + reply_message, |
| 78 | + downloaded_file_name, |
| 79 | + ) |
| 80 | + glitch_file = downloaded_file_name |
| 81 | + glitcher = ImageGlitcher() |
| 82 | + img = Image.open(glitch_file) |
| 83 | + glitch_img = glitcher.glitch_image(img, value, color_offset=True, gif=True) |
| 84 | + DURATION = 200 |
| 85 | + LOOP = 0 |
| 86 | + glitch_img[0].save( |
| 87 | + Glitched, |
| 88 | + format="GIF", |
| 89 | + append_images=glitch_img[1:], |
| 90 | + save_all=True, |
| 91 | + duration=DURATION, |
| 92 | + loop=LOOP, |
| 93 | + ) |
| 94 | + await event.edit("`Uploading Glitched Media...`") |
| 95 | + nosave = await event.client.send_file( |
| 96 | + event.chat_id, Glitched, force_document=False, reply_to=event.reply_to_msg_id |
| 97 | + ) |
| 98 | + await event.delete() |
| 99 | + os.remove(Glitched) |
| 100 | + await bot( |
| 101 | + functions.messages.SaveGifRequest( |
| 102 | + id=types.InputDocument( |
| 103 | + id=nosave.media.document.id, |
| 104 | + access_hash=nosave.media.document.access_hash, |
| 105 | + file_reference=nosave.media.document.file_reference, |
| 106 | + ), |
| 107 | + unsave=True, |
| 108 | + ) |
| 109 | + ) |
| 110 | + os.remove(glitch_file) |
| 111 | + |
| 112 | + |
| 113 | +@register(outgoing=True, pattern=r"^\.mmf(?: |$)(.*)") |
43 | 114 | async def mim(event): |
44 | 115 | if not event.reply_to_msg_id: |
45 | 116 | await event.edit( |
@@ -375,6 +446,14 @@ def deEmojify(inputString: str) -> str: |
375 | 446 | return re.sub(EMOJI_PATTERN, "", inputString) |
376 | 447 |
|
377 | 448 |
|
| 449 | +CMD_HELP.update( |
| 450 | + { |
| 451 | + "glitch": ".glitch <1-8>\ |
| 452 | + \nUsage: Reply a sticker/image and send with cmd.\ |
| 453 | + \nvalue is range 1-8 if doenst it will give default value which is 2" |
| 454 | + } |
| 455 | +) |
| 456 | + |
378 | 457 | CMD_HELP.update( |
379 | 458 | { |
380 | 459 | "memify": ".mmf texttop ; textbottom\ |
|
0 commit comments