Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
illvart committed Feb 13, 2024
1 parent 0ae7e38 commit 68cd185
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion getter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
4 changes: 2 additions & 2 deletions getter/core/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
28 changes: 16 additions & 12 deletions getter/core/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions getter/plugins/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
12 changes: 6 additions & 6 deletions getter/plugins/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`"
Expand All @@ -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!`")
Expand Down

0 comments on commit 68cd185

Please sign in to comment.