This commit is contained in:
Casey 2024-07-04 16:16:59 +03:00
parent 72b8c6274b
commit aee46cd9a4
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 24 additions and 18 deletions

View File

@ -1,4 +1,3 @@
import asyncio
from typing import Optional
from socketio import AsyncSimpleClient
@ -9,6 +8,7 @@ from base64 import b64decode
from random import choice
from json import load
class AsyncBotManager:
def __init__(self, base: str = "https://onemillioncheckboxes.com"):
self.base = base
@ -79,9 +79,7 @@ class AsyncBotManager:
current = self.canvas.getpixel((x, y)) > 0 # type: ignore
if current != expected:
print(bot_index, "swap", x, y)
await sio.emit("toggle_bit", {
"index": index
})
await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(0.25)
async def __aenter__(self):
@ -92,6 +90,11 @@ class AsyncBotManager:
self._shutdown = True
await self._listener_task
def copy(self):
copy = self.__class__(self.base)
copy.difference = dict.copy(self.difference)
return copy
async def amain():
with open("settings.json", "r") as fp:
@ -113,10 +116,8 @@ async def amain():
r, g, b, a = im.getpixel((x, y)) # type: ignore
if a < 128:
continue
pocket_x = x + ox
pocket_y = y + oy
ndx_start = pocket_x * 3 + pocket_y * 577 * 3
ndx_start = (x + ox + (y + oy) * 577) * 3
mgr.difference[ndx_start] = r > 128
mgr.difference[ndx_start + 1] = g > 128
mgr.difference[ndx_start + 2] = b > 128
@ -131,21 +132,26 @@ async def amain():
ndx_start: int = (x + ox + (y + oy) * 250) * 16
color = (r >> 3) << 13
color |= (g >> 2) << 5
color |= (b >> 3)
color |= b >> 3
for i in range(16):
mgr.difference[ndx_start + i] = ((color >> i) & 1) > 0
mgr.difference[ndx_start + i] = (
(color >> i) & 1
) > 0
if (n_proxies := len(settings["proxies"])):
await asyncio.gather(*[
mgr.writer(i, settings["proxies"][i % n_proxies]) for i in range(settings["n_bots"])
], return_exceptions=True)
if n_proxies := len(settings["proxies"]):
await asyncio.gather(
*[
mgr.writer(i, settings["proxies"][i % n_proxies])
for i in range(settings["n_bots"])
],
return_exceptions=True,
)
else:
await asyncio.gather(*[
mgr.writer(i) for i in range(settings["n_bots"])
], return_exceptions=True)
await asyncio.gather(
*[mgr.writer(i) for i in range(settings["n_bots"])],
return_exceptions=True,
)
if __name__ == "__main__":