From b9055327be8a129218e0d59e5de3e5dd1e6c48aa Mon Sep 17 00:00:00 2001 From: Devesh Pal Date: Sun, 10 Dec 2023 19:14:08 +0530 Subject: [PATCH 1/2] FIX: Rayso use playwright to generate rayso disable announcement updates make graph.org default domain --- plugins/beautify.py | 38 +++++++++++++++++++++++++++++++++----- pyUltroid/__main__.py | 10 ++++++---- pyUltroid/fns/tools.py | 3 ++- pyUltroid/startup/funcs.py | 3 +-- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/plugins/beautify.py b/plugins/beautify.py index 358fa9196c..903ab13197 100644 --- a/plugins/beautify.py +++ b/plugins/beautify.py @@ -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" @@ -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: @@ -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) diff --git a/pyUltroid/__main__.py b/pyUltroid/__main__.py index 24e295c1b0..70100e01d0 100644 --- a/pyUltroid/__main__.py +++ b/pyUltroid/__main__.py @@ -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)) diff --git a/pyUltroid/fns/tools.py b/pyUltroid/fns/tools.py index 75b548e516..2571314329 100644 --- a/pyUltroid/fns/tools.py +++ b/pyUltroid/fns/tools.py @@ -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 diff --git a/pyUltroid/startup/funcs.py b/pyUltroid/startup/funcs.py index b26199d28b..60458f9b79 100644 --- a/pyUltroid/startup/funcs.py +++ b/pyUltroid/startup/funcs.py @@ -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 @@ -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): From 7b7cb6d56e14e92a34994ef10f0e7cbe0d860913 Mon Sep 17 00:00:00 2001 From: Devesh Pal Date: Mon, 11 Dec 2023 11:25:49 +0530 Subject: [PATCH 2/2] Fix echo and setpic --- plugins/_chatactions.py | 2 +- plugins/profile.py | 2 +- pyUltroid/__init__.py | 2 +- resources/startup/optional-requirements.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/_chatactions.py b/plugins/_chatactions.py index cda3db4af8..8f1a9d3baa 100644 --- a/plugins/_chatactions.py +++ b/plugins/_chatactions.py @@ -200,7 +200,7 @@ async def chatBot_replies(e): return if check_echo(e.chat_id, e.sender_id): try: - await e.respond(e) + await e.respond(e.message) except Exception as er: LOGS.exception(er) key = udB.get_key("CHATBOT_USERS") or {} diff --git a/plugins/profile.py b/plugins/profile.py index a4ce3bd4e9..90b85e5e8b 100644 --- a/plugins/profile.py +++ b/plugins/profile.py @@ -83,7 +83,7 @@ async def _(ult): file = await ult.client.upload_file(replfile) try: if "pic" in mediainfo(reply_message.media): - await ult.client(UploadProfilePhotoRequest(file)) + await ult.client(UploadProfilePhotoRequest(file=file)) else: await ult.client(UploadProfilePhotoRequest(video=file)) await eod(ok, "`My Profile Photo has Successfully Changed !`") diff --git a/pyUltroid/__init__.py b/pyUltroid/__init__.py index 8f3f082ada..366bc7dc8f 100644 --- a/pyUltroid/__init__.py +++ b/pyUltroid/__init__.py @@ -77,7 +77,7 @@ class ULTConfig: if USER_MODE: asst = ultroid_bot else: - asst = UltroidClient(None, bot_token=udB.get_key("BOT_TOKEN"), udB=udB) + asst = UltroidClient("asst", bot_token=udB.get_key("BOT_TOKEN"), udB=udB) if BOT_MODE: ultroid_bot = asst diff --git a/resources/startup/optional-requirements.txt b/resources/startup/optional-requirements.txt index a521454495..209127a920 100644 --- a/resources/startup/optional-requirements.txt +++ b/resources/startup/optional-requirements.txt @@ -25,7 +25,7 @@ pytz qrcode requests tabulate -git+https://github.com/xditya/telegraph.git@41fd800#egg=telegraph +telegraph tgcrypto youtube-search-python yt-dlp