Advertisement
djimirji

Upvote BOT for Golos.io

Mar 15th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // У вас должен быть установлен nodejs
  2. // Установите зависимости для скрипта командой npm install golos-js
  3. // =====================================================================
  4. // Автор https://golos.io/@djimirji/
  5. // =====================================================================
  6. // Логин и пароль(постинг ключ) аккаунта который будет делать реблоги в свой блог
  7. const votersSemiBot = [
  8. {user:"djimirji", userpwd:"5555555555555555555555555555555555"},
  9. {user:"2", userpwd:"55555555555555555555555555555555555555"},
  10. {user:"3", userpwd:"55555555555555555555555555555555555"}
  11. ];
  12.  
  13. // Логин аккаунта на который должены подписываться пользователи, что бы их имена попали в белый список!
  14. const mainBot = 'djimirji';
  15.  
  16. //Вызов бота
  17. const UpVoteCall = '@djimirji up!';
  18.  
  19. // ======================= Коннект ==========================
  20. //const GOLOSNODE = "ws://localhost:9090"
  21. const GOLOSNODE = "wss://api.golos.cf"; //нода @vik
  22. // Подключение JavaScript библиотеки для работы c API голоса
  23. const golos = require('golos-js');
  24.  
  25. // Указываем ноду, к которой будет подключен скрипт
  26. golos.config.set('websocket', GOLOSNODE);
  27. // =====================================================================
  28.  
  29. //#######################################################################
  30. // =================== Удаление дублей =========================
  31. function removeDuplicates(arr){
  32.     let unique_array = []
  33.     for(let i = 0;i < arr.length; i++){
  34.         if(unique_array.indexOf(arr[i]) == -1){
  35.             unique_array.push(arr[i])
  36.         }
  37.     }
  38.     return unique_array
  39. }
  40. // =================== Конец удаления дублей ========================
  41. //##########################################################################
  42. // =================== Получение блогов =========================
  43. function getEachBlog(follower) {
  44.     let d = new Date();
  45.     let dt = d.toISOString().split('.')[0];
  46.     let author = follower;
  47.     let startPermlink = '';
  48.     let beforeDate = dt;
  49.     let limit = 3;
  50.    
  51.     return golos.api.getDiscussionsByAuthorBeforeDate(author, startPermlink, beforeDate, limit, async function(err, result) {  
  52.     });
  53. };
  54.  
  55. // =================== Конец получения постов из блогов =========================
  56. //##########################################################################
  57.  
  58. //##########################################################################
  59. // =================== Получения подписчиков =========================
  60. var startFollower = '';
  61. var followType = 'blog';
  62. var limit = 100;
  63. let i_followers = [];
  64. let lastFollower = '';
  65.  
  66. const getfollowers = (startFollower) => {      
  67.         golos.api.getFollowers(mainBot, startFollower, followType, limit, function(err, result) {
  68.             if ( ! err) {
  69.                
  70.                 for (let f of result){
  71.                     i_followers.push(f.follower);                  
  72.                 };                 
  73.                 lastFollower = i_followers[i_followers.length - 1];
  74.             };
  75.             if (startFollower === i_followers[i_followers.length - 1]) {
  76.                 //console.log("Всех выбрали");
  77.                 i_followers = removeDuplicates(i_followers);                       
  78.                                                                        
  79.                 setTimeout(() => {
  80.                     getblogs(i_followers);
  81.                 },1000);
  82.             }
  83.             else {
  84.                 getfollowers(lastFollower);
  85.             };         
  86.         });
  87.        
  88.     };
  89.        
  90. // =================== Конец функции получения подписчиков =========================
  91. //##########################################################################
  92. // =================== Получение коментариев =========================
  93.  
  94. function CallCommFromBlog (CommCheckAuthor, CommCheckLink) {   
  95.    
  96.     async function GetComments (CommCheckAuthor, CommCheckLink, commchildren) {    
  97.         function i_GetComments (Author, Link) {
  98.             return golos.api.getContentReplies(Author, Link,function(err, result) { });            
  99.         };
  100.         let FirstLevel = await i_GetComments (CommCheckAuthor, CommCheckLink);
  101.        
  102.         if (FirstLevel != null) {
  103.        
  104.             for (let i of FirstLevel){
  105.                 //console.log(i.author, i.body);
  106.                 if (i.children == 5){
  107.                     await GetComments (i.author, i.permlink, i.children + 10);
  108.                     //console.log("5 дочерних каментов");              
  109.                 }
  110.                 else if (i.children > 0){
  111.                     await GetComments (i.author, i.permlink, commchildren);
  112.                     //console.log("дочерних каментов", i.children);
  113.                 }
  114.                 else {};
  115.            
  116.                 if (i.body.toLowerCase().search(UpVoteCall) != '-1'){                  
  117.                     //console.log("Найден запрос", i.url, commchildren);
  118.                     let findedcall = '';
  119.                     if (commchildren > 10){
  120.                         findedcall = await i_GetComments (i.parent_author, i.parent_permlink);
  121.                         add_comm_to_array = {
  122.                             url: i.url,
  123.                             author: i.parent_author,
  124.                             permlink: i.parent_permlink,
  125.                             body: i.body
  126.                         }
  127.  
  128.                     }
  129.                     else {
  130.                         findedcall = await i_GetComments (i.author, i.permlink);
  131.                         add_comm_to_array = {
  132.                             url: i.url,
  133.                             author: i.author,
  134.                             permlink: i.permlink,
  135.                             body: i.body
  136.                         }
  137.                     }              
  138.                
  139.                     if ( findedcall != '' ) {
  140.                         let checkanswer = [];
  141.                         let str = "";
  142.                         for (let f of findedcall ){                          
  143.                             str = f.json_metadata.split(',"app":')[1];
  144.                             if (str != null){
  145.                                 str = str.substring(0, str.length - 2);
  146.                                 str = str.substring(1);
  147.                                 checkanswer.push(str);
  148.                             };
  149.                            
  150.                         }
  151.                        
  152.                         if (checkanswer.includes("djimirji upvote bot")){
  153.                             //console.log("Прокоментировано");
  154.                         }
  155.                         else {
  156.                             all_Comments_From_Blog.push(add_comm_to_array);
  157.                             //console.log("Коментарий не оставлен");
  158.                         };
  159.                        
  160.                     }              
  161.                     else {
  162.                         all_Comments_From_Blog.push(add_comm_to_array);
  163.                         //console.log("Коментарий не оставлен");
  164.                     };
  165.                 }
  166.             }      
  167.         }
  168.         else {
  169.             return;
  170.         };
  171.     }
  172.    
  173. GetComments (CommCheckAuthor, CommCheckLink, 0);
  174.  
  175. }; 
  176.    
  177. let all_Comments_From_Blog = [];
  178. function fill_call_bot (fill) {
  179.     all_Comments_From_Blog.push(fill);
  180. };
  181.  
  182. // =================== Конец получения коментариев =========================
  183. // =================== Проверка на апвоут ================================
  184.  
  185. function UpVoteCheck (url) {
  186.    
  187.     let str = url.split('#')[0];
  188.     str = str.split('@')[1];
  189.     let pauthor = str.split('/')[0];
  190.     let plink = str.split('/')[1];
  191.    
  192.     return golos.api.getActiveVotes(pauthor, plink, function(err, result) {
  193.     });
  194. };
  195.  
  196. // =================== Конец проверки на апвоут =========================
  197.  
  198. //##########################################################################
  199.  
  200. // =================== Коментарий ================================
  201.  
  202. function CommentAdd (parentAuthor, parentPermlink,body,p) {
  203.     let postingkey = votersSemiBot[0].userpwd;
  204. //  let permlink = 're-' + parentAuthor + '-' + parentPermlink + '-' + Date.now();
  205.     let permlink = 're-' + parentPermlink + '-' + Date.now();
  206.     let title = '';
  207.     let jsonMetadata = {
  208.                     "tags": ["djimirji"],
  209.                     "app": "djimirji upvote bot"
  210.                     }
  211.     setTimeout(() => {
  212.         console.log("Коментирую",parentAuthor,body);
  213.         return golos.broadcast.comment(postingkey, parentAuthor, parentPermlink, mainBot, permlink, title, body, jsonMetadata, function(err, result) {
  214.         //  console.log(err, result);  
  215.         });
  216.     },p);
  217. };
  218.  
  219. // =================== Конец кометария =============================
  220. // =================== Голосование =========================
  221.  
  222. function Vote (parent_author,parent_permlink,VOTEPOWER,postingkey,author,p) {
  223.     setTimeout(() => {
  224.     console.log("ГОЛОСУЮ",author, parent_author);
  225.     return golos.broadcast.vote(postingkey, author, parent_author, parent_permlink, VOTEPOWER * 100, function(err, result) {
  226.     });
  227.     },p);
  228.  
  229. };
  230.  
  231. // =================== Конец голосования =========================
  232. //################################################################################
  233. //##########################################################################
  234. var end_of_check_all_comments = '';
  235. async function getblogs (i_followers) {
  236.     let allblogs = [];
  237.     for (i=0;i<i_followers.length;i++){
  238.         let carentBlog = await getEachBlog(i_followers[i]);
  239.             if (carentBlog != null) {              
  240.                 carentBlog.forEach(function(item){
  241.                     //console.log(item.author);
  242.                     blg = {
  243.                         author: item.author,
  244.                         permlink: item.permlink                    
  245.                     }
  246.                     allblogs.push(blg);
  247.                 });
  248.                
  249.             }
  250.         if (i == i_followers.length -1 ){          
  251.             i_followers = []; //Чистим массив подписчиков
  252.             //console.log("Всего блогов",allblogs.length);          
  253.            
  254.             for (k=0;k < allblogs.length;k++){
  255.                 CallCommFromBlog(allblogs[k].author, allblogs[k].permlink);
  256.                
  257.                 if (k == allblogs.length - 1){
  258.                     //console.log(allblogs);
  259.                     allblogs = []; //Чистим массив блогов
  260.                     end_of_check_all_comments = 'end';
  261.                 };
  262.             };
  263.                        
  264.         };
  265.     }; 
  266. }
  267.  
  268.  
  269. function runBot() {
  270.     getfollowers();
  271.    
  272.     async function BroadcastCommentAndVote () {
  273.        
  274.         let p = 0;
  275.        
  276.         for (z=0;z < all_Comments_From_Blog.length;z++){
  277.             p = z * 21000;
  278.  
  279.             let upvoted = '';
  280.             let body = '';
  281.             let VOTEPOWER = '';
  282.             let str = all_Comments_From_Blog[z].url.split('#')[0];
  283.             str = str.split('@')[1];
  284.             let pauthor = str.split('/')[0];
  285.             let plink = str.split('/')[1];             
  286.            
  287.             let votecheck = await UpVoteCheck (all_Comments_From_Blog[z].url);
  288.             let voters = [];
  289.                 votecheck.forEach(function(item) {                                 
  290.                 voters.push(item.voter);               
  291.                 })             
  292.                 if (voters.includes(mainBot)) {
  293.                     upvoted = 1;               
  294.                 }
  295.                 else {
  296.                     upvoted = 0;
  297.                 }
  298.            
  299.             votersSemiBot.forEach(function (v) {
  300.                 console.log(p);
  301.                 if ((upvoted != 0) && (v.user == mainBot)){
  302.                     body = "💡 Этот пост уже получал upvote ранее :)";                    
  303.                     CommentAdd (all_Comments_From_Blog[z].author, all_Comments_From_Blog[z].permlink,body,p);                                                      
  304.                     return console.log(`\x1b[31m☹️ ${body} - ${all_Comments_From_Blog[z].author} - ${all_Comments_From_Blog[z].permlink} \x1b[0m`);
  305.                 }
  306.                 else {
  307.                     if (v.user == mainBot){
  308.                         VOTEPOWER = (Math.floor((Math.random() * 50) + 50));
  309.                         body = "💡 @" + pauthor + " получил апвоут на " + VOTEPOWER +"% :)"+ `<br>` + `<h6>` + "###### Что бы вызывать бота подпишись на меня! ######" + `</h6>` + "";
  310.                         CommentAdd (all_Comments_From_Blog[z].author, all_Comments_From_Blog[z].permlink,body,p);                                                      
  311.                         Vote(pauthor,plink,VOTEPOWER,v.userpwd,v.user,p);                          
  312.                         return console.log(`\x1b[96m💬 ${v.user} коментирует и голосует за ${pauthor}, по ссылке - ${plink} \x1b[0m`);
  313.                     }
  314.                     else {
  315.                         VOTEPOWER = 100;   
  316.                         Vote(pauthor,plink,VOTEPOWER,v.userpwd,v.user,p);
  317.                         return console.log(`\x1b[32m🔗 Голосует доп.аккаунт: ${v.user} силой ${VOTEPOWER}, за ${pauthor}, статья: ${plink} \x1b[0m`);
  318.                     }
  319.                 };
  320.             });
  321.            
  322.         }; 
  323.    
  324.     pause = ( all_Comments_From_Blog.length * 21000 ) + 70000; 
  325.     console.log("Пауза", pause/1000," сек.");
  326.     setTimeout(() => {
  327.         all_Comments_From_Blog = [];
  328.         end_of_check_all_comments = '';
  329.                
  330.         runBot();      
  331.     }, pause );
  332.            
  333.     }
  334.    
  335.     function checkArrayEmptines (){
  336.         if (end_of_check_all_comments == 'end') {
  337.             //console.log("Коментарии обработаны");                    
  338.             setTimeout(() => {
  339.                 BroadcastCommentAndVote();     
  340.             }, 5000);          
  341.         }
  342.         else {
  343.             setTimeout(checkArrayEmptines, 1000);
  344.             //console.log("Не все проверено, ждем");         
  345.         }
  346.     }
  347.     checkArrayEmptines();
  348. }
  349.  
  350. runBot();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement