This commit is contained in:
Astra 2018-05-26 18:36:00 -04:00
parent 73396ade4d
commit 1f57127ab9
7 changed files with 881 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
config.json

444
bspwn/glslsandbox.js Normal file
View file

@ -0,0 +1,444 @@
/* https://github.com/mrdoob/glsl-sandbox */
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (function () {
return window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback, element) {
window.setTimeout(callback, 1000 / 60);
};
})();
}
// Get older browsers safely through init code, so users can read the
// message about how to download newer browsers.
if (!Date.now) {
Date.now = function () {
return +new Date();
};
}
var quality = 1, quality_levels = [0.5, 1, 2, 4, 8];
var toolbar, compileButton, fullscreenButton, compileTimer, errorLines = [];
var canvas, gl, buffer, currentProgram, vertexPosition, screenVertexPosition,
parameters = { startTime: Date.now(), time: 0, mouseX: 0.5, mouseY: 0.5, screenWidth: 0, screenHeight: 0 },
surface = { centerX: 0, centerY: 0, width: 1, height: 1, isPanning: false, isZooming: false, lastX: 0, lastY: 0 },
frontTarget, backTarget, screenProgram, getWebGL, resizer = {}, compileOnChangeCode = true;
function init() {
console.log('initializing...');
if (!document.addEventListener) {
return;
}
canvas = document.createElement('canvas');
document.body.appendChild(canvas);
// Initialise WebGL
try {
gl = canvas.getContext('experimental-webgl', { preserveDrawingBuffer: true });
} catch (error) { }
if (gl) {
// enable dFdx, dFdy, fwidth
gl.getExtension('OES_standard_derivatives');
// Create vertex buffer (2 triangles)
buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([- 1.0, - 1.0, 1.0, - 1.0, - 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, - 1.0, 1.0]), gl.STATIC_DRAW);
// Create surface buffer (coordinates at screen corners)
surface.buffer = gl.createBuffer();
}
var clientXLast, clientYLast;
document.addEventListener('mousemove', function (event) {
var clientX = event.clientX;
var clientY = event.clientY;
if (clientXLast == clientX && clientYLast == clientY)
return;
clientXLast = clientX;
clientYLast = clientY;
parameters.mouseX = clientX / window.innerWidth;
parameters.mouseY = 1 - clientY / window.innerHeight;
}, false);
onWindowResize();
window.addEventListener('resize', onWindowResize, false);
compile();
compileScreenProgram();
}
function computeSurfaceCorners() {
if (gl) {
surface.width = surface.height * parameters.screenWidth / parameters.screenHeight;
var halfWidth = surface.width * 0.5, halfHeight = surface.height * 0.5;
gl.bindBuffer(gl.ARRAY_BUFFER, surface.buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
surface.centerX - halfWidth, surface.centerY - halfHeight,
surface.centerX + halfWidth, surface.centerY - halfHeight,
surface.centerX - halfWidth, surface.centerY + halfHeight,
surface.centerX + halfWidth, surface.centerY - halfHeight,
surface.centerX + halfWidth, surface.centerY + halfHeight,
surface.centerX - halfWidth, surface.centerY + halfHeight]), gl.STATIC_DRAW);
}
}
function resetSurface() {
surface.centerX = surface.centerY = 0;
surface.height = 1;
computeSurfaceCorners();
}
function compile() {
console.log('compiling shader...');
if (!gl) {
return;
}
var program = gl.createProgram();
var fragment = document.getElementById('shaderCode').textContent;
var vertex = document.getElementById('surfaceVertexShader').textContent;
var vs = createShader(vertex, gl.VERTEX_SHADER);
var fs = createShader(fragment, gl.FRAGMENT_SHADER);
if (vs == null || fs == null) return null;
gl.attachShader(program, vs);
gl.attachShader(program, fs);
gl.deleteShader(vs);
gl.deleteShader(fs);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
var error = gl.getProgramInfoLog(program);
compileButton.title = error;
console.error(error);
console.error('VALIDATE_STATUS: ' + gl.getProgramParameter(program, gl.VALIDATE_STATUS), 'ERROR: ' + gl.getError());
compileButton.style.color = '#ff0000';
compileButton.textContent = 'compiled with errors';
return;
}
if (currentProgram) {
gl.deleteProgram(currentProgram);
}
currentProgram = program;
// Cache uniforms
cacheUniformLocation(program, 'time');
cacheUniformLocation(program, 'mouse');
cacheUniformLocation(program, 'resolution');
cacheUniformLocation(program, 'backbuffer');
cacheUniformLocation(program, 'surfaceSize');
// Load program into GPU
gl.useProgram(currentProgram);
// Set up buffers
surface.positionAttribute = gl.getAttribLocation(currentProgram, "surfacePosAttrib");
gl.enableVertexAttribArray(surface.positionAttribute);
vertexPosition = gl.getAttribLocation(currentProgram, "position");
gl.enableVertexAttribArray(vertexPosition);
console.log('compilation finished');
}
function compileScreenProgram() {
console.log('compiling screen program...');
if (!gl) { return; }
var program = gl.createProgram();
var fragment = document.getElementById('fragmentShader').textContent;
var vertex = document.getElementById('vertexShader').textContent;
var vs = createShader(vertex, gl.VERTEX_SHADER);
var fs = createShader(fragment, gl.FRAGMENT_SHADER);
gl.attachShader(program, vs);
gl.attachShader(program, fs);
gl.deleteShader(vs);
gl.deleteShader(fs);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.error('VALIDATE_STATUS: ' + gl.getProgramParameter(program, gl.VALIDATE_STATUS), 'ERROR: ' + gl.getError());
return;
}
screenProgram = program;
gl.useProgram(screenProgram);
cacheUniformLocation(program, 'resolution');
cacheUniformLocation(program, 'texture');
screenVertexPosition = gl.getAttribLocation(screenProgram, "position");
gl.enableVertexAttribArray(screenVertexPosition);
console.log('compilation finished');
}
function cacheUniformLocation(program, label) {
if (program.uniformsCache === undefined) {
program.uniformsCache = {};
}
program.uniformsCache[label] = gl.getUniformLocation(program, label);
}
//
function createTarget(width, height) {
var target = {};
target.framebuffer = gl.createFramebuffer();
target.renderbuffer = gl.createRenderbuffer();
target.texture = gl.createTexture();
// set up framebuffer
gl.bindTexture(gl.TEXTURE_2D, target.texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
// set up renderbuffer
gl.bindRenderbuffer(gl.RENDERBUFFER, target.renderbuffer);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, target.renderbuffer);
// clean up
gl.bindTexture(gl.TEXTURE_2D, null);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return target;
}
function createRenderTargets() {
frontTarget = createTarget(parameters.screenWidth, parameters.screenHeight);
backTarget = createTarget(parameters.screenWidth, parameters.screenHeight);
}
//
var dummyFunction = function () { };
//
function htmlEncode(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
//
function createShader(src, type) {
var shader = gl.createShader(type);
var line, lineNum, lineError, index = 0, indexEnd;
gl.shaderSource(shader, src);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
var error = gl.getShaderInfoLog(shader);
// Remove trailing linefeed, for FireFox's benefit.
while ((error.length > 1) && (error.charCodeAt(error.length - 1) < 32)) {
error = error.substring(0, error.length - 1);
}
console.error(error);
return null;
}
return shader;
}
//
function onWindowResize(event) {
var isMaxWidth = ((resizer.currentWidth === resizer.maxWidth) || (resizer.currentWidth === resizer.minWidth)),
isMaxHeight = ((resizer.currentHeight === resizer.maxHeight) || (resizer.currentHeight === resizer.minHeight));
canvas.width = window.innerWidth / quality;
canvas.height = window.innerHeight / quality;
canvas.style.width = window.innerWidth + 'px';
canvas.style.height = window.innerHeight + 'px';
parameters.screenWidth = canvas.width;
parameters.screenHeight = canvas.height;
computeSurfaceCorners();
if (gl) {
gl.viewport(0, 0, canvas.width, canvas.height);
createRenderTargets();
}
}
//
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
if (!currentProgram) return;
parameters.time = Date.now() - parameters.startTime;
// Set uniforms for custom shader
gl.useProgram(currentProgram);
gl.uniform1f(currentProgram.uniformsCache['time'], parameters.time / 1000);
gl.uniform2f(currentProgram.uniformsCache['mouse'], parameters.mouseX, parameters.mouseY);
gl.uniform2f(currentProgram.uniformsCache['resolution'], parameters.screenWidth, parameters.screenHeight);
gl.uniform1i(currentProgram.uniformsCache['backbuffer'], 0);
gl.uniform2f(currentProgram.uniformsCache['surfaceSize'], surface.width, surface.height);
gl.bindBuffer(gl.ARRAY_BUFFER, surface.buffer);
gl.vertexAttribPointer(surface.positionAttribute, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.vertexAttribPointer(vertexPosition, 2, gl.FLOAT, false, 0, 0);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, backTarget.texture);
// Render custom shader to front buffer
gl.bindFramebuffer(gl.FRAMEBUFFER, frontTarget.framebuffer);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 6);
// Set uniforms for screen shader
gl.useProgram(screenProgram);
gl.uniform2f(screenProgram.uniformsCache['resolution'], parameters.screenWidth, parameters.screenHeight);
gl.uniform1i(screenProgram.uniformsCache['texture'], 1);
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.vertexAttribPointer(screenVertexPosition, 2, gl.FLOAT, false, 0, 0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, frontTarget.texture);
// Render front buffer to screen
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 6);
// Swap buffers
var tmp = frontTarget;
frontTarget = backTarget;
backTarget = tmp;
}

