Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Пишите письма [email protected]
- var bot = (function() {
- // topMsg('<b>Ошибка</b>:', 3, '#ffb4a3')
- var hello = ['Здравствуй', 'Привет', 'Ку', 'Салют'];
- function rand(min, max) {
- return Math.floor( Math.random() * (max - min + 1) + min );
- }
- function shuffle(arr) {
- var i = 0, j, l = arr.length, temp;
- while (i < l) {
- j = Math.floor(Math.random() * l);
- temp = arr[i];
- arr[i++] = arr[j];
- arr[j] = temp;
- }
- }
- function parseMessage(input, extra) {
- var ret = {
- title: '',
- media: ''
- },
- replacements = {
- hello: hello[ Math.floor( Math.random() * hello.length ) ],
- greeting: greeting()
- };
- for (var prop in extra) {
- replacements[prop] = extra[prop];
- }
- // {Вариант 1|Вариант 2|Вариант 3}
- ret.body = input.replace(/\{(.+?)\}/g, function(str, match) {
- match = match.split('|');
- return match[ Math.floor( Math.random() * match.length ) ];
- // %hello%, %name%
- }).replace(/%(.+?)%/g, function(str, match) {
- return replacements[match] ? replacements[match] : str;
- // <title>Заголовок</title>
- // <media>photo:1_2,audio:3_4,video:5_6</media>
- }).replace(/<(\w+)>(.*)<\/\1>/g, function(str, tag, content) {
- switch (tag) {
- case 'title':
- ret.title = content;
- return '';
- case 'media':
- ret.media = content;
- return '';
- }
- return str;
- });
- return ret;
- }
- function greeting() {
- var hour = new Date().getHours();
- return hour >= 22 || hour < 6 ? 'Доброй ночи' : ( hour >= 18 ? 'Добрый вечер' : (hour >= 12 ? 'Добрый день' : 'Доброе утро') );
- }
- function selDialog(peer, cb) {
- ajax.post('al_im.php', {
- act: 'a_start',
- peer: peer
- }, {
- onDone: function (response) {
- cb(response);
- }
- });
- }
- // Функция для вычисления хэша при отправке личного сообщения.
- //
- // im.js:2069
- // decHash: function(hash) {
- // (function(_){cur.decodedHashes[_]=(function(__){var ___=ge?'':'___';for(____=0;____<__.length;++____)___+=__.charAt(__.length-____-1);return geByClass?___:'___';})(_.substr(_.length-5)+_.substr(4,_.length-12));})(hash);
- // },
- function hashIM(hash) {
- return ( hash.slice(-5) + hash.substr(4, hash.length - 12) ).split('').reverse().join('');
- }
- function _sendIM(user_id, message, dialog) {
- message = parseMessage(message, {
- name: dialog.name,
- fullname: dialog.tab
- });
- ajax.post('al_im.php', {
- act: 'a_send',
- al: 1,
- to: user_id,
- title: message.title,
- msg: message.body,
- media: message.media,
- hash: hashIM(dialog.hash)
- }, {
- onDone: function (response) {
- console.log(response);
- Notifier.showEvent({
- title: 'Сообщение доставлено',
- text: '<a href="im?sel=' + user_id + '" target="_blank" class="mem_link">' + dialog.tab + '</a> получил' + (response.sex == 1 ? 'а' : '') + ' сообщение:<p>' + message.body + '</p>',
- author_photo: dialog.photo,
- author_link: '',
- add_photo: ''
- });
- }
- });
- }
- function sendIM(user_id, message) {
- selDialog(user_id, function(response) {
- _sendIM(user_id, message, response);
- });
- }
- function sendIM2List(opts) {
- var i = 0, loop = setInterval(function() {
- if (!opts.ids[i]) {
- console.log('Рассылка личных сообщений завершена.');
- return clearInterval(loop);
- }
- if ( !geByClass('captcha')[0] ) {
- setTimeout(function() {
- console.log('#' + (i + 1) + '\t' + new Date().getTime());
- sendIM(opts.ids[i++], opts.message);
- }, Math.floor(Math.random() * opts.variance));
- }
- }, opts.interval);
- }
- // получить список друзей
- // gid - id группы, если указан, то все друзья состоящие в группе обнуляются
- function getFriends(cb, opts) {
- opts = opts || {};
- opts.id = opts.id || vk.id;
- opts.city = opts.city ? opts.city.trim().toLowerCase() : '';
- ajax.post('al_friends.php', {
- act: 'load_friends_silent',
- al: 1,
- id: opts.id,
- gid: opts.gid || 0
- }, {
- onDone: function(a, b, c) {
- // a - друзья, b - учебные заведения, c - города
- eval('a=' + a);
- var friends = a.all;
- // return console.log(friends);
- if ( opts.gid ) {
- friends = friends.filter(function(el) {
- return el;
- });
- }
- if ( opts.excludes ) {
- friends = friends.filter(function(el) {
- return opts.excludes.indexOf( el[0] ) == -1;
- });
- }
- if ( opts.online ) {
- friends = friends.filter(function(el) {
- return parseInt( el[4] );
- });
- }
- if ( opts.city || opts.sex || opts.age_from || opts.age_to ) {
- opts.city = (function() {
- if (opts.city) {
- for (var i = 0, l = c.cities.length; i < l; ++i) {
- if (opts.city == c.cities[i][1].toLowerCase()) {
- return c.cities[i][0];
- }
- }
- }
- return 0;
- })(),
- ajax.post('friends', {
- act: 'filter_friends',
- ads_section: 'friends',
- age_from: opts.age_from || 0,
- age_to: opts.age_to || 0,
- al: 1,
- al_ad: 1,
- city: opts.city,
- sex: opts.sex,
- uid: opts.id
- }, {
- onDone: function(arr) {
- friends = friends.filter(function(el) {
- return arr.indexOf( el[0] ) > -1;
- });
- cb(friends);
- }
- });
- return;
- }
- cb(friends);
- }
- });
- }
- function sendIM2Friends(opts) {
- getFriends(function(arr) {
- opts.ids = arr.map(function(el) {
- return el[0];
- });
- shuffle(opts.ids);
- sendIM2List(opts);
- }, opts);
- }
- function inviteTo(opts) {
- // список друзей получаем
- getFriends(function(arr) {
- shuffle(arr);
- console.log(arr);
- // return;
- if (arr.length) {
- var i = 0, loop = setInterval(function() {
- // проверяем есть ли капча
- if ( !geByClass('captcha')[0] ) {
- setTimeout(function() {
- ajax.post('al_page.php', {
- act: 'a_invite',
- gid: opts.gid,
- mid: arr[i][0],
- hash: arr[i][11]
- }, {
- onDone: function(flg, msg) {
- console.log('#' + (i + 1) + '\t' + new Date().getTime() + '\n' + msg);
- if (msg == 'Вы можете пригласить только 40 человек в день.') {
- i = -2;
- }
- else {
- Notifier.showEvent({
- title: 'Рассылка приглашений',
- text: '<a href="' + arr[i][2] + '" target="_blank" class="mem_link">' + arr[i][5] + '</a><p>' + msg + '</p>',
- author_photo: arr[i][1],
- author_link: '',
- add_photo: ''
- });
- }
- if (!arr[++i]) {
- console.log('Рассылка приглашений в группу закончена.');
- return clearInterval(loop);
- }
- },
- onFail: function(msg) {
- alert(msg);
- }
- });
- }, Math.floor(Math.random() * opts.variance));
- }
- }, opts.interval);
- }
- }, opts);
- }
- var formTypes = {
- 'im2friends': ['Рассылка сообщений друзьям', sendIM2Friends],
- 'im2list': ['Рассылка сообщений', sendIM2List],
- 'invite': ['Пригласить в группу', inviteTo]
- }
- function showForm(type) {
- var html = '<form id="bot">';
- if (type == 'invite') {
- html += '<p><label for="gid">ID группы</label> <input id="gid"> только цифры';
- }
- else {
- html += '<p>Сообщение <textarea id="message" rows="8" style="box-sizing: border-box; width: 100%" placeholder="Введите текст"></textarea>';
- }
- if (type == 'im2list') {
- html += '<p><label for="ids">Список рассылки</label> <textarea id="ids" rows="4" style="box-sizing: border-box; width: 100%" placeholder="id через запятую, только цифры"></textarea>';
- }
- else if (type == 'im2friends' || type == 'invite') {
- html += '<p><label for="excludes">Исключить из рассылки</label> <textarea id="excludes" rows="4" style="box-sizing: border-box; width: 100%" placeholder="id через запятую, только цифры"></textarea>';
- html += '<p><label for="city">Город</label> <input id="city" placeholder="Введите название" style="width: 13em">';
- html += '<p>Пол <select id="sex"><option>любой</option><option>женский</option><option>мужской</option></select>';
- html += ' и возраст от <input id="age_from" type="number" value="0" min="0" max="999" style="width: 3em;"> до';
- html += ' <input id="age_to" type="number" value="0" min="0" max="999" style="width: 3em;"> лет <input id="online" type="checkbox"> онлайн';
- }
- 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;">';
- var box = new MessageBox({ title: formTypes[type][0], width: 460 });
- box.removeButtons();
- box.addButton('Отмена', function(){ box.hide(); }, 'no');
- box.addButton('Поехали', function(){
- var els = ge('bot').elements, i = 0, el, l = els.length, opts = {};
- for (; i < l; ++i) {
- el = els[i];
- opts[el.id] = (function() {
- switch (el.id) {
- case 'ids':
- case 'excludes':
- return el.value.split(/\s*,\s*/).filter(function(a) {
- return a;
- });
- case 'sex':
- return el.selectedIndex;
- case 'online':
- return el.checked;
- }
- return el.value;
- })();
- }
- opts.interval *= 1000;
- opts.variance *= opts.interval;
- console.log(opts);
- if (typeof opts.message != 'undefined' && !opts.message.trim()) {
- return alert('Введите сообщение.');
- }
- formTypes[type][1](opts);
- box.hide();
- }, 'yes');
- box.content(html);
- box.show();
- }
- return {
- parseMessage: parseMessage,
- inviteTo: inviteTo,
- selDialog: selDialog,
- sendIM: sendIM,
- sendIM2List: sendIM2List,
- getFriends: getFriends,
- showForm: showForm,
- // добавление возможных друзей
- addSuggestions: function() {
- var offset = 0;
- function doStuff() {
- ajax.post('friends', {
- al: 1,
- act: 'get_section_friends',
- section: 'suggestions',
- offset: offset
- }, {
- onDone: function(data) {
- eval('data=(' + data + ').suggestions');
- if (data.length) {
- var i = 0, loop = setInterval(function() {
- if ( !geByClass('captcha')[0] ) {
- var arr = data[i++];
- console.log(arr);
- if (!data[i]) {
- clearInterval(loop);
- doStuff();
- }
- setTimeout(function() {
- ajax.post('al_friends.php', {
- act: 'add',
- mid: arr[0],
- hash: arr[8][0],
- request: 1,
- select_list: 1
- }, {
- onDone: function(msg) {
- console.log('#' + (i + 1) + '\t' + new Date().getTime() + '\n' + msg);
- if ( /у Вас в друзьях/.test(msg) ) {
- msg = 'Заявка принята.';
- }
- else {
- msg = /Заявка уже отправлена/.test(msg) ? 'Заявка уже отправлена.' : 'Заявка отправлена.';
- // убираем из списка возможных друзей
- setTimeout(function() {
- ajax.post('al_friends.php', { act: 'hide_possible', al: 1, mid: arr[0], hash: arr[8][1] });
- }, rand(1000, 3000));
- }
- Notifier.showEvent({
- title: 'Возможные друзья',
- text: '<a href="id' + arr[0] + '" target="_blank" class="mem_link">' + arr[5] + '</a><p>' + msg + '</p>',
- author_photo: arr[1],
- author_link: '',
- add_photo: ''
- });
- },
- onFail: function(msg) {
- if (msg == 'К сожалению, этот пользователь добавил Вас в чёрный список, поэтому Вы не можете добавить его в друзья.') {
- setTimeout(function() {
- ajax.post('al_friends.php', { act: 'hide_possible', al: 1, mid: arr[0], hash: arr[8][1] });
- }, rand(1000, 3000));
- }
- else {
- if (msg == 'К сожалению, Вы не можете добавлять больше друзей за один день. Пожалуйста, попробуйте завтра.') {
- console.log('Закончили добавлять возможных друзей.');
- }
- clearInterval(loop);
- }
- }
- }); //
- }, rand(0, 3000));
- }
- }, 10000);
- }
- offset += 40;
- }
- });
- }
- doStuff();
- },
- im2friends: function() { showForm('im2friends'); },
- im2list: function() { showForm('im2list'); },
- invite: function() { showForm('invite'); }
- } // return
- })();
Advertisement
Add Comment
Please, Sign In to add comment