Skip to content

Instantly share code, notes, and snippets.

@skzap
Created June 29, 2020 18:20
Show Gist options
  • Select an option

  • Save skzap/82c5cdd7e72d3631063f8e2f27cee28d to your computer and use it in GitHub Desktop.

Select an option

Save skzap/82c5cdd7e72d3631063f8e2f27cee28d to your computer and use it in GitHub Desktop.
// modules
const fs = require('fs');
const axios = require('axios');
const hive = require('@hiveio/hive-js');
// variables
const wif = "PRIVATE_KEY_HERE"
const ratiox = 800
const timer = 60000
const titre = "CleanPlanet Upvote"
const jsonComment = JSON.stringify({
app: "CleanPlanet_Bot/0.1"
})
// code
var blocklastvote = 0
loadFile(function() {
checkBurnHistory()
setInterval(function() {
checkBurnHistory()
}, timer)
})
function loadFile(cb) {
fs.readFile("./block_hive.txt", 'utf8', function(err, contents) {
console.log("Bot restarted on block "+contents)
if (!err)
blocklastvote = parseInt(contents)
cb()
});
}
function checkBurnHistory() {
console.log("Checking @null history")
var url = "https://accounts.hive-engine.com/accountHistory?account=null&limit=100&offset=0&type=user&symbol=PLANET"
axios.get(url)
.then(function (response) {
for (let i = 0; i < response.data.length; i++) {
handleBurn(response.data[i])
}
})
.catch(function (error) {
console.log(error);
})
}
function handleBurn(burn) {
var quantity = parseFloat(burn.quantity)
var payer = burn.from
var memo = burn.memo
var lien = memo.split("@")
if (lien.length == 2) {
var contenu = lien[1].split("/")
if (contenu.length == 2) {
var author = contenu[0]
var permalink = contenu[1]
var nbBlock = parseInt(burn.blockNumber)
hive.api.getContent(author, permalink, function(err, result) {
if (err) return;
if (!result.json_metadata) return;
var tags = JSON.parse(result.json_metadata).tags
var weight = quantity*8000/ratiox
if (tags.indexOf('cleanplanet') > -1)
weight *= 1.25
weight = Math.floor(weight)
if (weight > 10000) weight = 10000
if (nbBlock > blocklastvote && weight > 0) {
console.log(payer+" burn "+quantity+" PLANET voting for "+author+"/"+permalink+" at "+weight/100+"%")
blocklastvote = nbBlock
fs.writeFile("./block_hive.txt", blocklastvote, function(err) {
if(err) {
return console.log(err);
}
});
hive.broadcast.vote(wif, voter, author, permalink, weight, function(err, result) {
if (!err) {
console.log("Vote done")
var commentaire = "Thanks to @"+payer+" for burning ["+quantity+" PLANET](https:\/\/hive-engine.com\/?p=market&t=PLANET)! You have been rewarded with a "+weight/100+"% vote. Your action makes this project grow and helps to$
var random = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
hive.broadcast.comment(wif, author, permalink, voter, random, titre, commentaire, jsonComment, function(err, result) {
if (!err)
console.log("Comment done")
else console.log(err)
});
}
});
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment