diff --git a/bot_extras.py b/bot_extras.py new file mode 100644 index 0000000..29e0ddc --- /dev/null +++ b/bot_extras.py @@ -0,0 +1,26 @@ +from listwork import * +from random import randint as ri + +# pas2( fill(...) ) -> 1/2 +def pas2(packed): + unpacked = unpack(packed["main"]) + new_pxls = [] + + pas = False + for i in unpacked: + if not pas: + new_pxls.append(i) + pas = True + else: + pas = False + packed = {"main": pack(new_pxls)} + return packed + +# rand(x1,y1, x2,y2) -> draw() or pas2() +def rand(x1,y1, x2,y2): + pxls = [] + for x in range(x1, x2 +1): + for y in range(y1, y2 +1): + pxls.append([x,y, ri(0,255), ri(0,255), ri(0,255)]) + packed = {"main": pack(pxls)} + return packed diff --git a/botv2.py b/botv2.py new file mode 100644 index 0000000..71dee7d --- /dev/null +++ b/botv2.py @@ -0,0 +1,65 @@ +import requests +from tqdm import tqdm +# Work with list-like objects +from listwork import * + +# Easy debug +from icecream import ic + +global server +#server = 'http://127.0.0.1:3333' +server = 'http://pb.gulyaipole.fun' + +# 0,0, 10,10, [0,0,0] +def fill(x1,y1, x2,y2, color): + pxls = [] + r = color[0] ; g = color[1] ; b = color[2] + for x in range(x1, x2+1): + for y in range(y1, y2+1): + pxls.append([x, y, r, g, b]) + #packed = {"main": pack(pxls)} + return pxls + +# draw( fill(...) ) +def draw(pxls): + global server + # Pack to 50 elements + push = [] + while len(pxls) > 100: + packs = [] + for i in range(100): + packs.append(pxls[0]) + pxls.pop(0) + push.append(pack(packs)) + push.append(pack(pxls)) # pack last + + for i in tqdm(push): + response = requests.post(server, {"main": i}) + while not response.text: + print("Error, retrying...") + response = requests.post(server, {"main": i}) + +# cfill(0,0, 10,10) +def cfill(x1,y1, x2,y2): + pxls = [] + for x in range(x1, x2+1): + for y in range(y1, y2+1): + pxls.append([x, y]) + packed = pack(pxls) + return packed + +# ccheck( packed([[0,0]]) ) or ccheck(cfill(...)) +def ccheck(packed): + global server + response = requests.get(f'{server}/get_color={packed}') + out = unpack(response.text) + return out + +from random import randint as ri +print( draw( fill(0,0, 10,10, [ri(0,255),ri(0,255),ri(0,255)]) ) ) + +#print(ccheck(pack([[0,0]]) )) +#print(ccheck(cfill(0,0, 10,10))) + +#from bot_extras import * +#print( draw(pas2( rand(0,0, 100,100) )) )