buddy

node MVC discord bot
Log | Files | Refs | README

ChannelUpdate.js (905B)


      1 'use strict';
      2 
      3 const Action = require('./Action');
      4 const Channel = require('../../structures/Channel');
      5 const { ChannelTypes } = require('../../util/Constants');
      6 
      7 class ChannelUpdateAction extends Action {
      8   handle(data) {
      9     const client = this.client;
     10 
     11     let channel = client.channels.cache.get(data.id);
     12     if (channel) {
     13       const old = channel._update(data);
     14 
     15       if (ChannelTypes[channel.type.toUpperCase()] !== data.type) {
     16         const newChannel = Channel.create(this.client, data, channel.guild);
     17         for (const [id, message] of channel.messages.cache) newChannel.messages.cache.set(id, message);
     18         newChannel._typing = new Map(channel._typing);
     19         channel = newChannel;
     20         this.client.channels.cache.set(channel.id, channel);
     21       }
     22 
     23       return {
     24         old,
     25         updated: channel,
     26       };
     27     }
     28 
     29     return {};
     30   }
     31 }
     32 
     33 module.exports = ChannelUpdateAction;