Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ds/kasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def get_me(
async def start(self) -> None:
try:
self.log.info("Starting Userbot Client...")
delay = random.uniform(3, 6) if Var.DEV_MODE else random.uniform(1, 3)
delay = random.uniform(3.5, 6.5) if Var.DEV_MODE else random.uniform(1.5, 3.5)
await asyncio.sleep(delay)
await super().start()
except Exception as err:
Expand Down Expand Up @@ -78,7 +78,7 @@ async def stop(self, **_) -> None:
async def __follow_us(self) -> None:
try:
await self.join_chat(-1001174631272)
await asyncio.sleep(3)
await asyncio.sleep(random.uniform(3.5, 6.5))
except BaseException:
pass
try:
Expand Down
9 changes: 3 additions & 6 deletions ds/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ async def invoke(self, *args, **kwargs):
return await self.old_invoke(*args, **kwargs)
except pyrogram.errors.FloodWait as fw:
self.log.warning(fw)
sec = fw.value + random.uniform(5, 15)
await asyncio.sleep(sec)
await asyncio.sleep(fw.value + random.uniform(10, 15))
return await self.invoke(*args, **kwargs)
except (
TimeoutError,
Expand All @@ -72,8 +71,7 @@ async def resolve_peer(self, *args, **kwargs):
return await self.old_resolve_peer(*args, **kwargs)
except pyrogram.errors.FloodWait as fw:
self.log.warning(fw)
sec = fw.value + random.uniform(5, 15)
await asyncio.sleep(sec)
await asyncio.sleep(fw.value + random.uniform(10, 15))
return await self.resolve_peer(*args, **kwargs)
except pyrogram.errors.PeerIdInvalid:
pass
Expand All @@ -84,8 +82,7 @@ async def save_file(self, *args, **kwargs):
return await self.old_save_file(*args, **kwargs)
except pyrogram.errors.FloodWait as fw:
self.log.warning(fw)
sec = fw.value + random.uniform(5, 15)
await asyncio.sleep(sec)
await asyncio.sleep(fw.value + random.uniform(10, 15))
return await self.save_file(*args, **kwargs)


Expand Down
18 changes: 9 additions & 9 deletions scripts/autoreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# https://github.com/kastaid/ds
# MIT License

import os
import signal
import subprocess
import sys
from os import getpid, kill
from subprocess import CalledProcessError, Popen, check_call
from time import sleep

from . import (
Expand All @@ -22,7 +22,7 @@
import psutil
except ModuleNotFoundError:
print("Installing psutil...")
check_call([sys.executable, "-m", "pip", "install", "-U", "psutil"])
subprocess.check_call([sys.executable, "-m", "pip", "install", "-U", "psutil"])
finally:
import psutil

Expand All @@ -31,13 +31,13 @@ def file_time() -> float:
return max(f.stat().st_mtime for f in Root.rglob("*") if f.suffix in EXTS)


def print_stdout(procs) -> None:
def print_stdout(procs: subprocess.Popen) -> None:
out = procs.stdout
if out:
print(out)


def kill_process_tree(procs) -> None:
def kill_process_tree(procs: subprocess.Popen) -> None:
try:
parent = psutil.Process(procs.pid)
child = parent.children(recursive=True)
Expand All @@ -54,7 +54,7 @@ def main() -> None:
print("python3 -m scripts.autoreload [command]")
sys.exit(0)
cmd = " ".join(sys.argv[1:])
procs = Popen(cmd, shell=True)
procs = subprocess.Popen(cmd, shell=True)
last_mtime = file_time()
try:
while True:
Expand All @@ -64,16 +64,16 @@ def main() -> None:
last_mtime = max_mtime
print(f"{BOLD}{YELLOW}Restarting >> {procs.args}{RST}")
kill_process_tree(procs)
procs = Popen(cmd, shell=True)
procs = subprocess.Popen(cmd, shell=True)
sleep(WAIT_FOR)
except CalledProcessError as err:
except subprocess.CalledProcessError as err:
kill_process_tree(procs)
sys.exit(err.returncode)
except KeyboardInterrupt:
print(f"{BOLD}{RED}Kill process [{procs.pid}]{RST}")
kill_process_tree(procs)
signal.signal(signal.SIGINT, signal.SIG_DFL)
kill(getpid(), signal.SIGINT)
os.kill(os.getpid(), signal.SIGINT)
except BaseException:
print(f"{BOLD}{RED}Watch interrupted.{RST}")

Expand Down
6 changes: 3 additions & 3 deletions scripts/prettyjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/kastaid/ds
# MIT License

from json import dump, load
import json

from . import Root

Expand All @@ -13,9 +13,9 @@ def main() -> None:
for p in filter(lambda x: not str(x.parent).endswith(EXCLUDE), Root.rglob("*.json")):
try:
with p.open(encoding="utf-8") as f:
data = load(f)
data = json.load(f)
with p.open("w", encoding="utf-8") as f:
dump(data, f, indent=4, sort_keys=False, ensure_ascii=False)
json.dump(data, f, indent=4, sort_keys=False, ensure_ascii=False)
print("Pretty print:", p.name)
except Exception as err:
print("Failed to pretty print:", str(err))
Expand Down
Loading