REEEEEEEEEEEE

This commit is contained in:
Casey 2024-07-07 21:31:22 +03:00
parent 522b9b06f8
commit d5ac5e8583
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 26 additions and 22 deletions

View File

@ -47,7 +47,7 @@ class AsyncBotManager:
@staticmethod @staticmethod
def get_text_image(text: str, font: ImageFont.ImageFont | ImageFont.FreeTypeFont) -> Image.Image: def get_text_image(text: str, font: ImageFont.ImageFont | ImageFont.FreeTypeFont) -> Image.Image:
left, top, right, bottom = font.getbbox(text) left, top, right, bottom = font.getbbox(text)
with Image.new("LA", (int(right - left) + 4, int(bottom - top) + 8), 0) as im: with Image.new("LA", (int(right - left) + 4, int(bottom - top) + 16), 0) as im:
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
draw.rectangle((0, 0, im.width, im.height), (0, 0)) draw.rectangle((0, 0, im.width, im.height), (0, 0))
draw.text((left + 2, top + 2), text, font=font, fill=(255, 0), draw.text((left + 2, top + 2), text, font=font, fill=(255, 0),
@ -192,7 +192,7 @@ class AsyncBotManager:
else: else:
print("unknown event", event, data) print("unknown event", event, data)
now = time_now() now = time_now()
if (now - self._last_printout) > 10: if (now - self._last_printout) > 5:
outgoing = self._written_boxes / (now - self._last_printout) outgoing = self._written_boxes / (now - self._last_printout)
incoming = self._read_boxes / (now - self._last_printout) incoming = self._read_boxes / (now - self._last_printout)
print() print()
@ -239,6 +239,7 @@ class AsyncBotManager:
): ):
proxy = ProxyConnector.from_url(proxy_url) if proxy_url else None proxy = ProxyConnector.from_url(proxy_url) if proxy_url else None
await self.ready_event.wait() await self.ready_event.wait()
try:
async with ClientSession(connector=proxy, timeout=TIMEOUT) as http: async with ClientSession(connector=proxy, timeout=TIMEOUT) as http:
async with AsyncSimpleClient(http_session=http) as sio: async with AsyncSimpleClient(http_session=http) as sio:
await sio.connect(f"{self.base}/socket.io") await sio.connect(f"{self.base}/socket.io")
@ -257,8 +258,11 @@ class AsyncBotManager:
await sio.emit("toggle_bit", {"index": index}) await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(delay) await asyncio.sleep(delay)
self._active.add(bot_index) self._active.add(bot_index)
with suppress(): with suppress(BaseException):
await sio.receive(0.1) await sio.receive(0.1)
print(f"Worker {bot_index} stopped: shutdown")
except Exception as e:
print(f"Worker {bot_index} died: {e!r}")
async def __aenter__(self): async def __aenter__(self):
self._listener_task = asyncio.create_task(self.listener()) self._listener_task = asyncio.create_task(self.listener())