Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
288
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:"1", userpwd:"5555555555555555555555555555555555555555555"},
  9. {user:"2", userpwd:"5555555555555555555555555555555555555555555"},
  10. {user:"3", userpwd:"5555555555555555555555555555555555555555555"}
  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.                             str = str.substring(0, str.length - 2);
  145.                             str = str.substring(1)
  146.                             checkanswer.push(str);
  147.                         }
  148.                        
  149.                         if (checkanswer.includes("djimirji upvote bot")){
  150.                             //console.log("Прокоментировано");
  151.                         }
  152.                         else {
  153.                             all_Comments_From_Blog.push(add_comm_to_array);
  154.                             //console.log("Коментарий не оставлен");
  155.                         };
  156.                        
  157.                     }              
  158.                     else {
  159.                         all_Comments_From_Blog.push(add_comm_to_array);
  160.                         //console.log("Коментарий не оставлен");
  161.                     };
  162.                 }
  163.             }      
  164.         }
  165.         else {
  166.             return;
  167.         };
  168.     }
  169.    
  170. GetComments (CommCheckAuthor, CommCheckLink, 0);
  171.  
  172. }; 
  173.    
  174. let all_Comments_From_Blog = [];
  175. function fill_call_bot (fill) {
  176.     all_Comments_From_Blog.push(fill);
  177. };
  178.  
  179. // =================== Конец получения коментариев =========================
  180. // =================== Проверка на апвоут ================================
  181.  
  182. function UpVoteCheck (url) {
  183.    
  184.     let str = url.split('#')[0];
  185.     str = str.split('@')[1];
  186.     let pauthor = str.split('/')[0];
  187.     let plink = str.split('/')[1];
  188.    
  189.     return golos.api.getActiveVotes(pauthor, plink, function(err, result) {
  190.     });
  191. };
  192.  
  193. // =================== Конец проверки на апвоут =========================
  194.  
  195. //##########################################################################
  196.  
  197. // =================== Коментарий ================================
  198.  
  199. function CommentAdd (parentAuthor, parentPermlink,body,p) {
  200.     let postingkey = votersSemiBot[0].userpwd;
  201.     let permlink = 're-' + parentAuthor + '-' + parentPermlink + '-' + Date.now();
  202.     let title = '';
  203.     let jsonMetadata = {
  204.                     "tags": ["djimirji"],
  205.                     "app": "djimirji upvote bot"
  206.                     }
  207.     setTimeout(() => {
  208.         console.log("Коментирую",parentAuthor,body);
  209.         return golos.broadcast.comment(postingkey, parentAuthor, parentPermlink, mainBot, permlink, title, body, jsonMetadata, function(err, result) {     
  210.         });
  211.     },p);
  212. };
  213.  
  214. // =================== Конец кометария =============================
  215. // =================== Голосование =========================
  216.  
  217. function Vote (parent_author,parent_permlink,VOTEPOWER,postingkey,author,p) {
  218.     setTimeout(() => {
  219.     console.log("ГОЛОСУЮ",author, parent_author);
  220.     return golos.broadcast.vote(postingkey, author, parent_author, parent_permlink, VOTEPOWER * 100, function(err, result) {
  221.     });
  222.     },p);
  223.  
  224. };
  225.  
  226. // =================== Конец голосования =========================
  227. //##########################################################################
  228. var end_of_check_all_comments = '';
  229. async function getblogs (i_followers) {
  230.     let allblogs = [];
  231.     for (i=0;i<i_followers.length;i++){
  232.         let carentBlog = await getEachBlog(i_followers[i]);
  233.             if (carentBlog != null) {              
  234.                 carentBlog.forEach(function(item){
  235.                     //console.log(item.author);
  236.                     blg = {
  237.                         author: item.author,
  238.                         permlink: item.permlink                    
  239.                     }
  240.                     allblogs.push(blg);
  241.                 });
  242.                
  243.             }
  244.         if (i == i_followers.length -1 ){          
  245.             i_followers = []; //Чистим массив подписчиков
  246.             //console.log("Всего блогов",allblogs.length);          
  247.            
  248.             for (k=0;k < allblogs.length;k++){
  249.                 CallCommFromBlog(allblogs[k].author, allblogs[k].permlink);
  250.                
  251.                 if (k == allblogs.length - 1){
  252.                     //console.log(allblogs);
  253.                     allblogs = []; //Чистим массив блогов
  254.                     end_of_check_all_comments = 'end';
  255.                 };
  256.             };
  257.                        
  258.         };
  259.     }; 
  260. }
  261. //getblogs(['faalex']);
  262.  
  263.  
  264. function runBot() {
  265.     getfollowers();
  266.    
  267.     async function BroadcastCommentAndVote () {
  268.        
  269.         let p = 0;
  270.        
  271.         for (z=0;z < all_Comments_From_Blog.length;z++){
  272.             p = z * 21000;
  273.  
  274.             let upvoted = '';
  275.             let body = '';
  276.             let VOTEPOWER = '';
  277.             let str = all_Comments_From_Blog[z].url.split('#')[0];
  278.             str = str.split('@')[1];
  279.             let pauthor = str.split('/')[0];
  280.             let plink = str.split('/')[1];             
  281.            
  282.             let votecheck = await UpVoteCheck (all_Comments_From_Blog[z].url);
  283.             let voters = [];
  284.                 votecheck.forEach(function(item) {                                 
  285.                 voters.push(item.voter);               
  286.                 })             
  287.                 if (voters.includes(mainBot)) {
  288.                     upvoted = 1;               
  289.                 }
  290.                 else {
  291.                     upvoted = 0;
  292.                 }
  293.            
  294.             votersSemiBot.forEach(function (v) {
  295.                 console.log(p);
  296.                 if ((upvoted != 0) && (v.user == mainBot)){
  297.                     body = "💡 Этот пост уже получал upvote ранее :)";                    
  298.                     CommentAdd (all_Comments_From_Blog[z].author, all_Comments_From_Blog[z].permlink,body,p);
  299.                     return console.log(`\x1b[31m☹️ ${body} - ${all_Comments_From_Blog[z].author} - ${all_Comments_From_Blog[z].permlink} \x1b[0m`);
  300.                 }
  301.                 else {
  302.                     if (v.user == mainBot){
  303.                         VOTEPOWER = (Math.floor((Math.random() * 50) + 50));
  304.                         body = "💡 @" + pauthor + " получил апвоут на " + VOTEPOWER +"% :)";
  305.                         CommentAdd (all_Comments_From_Blog[z].author, all_Comments_From_Blog[z].permlink,body,p);                                                      
  306.                         Vote(pauthor,plink,VOTEPOWER,v.userpwd,v.user,p);                          
  307.                         return console.log(`\x1b[96m💬 ${v.user} коментирует и голосует за ${pauthor}, по ссылке - ${plink} \x1b[0m`);
  308.                     }
  309.                     else {
  310.                         VOTEPOWER = 100;   
  311.                         Vote(pauthor,plink,VOTEPOWER,v.userpwd,v.user,p);
  312.                         return console.log(`\x1b[32m🔗 Голосует доп.аккаунт: ${v.user} силой ${VOTEPOWER}, за ${pauthor}, статья: ${plink} \x1b[0m`);
  313.                     }
  314.                 };
  315.             });
  316.            
  317.         }; 
  318.    
  319.     pause = all_Comments_From_Blog.length * 21000;
  320.     setTimeout(() => {
  321.         all_Comments_From_Blog = [];
  322.         end_of_check_all_comments = '';
  323.         console.log("Пауза", pause);
  324.         runBot();      
  325.     }, pause + 70000);
  326.            
  327.     }
  328.    
  329.     function checkArrayEmptines (){
  330.         if (end_of_check_all_comments == 'end') {
  331.             //console.log("Коментарии обработаны");                    
  332.             setTimeout(() => {
  333.                 BroadcastCommentAndVote();     
  334.             }, 5000);          
  335.         }
  336.         else {
  337.             setTimeout(checkArrayEmptines, 1000);
  338.             //console.log("Не все проверено, ждем");         
  339.         }
  340.     }
  341.     checkArrayEmptines();
  342. }
  343.  
  344. runBot();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement