Skip to content

Commit

Permalink
FIX: Rayso
Browse files Browse the repository at this point in the history
use playwright to generate rayso

disable announcement updates

make graph.org default domain
  • Loading branch information
New-dev0 committed Dec 10, 2023
1 parent 41fb5b5 commit b905532
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
38 changes: 33 additions & 5 deletions plugins/beautify.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
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"

Expand Down Expand Up @@ -104,6 +105,12 @@ async def crbn(event):

@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:
Expand All @@ -118,19 +125,40 @@ async def pass_on(ult):
[f"- `{th_}`" for th_ in RaySoTheme]
)

await ult.eor(text)
await proc.eor(text)
return
else:
try:
text = ult.text.split(maxsplit=1)[1]
except IndexError:
pass
if not theme:
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)
await ult.reply(
file=await Carbon(text, rayso=True, title=title, theme=theme, darkMode=dark)
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)
10 changes: 6 additions & 4 deletions pyUltroid/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ def main():
# Send/Ignore Deploy Message..
if not udB.get_key("LOG_OFF"):
ultroid_bot.run_in_loop(ready())
if AsyncIOScheduler:
scheduler = AsyncIOScheduler()
scheduler.add_job(fetch_ann, "interval", minutes=12 * 60)
scheduler.start()

# TODO: Announcement API IS DOWN
# if AsyncIOScheduler:
# scheduler = AsyncIOScheduler()
# scheduler.add_job(fetch_ann, "interval", minutes=12 * 60)
# scheduler.start()

# Edit Restarting Message (if It's restarting)
ultroid_bot.run_in_loop(WasItRestart(udB))
Expand Down
3 changes: 2 additions & 1 deletion pyUltroid/fns/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ def telegraph_client():
from .. import udB, ultroid_bot

token = udB.get_key("_TELEGRAPH_TOKEN")
TelegraphClient = Telegraph(token)
TELEGRAPH_DOMAIN = udB.get_key("GRAPH_DOMAIN")
TelegraphClient = Telegraph(token, domain=TELEGRAPH_DOMAIN or "graph.org")
if token:
TELEGRAPH.append(TelegraphClient)
return TelegraphClient
Expand Down
3 changes: 1 addition & 2 deletions pyUltroid/startup/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ async def fetch_ann():

get_ = udB.get_key("OLDANN") or []
chat_id = udB.get_key("LOG_CHANNEL")

try:
updts = await async_searcher(
"https://ultroid-api.vercel.app/announcements", post=True, re_json=True
Expand Down Expand Up @@ -507,7 +506,7 @@ async def ready():
LOGS.exception(ef)
if spam_sent and not spam_sent.media:
udB.set_key("LAST_UPDATE_LOG_SPAM", spam_sent.id)
await fetch_ann()
# TODO: await fetch_ann()


async def WasItRestart(udb):
Expand Down

0 comments on commit b905532

Please sign in to comment.