Spaces:
Running
Running
File size: 4,740 Bytes
fefc4fb |
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# Ultroid - UserBot
# Copyright (C) 2021-2023 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
from . import get_help
__doc__ = get_help("help_beautify")
import os
import random
from telethon.utils import get_display_name
from urllib.parse import urlencode
from . import Carbon, ultroid_cmd, get_string, inline_mention
from secrets import token_hex
_colorspath = "resources/colorlist.txt"
if os.path.exists(_colorspath):
with open(_colorspath, "r") as f:
all_col = f.read().split()
else:
all_col = []
@ultroid_cmd(
pattern="(rc|c)arbon",
)
async def cr_bn(event):
xxxx = await event.eor(get_string("com_1"))
te = event.pattern_match.group(1)
col = random.choice(all_col) if te[0] == "r" else "White"
if event.reply_to_msg_id:
temp = await event.get_reply_message()
if temp.media:
b = await event.client.download_media(temp)
with open(b) as a:
code = a.read()
os.remove(b)
else:
code = temp.message
else:
try:
code = event.text.split(" ", maxsplit=1)[1]
except IndexError:
return await xxxx.eor(get_string("carbon_2"))
xx = await Carbon(code=code, file_name="ultroid_carbon", backgroundColor=col)
if isinstance(xx, dict):
await xxxx.edit(f"`{xx}`")
return
await xxxx.delete()
await event.reply(
f"Carbonised by {inline_mention(event.sender)}",
file=xx,
)
@ultroid_cmd(
pattern="ccarbon( (.*)|$)",
)
async def crbn(event):
match = event.pattern_match.group(1).strip()
if not match:
return await event.eor(get_string("carbon_3"))
msg = await event.eor(get_string("com_1"))
if event.reply_to_msg_id:
temp = await event.get_reply_message()
if temp.media:
b = await event.client.download_media(temp)
with open(b) as a:
code = a.read()
os.remove(b)
else:
code = temp.message
else:
try:
match = match.split(" ", maxsplit=1)
code = match[1]
match = match[0]
except IndexError:
return await msg.eor(get_string("carbon_2"))
xx = await Carbon(code=code, backgroundColor=match)
await msg.delete()
await event.reply(
f"Carbonised by {inline_mention(event.sender)}",
file=xx,
)
RaySoTheme = [
"meadow",
"breeze",
"raindrop",
"candy",
"crimson",
"falcon",
"sunset",
"midnight",
]
@ultroid_cmd(pattern="rayso")
async def pass_on(ult):
try:
from playwright.async_api import async_playwright
except ImportError:
await ult.eor("`playwright` is not installed!\nPlease install it to use this command..")
return
proc = await ult.eor(get_string("com_1"))
spli = ult.text.split()
theme, dark, title, text = None, True, get_display_name(ult.chat), None
if len(spli) > 2:
if spli[1] in RaySoTheme:
theme = spli[1]
dark = spli[2].lower().strip() in ["true", "t"]
elif len(spli) > 1:
if spli[1] in RaySoTheme:
theme = spli[1]
elif spli[1] == "list":
text = "**List of Rayso Themes:**\n" + "\n".join(
[f"- `{th_}`" for th_ in RaySoTheme]
)
await proc.eor(text)
return
else:
try:
text = ult.text.split(maxsplit=1)[1]
except IndexError:
pass
if not theme or theme not in RaySoTheme:
theme = random.choice(RaySoTheme)
if ult.is_reply:
msg = await ult.get_reply_message()
text = msg.message
title = get_display_name(msg.sender)
name = token_hex(8) + ".png"
data = {
"darkMode": dark,
"theme": theme,
"title": title
}
url = f"https://ray.so/#{urlencode(data)}"
async with async_playwright() as play:
chrome = await play.chromium.launch()
page = await chrome.new_page()
await page.goto(url)
await page.wait_for_load_state("networkidle")
elem = await page.query_selector("textarea[class='Editor_textarea__sAyL_']")
await elem.type(text)
button = await page.query_selector("button[class='ExportButton_button__d___t']")
await button.click()
async with page.expect_download() as dl:
dled = await dl.value
await dled.save_as(name)
await proc.reply(
file=name
)
await proc.try_delete()
os.remove(name)
|