93
bspwn/index.js Normal file
View file

@ -0,0 +1,93 @@
/*
EndPwn3.2 Stage 2 Payload
Copyright 2018 EndPwn Project
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
https://github.com/endpwn/
*/
// we just get remote because nothing in the root of the module is useful to us
const electron = require('electron').remote;
const fs = require('original-fs');
const data = electron.app.getPath('userData') + '/';
function bsprint(str) {
console.log(`%c[bspwn]%c ` + str, 'font-weight:bold;color:#0cc', '');
}
function bswarn(str) {
console.warn(`%c[bspwn]%c ` + str, 'font-weight:bold;color:#0cc', '');
}
// basically took this one verbatim from epapi bc i couldnt be fucked to reimplement it
function bserror(t, e) {
console.error(`%c[bspwn]%c ${t}:\n\n`, 'font-weight:bold;color:#0cc', '', e);
}
exports.go = function () {
// crashing the preload script is very bad and definitely not something we want to do, so we catch our errors
try {
bsprint('initializing...');
if (location.hostname.indexOf('discordapp') == -1) {
bswarn('hm, not running under discordapp, let\'s abort...');
return;
}
// apparently tripping hasSuspiciousCode() makes discord not report errors, so lets do that on purpose
window.BetterDiscord = 'this is a dummy value to trip hasSuspiciousCode()';
// make sure crispr and epapi are actually there before trying to load them
var crisprFound = fs.existsSync(data + 'crispr.js');
var epapiFound = fs.existsSync(data + 'epapi.js');
if (!epapiFound) {
bswarn('EPAPI not detected, aborting...');
return;
}
if (!crisprFound) bswarn('CRISPR not detected');
// load our friends :)
var crispr = require(data + 'crispr.js');
var epapi = require(data + 'epapi.js');
// these are the bootstrap properties we pass to crispr and epapi
var properties = {
name: 'EndPwn3',
version: {
major: 3,
minor: 2,
toString: function () {
return `v${this.major}.${this.minor}`;
}
},
method: 'bspwn',
brand: true,
native: true
};
// start crispr
if (crisprFound) crispr.go(properties);
// delay epapi until dom-ready to prevent errors
electron.getCurrentWindow().webContents.on('dom-ready', () => epapi.go(properties));
}
catch (ex) {
bserror('exception during init', ex);
}
};

