Last active
March 30, 2022 02:52
-
-
Save kpmcc/c84f0f3ee20928df97c7dfe2a0d647f0 to your computer and use it in GitHub Desktop.
A simple bot to interact with https://rc-place.fly.dev/.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Using this currently requires a file called 'token.txt' | |
# with one's Personal Access Token to be able to interact | |
# with the canvas. | |
import requests | |
import os | |
import time | |
colorwords = [ | |
"black", | |
"forest", | |
"green", | |
"lime", | |
"blue", | |
"cornflowerblue", | |
"sky", | |
"cyan", | |
"red", | |
"burnt-orange", | |
"orange", | |
"yellow", | |
"purple", | |
"hot-pink", | |
"pink", | |
"white", | |
] | |
def get_user_token(userTokenFilename): | |
with open(userTokenFilename, "r") as userTokenFile: | |
txt = userTokenFile.read() | |
txt = txt.strip() | |
return txt | |
def borderCheck(x, y, currentVelocity): | |
velocity = currentVelocity | |
if x == 99: | |
velocity[0] = -1 | |
elif x == 0: | |
velocity[0] = 1 | |
if y == 99: | |
velocity[1] = -1 | |
elif y == 0: | |
velocity[1] = 1 | |
return velocity | |
def main(): | |
board_size = [100, 100] | |
x = 96 | |
y = 88 | |
velocity = [1, 1] | |
boardState = getBoardState() | |
while True: | |
setPixel(x, y, colorwords[boardState[y][x]]) | |
time.sleep(0.01) | |
x += velocity[0] | |
y += velocity[1] | |
setPixel(x, y, "purple") | |
time.sleep(0.05) | |
velocity = borderCheck(x, y, velocity) | |
def getBoardState(): | |
apiUrl = "https://rc-place.fly.dev/tiles" | |
userToken = get_user_token("token.txt") | |
headers = { | |
"Authorization": "Bearer " + userToken, | |
"Content-Type": "application/json", | |
} | |
return requests.get(apiUrl, headers=headers).json()["tiles"] | |
def setPixel(x, y, color): | |
apiUrl = "https://rc-place.fly.dev/tile" | |
userToken = get_user_token("token.txt") | |
data = {"x": x, "y": y, "color": color} | |
headers = { | |
"Authorization": "Bearer " + userToken, | |
"Content-Type": "application/json", | |
} | |
r = requests.post(apiUrl, headers=headers, json=data) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment