diff --git a/.gitignore b/.gitignore index 0540138..2abb34b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ rgb111-full.png state-new.json settings.json screenshots/ +avoid.png +result.png diff --git a/async-bot.py b/async-bot.py index d3071b6..86f0391 100644 --- a/async-bot.py +++ b/async-bot.py @@ -19,6 +19,7 @@ class AsyncBotManager: self.difference: dict[int, bool] = {} self._last_update = 0 self._shutdown: bool = False + self.avoid: set[range] = set() def put_text(self, x: int, y: int, text: str): with Image.new("LA", (int(self.font.getlength(text) + 12), 16)) as im: @@ -37,6 +38,29 @@ class AsyncBotManager: if a: self.difference[x + ox + (y + oy) * 1000] = l > 0 + def add_avoid_rect(self, sx: int, sy: int, w: int, h: int): + for y in range(sy, sy + h): + ox = y * 1000 + self.add_avoid_range(sx + ox, sx + w + ox) + + def add_avoid_range(self, start: int, stop: int, step: int = 1): + self.avoid.add(range(start, stop, step)) + + def get_difference_image(self) -> Image.Image: + with Image.new("LA", (1000, 1000), 0) as im: + for index, expected in self.difference.items(): + y, x = divmod(index, 1000) + im.putpixel((x, y), (255 if expected else 0, 255)) + return im.copy() + + def get_avoid_image(self) -> Image.Image: + with Image.new("RGB", (1000, 1000), (0, 255, 0)) as im: + for rng in self.avoid: + for index in rng: + y, x = divmod(index, 1000) + im.putpixel((x, y), (255, 0, 0)) + return im.copy() + async def listener(self): async with ClientSession() as http: async with http.get(f"{self.base}/api/initial-state") as req: @@ -58,7 +82,7 @@ class AsyncBotManager: bits_on, bits_off, timestamp = data if timestamp < self._last_update: print("SKIPPING UPDATES: TOO OLD") - self._last_update: int = data["timestamp"] + self._last_update: int = timestamp for ndx in bits_on: y, x = divmod(ndx, 1000) self.canvas.putpixel((x, y), 255) @@ -102,6 +126,11 @@ async def amain(): async with AsyncBotManager() as mgr: mgr.font = ImageFont.truetype(settings["font"], 8) + for avoid in settings["avoid"]: + if avoid["type"] == "rect": + mgr.add_avoid_rect(avoid["x"], avoid["y"], avoid["w"], avoid["h"]) + elif avoid["type"] == "range": + mgr.add_avoid_range(avoid["start"], avoid["stop"], avoid["step"]) for elem in settings["elements"]: if elem["type"] == "text": mgr.put_text(elem["x"], elem["y"], elem["text"]) @@ -139,6 +168,9 @@ async def amain(): (color >> i) & 1 ) > 0 + mgr.get_difference_image().save("result.png") + mgr.get_avoid_image().save("avoid.png") + if n_proxies := len(settings["proxies"]): await asyncio.gather( *[ diff --git a/settings.json b/settings.json index b345061..8b1fb0f 100644 --- a/settings.json +++ b/settings.json @@ -2,9 +2,26 @@ "url": "https://onemillioncheckboxes.com", "font": "./ic8x8u.ttf", "proxies": [ - ], - "n_bots": 10, + "n_bots": 5, + "avoid": [ + { + "type": "rect", + "x": 0, + "y": 0, + "w": 1000, + "h": 10, + "description": "Not ruining fun for normal users" + }, + { + "type": "rect", + "x": 732, + "y": 184, + "w": 231, + "h": 326, + "description": "The Bald Critic" + } + ], "elements": [ { "type": "rgb111", @@ -38,7 +55,7 @@ }, { "type": "image", - "path": "./lawbymike.png", + "path": "./astley.png", "x": 150, "y": 420 }, @@ -47,6 +64,12 @@ "path": "./colon3.png", "x": 333, "y": 333 + }, + { + "type": "text", + "text": "7H3 V01D C0N5UME5 U5 ALL", + "x": 32, + "y": 32 } ] }