204
bspwn/updater.html Normal file
View file

@ -0,0 +1,204 @@
<!--
EndPwn3.2 Updater
Copyright 2018 EndPwn Project
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
https://github.com/endpwn/
-->
<html>
<head>
<script src="glslsandbox.js"></script>
<script id="shaderCode" type="x-shader/x-fragment">
#ifdef GL_ES
precision mediump float;
#endif
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
vec3 h() {
vec2 pos = ( gl_FragCoord.xy / resolution.xy ) - vec2(0.5,0.5);
float horizon = 0.0;
float fov = 0.5;
float scaling = 0.1;
vec3 p = vec3(pos.x, fov, pos.y - horizon);
vec2 s = vec2(p.x/p.z, p.y/p.z + 2.0 * time * sign(p.z)) * scaling;
//checkboard texture
float color = sign((mod(s.x, 0.1) - 0.05) * (mod(s.y, 0.1) - 0.05));
//fading
color *= p.z*p.z*10.0;
color = clamp(color,0.0,1.0);
color /= 2.0;
return vec3(0.0,color,color); // made this cyan to differentiate between 3.1 and 3.2
}
void main( void ) {
gl_FragColor = vec4( h(), 1.0 );
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 resolution;
uniform sampler2D texture;
void main() {
vec2 uv = gl_FragCoord.xy / resolution.xy;
gl_FragColor = texture2D( texture, uv );
}
</script>
<script id="vertexShader" type="x-shader/x-vertex">
attribute vec3 position;
void main() {
gl_Position = vec4( position, 1.0 );
}
</script>
<script id="surfaceVertexShader" type="x-shader/x-vertex">
attribute vec3 position;
attribute vec2 surfacePosAttrib;
varying vec2 surfacePosition;
void main() {
surfacePosition = surfacePosAttrib;
gl_Position = vec4( position, 1.0 );
}
</script>
<style>
* {
margin: 0;
padding: 0;
}
body {
font-family: sans-serif;
text-align: center;
background-color: #2f3136;
color: #ffffff
}
div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: linear-gradient(to bottom right, #0ff, #f0f);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 96px;
}
span {
position: absolute;
top: 0%;
left: 50%;
transform: translate(-50%, 0%);
color: #f00;
font-size: 16px;
}
canvas {
display: block;
position: absolute;
z-index: -1;
}
</style>
<script>
// wait until DOM is ready so that error messages can display properly
window.onload = () => {
init();
if (gl) animate();
setTimeout(async () => {
try {
window.electron = require('electron').remote;
window.fs = require('original-fs');
const data = electron.app.getPath('userData');
// TODO: make this...not constant
const approot = 'https://ep3staging.dr1ft.xyz';
// continue to discord
function load() {
var branch = DiscordNative.globals.releaseChannel;
electron.getCurrentWindow().loadURL('https://' + (branch != 'stable' && branch != 'development' ? branch + '.' : '') + 'discordapp.com/channels/@me');
}
// make the plugins and styles dirs if they dont exist
if (!fs.existsSync(data + '/plugins')) fs.mkdirSync(data + '/plugins');
if (!fs.existsSync(data + '/styles')) fs.mkdirSync(data + '/styles');
// dont update stuff if DONTUPDATE exists
if (!fs.existsSync(data + '/DONTUPDATE')) {
// get files
fs.writeFileSync(data + '/epapi.js', await (await fetch('https://endpwn.github.io/epapi/epapi.js?_=' + Date.now())).text());
fs.writeFileSync(data + '/crispr.js', await (await fetch('https://endpwn.github.io/crispr/crispr.js?_=' + Date.now())).text());
fs.writeFileSync(data + '/plugins/system.js', await (await fetch(approot + '/plugin/system.js?_=' + Date.now())).text());
fs.writeFileSync(data + '/plugins/customizer.js', await (await fetch(approot + '/plugin/customizer.js?_=' + Date.now())).text());
fs.writeFileSync(data + '/plugins/settings.js', await (await fetch(approot + '/plugin/settings.js?_=' + Date.now())).text());
fs.writeFileSync(data + '/styles/system.css', await (await fetch(approot + '/plugin/system.css?_=' + Date.now())).text());
}
setTimeout(load, 1000);
}
catch (ex) {
console.error(ex);
alert('Updater failed. Check the console for details.', 'EndPwn3.2');
}
}, 500);
};
</script>
</head>
<body>
<div>&Sigma;ndPwn&sup3;</div>
</body>
</html>

1
files/index.js Normal file
View file

@ -0,0 +1 @@
module.exports = require('./core');

1
files/package.json Normal file
View file

@ -0,0 +1 @@
{"name":"discord_desktop_core","version":"0.0.0","private":"true","main":"index.js"}

137
scrape.js Normal file
View file

@ -0,0 +1,137 @@
#!/usr/bin/node --expose-gc
const fetch = require('node-fetch');
const request = require('request');
const fs = require('fs');
const ncp = require('ncp');
const asar = require('asar');
const archiver = require('archiver');
const exec = require('child_process').exec;
const branches = ['canary', 'ptb', 'stable'];
const platforms = ['win', 'linux', 'osx'];
console.log('loading config...');
var config = fs.existsSync('config.json') ?
JSON.parse(fs.readFileSync('config.json').toString()) :
{};
var lastver = {};
function patch(target, resolve) {
console.log('extracting zip...');
if (!fs.existsSync(target)) fs.mkdirSync(target);
console.log(`unzip -o ${target}.orig.zip -d ${target}`);
var child = exec(`unzip -o ${target}.orig.zip -d ${target}`);
child.stdout.pipe(process.stdout);
child.on('exit', () => {
path = target + '/core';
console.log('extracting asar...');
asar.extractAll(path + '.asar', path);
console.log('patching mainScreen.js...');
var mainScreen = fs.readFileSync(path + '/app/mainScreen.js').toString();
mainScreen = mainScreen
.replace(/nodeIntegration: false,/, 'nodeIntegration: true,')
.replace(/mainWindow\.loadURL\(URL_TO_LOAD\);/, "mainWindow.loadURL(_url.format({ pathname: _path2.default.join(__dirname, 'bspwn/updater.html'), protocol: 'file:', slashes: true }));");
fs.writeFileSync(path + '/app/mainScreen.js', mainScreen);
console.log('patching mainScreenPreload.js...');
var mainScreenPreload = fs.readFileSync(path + '/app/mainScreenPreload.js').toString();
mainScreenPreload = mainScreenPreload
.replace(/var electron = require\('electron'\);/, "var bspwn = require('./bspwn');\nbspwn.go();\nvar electron = require('electron');");
fs.writeFileSync(path + '/app/mainScreenPreload.js', mainScreenPreload);
console.log('copying bspwn files...')
ncp.ncp(__dirname + '/bspwn', path + '/app/bspwn', () => {
console.log('zipping it all up...');
var archive = archiver('zip');
var output = fs.createWriteStream(config.target || './' + target + '.zip');
archive.pipe(output);
archive.directory(path, 'core');
archive.file(__dirname + '/files/index.js', { name: 'index.js' });
archive.file(target + '/package.json', { name: 'package.json' });
archive.finalize();
//output.close(resolve);
resolve();
});
});
}
async function scrape() {
console.log('scraping...');
try {
for (b in branches) {
var branch = branches[b];
for (p in platforms) {
await new Promise(async (resolve, reject) => {
var platform = platforms[p];
var ident = `${branch}-${platform}`;
var currentver = await fetch(`https://discordapp.com/api/updates/${branch}?platform=${platform}`);
currentver = await currentver.json();
currentver = currentver.name;
var modules = await fetch(`https://discordapp.com/api/modules/${branch}/versions.json?platform=${platform}&host_version=${currentver}`);
modules = await modules.json();
var verstring = `${currentver}-${modules.discord_desktop_core}`;
console.log(`${ident} ${verstring}`);
if (!lastver[ident] || verstring > lastver[ident]) {
console.log('update available, fetching...');
lastver[ident] = verstring;
var target = `https://discordapp.com/api/modules/${branch}/discord_desktop_core/${modules.discord_desktop_core}?platform=${platform}&host_version=${currentver}`;
console.log(target);
request({
followAllRedirects: true,
url: target,
encoding: null
}, (err, response, body) => {
fs.writeFile(ident + '.orig.zip', body, () => {
console.log('done downloading');
patch(ident, resolve);
})
});
}
else resolve();
});
}
}
}
catch (ex) {
console.log(ex);
}
console.log('scraping again in 15 minutes');
global.gc();
}
setInterval(scrape, 15 * 60 * 1000);
//setInterval(scrape, 60*1000);
scrape();