forked from TeamUltroid/UltroidAddons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text2gif.py
62 lines (50 loc) · 1.49 KB
/
text2gif.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# " Made by @e3ris for Ultroid "
# < https://github.com/TeamUltroid/Ultroid >
# This Plugin uses @Text2gifBot.
"""
✘ **Makes Fancy Gif from your Words!**
✘ `{i}t2g <some_text>`
`Convert Text to Gif...`
"""
import os
import random
import re
import emoji
from telethon.utils import get_input_document
from . import *
chat = "text2gifBot"
def remove_emoji(string):
return emoji.get_emoji_regexp().sub("", string)
@ultroid_cmd(pattern="t2g ?(.*)")
async def t2g(e):
eris = await eor(e, "`...`")
input_args = e.pattern_match.group(1)
if not input_args:
input_args = "No Text was Given :(("
args = remove_emoji(input_args)
try:
t2g = await e.client.inline_query(chat, args)
doc = t2g[random.randrange(0, len(t2g) - 1)]
try:
file = await doc.download_media()
done = await e.client.send_file(
e.chat_id, file=file, reply_to=e.reply_to_msg_id
)
os.remove(file)
except AttributeError:
# for files, without write Method
done = await doc.click(e.chat_id, reply_to=e.reply_to_msg_id)
await eris.delete()
except Exception as fn:
return await eod(eris, f"**ERROR** : `{fn}`")
await cleargif(done)
async def cleargif(gif_):
try:
await ultroid(
functions.messages.SaveGifRequest(
id=get_input_document(gif_),
unsave=True,
)
)
except Exception as E:
LOGS.info(E)