Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. bot.on('messageReactionAdd', async (reaction, user) => {
  2. const message = reaction.message;
  3. if (reaction.emoji.name !== '⭐') return;
  4.  
  5. if (message.author.id === user.id) return message.channel.send(`${user}, you cannot star your own messages.`);
  6. if (message.author.bot) return message.channel.send(`${user}, you cannot star bot messages.`);
  7.  
  8. const starChannel = message.guild.channels.find(channel => channel.name == 'starboard')
  9. if (!starChannel) return message.channel.send(`It appears that you do not have a starboard channel.`);
  10.  
  11. const fetch = await starChannel.fetchMessages({ limit: 100 });
  12. const stars = fetch.find(m => m.embeds[0].footer.text.startsWith('⭐') && m.embeds[0].footer.text.endsWith(message.id));
  13.  
  14.  
  15. if (stars) {
  16. const star = /^\⭐\s([0-9]{1,3})\s\|\s([0-9]{17,20})/.exec(stars.embeds[0].footer.text);
  17. const foundStar = stars.embeds[0];
  18.  
  19. const image = message.attachments.size > 0 ? await this.extension(reaction, message.attachments.array()[0].url) : '';
  20. const embed = new RichEmbed()
  21. .setColor(foundStar.color)
  22. .setDescription(foundStar.description)
  23. .setAuthor(message.author.tag, message.author.displayAvatarURL)
  24. .setTimestamp()
  25. .setFooter(`⭐ ${parseInt(star[1])+1} | ${message.id}`)
  26. .setImage(image);
  27. const starMsg = await starChannel.fetchMessage(stars.id);
  28. await starMsg.edit({ embed });
  29. }
  30.  
  31. if (!stars) {
  32. const image = message.attachments.size > 0 ? await this.extension(reaction, message.attachments.array()[0].url) : '';
  33.  
  34. if (image === '' && message.cleanContent.length < 1) return message.channel.send(`${user}, you cannot star an empty message.`);
  35. const embed = new RichEmbed()
  36. .setColor(15844367)
  37. .setDescription(message.cleanContent)
  38. .setAuthor(message.author.tag, message.author.displayAvatarURL)
  39. .setTimestamp(new Date())
  40. .setFooter(`⭐ 1 | ${message.id}`)
  41. .setImage(image);
  42. await starChannel.send({ embed });
  43. }
  44.  
  45. extension(reaction, attachment)
  46. const imageLink = attachment.split('.');
  47. const typeOfImage = imageLink[imageLink.length - 1];
  48. const image = /(jpg|jpeg|png|gif)/gi.test(typeOfImage);
  49. if (!image) return '';
  50. return attachment;
  51.  
  52.  
  53. })
  54.  
  55. bot.on('messageReactionRemove', async (reaction, user) => {
  56. const message = reaction.message;
  57. if (message.author.id === user.id) return;
  58. if (reaction.emoji.name !== '⭐') return;
  59.  
  60. const starChannel = message.guild.channels.find(channel => channel.name == 'starboard')
  61. if (!starChannel) return message.channel.send(`It appears that you do not have a starboard channel.`);
  62.  
  63. const fetchedMessages = await starChannel.fetchMessages({ limit: 100 });
  64. const stars = fetchedMessages.find(m => m.embeds[0].footer.text.startsWith('⭐') && m.embeds[0].footer.text.endsWith(reaction.message.id));
  65. if (stars) {
  66. const star = /^\⭐\s([0-9]{1,3})\s\|\s([0-9]{17,20})/.exec(stars.embeds[0].footer.text);
  67. const foundStar = stars.embeds[0];
  68. const image = message.attachments.size > 0 ? await this.extension(reaction, message.attachments.array()[0].url) : '';
  69. const embed = new RichEmbed()
  70. .setColor(foundStar.color)
  71. .setDescription(foundStar.description)
  72. .setAuthor(message.author.tag, message.author.displayAvatarURL)
  73. .setTimestamp()
  74. .setFooter(`⭐ ${parseInt(star[1])-1} | ${message.id}`)
  75. .setImage(image);
  76. const starMsg = await starChannel.fetchMessage(stars.id);
  77. await starMsg.edit({ embed });
  78. if(parseInt(star[1]) - 1 == 0) return starMsg.delete(1000);
  79. }
  80.  
  81. extension(reaction, attachment)
  82. const imageLink = attachment.split('.');
  83. const typeOfImage = imageLink[imageLink.length - 1];
  84. const image = /(jpg|jpeg|png|gif)/gi.test(typeOfImage);
  85. if (!image) return '';
  86. return attachment;
  87.  
  88.  
  89. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement