buddy

node MVC discord bot
Log | Files | Refs | README

GuildEmojisUpdate.js (928B)


      1 'use strict';
      2 
      3 const Action = require('./Action');
      4 
      5 class GuildEmojisUpdateAction extends Action {
      6   handle(data) {
      7     const guild = this.client.guilds.cache.get(data.guild_id);
      8     if (!guild || !guild.emojis) return;
      9 
     10     const deletions = new Map(guild.emojis.cache);
     11 
     12     for (const emoji of data.emojis) {
     13       // Determine type of emoji event
     14       const cachedEmoji = guild.emojis.cache.get(emoji.id);
     15       if (cachedEmoji) {
     16         deletions.delete(emoji.id);
     17         if (!cachedEmoji.equals(emoji)) {
     18           // Emoji updated
     19           this.client.actions.GuildEmojiUpdate.handle(cachedEmoji, emoji);
     20         }
     21       } else {
     22         // Emoji added
     23         this.client.actions.GuildEmojiCreate.handle(guild, emoji);
     24       }
     25     }
     26 
     27     for (const emoji of deletions.values()) {
     28       // Emoji deleted
     29       this.client.actions.GuildEmojiDelete.handle(emoji);
     30     }
     31   }
     32 }
     33 
     34 module.exports = GuildEmojisUpdateAction;