UNPKG

detritus-client

Version:

A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.

129 lines (128 loc) 4.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuditLogOptions = exports.AuditLogChange = exports.AuditLog = void 0; const basecollection_1 = require("../collections/basecollection"); const baseset_1 = require("../collections/baseset"); const utils_1 = require("../utils"); const constants_1 = require("../constants"); const basestructure_1 = require("./basestructure"); const keysAuditLog = new baseset_1.BaseSet([ constants_1.DiscordKeys.ACTION_TYPE, constants_1.DiscordKeys.CHANGES, constants_1.DiscordKeys.GUILD_ID, constants_1.DiscordKeys.ID, constants_1.DiscordKeys.OPTIONS, constants_1.DiscordKeys.REASON, constants_1.DiscordKeys.TARGET, constants_1.DiscordKeys.TARGET_ID, constants_1.DiscordKeys.USER, constants_1.DiscordKeys.USER_ID, ]); /** * Guild Audit Log * @category Structure */ class AuditLog extends basestructure_1.BaseStructure { constructor(client, data, isClone) { super(client, undefined, isClone); this._uncloneable = true; this._keys = keysAuditLog; this.changes = new basecollection_1.BaseCollection(); this.id = ''; this.guildId = ''; this.merge(data); } get createdAt() { return new Date(this.createdAtUnix); } get createdAtUnix() { return utils_1.Snowflake.timestamp(this.id); } get guild() { return this.client.guilds.get(this.guildId) || null; } mergeValue(key, value) { if (value !== undefined) { switch (key) { case constants_1.DiscordKeys.CHANGES: { this.changes.clear(); for (let raw of value) { const change = new AuditLogChange(this, raw); this.changes.set(change.key, change); } } ; return; case constants_1.DiscordKeys.OPTIONS: { value = new AuditLogOptions(this, value); } ; break; } return super.mergeValue(key, value); } } } exports.AuditLog = AuditLog; const keysAuditLogChange = new baseset_1.BaseSet([ constants_1.DiscordKeys.KEY, constants_1.DiscordKeys.NEW_VALUE, constants_1.DiscordKeys.OLD_VALUE, ]); /** * Guild Audit Log Change, used in [[AuditLog]] * @category Structure */ class AuditLogChange extends basestructure_1.BaseStructure { constructor(log, data) { super(log.client, undefined, log._clone); this._uncloneable = true; this._keys = keysAuditLogChange; this.log = log; this.merge(data); Object.defineProperty(this, 'log', { enumerable: false, writable: false }); } } exports.AuditLogChange = AuditLogChange; const keysAuditLogOptions = new baseset_1.BaseSet([ constants_1.DiscordKeys.CHANNEL, constants_1.DiscordKeys.CHANNEL_ID, constants_1.DiscordKeys.COUNT, constants_1.DiscordKeys.DELETE_MEMBER_DAYS, constants_1.DiscordKeys.ID, constants_1.DiscordKeys.MEMBERS_REMOVED, constants_1.DiscordKeys.SUBTARGET, constants_1.DiscordKeys.TYPE, ]); /** * Guild Audit Log Options, used in [[AuditLog]] * @category Structure */ class AuditLogOptions extends basestructure_1.BaseStructure { constructor(log, data) { super(log.client, undefined, log._clone); this._uncloneable = true; this._keys = keysAuditLogOptions; this.log = log; this.merge(data); Object.defineProperty(this, 'log', { enumerable: false, writable: false }); } mergeValue(key, value) { if (value !== undefined) { switch (key) { case constants_1.DiscordKeys.COUNT: case constants_1.DiscordKeys.DELETE_MEMBER_DAYS: case constants_1.DiscordKeys.MEMBERS_REMOVED: { value = parseInt(value); } ; break; } return super.mergeValue(key, value); } } } exports.AuditLogOptions = AuditLogOptions;