STEEMIT PROGRAMMING BY ALEXMOVE: NODEJS for posting a comment with a check condition. Публикация комментарий с проверкой условий

in Steem-BRU (BY-RU-UA)4 years ago

Facebook-публикация 940x788  пикс (2).jpeg

Стоит обратить внимание на отличные публикации на эту тему:
https://steemit.com/javascript/@money-dreamer/nodejs-steemit-bot-tutorial

Тут есть описание как сделать аккаунт на GitHub, что и для меня является зоной роста уже длительное время.

https://github.com/upmeboost-utopian/utopian-io-tutorials
А вот и скрипты для разбора и тернировок.

Пишем комментарий

Начало скрипта

//<b>вот тут вы указываете время задержки между выполнением скрипта, вы можете указать 1 минуту либо, как тут 0.1 или 0.2 по желанию. Либо наоборот 2-3-5 минут. Скрипт будет работать в цикле </b>
var minutes = 0.1, the_interval = minutes * 60 * 1000;
setInterval(function() {
  console.log("I am doing my 0.1 minutes check");

  function sleep(milliseconds) {
    const date = Date.now();
    let currentDate = null;
    do {
      currentDate = Date.now();
    } while (currentDate - date < milliseconds);
  }

const dsteem = require('dsteem');
let opts = {};
//connect to production server

const steem = require('steem');
steem.api.setOptions({ url: 'https://api.steemit.com' });
steem.api.streamOperations(function (err, ops) {
  
});

var re = /\r\n/
function randomInt(min,max){
    return Math.floor(Math.random() * (max - min) + min);
    }
  
let wifkey = 'xxxxxxxx';
let votey = "alexmove";
opts.addressPrefix = 'STM';
opts.chainId =
    '0000000000000000000000000000000000000000000000000000000000000000';
//connect to server which is connected to the network/production
const client = new dsteem.Client('https://api.steemit.com');

let bd ='sd';
let bodyR;

const fs = require("fs");

let quiz = fs.readFileSync("quiz.txt", "utf8");
let quizrus = fs.readFileSync("quizrus.txt", "utf8");

//urltxt = quiz.split (/\n/);
var re = /\r\n/
urltxt = quiz.split(re);;
urltxtrus = quizrus.split(re);;

async function main() {
    const query = '/@alexmove/recent-replies';
    client.database
        .call('get_state', [query])
        .then(result => {
            if (!(Object.keys(result.content).length === 0 && result.content.constructor === Object)) {
                var replies = [];
                Object.keys(result.content).forEach(key => {
                    const reply = result.content[key];
                    const author = reply.author;
                    const created = new Date(reply.created).toDateString();
                    const body = reply.body;
                    const netvotes = reply.net_votes;
                    let bodyLowerCase = body.toLowerCase();

                    let permlinkR = reply.permlink;
                    const fs = require("fs");

                  //  console.log("Синхронное чтение файла")
                    let bd = fs.readFileSync("bd.txt", "utf8");
        
   <b> //Вот как раз тут! И можно указать на что реагировать в комментариях. Это для файла с первым вариантом вопросов      </b>        
    if (bodyLowerCase.indexOf(' ') !== -1) 
    //if (bodyLowerCase.indexOf('!quiz') !== -1) 

    {
    
    if (bd.indexOf(permlinkR) === -1) 
    {

    //console.log('огогогогого')

        bd = bd + permlinkR;

        fs.writeFileSync("bd.txt",bd)

        bodyR = urltxt[randomInt(1,urltxt.length-1)];
        marker = `ЗАРАБОТАЛО14!!!!!`+bodyR+'<HR>';
        let permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();
        function sleep(milliseconds) {
            const date = Date.now();
            let currentDate = null;
            do {
              currentDate = Date.now();
            } while (currentDate - date < milliseconds);
          }
          
         // console.log("Hello "+permlinkR+author);
         console.log(marker);

        steem.broadcast.comment(
            wifkey, // Your posting wif
            author, // Parent Author
            permlinkR, // Parent Permlink
        votey,
        permlink, // Your post permlink
        '', // Title
        bodyR, // Body
        { tags: ['thanks'], app: 'ganeshaway' }, // Json Metadata
        function(err, result) {
            console.log(err, result)});




    }
    <b>  //Вот как раз тут! Это для варианта второго вопросов</b>
    } else if (bodyLowerCase.indexOf('!вопрос') !== -1) 
    {
     //   console.log("RUS");

     if (bd.indexOf(permlinkR) === -1) 
     {
         bd = bd + permlinkR;
        fs.writeFileSync("bd.txt",bd)

        bodyRus = urltxtrus[randomInt(1,urltxtrus.length-1)];
        marker = `РУССКИЙ!!!!!`+bodyR+'<HR>';
        let permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();

          
         // sleep(20000);
         console.log(marker);

        steem.broadcast.comment(
            wifkey, // Your posting wif
            author, // Parent Author
            permlinkR, // Parent Permlink
        votey,
        permlink, // Your post permlink
        '', // Title
        bodyRus, // Body
        { tags: ['thanks'], app: 'ganeshaway' }, // Json Metadata
        function(err, result) {
            console.log(err, result)});

        }
} else {marker = "Нет!! либо уже есть вопрос";};

                    replies.push(
                        ``
                    );
                });
               // document.getElementById('replies').style.display = 'block';
               // document.getElementById('replies').innerHTML = replies.join('');
            }
        })
        .catch(err => {
            console.log(err);
            alert('Error occured, please reload the page');
        });
}
//catch error messages
main().catch(console.error);

  // do your stuff here
}, the_interval);


Конец скрипта

Прошлые посты по NODEJS:

https://steemit.com/hive-171319/@alexmove/nodejs-how-to-work-in-steem-steemit-basics-of-work-osnovy-raboty
https://steemit.com/hive-171319/@alexmove/nodejs-dlya-steemit-analiz-kolichestva-naibolee-vstrechayushikhsya-slov-v-postakh-nodejs-for-steemit-analysis-of-the-number-of

Есть вопросы? Пишите!
Всех благ.

Coin Marketplace

STEEM 0.13
TRX 0.33
JST 0.034
BTC 110789.00
ETH 4298.46
USDT 1.00
SBD 0.82