gaber-elsayed

weekly joins JS

Apr 3rd, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. I'm using ENMAP btw for the weekly joins
  2. {
  3. CronJob
  4. } = require('cron'),
  5. Enmap = require('enmap')
  6.  
  7. client.join = new Enmap({name: "joins", autoFetch: true, fetchAll: true})
  8. const job = new CronJob('0 12 * * Sun', () => {
  9. client.joins.clear()
  10. }, null, true, 'America/Los_Angeles')
  11.  
  12. Index.js file ^^
  13.  
  14. guildMemberAdd event
  15.  
  16. client.joins.ensure(member.guild.id, {
  17. "monday": 0,
  18. "tuesday": 0,
  19. "wednesday": 0,
  20. "thursday": 0,
  21. "friday": 0,
  22. "saturday": 0,
  23. "sunday": 0,
  24. })
  25.  
  26. let days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  27. let dayName = days[new Date().getDay()].toLowerCase()
  28.  
  29. client.joins.inc(member.guild.id, dayName)
  30.  
  31.  
  32. Command file.js
  33. const guildJoins = client.joins.ensure(message.guild.id, {
  34. "monday": 0,
  35. "tuesday": 0,
  36. "wednesday": 0,
  37. "thursday": 0,
  38. "friday": 0,
  39. "saturday": 0,
  40. "sunday": 0,
  41. })
  42.  
  43. const chart = {
  44. type: 'line',
  45. data: {
  46. labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
  47. datasets: [{
  48. label: 'Joins',
  49. data: Object.values(guildJoins)
  50. }]
  51. }
  52. }
  53.  
  54. let enChart = encodeURIComponent(JSON.stringify(chart))
  55. const chartUrl = `https://quickchart.io/chart?c=${enChart}&backgroundColor=(rgb(47,%2049,%2054))`;
  56. message.channel.send(new Discord.MessageAttachment(chartUrl, "chart.png"))
Advertisement
Add Comment
Please, Sign In to add comment