Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit 76c5ad5

Browse files
alfianandaaMoveAngel
authored andcommitted
multimemes: add glitch module
• Ported from userge • Merged to multimemes Signed-off-by: Alfiananda P.A <[email protected]> Signed-off-by: MoveAngel <[email protected]>
1 parent 8d8c82b commit 76c5ad5

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dnspython
1111
deezloader
1212
emoji
1313
gitpython
14+
glitch_this
1415
google-api-python-client
1516
google-auth-httplib2
1617
google-auth-oauthlib
@@ -54,4 +55,4 @@ urbandict
5455
wikipedia
5556
PyGithub
5657
python-dateutil
57-
youtube_search
58+
youtube_search

userbot/modules/multimemes.py

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
import re
1515
from asyncio.exceptions import TimeoutError
1616

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
1920
from telethon.errors.rpcerrorlist import YouBlockedUserError
2021
from telethon.tl.types import DocumentAttributeFilename
2122

2223
from userbot import CMD_HELP, TEMP_DOWNLOAD_DIRECTORY, bot
2324
from userbot.events import register
2425

26+
Glitched = TEMP_DOWNLOAD_DIRECTORY + "glitch.gif"
27+
2528
EMOJI_PATTERN = re.compile(
2629
"["
2730
"\U0001F1E0-\U0001F1FF" # flags (iOS)
@@ -39,7 +42,75 @@
3942
)
4043

4144

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(?: |$)(.*)")
43114
async def mim(event):
44115
if not event.reply_to_msg_id:
45116
await event.edit(
@@ -375,6 +446,14 @@ def deEmojify(inputString: str) -> str:
375446
return re.sub(EMOJI_PATTERN, "", inputString)
376447

377448

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+
378457
CMD_HELP.update(
379458
{
380459
"memify": ".mmf texttop ; textbottom\

0 commit comments

Comments
 (0)