Skip to content

Instantly share code, notes, and snippets.

@fsjuhl
Last active November 12, 2019 17:41
Show Gist options
  • Save fsjuhl/94280938b1593645fa76a9c6a23208f5 to your computer and use it in GitHub Desktop.
Save fsjuhl/94280938b1593645fa76a9c6a23208f5 to your computer and use it in GitHub Desktop.
const axios = require("axios")
const Discord = require("discord.js")
const qs = require("querystring")
const { randomProxy } = require("./config")
let prevState = "INIT" // OOS || IN STOCK || String
let prevScriptState = "INIT"
const testWebhook = new Discord.WebhookClient("", "")
const peachypingsWebhook = new Discord.WebhookClient("", "")
const webhooks = [
peachypingsWebhook
]
function sendChange(change, prev, news) {
webhooks.forEach((webhook) => {
webhook.send({
embeds: [ {
title: `Cyber ${change} state changed`,
fields: [ {
name: "Old state",
value: prev
}, {
name: "New state",
value: news
} ].filter(field => field.value)
} ]
}).then(() => {
webhook.send("@everyone")
})
})
}
async function main() {
try {
const state = await axios.post("https://cybersole.io/api/payment/purchase", qs.stringify({
Password: "who",
Email: "let@the.dogs",
Token: "out"
}), {
headers: {
"content-type": "application/x-www-form-urlencoded"
},
httpsAgent: randomProxy()
})
.then(response => ({ data: response.data, status: response.status.toString() }))
.catch(error => ({ data: error.response.data, status: error.response.status.toString() }))
let newState
if (typeof state.data === "object") {
if (state.data.code == "out_of_inventory") {
newState = `OOS (${state.status})`
} else if (state.data.code == "dup_order" || state.data.code == "invalid_password") {
newState = `IN STOCK (${state.status})`
} else {
newState = `Unknown error (${state.status}) : ${state.data.toString().substr(0, 750)}`
}
} else {
// Make state = body (the error)
const body = state.data.toString()
if (body.indexOf("<title>Site Under Construction</title>") != -1) {
newState = `Site being updated (${state.status})`
} else if (body.indexOf("<title>ERROR: The requested URL could not be retrieved</title>") != -1) {
newState = `URL not found (${state.status})`
} else if (body.indexOf("<title>502 - Web server received an invalid response while acting as a gateway or proxy server.</title>") != -1) {
newState = `Server error (${state.status})`
} else if (body.indexOf("<title>ERROR: Proxy Server Access Denied</title>") != -1) {
newState = `Proxy error (${state.status})`
} else if (body.indexOf("Service Unavailable") != -1 || body.indexOf("The service is unavailable.") != -1) {
newState = `Site temporarely down. (${state.status})`
} else {
newState = `Unknown error (${state.status}) : ${body.substr(0, 750)}`
}
}
if (prevState != "INIT" && prevState != newState) {
sendChange("website", prevState, newState)
}
console.log(`CYBER | Cybersole website state: ${newState}`)
prevState = newState
// script
const scriptState = await axios.get("https://cdn.cybersole.io/scripts/purchase.js", {
httpsAgent: randomProxy()
})
.then(res => ({ data: res.data, status: res.status.toString() }))
.catch(err => ({ data: err.response.data, status: err.response.status.toString() }))
let newScriptState
const scriptBody = scriptState.data.toString()
if (scriptBody.toLowerCase().includes("stripe")) {
newScriptState = scriptBody
} else {
newScriptState = `Unknown error (${state.status}) : ${body.substr(0, 750)}`
}
if (prevScriptState != "INIT" && prevScriptState != newScriptState) {
sendChange("script", prevScriptState, newScriptState)
}
console.log(`CYBER | Cybersole script state: ${newScriptState}`)
prevScriptState = newScriptState
} catch (error) {
console.log(error)
testWebhook.send(error.toString())
}
}
module.exports = main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment