forked from athphane/userbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarbon.py
More file actions
85 lines (68 loc) · 2.58 KB
/
carbon.py
File metadata and controls
85 lines (68 loc) · 2.58 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
from asyncio import sleep
from pyrogram import Filters, Message
from userbot import UserBot
from userbot.plugins.help import add_command_help
CARBON_LANG = "py"
@UserBot.on_message(Filters.command("carbon", ".") & Filters.me)
async def carbon_test(_, message: Message):
"""
Receives text and makes a carbon image using the text
Eg: .carbon your code here (multi line supported)
"""
carbon_text = message.text[8:]
# Write the code to a file cause carbon-now-cli wants a file.
file = "userbot/downloads/carbon.{}".format(get_carbon_lang())
with open(file, "w+") as f:
f.write(carbon_text)
await message.edit_text("Carbonizing code...")
# Do the thing
os.system("carbon-now -h -t userbot/downloads/carbon {}".format(file))
# await message.edit_text("Carbonizing completed...")
# Send the thing
await UserBot.send_photo(message.chat.id, 'userbot/downloads/carbon.png')
await message.delete()
@UserBot.on_message(Filters.command('carbonlang', '.') & Filters.me)
async def update_carbon_lang(_, message: Message):
"""
Set language to use Carbon with.
Eg: .carbonlang js -> will set the file type to js
"""
global CARBON_LANG
cmd = message.command
type_text = ""
if len(cmd) > 1:
type_text = " ".join(cmd[1:])
elif message.reply_to_message and len(cmd) == 1:
type_text = message.reply_to_message.text
elif not message.reply_to_message and len(cmd) == 1:
await message.edit("Give me something to carbonize")
await sleep(2)
await message.delete()
return
CARBON_LANG = type_text
await message.edit_text("Carbon type set to {}".format(type_text))
await sleep(2)
await message.delete()
@UserBot.on_message(Filters.command('carbonlang', '!') & Filters.me)
async def send_carbon_lang(_, message: Message):
"""
Edits message to show current set carbon language
"""
await message.edit_text(get_carbon_lang())
await sleep(5)
await message.delete()
def get_carbon_lang():
"""
Gets carbon language. Default py
"""
return CARBON_LANG
add_command_help(
'carbon', [
['.carbon', 'Generates a carbon image of your code.\nUsage: `.carbon` reply to message or command args'],
['.carbonlang', 'Change carbon language for syntax highlighting.\nUsage: `.carbonlang` reply to message or '
'command args\n'
'Please use file extensions for best results.'],
['!carbonlang', 'Show current carbon language. Default is python.\nUsage: `!carbonlang`'],
]
)