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

Commit f0853e8

Browse files
committed
Userbot: Publish Figlet and Memify module
1 parent 5ef354b commit f0853e8

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Pillow>=5.3.0
2525
psycopg2
2626
psycopg2-binary
2727
pybase64>=0.4.0
28+
pyfiglet
2829
pylast
2930
pySmartDL
3031
python-barcode

userbot/modules/figlet.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import asyncio
2+
import pyfiglet
3+
from telethon import events, functions
4+
from userbot import CMD_HELP
5+
from userbot.events import register
6+
import sys
7+
8+
@register(outgoing=True, pattern="^.figlet(?: |$)(.*)")
9+
async def figlet(event):
10+
if event.fwd_from:
11+
return
12+
CMD_FIG = {"slant": "slant", "3D": "3-d", "5line": "5lineoblique", "alpha": "alphabet", "banner": "banner3-D", "doh": "doh", "iso": "isometric1", "letter": "letters", "allig": "alligator", "dotm": "dotmatrix", "bubble": "bubble", "bulb": "bulbhead", "digi": "digital"}
13+
input_str = event.pattern_match.group(1)
14+
if "|" in input_str:
15+
text, cmd = input_str.split("|", maxsplit=1)
16+
elif input_str is not None:
17+
cmd = None
18+
text = input_str
19+
else:
20+
await event.edit("Please add some text to figlet")
21+
return
22+
if cmd is not None:
23+
try:
24+
font = CMD_FIG[cmd]
25+
except KeyError:
26+
await event.edit("Invalid selected font.")
27+
return
28+
result = pyfiglet.figlet_format(text, font=font)
29+
else:
30+
result = pyfiglet.figlet_format(text)
31+
await event.respond("‌‌‎`{}`".format(result))
32+
await event.delete()
33+
34+
CMD_HELP.update({
35+
"figlet":
36+
".figlet \
37+
\nUsage: Enhance ur text to strip line with anvil.\n"
38+
})

userbot/modules/memify.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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

Comments
 (0)