gaber-elsayed

webhook

Sep 4th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. const Topgg = require(`@top-gg/sdk`)
  2. const api = new Topgg.Api(process.env["TOPGG_API_TOKEN"])
  3. const {WebhookClient} = require("discord.js")
  4. const hook = new WebhookClient(process.env["DISCORD_WEBHOOK_ID"], process.env["DISCORD_WEBHOOK_TOKEN"])
  5. const db = require("quick.db");
  6. const CronJob = require("cron").CronJob;
  7.  
  8. const express = require("express")
  9. const app = express()
  10. const webhook = new Topgg.Webhook(process.env["TOPGG_WEBHOOK_PASS"])
  11.  
  12. app.post("/dblwebhook", webhook.listener(vote => {
  13. if(!db.get("votes").includes(vote.user)) db.push("votes", vote.user)
  14. hook.send(`<@${vote.user}> just voted! Thank you for your support!`);
  15. }))
  16.  
  17. job = new CronJob("0 */5 * * * *", async function(){
  18. users = db.get("votes")
  19. newusers = [];
  20. for(let x = 0; x < users.length;x++){
  21. user = users[x]
  22. voted = await api.hasVoted(user)
  23. if(!voted){
  24. hook.send(`<@${user}> your vote for our bot expired.`)
  25. }else{
  26. newusers.push(user)
  27. }
  28. }
  29. db.set("votes", newusers)
  30. });
  31. job.start();
  32.  
  33. app.listen(3000)
Advertisement
Add Comment
Please, Sign In to add comment