ccprojects commited on
Commit
1835f3c
Β·
verified Β·
1 Parent(s): 755da99

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +9 -29
index.js CHANGED
@@ -1,7 +1,6 @@
1
  const express = require('express')
2
  const { WebhookClient, EmbedBuilder } = require('discord.js')
3
  const axios = require('axios')
4
- const { GoogleGenerativeAI } = require('@google/generative-ai')
5
 
6
  const app = express()
7
  const port = process.env.PORT || 7860
@@ -18,9 +17,6 @@ const webhook = new WebhookClient({
18
  url: 'https://discord.com/api/webhooks/1389959240340213910/eaxo0emjjL4XW6A1M8jAnyftIodvpUVYqmboYnSvqkq8BGaR6IGFFwnfcrhXTyWXiw0z'
19
  })
20
 
21
- const genAI = new GoogleGenerativeAI("AIzaSyACBopnf2eRynlRpaxHKBZ9x6XtD2U9tBo")
22
- const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" })
23
-
24
  const endVotenoti = false
25
 
26
  let messageRef = null
@@ -33,11 +29,11 @@ async function fetchVotes() {
33
  }
34
 
35
  function formatPlace(index) {
36
- const emoji = ['πŸ₯‡ 1st', 'πŸ₯ˆ 2nd', 'πŸ₯‰ 3rd', 'πŸ… 4th']
37
  return index < 4 ? emoji[index] : `${index + 1}th`
38
  }
39
 
40
- function createEmbed(data, analysis, ended) {
41
  const fields = data.map((item, index) => ({
42
  name: formatPlace(index),
43
  value: `**${item.levelname}**\nCreator: ${item.Creator}\nVotes: ${item.votes}`,
@@ -45,35 +41,16 @@ function createEmbed(data, analysis, ended) {
45
  }))
46
  const time = new Date().toLocaleString('en-US', { timeZone: 'Asia/Manila' })
47
  return new EmbedBuilder()
48
- .setTitle(ended ? 'πŸ“Š Final Vote Result' : 'πŸ“Š Live Vote Status for **Power Gauntlet**')
49
  .addFields(fields)
50
- .addFields({ name: 'πŸ“ AI Vote Report', value: analysis })
51
  .setColor(ended ? 0xff5555 : 0x00ffff)
52
  .setFooter({ text: `Updated the vote at ${time} | Today` })
53
  }
54
 
55
- async function analyzeVotes(currentVotes) {
56
- const changes = currentVotes.map(item => {
57
- const prev = previousVotes[item.levelname] || 0
58
- const diff = item.votes - prev
59
- return `${item.levelname} by ${item.Creator}: ${item.votes} votes (${diff >= 0 ? '+' : ''}${diff})`
60
- }).join('\n')
61
- const prompt = `You are a voting analyst. Here's the vote update:\n\n${changes}\n\nSummarize what happened in this update.`
62
- const result = await model.generateContent({ contents: [{ role: 'user', parts: [{ text: prompt }] }] })
63
- const response = await result.response
64
- return response.text().trim()
65
- }
66
-
67
  async function updateVotes() {
68
  const data = await fetchVotes()
69
- const currentVotes = data.map(item => ({
70
- ...item,
71
- previous: previousVotes[item.levelname] || 0,
72
- diff: item.votes - (previousVotes[item.levelname] || 0)
73
- }))
74
- const analysis = await analyzeVotes(currentVotes)
75
- const embed = createEmbed(currentVotes, analysis, endVotenoti)
76
  data.forEach(item => previousVotes[item.levelname] = item.votes)
 
77
 
78
  if (endVotenoti) {
79
  if (!messageSent) {
@@ -86,11 +63,14 @@ async function updateVotes() {
86
  messageRef = sent
87
  setInterval(updateVotes, 120000)
88
  } else {
89
- await webhook.editMessage(messageRef.id, { content: 'The vote status', embeds: [embed] })
 
 
 
90
  }
91
  }
92
 
93
- console.log(`[${new Date().toLocaleTimeString('en-US', { hour12: false })}] Updated votes and AI analysis sent.`)
94
  }
95
 
96
  updateVotes()
 
1
  const express = require('express')
2
  const { WebhookClient, EmbedBuilder } = require('discord.js')
3
  const axios = require('axios')
 
4
 
5
  const app = express()
6
  const port = process.env.PORT || 7860
 
17
  url: 'https://discord.com/api/webhooks/1389959240340213910/eaxo0emjjL4XW6A1M8jAnyftIodvpUVYqmboYnSvqkq8BGaR6IGFFwnfcrhXTyWXiw0z'
18
  })
19
 
 
 
 
20
  const endVotenoti = false
21
 
22
  let messageRef = null
 
29
  }
30
 
31
  function formatPlace(index) {
32
+ const emoji = ['<:1stplace:1389968087670980748> 1st', '<:2ndplace:1389967997149647010> 2nd', '<:3rdplace:1389968298569109565> 3rd', '<:4thplace:1389968392504610916> 4th']
33
  return index < 4 ? emoji[index] : `${index + 1}th`
34
  }
35
 
36
+ function createEmbed(data, ended) {
37
  const fields = data.map((item, index) => ({
38
  name: formatPlace(index),
39
  value: `**${item.levelname}**\nCreator: ${item.Creator}\nVotes: ${item.votes}`,
 
41
  }))
42
  const time = new Date().toLocaleString('en-US', { timeZone: 'Asia/Manila' })
43
  return new EmbedBuilder()
44
+ .setTitle(ended ? 'πŸ“Š Final Vote Result' : '<:infolevel:1373653092758982687> Live Vote Status for **Power Gauntlet**')
45
  .addFields(fields)
 
46
  .setColor(ended ? 0xff5555 : 0x00ffff)
47
  .setFooter({ text: `Updated the vote at ${time} | Today` })
48
  }
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
  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()