stuppid_bot

Untitled

Mar 25th, 2013
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Пишите письма [email protected]
  2.  
  3. var bot = (function() {
  4.     // topMsg('<b>Ошибка</b>:', 3, '#ffb4a3')
  5.     var hello = ['Здравствуй', 'Привет', 'Ку', 'Салют'];
  6.  
  7.     function rand(min, max) {
  8.         return Math.floor( Math.random() * (max - min + 1) + min );
  9.     }
  10.  
  11.     function shuffle(arr) {
  12.         var i = 0, j, l = arr.length, temp;
  13.        
  14.         while (i < l) {
  15.             j = Math.floor(Math.random() * l);
  16.             temp = arr[i];
  17.             arr[i++] = arr[j];
  18.             arr[j] = temp;
  19.         }
  20.     }
  21.    
  22.     function parseMessage(input, extra) {
  23.         var ret = {
  24.                 title: '',
  25.                 media: ''
  26.             },
  27.            
  28.             replacements = {
  29.                 hello: hello[ Math.floor( Math.random() * hello.length ) ],
  30.                 greeting: greeting()
  31.             };
  32.            
  33.         for (var prop in extra) {
  34.             replacements[prop] = extra[prop];
  35.         }
  36.    
  37.         // {Вариант 1|Вариант 2|Вариант 3}
  38.         ret.body = input.replace(/\{(.+?)\}/g, function(str, match) {
  39.             match = match.split('|');
  40.             return match[ Math.floor( Math.random() * match.length ) ];
  41.         // %hello%, %name%
  42.         }).replace(/%(.+?)%/g, function(str, match) {
  43.             return replacements[match] ? replacements[match] : str;
  44.         // <title>Заголовок</title>
  45.         // <media>photo:1_2,audio:3_4,video:5_6</media>
  46.         }).replace(/<(\w+)>(.*)<\/\1>/g, function(str, tag, content) {
  47.             switch (tag) {
  48.                 case 'title':
  49.                     ret.title = content;
  50.                     return '';
  51.            
  52.                 case 'media':
  53.                     ret.media = content;
  54.                     return '';
  55.             }
  56.            
  57.             return str;
  58.         });
  59.  
  60.         return ret;
  61.     }
  62.    
  63.     function greeting() {
  64.         var hour = new Date().getHours();
  65.         return hour >= 22 || hour < 6 ? 'Доброй ночи' : ( hour >= 18 ? 'Добрый вечер' : (hour >= 12 ? 'Добрый день' : 'Доброе утро') );
  66.     }
  67.    
  68.     function selDialog(peer, cb) {
  69.         ajax.post('al_im.php', {
  70.             act: 'a_start',
  71.             peer: peer
  72.         }, {
  73.             onDone: function (response) {
  74.                 cb(response);
  75.             }
  76.         });
  77.     }
  78.    
  79.     // Функция для вычисления хэша при отправке личного сообщения.
  80.     //
  81.     // im.js:2069
  82.     // decHash: function(hash) {
  83.     //   (function(_){cur.decodedHashes[_]=(function(__){var ___=ge?'':'___';for(____=0;____<__.length;++____)___+=__.charAt(__.length-____-1);return geByClass?___:'___';})(_.substr(_.length-5)+_.substr(4,_.length-12));})(hash);
  84.     // },  
  85.     function hashIM(hash) {
  86.         return ( hash.slice(-5) + hash.substr(4, hash.length - 12) ).split('').reverse().join('');
  87.     }
  88.  
  89.     function _sendIM(user_id, message, dialog) {
  90.         message = parseMessage(message, {
  91.             name: dialog.name,
  92.             fullname: dialog.tab
  93.         });
  94.    
  95.         ajax.post('al_im.php', {
  96.             act: 'a_send',
  97.             al: 1,
  98.             to: user_id,
  99.             title: message.title,
  100.             msg: message.body,
  101.             media: message.media,
  102.             hash: hashIM(dialog.hash)        
  103.         }, {
  104.             onDone: function (response) {
  105.                 console.log(response);
  106.                 Notifier.showEvent({
  107.                     title: 'Сообщение доставлено',
  108.                     text: '<a href="im?sel=' + user_id + '" target="_blank" class="mem_link">' + dialog.tab + '</a> получил' + (response.sex == 1 ? 'а' : '') + ' сообщение:<p>' + message.body + '</p>',                            
  109.                     author_photo: dialog.photo,
  110.                     author_link: '',
  111.                     add_photo: ''                                  
  112.                 });              
  113.             }
  114.         });
  115.     }
  116.  
  117.     function sendIM(user_id, message) {
  118.         selDialog(user_id, function(response) {
  119.             _sendIM(user_id, message, response);
  120.         });
  121.     }
  122.    
  123.     function sendIM2List(opts) {
  124.         var i = 0, loop = setInterval(function() {
  125.             if (!opts.ids[i]) {
  126.                 console.log('Рассылка личных сообщений завершена.');
  127.                 return clearInterval(loop);
  128.             }
  129.            
  130.             if ( !geByClass('captcha')[0] ) {              
  131.                 setTimeout(function() {
  132.                     console.log('#' + (i + 1) + '\t' + new Date().getTime());
  133.                     sendIM(opts.ids[i++], opts.message);
  134.                 }, Math.floor(Math.random() * opts.variance));
  135.             }
  136.         }, opts.interval);
  137.     }
  138.    
  139.      
  140.     // получить список друзей
  141.     // gid - id группы, если указан, то все друзья состоящие в группе обнуляются
  142.     function getFriends(cb, opts) {
  143.         opts = opts || {};
  144.         opts.id = opts.id || vk.id;
  145.         opts.city = opts.city ? opts.city.trim().toLowerCase() : '';
  146.        
  147.         ajax.post('al_friends.php', {
  148.             act: 'load_friends_silent',
  149.             al: 1,
  150.             id: opts.id,
  151.             gid: opts.gid || 0        
  152.         }, {
  153.             onDone: function(a, b, c) {
  154.                 // a - друзья, b - учебные заведения, c - города  
  155.                 eval('a=' + a);
  156.                 var friends = a.all;
  157.                 // return console.log(friends);
  158.                
  159.                 if ( opts.gid ) {
  160.                     friends = friends.filter(function(el) {
  161.                         return el;
  162.                     });
  163.                 }
  164.                
  165.                 if ( opts.excludes ) {
  166.                     friends = friends.filter(function(el) {
  167.                         return opts.excludes.indexOf( el[0] ) == -1;
  168.                     });
  169.                 }                          
  170.                
  171.                 if ( opts.online ) {
  172.                     friends = friends.filter(function(el) {
  173.                         return parseInt( el[4] );
  174.                     });
  175.                 }
  176.                
  177.                 if ( opts.city || opts.sex || opts.age_from || opts.age_to ) {  
  178.                     opts.city = (function() {                        
  179.                         if (opts.city) {                          
  180.                             for (var i = 0, l = c.cities.length; i < l; ++i) {
  181.                                 if (opts.city == c.cities[i][1].toLowerCase()) {
  182.                                     return c.cities[i][0];
  183.                                 }
  184.                             }
  185.                         }
  186.  
  187.                         return 0;
  188.                     })(),                
  189.                
  190.                     ajax.post('friends', {
  191.                         act: 'filter_friends',
  192.                         ads_section: 'friends',
  193.                         age_from: opts.age_from || 0,
  194.                         age_to: opts.age_to || 0,
  195.                         al: 1,
  196.                         al_ad: 1,
  197.                         city: opts.city,
  198.                         sex: opts.sex,
  199.                         uid: opts.id
  200.                     }, {
  201.                         onDone: function(arr) {
  202.                             friends = friends.filter(function(el) {
  203.                                 return arr.indexOf( el[0] ) > -1;
  204.                             });
  205.                            
  206.                             cb(friends);
  207.                         }
  208.                     });
  209.                    
  210.                     return;
  211.                 }
  212.                
  213.                 cb(friends);
  214.             }
  215.         });
  216.     }
  217.    
  218.     function sendIM2Friends(opts) {
  219.         getFriends(function(arr) {
  220.             opts.ids = arr.map(function(el) {
  221.                 return el[0];
  222.             });
  223.  
  224.             shuffle(opts.ids);            
  225.             sendIM2List(opts);
  226.         }, opts);
  227.     }
  228.    
  229.     function inviteTo(opts) {  
  230.         // список друзей получаем
  231.         getFriends(function(arr) {
  232.             shuffle(arr);
  233.             console.log(arr);
  234.             // return;
  235.  
  236.             if (arr.length) {
  237.                 var i = 0, loop = setInterval(function() {
  238.                     // проверяем есть ли капча
  239.                     if ( !geByClass('captcha')[0] ) {
  240.                         setTimeout(function() {
  241.                             ajax.post('al_page.php', {
  242.                                 act: 'a_invite',
  243.                                 gid: opts.gid,
  244.                                 mid: arr[i][0],
  245.                                 hash: arr[i][11]
  246.                             }, {
  247.                                 onDone: function(flg, msg) {
  248.                                     console.log('#' + (i + 1) + '\t' + new Date().getTime() + '\n' + msg);
  249.  
  250.                                     if (msg == 'Вы можете пригласить только 40 человек в день.') {                                                                            
  251.                                         i = -2;
  252.                                     }
  253.                                     else {
  254.                                         Notifier.showEvent({
  255.                                             title: 'Рассылка приглашений',
  256.                                             text: '<a href="' + arr[i][2] + '" target="_blank" class="mem_link">' + arr[i][5] + '</a><p>' + msg + '</p>',                            
  257.                                             author_photo: arr[i][1],
  258.                                             author_link: '',
  259.                                             add_photo: ''                                  
  260.                                         });  
  261.                                     }
  262.  
  263.                                     if (!arr[++i]) {
  264.                                         console.log('Рассылка приглашений в группу закончена.');
  265.                                         return clearInterval(loop);
  266.                                     }
  267.                                 },
  268.  
  269.                                 onFail: function(msg) {
  270.                                     alert(msg);
  271.                                 }
  272.                             });
  273.                         }, Math.floor(Math.random() * opts.variance));
  274.                     }
  275.                 }, opts.interval);          
  276.             }        
  277.         }, opts);
  278.     }
  279.    
  280.     var formTypes = {
  281.         'im2friends': ['Рассылка сообщений друзьям', sendIM2Friends],
  282.         'im2list': ['Рассылка сообщений', sendIM2List],
  283.         'invite': ['Пригласить в группу', inviteTo]
  284.     }
  285.    
  286.     function showForm(type) {
  287.         var html = '<form id="bot">';
  288.        
  289.         if (type == 'invite') {
  290.             html += '<p><label for="gid">ID группы</label> <input id="gid"> только цифры';
  291.         }  
  292.         else {
  293.             html += '<p>Сообщение <textarea id="message" rows="8" style="box-sizing: border-box; width: 100%" placeholder="Введите текст"></textarea>';
  294.         }
  295.        
  296.         if (type == 'im2list') {
  297.             html += '<p><label for="ids">Список рассылки</label> <textarea id="ids" rows="4" style="box-sizing: border-box; width: 100%" placeholder="id через запятую, только цифры"></textarea>';
  298.         }      
  299.         else if (type == 'im2friends' || type == 'invite') {
  300.             html += '<p><label for="excludes">Исключить из рассылки</label> <textarea id="excludes" rows="4" style="box-sizing: border-box; width: 100%" placeholder="id через запятую, только цифры"></textarea>';
  301.             html += '<p><label for="city">Город</label> <input id="city" placeholder="Введите название" style="width: 13em">';
  302.             html += '<p>Пол <select id="sex"><option>любой</option><option>женский</option><option>мужской</option></select>';
  303.             html += ' и возраст от <input id="age_from" type="number" value="0" min="0" max="999" style="width: 3em;"> до';
  304.             html += ' <input id="age_to" type="number" value="0" min="0" max="999" style="width: 3em;"> лет <input id="online" type="checkbox"> онлайн';
  305.         }
  306.        
  307.         html += '<p>Интервал <input id="interval" type="number" value="5" min="1" max="999" style="width: 3em;"> сек. с отклонение <input id="variance" type="number" value="0.1" min="0" max="1" step="0.1" style="width: 3em;">';
  308.  
  309.         var box = new MessageBox({ title: formTypes[type][0], width: 460 });  
  310.         box.removeButtons();      
  311.         box.addButton('Отмена', function(){ box.hide(); }, 'no');
  312.         box.addButton('Поехали', function(){
  313.             var els = ge('bot').elements, i = 0, el, l = els.length, opts = {};  
  314.            
  315.             for (; i < l; ++i) {
  316.                 el = els[i];
  317.                
  318.                 opts[el.id] = (function() {
  319.                     switch (el.id) {
  320.                         case 'ids':
  321.                         case 'excludes':
  322.                             return el.value.split(/\s*,\s*/).filter(function(a) {
  323.                                 return a;
  324.                             });
  325.                            
  326.                         case 'sex':
  327.                             return el.selectedIndex;
  328.                            
  329.                         case 'online':
  330.                             return el.checked;
  331.                     }
  332.                    
  333.                     return el.value;
  334.                 })();
  335.             }
  336.            
  337.             opts.interval *= 1000;
  338.             opts.variance *= opts.interval;
  339.            
  340.             console.log(opts);
  341.            
  342.             if (typeof opts.message != 'undefined' && !opts.message.trim()) {
  343.                 return alert('Введите сообщение.');      
  344.             }
  345.            
  346.             formTypes[type][1](opts);
  347.             box.hide();
  348.         }, 'yes');
  349.         box.content(html);
  350.         box.show();
  351.     }
  352.  
  353.     return {
  354.         parseMessage: parseMessage,
  355.         inviteTo: inviteTo,
  356.         selDialog: selDialog,
  357.         sendIM: sendIM,
  358.         sendIM2List: sendIM2List,
  359.         getFriends: getFriends,
  360.         showForm: showForm,
  361.        
  362.         // добавление возможных друзей
  363.         addSuggestions: function() {
  364.             var offset = 0;
  365.            
  366.             function doStuff() {
  367.                 ajax.post('friends', {
  368.                     al: 1,
  369.                     act: 'get_section_friends',
  370.                     section: 'suggestions',
  371.                     offset: offset
  372.                 }, {
  373.                     onDone: function(data) {
  374.                         eval('data=(' + data + ').suggestions');
  375.                        
  376.                         if (data.length) {
  377.                             var i = 0, loop = setInterval(function() {  
  378.                                 if ( !geByClass('captcha')[0] ) {
  379.                                     var arr = data[i++];
  380.                                     console.log(arr);
  381.                                    
  382.                                     if (!data[i]) {
  383.                                         clearInterval(loop);
  384.                                         doStuff();
  385.                                     }
  386.                                
  387.                                     setTimeout(function() {
  388.                                         ajax.post('al_friends.php', {
  389.                                             act: 'add',
  390.                                             mid: arr[0],
  391.                                             hash: arr[8][0],
  392.                                             request: 1,
  393.                                             select_list: 1
  394.                                         }, {
  395.                                             onDone: function(msg) {
  396.                                                 console.log('#' + (i + 1) + '\t' + new Date().getTime() + '\n' + msg);
  397.  
  398.                                                 if ( /у Вас в друзьях/.test(msg) ) {
  399.                                                     msg = 'Заявка принята.';
  400.                                                 }
  401.                                                 else {                                              
  402.                                                     msg = /Заявка уже отправлена/.test(msg) ? 'Заявка уже отправлена.' : 'Заявка отправлена.';
  403.  
  404.                                                     // убираем из списка возможных друзей
  405.                                                     setTimeout(function() {
  406.                                                         ajax.post('al_friends.php', { act: 'hide_possible', al: 1, mid: arr[0], hash: arr[8][1] });
  407.                                                     }, rand(1000, 3000));
  408.                                                 }                                                                                                                            
  409.  
  410.                                                 Notifier.showEvent({
  411.                                                     title: 'Возможные друзья',
  412.                                                     text: '<a href="id' + arr[0] + '" target="_blank" class="mem_link">' + arr[5] + '</a><p>' + msg + '</p>',                            
  413.                                                     author_photo: arr[1],
  414.                                                     author_link: '',
  415.                                                     add_photo: ''                                  
  416.                                                 });                                                                                                                            
  417.                                             },
  418.  
  419.                                             onFail: function(msg) {
  420.                                                 if (msg == 'К сожалению, этот пользователь добавил Вас в чёрный список, поэтому Вы не можете добавить его в друзья.') {
  421.                                                      setTimeout(function() {
  422.                                                         ajax.post('al_friends.php', { act: 'hide_possible', al: 1, mid: arr[0], hash: arr[8][1] });
  423.                                                     }, rand(1000, 3000));
  424.                                                 }
  425.                                                 else {
  426.                                                     if (msg == 'К сожалению, Вы не можете добавлять больше друзей за один день. Пожалуйста, попробуйте завтра.') {
  427.                                                         console.log('Закончили добавлять возможных друзей.');
  428.                                                     }
  429.                                                    
  430.                                                     clearInterval(loop);                                                    
  431.                                                 }
  432.                                             }
  433.                                         }); //
  434.                                     }, rand(0, 3000));
  435.                                 }
  436.                             }, 10000);              
  437.                         }
  438.                                    
  439.                         offset += 40;
  440.                     }
  441.                 });
  442.             }
  443.            
  444.             doStuff();
  445.         },
  446.        
  447.        
  448.         im2friends: function() { showForm('im2friends'); },
  449.         im2list: function() { showForm('im2list'); },
  450.         invite: function() { showForm('invite'); }
  451.     } // return
  452. })();
Advertisement
Add Comment
Please, Sign In to add comment