Added delay parameter and brough Casey back

This commit is contained in:
Casey 2024-07-04 18:59:09 +03:00
parent 5f885b8b5b
commit d0b061f3db
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
3 changed files with 22 additions and 6 deletions

View File

@ -102,7 +102,12 @@ class AsyncBotManager:
else: else:
print("unknown event", event, data) print("unknown event", event, data)
async def writer(self, bot_index: int, proxy_url: Optional[str] = None): async def writer(
self,
bot_index: int,
proxy_url: Optional[str] = None,
delay: float = 0.25,
):
proxy = ProxyConnector.from_url(proxy_url) if proxy_url else None proxy = ProxyConnector.from_url(proxy_url) if proxy_url else None
async with ClientSession(connector=proxy) as http: async with ClientSession(connector=proxy) as http:
async with AsyncSimpleClient(http_session=http) as sio: async with AsyncSimpleClient(http_session=http) as sio:
@ -116,7 +121,7 @@ class AsyncBotManager:
if current != expected: if current != expected:
print(f"[{bot_index:2d}] swap {x:3d} {y:3d}") print(f"[{bot_index:2d}] swap {x:3d} {y:3d}")
await sio.emit("toggle_bit", {"index": index}) await sio.emit("toggle_bit", {"index": index})
await asyncio.sleep(0.25) await asyncio.sleep(delay)
break break
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
@ -204,7 +209,11 @@ async def amain():
if n_proxies := len(settings["proxies"]): if n_proxies := len(settings["proxies"]):
await asyncio.gather( await asyncio.gather(
*[ *[
mgr.writer(i, settings["proxies"][i % n_proxies]) mgr.writer(
i,
settings["proxies"][i % n_proxies],
settings["delay"],
)
for i in range(settings["n_bots"]) for i in range(settings["n_bots"])
], ],
return_exceptions=True, return_exceptions=True,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -2,7 +2,8 @@
"url": "https://onemillioncheckboxes.com", "url": "https://onemillioncheckboxes.com",
"font": "./ic8x8u.ttf", "font": "./ic8x8u.ttf",
"proxies": [], "proxies": [],
"n_bots": 3, "n_bots": 5,
"delay": 0.125,
"avoid": [ "avoid": [
{ {
"type": "rect", "type": "rect",
@ -70,8 +71,14 @@
{ {
"type": "image", "type": "image",
"path": "./pictures/neko.png", "path": "./pictures/neko.png",
"x": 32, "x": 263,
"y": 64 "y": 229
},
{
"type": "image",
"path": "./pictures/casey.png",
"x": 256,
"y": 256
} }
] ]
} }