52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import request from 'request';
|
|
import { accounts } from './accounts.json';
|
|
import { HEADERS, SERVER_URL } from './config';
|
|
|
|
export default class Weekly {
|
|
constructor() {
|
|
this.logger = null;
|
|
this.playersUpdated = 0;
|
|
this.playersReturned = 0;
|
|
}
|
|
|
|
async run() {
|
|
console.log(`You have ${accounts.length} players available!\n`);
|
|
accounts.forEach(this.makeItRain.bind(this));
|
|
|
|
const getSummary = setInterval(() => {
|
|
if (this.playersReturned === accounts.length) {
|
|
console.log(`${this.playersUpdated} of ${accounts.length} players have been given extra lives!`);
|
|
clearInterval(getSummary);
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
makeItRain(player) {
|
|
const { username } = player;
|
|
|
|
request({
|
|
method: 'POST',
|
|
url: `https://${SERVER_URL}/easter-eggs/makeItRain`,
|
|
headers: {
|
|
...HEADERS,
|
|
authorization: `Bearer ${player.accessToken}`,
|
|
}
|
|
}, (error, response, body) => {
|
|
this.playersReturned++;
|
|
try {
|
|
const result = JSON.parse(body);
|
|
const { error } = result;
|
|
|
|
if (error) {
|
|
console.log(`${username}\thas already claimed their weekly life!`);
|
|
} else {
|
|
console.log(`${username}\thas been given an extra life!`);
|
|
this.playersUpdated++;
|
|
}
|
|
} catch (error) {
|
|
console.log('Error\n', error.toString('utf8'));
|
|
}
|
|
});
|
|
}
|
|
}
|