Skip to content

Commit

Permalink
fixed sudo and carbon
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed May 18, 2020
1 parent c394d37 commit f2d19ec
Showing 3 changed files with 53 additions and 26 deletions.
75 changes: 51 additions & 24 deletions userge/plugins/fun/carbon.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import asyncio
from urllib.parse import quote_plus

import aiofiles
from selenium import webdriver
from pyrogram.errors.exceptions.bad_request_400 import YouBlockedUser

@@ -63,45 +64,67 @@ async def carbon_(message: Message):
reply_to_message_id=replied.message_id if replied else None)
)
else:
if message.reply_to_message:
code = message.reply_to_message.text
message_id = message.reply_to_message.message_id
else:
code = message.input_str
input_str = message.input_str
replied = message.reply_to_message
theme = 'seti'
lang = 'auto'
if replied and (replied.text
or (replied.document and 'text' in replied.document.mime_type)):
message_id = replied.message_id
if replied.document:
await message.edit("`Downloading File...`")
path_ = await userge.download_media(replied, file_name=Config.DOWN_PATH)
async with aiofiles.open(path_) as file_:
code = await file_.read()
os.remove(path_)
else:
code = replied.text
if input_str:
if '|' in input_str:
args = input_str.split('|')
if len(args) == 2:
theme = args[0].strip()
lang = args[1].strip()
else:
theme = input_str
elif input_str:
message_id = message.message_id
if not code:
if '|' in input_str:
args = input_str.split('|')
if len(args) == 3:
theme = args[0].strip()
lang = args[1].strip()
code = args[2].strip()
elif len(args) == 2:
theme = args[0].strip()
code = args[1].strip()
else:
code = input_str
else:
await message.err("need input text!")
return
theme = 'seti'
lang = 'auto'
if '|' in code:
args = code.split('|')
if len(args) == 3:
theme = args[0].strip()
lang = args[1].strip()
code = args[2].strip()
elif len(args) == 2:
theme = args[0].strip()
code = args[1].strip()
await message.edit("`Creating a Carbon...`")
code = quote_plus(code)
await message.edit("`Processing... 25%`")
await message.edit("`Processing... 20%`")
carbon_path = os.path.join(Config.DOWN_PATH, "carbon.png")
if os.path.isfile(carbon_path):
os.remove(carbon_path)
url = CARBON.format(theme=theme, lang=lang, code=code)
if len(url) > 2590:
await message.err("input too large!")
return
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = Config.GOOGLE_CHROME_BIN
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-gpu")
prefs = {'download.default_directory': './'}
prefs = {'download.default_directory': Config.DOWN_PATH}
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get(url)
await message.edit("`Processing... 50%`")
await message.edit("`Processing... 40%`")
driver.command_executor._commands["send_command"] = (
"POST", '/session/$sessionId/chromium/send_command')
params = {
@@ -112,10 +135,14 @@ async def carbon_(message: Message):
}
}
driver.execute("send_command", params)
driver.find_element_by_xpath("//button[contains(text(),'Export')]").click()
#driver.find_element_by_xpath("//button[contains(text(),'4x')]").click()
#driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click()
await message.edit("`Processing... 75%`")
# driver.find_element_by_xpath("//button[contains(text(),'Export')]").click()
driver.find_element_by_id("export-menu").click()
await asyncio.sleep(1)
await message.edit("`Processing... 60%`")
driver.find_element_by_xpath("//button[contains(text(),'4x')]").click()
await asyncio.sleep(1)
driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click()
await message.edit("`Processing... 80%`")
while not os.path.isfile(carbon_path):
await asyncio.sleep(0.5)
await message.edit("`Processing... 100%`")
2 changes: 1 addition & 1 deletion userge/plugins/utils/sudo.py
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ async def add_sudo_cmd(message: Message):
cmd = cmd.lstrip(Config.CMD_TRIGGER)
if cmd in Config.ALLOWED_COMMANDS:
await message.edit(f"cmd : `{cmd}` already in **SUDO**!", del_in=5)
elif cmd not in [c_d.lstrip('.') for c_d in userge.get_help(all_cmds=True)[0]]:
elif cmd not in [c_d.lstrip(Config.CMD_TRIGGER) for c_d in list(userge.manager.enabled_commands)]:
await message.edit(f"cmd : `{cmd}` 🤔, is that a command ?", del_in=5)
else:
Config.ALLOWED_COMMANDS.add(cmd)
2 changes: 1 addition & 1 deletion userge/versions.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
__version_mjaor__ = 0
__version_minor__ = 1
__version_micro__ = 5
__version_beta__ = 4
__version_beta__ = 5

__version__ = "{}.{}.{}".format(__version_mjaor__,
__version_minor__,

0 comments on commit f2d19ec

Please sign in to comment.