From 68cd185292bdf78237eb43f4185c2aa19283f16e Mon Sep 17 00:00:00 2001 From: illvart Date: Wed, 14 Feb 2024 03:29:16 +0700 Subject: [PATCH] update --- getter/config.py | 2 +- getter/core/helper.py | 4 ++-- getter/core/tools.py | 28 ++++++++++++++++------------ getter/plugins/chat.py | 1 + getter/plugins/utility.py | 12 ++++++------ 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/getter/config.py b/getter/config.py index 919ada9..5a4284a 100644 --- a/getter/config.py +++ b/getter/config.py @@ -81,7 +81,7 @@ class Var: else: hl = "".join(Var.HANDLER.split()) -BOTLOGS_CACHE: set[int] = set() +BOTLOGS_CACHE: list[int] = [] DEV_CMDS: dict[str, list[str]] = {} SUDO_CMDS: dict[str, list[str]] = {} INVITE_WORKER: dict[str, Any] = {} diff --git a/getter/core/helper.py b/getter/core/helper.py index 9cc0cb3..417cc50 100644 --- a/getter/core/helper.py +++ b/getter/core/helper.py @@ -95,10 +95,10 @@ def is_heroku(self) -> bool: async def get_botlogs() -> int: if BOTLOGS_CACHE: - return next((i for i in sorted(BOTLOGS_CACHE, reverse=True)), 0) + return next(reversed(BOTLOGS_CACHE), 0) b = await gvar("BOTLOGS", use_cache=True) i = int(Var.BOTLOGS or b or 0) - BOTLOGS_CACHE.add(i) + BOTLOGS_CACHE.append(i) return i diff --git a/getter/core/tools.py b/getter/core/tools.py index 86c6c35..fa8c2c6 100644 --- a/getter/core/tools.py +++ b/getter/core/tools.py @@ -14,13 +14,13 @@ from typing import Any import aiofiles import aiohttp -import telegraph +import telegraph.aio from getter import __version__, LOOP, EXECUTOR from getter.logger import LOG from .db import gvar, sgvar from .utils import get_random_hex -_TGH: list[telegraph.api.Telegraph] = [] +_TGH: list[telegraph.aio.Telegraph] = [] def is_termux() -> bool: @@ -226,22 +226,26 @@ def Pinger(addr: str) -> str: return "--ms" -async def Telegraph(author_name: str) -> telegraph.api.Telegraph: +async def Telegraph( + author: str | None = None, +) -> telegraph.aio.Telegraph: if _TGH: - return next((_ for _ in sorted(_TGH, reverse=True)), None) + return next(reversed(_TGH), None) token = await gvar("_TELEGRAPH_TOKEN") - client = telegraph.Telegraph(token) + api = telegraph.aio.Telegraph(token) if token: - _TGH.append(client) - return client + _TGH.append(api) + return api + if author is None: + return api try: - client.create_account( + await api.create_account( short_name="getteruser", - author_name=author_name[:128], + author_name=author[:128], author_url="https://t.me/kastaid", ) except BaseException: return None - await sgvar("_TELEGRAPH_TOKEN", client.get_access_token()) - _TGH.append(client) - return client + await sgvar("_TELEGRAPH_TOKEN", api.get_access_token()) + _TGH.append(api) + return api diff --git a/getter/plugins/chat.py b/getter/plugins/chat.py index bcc5d93..0c31645 100644 --- a/getter/plugins/chat.py +++ b/getter/plugins/chat.py @@ -497,6 +497,7 @@ async def _(kst): "{i}copy [reply]": "Copy the replied message.", "{i}nodraft": "Clear all drafts.", "{i}noghost": "Delete all chats with deleted account users/bots.", + "{i}cleanuser": "Delete all user chats.", "{i}nouser": "Archive all chats with users.", "{i}nobot": "Archive all chats with bots.", "{i}nochannel": "Archive all channels.", diff --git a/getter/plugins/utility.py b/getter/plugins/utility.py index 0f954fd..d79b95d 100644 --- a/getter/plugins/utility.py +++ b/getter/plugins/utility.py @@ -10,7 +10,6 @@ from html import escape from mimetypes import guess_extension import aiofiles -import telegraph from bs4 import BeautifulSoup from PIL import Image from telethon.tl import types as typ @@ -362,7 +361,9 @@ async def _(kst): res = file if mt not in ("document", "text"): try: - link = "https://telegra.ph" + next((_ for _ in telegraph.upload_file(res)), "") + tg = await Telegraph() + up = await tg.upload_file(res) + link = "https://telegra.ph" + next((_ for _ in up), "") push = f"**Telegraph:** [Telegraph Link]({link})" except Exception as err: push = f"**ERROR:**\n`{err}`" @@ -373,10 +374,9 @@ async def _(kst): text = (Root / res).read_text() (Root / res).unlink(missing_ok=True) tg = await Telegraph(ga.full_name) - push = tg.create_page( - title=text[:256], - content=[text], - ) + if not tg: + return await yy.eod("`Try again now!`") + push = await tg.create_page(title=text[:256], content=[text]) res = push.get("url") if not res: return await yy.eod("`Try again now!`")