seyfert
Version:
The most advanced framework for discord bots
122 lines (121 loc) • 5.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationShorter = void 0;
const __1 = require("../..");
const client_1 = require("../../client");
const base_1 = require("./base");
class ApplicationShorter extends base_1.BaseShorter {
/**
* Lists the emojis for the application.
* @returns The emojis.
*/
async listEmojis(force = false) {
if (!force) {
const cached = (await this.client.cache.emojis?.values(this.client.applicationId));
if (cached?.length)
return cached;
}
const data = await this.client.proxy.applications(this.client.applicationId).emojis.get();
await this.client.cache.emojis?.set(__1.CacheFrom.Rest, data.items.map(e => [e.id, e]), this.client.applicationId);
return data.items.map(e => client_1.Transformers.ApplicationEmoji(this.client, e));
}
/**
* Gets an emoji for the application.
* @param emojiId The ID of the emoji.
* @returns The emoji.
*/
async getEmoji(emojiId, force = false) {
if (!force) {
const cached = (await this.client.cache.emojis?.get(emojiId));
if (cached)
return cached;
}
const data = await this.client.proxy.applications(this.client.applicationId).emojis(emojiId).get();
await this.client.cache.emojis?.set(__1.CacheFrom.Rest, data.id, this.client.applicationId, data);
return client_1.Transformers.ApplicationEmoji(this.client, data);
}
/**
* Creates a new emoji for the application.
* @param body.name The name of the emoji.
* @param body.image The [image data string](https://discord.com/developers/docs/reference#image-data) of the emoji.
* @returns The created emoji.
*/
async createEmoji(raw) {
const data = await this.client.proxy
.applications(this.client.applicationId)
.emojis.post({ body: { ...raw, image: await (0, __1.resolveImage)(raw.image) } });
await this.client.cache.emojis?.set(__1.CacheFrom.Rest, data.id, this.client.applicationId, data);
return client_1.Transformers.ApplicationEmoji(this.client, data);
}
/**
* Edits an emoji for the application.
* @param emojiId The ID of the emoji.
* @param body.name The new name of the emoji.
* @returns The edited emoji.
*/
async editEmoji(emojiId, body) {
const data = await this.client.proxy.applications(this.client.applicationId).emojis(emojiId).patch({ body });
await this.client.cache.emojis?.patch(__1.CacheFrom.Rest, emojiId, this.client.applicationId, data);
return client_1.Transformers.ApplicationEmoji(this.client, data);
}
/**
* Deletes an emoji for the application.
* @param emojiId The ID of the emoji.
*/
deleteEmoji(emojiId) {
return this.client.proxy.applications(this.client.applicationId).emojis(emojiId).delete();
}
/**
* Lists the entitlements for the application.
* @param [query] The query parameters.
*/
listEntitlements(query) {
return this.client.proxy
.applications(this.client.applicationId)
.entitlements.get({ query })
.then(et => et.map(e => client_1.Transformers.Entitlement(this.client, e)));
}
/**
* Consumes an entitlement for the application.
* @param entitlementId The ID of the entitlement.
*/
consumeEntitlement(entitlementId) {
return this.client.proxy.applications(this.client.applicationId).entitlements(entitlementId).consume.post();
}
/**
* Creates a test entitlement for the application.
* @param body The body of the request.
*/
createTestEntitlement(body) {
return this.client.proxy
.applications(this.client.applicationId)
.entitlements.post({ body })
.then(et => client_1.Transformers.Entitlement(this.client, et));
}
/**
* Deletes a test entitlement for the application.
* @param entitlementId The ID of the entitlement.
*/
deleteTestEntitlement(entitlementId) {
return this.client.proxy.applications(this.client.applicationId).entitlements(entitlementId).delete();
}
/**
* Lists the SKUs for the application.
* @returns The SKUs.
*/
listSKUs() {
return this.client.proxy.applications(this.client.applicationId).skus.get();
}
async fetch() {
const data = await this.client.proxy.applications('@me').get();
return client_1.Transformers.Application(this.client, data);
}
async edit(body) {
const data = await this.client.proxy.applications('@me').patch({ body });
return client_1.Transformers.Application(this.client, data);
}
getActivityInstance(instanceId) {
return this.client.proxy.applications(this.client.applicationId)['activity-instances'](instanceId).get();
}
}
exports.ApplicationShorter = ApplicationShorter;