SHARE
TWEET

Untitled

a guest Jul 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { VK, Keyboard } = new require('vk-io');
  2. const vk = new VK();
  3. const token_user = new VK();
  4. const fs = require("fs");
  5. const commands = [];
  6. const request = require('prequest');
  7. const { SessionManager } = require('@vk-io/session');
  8. const { SceneManager, StepScene } = require('@vk-io/scenes');
  9.  
  10. const utils = {
  11.     sp: (int) => {
  12.         int = int.toString();
  13.         return int.split('').reverse().join('').match(/[0-9]{1,3}/g).join('.').split('').reverse().join('');
  14.     },
  15.     kek: (int) => {
  16.         int = int.toString();
  17.         return int.split('').reverse().join('').match(/[0-9]{1,1}/g).join('.').split('').reverse().join('');
  18.     },
  19.     rn: (int, fixed) => {
  20.         if (int === null) return null;
  21.         if (int === 0) return '0';
  22.         fixed = (!fixed || fixed < 0) ? 0 : fixed;
  23.         let b = (int).toPrecision(2).split('e'),
  24.             k = b.length === 1 ? 0 : Math.floor(Math.min(b[1].slice(1), 14) / 3),
  25.             c = k < 1 ? int.toFixed(0 + fixed) : (int / Math.pow(10, k * 3) ).toFixed(1 + fixed),
  26.             d = c < 0 ? c : Math.abs(c),
  27.             e = d + ['', 'тыс', 'млн', 'млрд', 'трлн'][k];
  28.  
  29.             e = e.replace(/e/g, '');
  30.             e = e.replace(/\+/g, '');
  31.             e = e.replace(/Infinity/g, 'ДОХЕРА');
  32.  
  33.         return e;
  34.     },
  35.     gi: (int) => {
  36.         int = int.toString();
  37.  
  38.         let text = ``;
  39.         for (let i = 0; i < int.length; i++)
  40.         {
  41.             text += `${int[i]}&#8419;`;
  42.         }
  43.  
  44.         return text;
  45.     },
  46.     decl: (n, titles) => { return titles[(n % 10 === 1 && n % 100 !== 11) ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] },
  47.     random: (x, y) => {
  48.         return y ? Math.round(Math.random() * (y - x)) + x : Math.round(Math.random() * x);
  49.     },
  50.     pick: (array) => {
  51.         return array[utils.random(array.length - 1)];
  52.     }
  53. }
  54.  
  55. let users = require('./users.json');
  56. let buttons = [];
  57. let stats = {
  58.     messages: {
  59.         inbox: 0,
  60.         outbox: 0
  61.     },
  62.     new_users: 0,
  63.     bot_start: Date.now()
  64. }
  65.  
  66.  
  67. async function saveUsers()
  68. {
  69.     require('fs').writeFileSync('./users.json', JSON.stringify(users, null, '\t'));
  70.     return true;
  71. }
  72.  
  73. vk.setOptions({ token: '1d56c84de9bce8aa152684c2f2f8b1093959bb7a3f4013574f96875067c838275458e42e64caff91d8cc7', pollingGroupId: 182782568 });
  74. const { updates, snippets } = vk;
  75.  
  76. updates.startPolling();
  77. updates.on('message', async (message, context) => {
  78.     stats.messages.inbox += 1;
  79.     if(Number(message.senderId) <= 0) return;
  80.     if(/\[public\|(.*)\]/i.test(message.text)) message.text = message.text.replace(/\[public\|(.*)\]/ig, '').trim();
  81.  
  82.     if(!users.find(x=> x.id === message.senderId))
  83.     {
  84.         const [user_info] = await vk.api.users.get({ user_id: message.senderId });
  85.         const date = new Date();
  86.  
  87.         users.push({
  88.             id: message.senderId,
  89.             uid: users.length,
  90.             balance: 100,  
  91.             tag: user_info.first_name
  92.         });
  93.     }
  94.  
  95.     message.user = users.find(x=> x.id === message.senderId);
  96.     if(message.user.ban) return;
  97.  
  98.     const bot = (text, params) => {
  99.         return message.send(`${message.user.mention ? `@id${message.user.id} (${message.user.tag})` : `${message.user.tag}`}, ${text}`, params);
  100.     }
  101.  
  102.     const command = commands.find(x=> message.text);
  103.     if(!command) return;
  104.  
  105.  
  106.     message.args = message.text.match(command[0]);
  107.     await command[1](message, bot);
  108.  
  109.     console.log(`Пользователь ${utils.sp(message.user.uid)}: ${message.text}`)
  110. });
  111.  
  112. function getUnix() {
  113.     return Date.now();
  114. }
  115.  
  116. function unixStamp(stamp) {
  117.     let date = new Date(stamp),
  118.         year = date.getFullYear(),
  119.         month = date.getMonth() + 1,
  120.         day = date.getDate(),
  121.         hour = date.getHours() < 10 ? "0"+date.getHours() : date.getHours(),
  122.         mins = date.getMinutes() < 10 ? "0"+date.getMinutes() : date.getMinutes(),
  123.         secs = date.getSeconds() < 10 ? "0"+date.getSeconds() : date.getSeconds();
  124.  
  125.     return `${day}.${month}.${year}, ${hour}:${mins}:${secs}`;
  126. }
  127.  
  128. function unixStampLeft(stamp) {
  129.     stamp = stamp / 1000;
  130.  
  131.     let s = stamp % 60;
  132.     stamp = ( stamp - s ) / 60;
  133.  
  134.     let m = stamp % 60;
  135.     stamp = ( stamp - m ) / 60;
  136.  
  137.     let h = ( stamp ) % 24;
  138.     let d = ( stamp - h ) / 24;
  139.  
  140.     let text = ``;
  141.  
  142.     if(d > 0) text += Math.floor(d) + " д. ";
  143.     if(h > 0) text += Math.floor(h) + " ч. ";
  144.     if(m > 0) text += Math.floor(m) + " мин. ";
  145.     if(s > 0) text += Math.floor(s) + " с.";
  146.  
  147.     return text;
  148. }
  149.  
  150. const cmd = {
  151.     hear: (p, f) => {
  152.         commands.push([p, f]);
  153.     }
  154. }
  155.  
  156. const sessionManager = new SessionManager();
  157. const sceneManager = new SceneManager();
  158.  
  159. sceneManager.addScene(new StepScene('signup', [
  160.     (message) => {
  161.         if (message.scene.step.firstTime || !message.text) {
  162.             return message.send(`What\'s your name?`);
  163.         }
  164.  
  165.         message.scene.state.firstName = message.text;
  166.  
  167.         return message.scene.step.next();
  168.     },
  169.     (message) => {
  170.         if (message.scene.step.firstTime || !message.text) {
  171.             return message.send(`How old are you?`);
  172.         }
  173.  
  174.         message.scene.state.age = Number(message.text);
  175.  
  176.         return message.scene.step.next();
  177.     },
  178.     async (message) => {
  179.         const { firstName, age } = message.scene.state;
  180.  
  181.         await message.send(`👤 ${firstName} ${age} ages`);
  182.  
  183.         await message.scene.leave();
  184.     }
  185. ]));
  186.  
  187. updates.on('message', sessionManager.middleware);
  188. updates.on('message', sceneManager.middleware);
  189.  
  190. cmd.hear(/^(?:signupp)$/i, (context) => {
  191.     return context.scene.enter('signup');
  192. });
  193.  
  194. vk.updates.start().catch(console.error);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top