-
Notifications
You must be signed in to change notification settings - Fork 0
/
ncode.py
50 lines (43 loc) · 1.3 KB
/
ncode.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
# oreo - UserBot
"""
✘ Commands Available -
• `{i}ncode <file>`
Use - Paste the contents of file and send as pic.
"""
import pygments
from pygments.formatters import ImageFormatter
from pygments.lexers import Python3Lexer
from . import oreo_cmd, check_filename
@oreo_cmd(pattern="ncode$")
async def coder_print(event):
if not event.reply_to_msg_id:
return await event.eor("`Reply to a file or message!`", time=5)
msg = await event.get_reply_message()
if msg.document:
a = await event.client.download_media(
await event.get_reply_message(), check_filename("ncode.png")
)
with open(a, "r") as s:
c = s.read()
else:
a = None
c = msg.text
pygments.highlight(
c,
Python3Lexer(),
ImageFormatter(line_numbers=True),
check_filename("result.png"),
)
res = await event.client.send_message(
event.chat_id,
"**Pasting this code on my page...**",
reply_to=event.reply_to_msg_id,
)
await event.client.send_file(
event.chat_id, "result.png", force_document=True, reply_to=event.reply_to_msg_id
)
await res.delete()
await event.delete()
if a:
os.remove(a)
os.remove("result.png")