Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. const evk = require('easyvk')
  5. const path = require('path')
  6.  
  7. const config = {
  8.   BOT_ID: 176316300,
  9.   START_MESSAGE: 'помощь'
  10. }
  11.  
  12. evk({
  13.   username: 'Аккаунт',
  14.   password: 'Пароль',
  15.   session_file: path.join(__dirname, '.vk')
  16. }).then(async vk => {
  17.  
  18.   let startDate = 0;
  19.   let timings = [];
  20.  
  21.   async function  reSend () {
  22.     return new Promise((resolve, reject) => {
  23.       vk.call('messages.send', {
  24.         peer_id: -config.BOT_ID,
  25.         message: config.START_MESSAGE
  26.       }).then(async () => {
  27.         startDate = new Date().getTime()
  28.  
  29.         if (timings.length < 10) {
  30.           console.log(Math.floor(timings.length/10 * 100) + '%')
  31.           setTimeout(() => {
  32.             reSend().then(resolve, reject)
  33.           }, 5000)
  34.         } else {
  35.           resolve(true)
  36.         }
  37.       })
  38.     })
  39.   }
  40.  
  41.   let {connection: user}  = await vk.longpoll.connect();
  42.  
  43.   user.on("message", (msg) => {
  44.    
  45.     if (msg[3] == -config.BOT_ID && !(msg[2] & 2)) {
  46.       timings.push(new Date().getTime() - startDate)
  47.     }
  48.  
  49.   });
  50.  
  51.   await reSend();
  52.  
  53.   console.log(timings.length)
  54.  
  55.   let sum = 0;
  56.   timings.forEach(t => {sum += t})
  57.   sum /= timings.length;
  58.  
  59.   console.log(sum)
  60. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement