Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Commit

Permalink
Cleanup bot.js for token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
KalleStruik committed Apr 3, 2022
1 parent 38f972a commit 30eddef
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fetch from 'node-fetch';
import getPixels from "get-pixels";
import WebSocket from 'ws';

const VERSION_NUMBER = 2;
const VERSION_NUMBER = 3;

console.log(`PlaceNL headless client V${VERSION_NUMBER}`);

Expand Down Expand Up @@ -119,6 +119,7 @@ function startPlacement() {

async function refreshTokens() {
let tokens = [];
let cookies = [];
for (const cookie of redditSessionCookies) {
const response = await fetch("https://www.reddit.com/r/place/", {
headers: {
Expand Down Expand Up @@ -226,7 +227,6 @@ async function attemptPlace(accessToken) {
const data = await res.json();
try {
if (data.errors) {
console.log(data.errors)
const error = data.errors[0];
const nextPixel = error.extensions.nextAvailablePixelTs + 3000;
const nextPixelDate = new Date(nextPixel);
Expand All @@ -248,7 +248,6 @@ async function attemptPlace(accessToken) {

function place(x, y, color, accessToken = defaultAccessToken) {
socket.send(JSON.stringify({ type: 'placepixel', x, y, color }));
console.log("Placing pixel at (" + x + ", " + y + ") with color: " + color)
return fetch('https://gql-realtime-2.reddit.com/query', {
method: 'POST',
body: JSON.stringify({
Expand Down Expand Up @@ -343,7 +342,6 @@ function getMapFromUrl(url) {
reject()
return
}
console.log("got pixels", pixels.shape.slice())
resolve(pixels)
})
});
Expand Down

0 comments on commit 30eddef

Please sign in to comment.