Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. async function updateWidget() {
  2. console.log("Обновляю виджет...")
  3. var tops = []
  4. for (i=1;i<200000;i++) {
  5. if(acc.users[i]) {
  6. if(acc.users[i].level < 4 && acc.users[i].block_top == false) {
  7. tops.push({id: i, idvk: acc.users[i].id, lvl: acc.users[i].donate});
  8. }
  9. }
  10. }
  11. tops.sort(function(a, b) {
  12. if (b.lvl > a.lvl) return 1
  13. if (b.lvl < a.lvl) return -1
  14. return 0
  15. })
  16.  
  17. var script = {
  18. title: `Топ лучших игроков`,
  19. head: [
  20.  
  21. {
  22. text: 'Ник'
  23. },
  24.  
  25. {
  26. text: 'Деньги',
  27. align: 'right'
  28. },
  29.  
  30. {
  31. text: 'Снежинки❄️',
  32. align: 'right'
  33. }
  34. ],
  35. body: []
  36. }
  37.  
  38. for (var g = 0; g < 10; g++) {
  39. if (tops.length > g) {
  40. let ups = g;
  41. ups += 1;
  42. if(g <= 8) ups = `${ups}`
  43. if(g == 9) ups = `10`
  44. script.body.push([
  45.  
  46. {
  47. icon_id: `id${tops[g].idvk}`,
  48. text: `${acc.users[tops[g].id].prefix}`,
  49. url: `vk.com/id${tops[g].idvk}`
  50. },
  51.  
  52. {
  53. text: `${spaces(acc.users[tops[g].id].balance)}$`
  54. },
  55.  
  56. {
  57. text: `❄️${spaces(tops[g].lvl)}`
  58. },
  59. ])
  60. }
  61. }
  62. requests.post({url: 'https://api.vk.com/method/appWidgets.update', form:{
  63. v: '5.95',
  64. type: 'table',
  65. code: `return ${JSON.stringify(script)};`,
  66. access_token: '' // Специальный токен с уровнем доступа app_widgets
  67. }
  68. },
  69. function(err, resp, body) {
  70. console.log(body)
  71. }
  72. )
  73. console.log("Виджет обновлён!")
  74. }
  75. updateWidget()
  76. setInterval(updateWidget, 99999)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement