Q
Q
quick_6_response2019-09-27 17:17:01
In contact with
quick_6_response, 2019-09-27 17:17:01

How to write the code for the group widget correctly?

There is a certain bot, you need to install a widget in it.
I can't understand the top sorting structure and the correct setting.
Here is the widget code:

async function updateWidget() {
  let tops = [] 
users.map(user=>{ 
if(user.balance < 4) { 
        top.push({id: user.id, uid: user.uid, tag: user.tag, balance: user.balance}) 
      }
     })
  
  tops.sort((a, b)=>{ 
return b.balance - a.balance 
}) 

  var script = {
    title: `Топ лучших игроков`, 
    head: [

    {
      text: 'Ник'
    },

    {
      text: 'Деньги1',
      align: 'right'
    },

    {
      text: 'Рейтинг',
      align: 'right'
    }
    ],
    body: []
  }

  for (let g = 0; g < 10; g++) { 
if (top.length > g) { 
          script.body.push([

          {
            icon_id: `id${tops[g].id}`,
            text: `${users[top[g].uid].tag}`,
            url: `vk.com/id${top[g].id}`
          },

          {
            text: `${utils.sp(users[top[g].uid].balance)}` 
          },

          {
            text: `${utils.sp(users[top[g].uid].balance)}`
          },
          ])
      } 
    }
    requests.post({url: 'https://api.vk.com/method/appWidgets.update', form:{
      v: '5.95', 
      type: 'table', 
      code: `return ${JSON.stringify(script)};`, 
      access_token: 'токен от виджета'
    }
  },
  function(err, resp, body) {
    console.log(body)
  })
  }
  updateWidget()
  setInterval(updateWidget, 60000)

Can you help with something?))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question