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
def get_text_image(text: str, font: ImageFont.ImageFont | ImageFont.FreeTypeFont) -> Image.Image:
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.rectangle((0, 0, im.width, im.height), (0, 0))
draw.text((left + 2, top + 2), text, font=font, fill=(255, 0),
@ -192,7 +192,7 @@ class AsyncBotManager:
else:
print("unknown event", event, data)
now = time_now()
if (now - self._last_printout) > 10:
if (now - self._last_printout) > 5:
outgoing = self._written_boxes / (now - self._last_printout)
incoming = self._read_boxes / (now - self._last_printout)
print()
@ -239,26 +239,30 @@ class AsyncBotManager:
):
proxy = ProxyConnector.from_url(proxy_url) if proxy_url else None
await self.ready_event.wait()
async with ClientSession(connector=proxy, timeout=TIMEOUT) as http:
async with AsyncSimpleClient(http_session=http) as sio:
await sio.connect(f"{self.base}/socket.io")
print(f"Writer {bot_index} connected")
offset = 0
while not self._shutdown:
diff = list(self.difference.items())
diff = sorted(diff, key=lambda kv: kv[0])
for _ in range(100):
index, expected = diff[offset % len(diff)]
offset += randint(0, 1000)
y, x = divmod(index, 1000)
current = self.canvas.getpixel((x, y)) > 0 # type: ignore
if current != expected:
self._written_boxes += 1
await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(delay)
self._active.add(bot_index)
with suppress():
await sio.receive(0.1)
try:
async with ClientSession(connector=proxy, timeout=TIMEOUT) as http:
async with AsyncSimpleClient(http_session=http) as sio:
await sio.connect(f"{self.base}/socket.io")
print(f"Writer {bot_index} connected")
offset = 0
while not self._shutdown:
diff = list(self.difference.items())
diff = sorted(diff, key=lambda kv: kv[0])
for _ in range(100):
index, expected = diff[offset % len(diff)]
offset += randint(0, 1000)
y, x = divmod(index, 1000)
current = self.canvas.getpixel((x, y)) > 0 # type: ignore
if current != expected:
self._written_boxes += 1
await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(delay)
self._active.add(bot_index)
with suppress(BaseException):
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):
self._listener_task = asyncio.create_task(self.listener())