mirror of
https://github.com/danbulant/discord.js
synced 2026-06-18 22:21:17 +00:00
* Initial commit: add 5 initial managers - Base manager - GuildChannelManager - MessageManager - PresenceManager - Reaction Manager - Added LimitedCollection * Add GuildEmojiManager, various fixes * Modify some managers and add guildmembermanager * Initial integration * Delete old stores * Integration part two, removed LRUCollection - Most of the integration has been finished - TODO typings - Removed LRUCollection, needless sweeping * Typings + stuff i somehow missed in ChannelManager * LimitedCollection typings/ final changes * Various jsdoc and syntactical fixes, Removed Util.mixin() * tslint fix * Grammatical and logical changes * Delete temporary file placed by mistake * Grammatical changes * Add missing type * Update jsdoc examples * fix: ChannelManager#remove should call cache#delete not cache#remove * fix recursive require * Fix missed cache in util * fix: more missed cache * Remove accidental _fetchMany change from #3645 * fix: use .cache.delete() over .remove() * fix: missing cache in ReactionCollector * fix: missed cache in client * fix: members is a collection not a manager Co-Authored-By: Sugden <28943913+NotSugden@users.noreply.github.com> * fix: various docs and cache fixes * fix: missed cache * fix: missing _roles * Final testing and debugging * LimitedCollection: return the Collection instead of undefined on .set * Add cache to BaseManager in typings * Commit fixes i forgot to stage yesterday * Update invite events * Account for new commit * fix: MessageReactionRemoveAll should call .cache.clear() * fix: add .cache at various places, correct return type * docs: remove mentions of 'store' * Add extra documented properties to typings Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
158 lines
3.6 KiB
JavaScript
158 lines
3.6 KiB
JavaScript
'use strict';
|
|
|
|
const Base = require('./Base');
|
|
|
|
/**
|
|
* The information account for an integration
|
|
* @typedef {Object} IntegrationAccount
|
|
* @property {string} id The id of the account
|
|
* @property {string} name The name of the account
|
|
*/
|
|
|
|
/**
|
|
* Represents a guild integration.
|
|
*/
|
|
class Integration extends Base {
|
|
constructor(client, data, guild) {
|
|
super(client);
|
|
|
|
/**
|
|
* The guild this integration belongs to
|
|
* @type {Guild}
|
|
*/
|
|
this.guild = guild;
|
|
|
|
/**
|
|
* The integration id
|
|
* @type {Snowflake}
|
|
*/
|
|
this.id = data.id;
|
|
|
|
/**
|
|
* The integration name
|
|
* @type {string}
|
|
*/
|
|
this.name = data.name;
|
|
|
|
/**
|
|
* The integration type (twitch, youtube, etc)
|
|
* @type {string}
|
|
*/
|
|
this.type = data.type;
|
|
|
|
/**
|
|
* Whether this integration is enabled
|
|
* @type {boolean}
|
|
*/
|
|
this.enabled = data.enabled;
|
|
|
|
/**
|
|
* Whether this integration is syncing
|
|
* @type {boolean}
|
|
*/
|
|
this.syncing = data.syncing;
|
|
|
|
/**
|
|
* The role that this integration uses for subscribers
|
|
* @type {Role}
|
|
*/
|
|
this.role = this.guild.roles.cache.get(data.role_id);
|
|
|
|
/**
|
|
* The user for this integration
|
|
* @type {User}
|
|
*/
|
|
this.user = this.client.users.add(data.user);
|
|
|
|
/**
|
|
* The account integration information
|
|
* @type {IntegrationAccount}
|
|
*/
|
|
this.account = data.account;
|
|
|
|
/**
|
|
* The last time this integration was last synced
|
|
* @type {number}
|
|
*/
|
|
this.syncedAt = data.synced_at;
|
|
this._patch(data);
|
|
}
|
|
|
|
_patch(data) {
|
|
/**
|
|
* The behavior of expiring subscribers
|
|
* @type {number}
|
|
*/
|
|
this.expireBehavior = data.expire_behavior;
|
|
|
|
/**
|
|
* The grace period before expiring subscribers
|
|
* @type {number}
|
|
*/
|
|
this.expireGracePeriod = data.expire_grace_period;
|
|
}
|
|
|
|
/**
|
|
* Sync this integration
|
|
* @returns {Promise<Integration>}
|
|
*/
|
|
sync() {
|
|
this.syncing = true;
|
|
return this.client.api.guilds(this.guild.id).integrations(this.id).post()
|
|
.then(() => {
|
|
this.syncing = false;
|
|
this.syncedAt = Date.now();
|
|
return this;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* The data for editing an integration.
|
|
* @typedef {Object} IntegrationEditData
|
|
* @property {number} [expireBehavior] The new behaviour of expiring subscribers
|
|
* @property {number} [expireGracePeriod] The new grace period before expiring subscribers
|
|
*/
|
|
|
|
/**
|
|
* Edits this integration.
|
|
* @param {IntegrationEditData} data The data to edit this integration with
|
|
* @param {string} reason Reason for editing this integration
|
|
* @returns {Promise<Integration>}
|
|
*/
|
|
edit(data, reason) {
|
|
if ('expireBehavior' in data) {
|
|
data.expire_behavior = data.expireBehavior;
|
|
data.expireBehavior = null;
|
|
}
|
|
if ('expireGracePeriod' in data) {
|
|
data.expire_grace_period = data.expireGracePeriod;
|
|
data.expireGracePeriod = null;
|
|
}
|
|
// The option enable_emoticons is only available for Twitch at this moment
|
|
return this.client.api.guilds(this.guild.id).integrations(this.id).patch({ data, reason })
|
|
.then(() => {
|
|
this._patch(data);
|
|
return this;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Deletes this integration.
|
|
* @returns {Promise<Integration>}
|
|
* @param {string} [reason] Reason for deleting this integration
|
|
*/
|
|
delete(reason) {
|
|
return this.client.api.guilds(this.guild.id).integrations(this.id).delete({ reason })
|
|
.then(() => this);
|
|
}
|
|
|
|
toJSON() {
|
|
return super.toJSON({
|
|
role: 'roleID',
|
|
guild: 'guildID',
|
|
user: 'userID',
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = Integration;
|