buddy

node MVC discord bot
Log | Files | Refs | README

UserUpdate.js (804B)


      1 'use strict';
      2 
      3 const Action = require('./Action');
      4 const { Events } = require('../../util/Constants');
      5 
      6 class UserUpdateAction extends Action {
      7   handle(data) {
      8     const client = this.client;
      9 
     10     const newUser = client.users.cache.get(data.id);
     11     const oldUser = newUser._update(data);
     12 
     13     if (!oldUser.equals(newUser)) {
     14       /**
     15        * Emitted whenever a user's details (e.g. username) are changed.
     16        * @event Client#userUpdate
     17        * @param {User} oldUser The user before the update
     18        * @param {User} newUser The user after the update
     19        */
     20       client.emit(Events.USER_UPDATE, oldUser, newUser);
     21       return {
     22         old: oldUser,
     23         updated: newUser,
     24       };
     25     }
     26 
     27     return {
     28       old: null,
     29       updated: null,
     30     };
     31   }
     32 }
     33 
     34 module.exports = UserUpdateAction;