ccprojects commited on
Commit
12a41ce
·
verified ·
1 Parent(s): f5cfcf0

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +8 -6
index.js CHANGED
@@ -49,8 +49,13 @@ function createEmbed(data, ended) {
49
 
50
  async function updateVotes() {
51
  const data = await fetchVotes()
 
 
 
 
 
 
52
  data.forEach(item => previousVotes[item.levelname] = item.votes)
53
- const embed = createEmbed(data, endVotenoti)
54
 
55
  if (endVotenoti) {
56
  if (!messageSent) {
@@ -63,14 +68,11 @@ async function updateVotes() {
63
  messageRef = sent
64
  setInterval(updateVotes, 120000)
65
  } else {
66
- const fetched = await webhook.fetchMessage(messageRef.id)
67
- if (fetched.reactions.cache.size === 0) {
68
- await webhook.editMessage(messageRef.id, { content: 'The vote status', embeds: [embed] })
69
- }
70
  }
71
  }
72
 
73
- console.log(`[${new Date().toLocaleTimeString('en-US', { hour12: false })}] Updated vote status`)
74
  }
75
 
76
  updateVotes()
 
49
 
50
  async function updateVotes() {
51
  const data = await fetchVotes()
52
+ const currentVotes = data.map(item => ({
53
+ ...item,
54
+ previous: previousVotes[item.levelname] || 0,
55
+ diff: item.votes - (previousVotes[item.levelname] || 0)
56
+ }))
57
+ const embed = createEmbed(currentVotes, endVotenoti)
58
  data.forEach(item => previousVotes[item.levelname] = item.votes)
 
59
 
60
  if (endVotenoti) {
61
  if (!messageSent) {
 
68
  messageRef = sent
69
  setInterval(updateVotes, 120000)
70
  } else {
71
+ await webhook.editMessage(messageRef.id, { content: 'The vote status', embeds: [embed] })
 
 
 
72
  }
73
  }
74
 
75
+ console.log(`[${new Date().toLocaleTimeString('en-US', { hour12: false })}] Vote updated.`)
76
  }
77
 
78
  updateVotes()