fix: some shorters doesn't return structs (#183)

This commit is contained in:
Marcos Susaña 2024-04-15 14:48:44 -04:00 committed by GitHub
parent c573ca9909
commit 38ef5d91cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 68 additions and 29 deletions

View File

@ -19,6 +19,7 @@ import {
GuildMember, GuildMember,
Sticker, Sticker,
type CreateStickerBodyRequest, type CreateStickerBodyRequest,
AutoModerationRule,
} from '../../structures'; } from '../../structures';
import channelFrom from '../../structures/channels'; import channelFrom from '../../structures/channels';
import { BaseShorter } from './base'; import { BaseShorter } from './base';
@ -197,7 +198,11 @@ export class GuildShorter extends BaseShorter {
* @param guildId The ID of the guild. * @param guildId The ID of the guild.
* @returns A Promise that resolves to an array of auto-moderation rules. * @returns A Promise that resolves to an array of auto-moderation rules.
*/ */
list: (guildId: string) => this.client.proxy.guilds(guildId)['auto-moderation'].rules.get(), list: (guildId: string) =>
this.client.proxy
.guilds(guildId)
['auto-moderation'].rules.get()
.then(rules => rules.map(rule => new AutoModerationRule(this.client, rule))),
/** /**
* Creates a new auto-moderation rule in the guild. * Creates a new auto-moderation rule in the guild.
@ -206,7 +211,10 @@ export class GuildShorter extends BaseShorter {
* @returns A Promise that resolves to the created auto-moderation rule. * @returns A Promise that resolves to the created auto-moderation rule.
*/ */
create: (guildId: string, body: RESTPostAPIAutoModerationRuleJSONBody) => create: (guildId: string, body: RESTPostAPIAutoModerationRuleJSONBody) =>
this.client.proxy.guilds(guildId)['auto-moderation'].rules.post({ body }), this.client.proxy
.guilds(guildId)
['auto-moderation'].rules.post({ body })
.then(rule => new AutoModerationRule(this.client, rule)),
/** /**
* Deletes an auto-moderation rule from the guild. * Deletes an auto-moderation rule from the guild.
@ -226,7 +234,11 @@ export class GuildShorter extends BaseShorter {
* @returns A Promise that resolves to the fetched auto-moderation rule. * @returns A Promise that resolves to the fetched auto-moderation rule.
*/ */
fetch: (guildId: string, ruleId: string) => { fetch: (guildId: string, ruleId: string) => {
return this.client.proxy.guilds(guildId)['auto-moderation'].rules(ruleId).get(); return this.client.proxy
.guilds(guildId)
['auto-moderation'].rules(ruleId)
.get()
.then(rule => new AutoModerationRule(this.client, rule));
}, },
/** /**
@ -243,7 +255,11 @@ export class GuildShorter extends BaseShorter {
body: ObjectToLower<RESTPatchAPIAutoModerationRuleJSONBody>, body: ObjectToLower<RESTPatchAPIAutoModerationRuleJSONBody>,
reason?: string, reason?: string,
) => { ) => {
return this.client.proxy.guilds(guildId)['auto-moderation'].rules(ruleId).patch({ body, reason }); return this.client.proxy
.guilds(guildId)
['auto-moderation'].rules(ruleId)
.patch({ body, reason })
.then(rule => new AutoModerationRule(this.client, rule));
}, },
}; };
} }

View File

@ -15,11 +15,10 @@ export class RoleShorter extends BaseShorter {
* @param reason The reason for creating the role. * @param reason The reason for creating the role.
* @returns A Promise that resolves when the role is created. * @returns A Promise that resolves when the role is created.
*/ */
create(guildId: string, body: RESTPostAPIGuildRoleJSONBody, reason?: string) { async create(guildId: string, body: RESTPostAPIGuildRoleJSONBody, reason?: string) {
return this.client.proxy const res = await this.client.proxy.guilds(guildId).roles.post({ body, reason });
.guilds(guildId) await this.client.cache.roles?.setIfNI('Guilds', res.id, guildId, res);
.roles.post({ body, reason }) return new GuildRole(this.client, res, guildId);
.then(res => this.client.cache.roles?.setIfNI('Guilds', res.id, guildId, res));
} }
/** /**
@ -52,12 +51,10 @@ export class RoleShorter extends BaseShorter {
* @param reason The reason for editing the role. * @param reason The reason for editing the role.
* @returns A Promise that resolves when the role is edited. * @returns A Promise that resolves when the role is edited.
*/ */
edit(guildId: string, roleId: string, body: RESTPatchAPIGuildRoleJSONBody, reason?: string) { async edit(guildId: string, roleId: string, body: RESTPatchAPIGuildRoleJSONBody, reason?: string) {
return this.client.proxy const res = await this.client.proxy.guilds(guildId).roles(roleId).patch({ body, reason });
.guilds(guildId) await this.client.cache.roles?.setIfNI('Guilds', roleId, guildId, res);
.roles(roleId) return new GuildRole(this.client, res, guildId);
.patch({ body, reason })
.then(res => this.client.cache.roles?.setIfNI('Guilds', roleId, guildId, res));
} }
/** /**
@ -67,12 +64,10 @@ export class RoleShorter extends BaseShorter {
* @param reason The reason for deleting the role. * @param reason The reason for deleting the role.
* @returns A Promise that resolves when the role is deleted. * @returns A Promise that resolves when the role is deleted.
*/ */
delete(guildId: string, roleId: string, reason?: string) { async delete(guildId: string, roleId: string, reason?: string) {
return this.client.proxy const res = await this.client.proxy.guilds(guildId).roles(roleId).delete({ reason });
.guilds(guildId) this.client.cache.roles?.removeIfNI('Guilds', roleId, guildId);
.roles(roleId) return new GuildRole(this.client, res, guildId);
.delete({ reason })
.then(() => this.client.cache.roles?.removeIfNI('Guilds', roleId, guildId));
} }
/** /**

View File

@ -1,28 +1,50 @@
import type { RESTPatchAPIGuildTemplateJSONBody, RESTPostAPIGuildTemplatesJSONBody } from 'discord-api-types/v10'; import type { RESTPatchAPIGuildTemplateJSONBody, RESTPostAPIGuildTemplatesJSONBody } from 'discord-api-types/v10';
import { BaseShorter } from './base'; import { BaseShorter } from './base';
import { GuildTemplate } from '../..';
export class TemplateShorter extends BaseShorter { export class TemplateShorter extends BaseShorter {
fetch(code: string) { fetch(code: string) {
return this.client.proxy.guilds.templates(code).get(); return this.client.proxy.guilds
.templates(code)
.get()
.then(template => new GuildTemplate(this.client, template));
} }
list(guildId: string) { list(guildId: string) {
return this.client.proxy.guilds(guildId).templates.get(); return this.client.proxy
.guilds(guildId)
.templates.get()
.then(list => list.map(template => new GuildTemplate(this.client, template)));
} }
create(guildId: string, body: RESTPostAPIGuildTemplatesJSONBody) { create(guildId: string, body: RESTPostAPIGuildTemplatesJSONBody) {
return this.client.proxy.guilds(guildId).templates.post({ body }); return this.client.proxy
.guilds(guildId)
.templates.post({ body })
.then(template => new GuildTemplate(this.client, template));
} }
sync(guildId: string, code: string) { sync(guildId: string, code: string) {
return this.client.proxy.guilds(guildId).templates(code).put({}); return this.client.proxy
.guilds(guildId)
.templates(code)
.put({})
.then(template => new GuildTemplate(this.client, template));
} }
edit(guildId: string, code: string, body: RESTPatchAPIGuildTemplateJSONBody) { edit(guildId: string, code: string, body: RESTPatchAPIGuildTemplateJSONBody) {
return this.client.proxy.guilds(guildId).templates(code).patch({ body }); return this.client.proxy
.guilds(guildId)
.templates(code)
.patch({ body })
.then(template => new GuildTemplate(this.client, template));
} }
delete(guildId: string, code: string) { delete(guildId: string, code: string) {
return this.client.proxy.guilds(guildId).templates(code).delete(); return this.client.proxy
.guilds(guildId)
.templates(code)
.delete()
.then(template => new GuildTemplate(this.client, template));
} }
} }

View File

@ -47,9 +47,15 @@ export class WebhookShorter extends BaseShorter {
options: WebhookShorterOptionalParams, options: WebhookShorterOptionalParams,
) { ) {
if (options.token) { if (options.token) {
return this.client.proxy.webhooks(webhookId)(options.token).patch({ body, reason: options.reason, auth: false }); return this.client.proxy
.webhooks(webhookId)(options.token)
.patch({ body, reason: options.reason, auth: false })
.then(webhook => new Webhook(this.client, webhook));
} }
return this.client.proxy.webhooks(webhookId).patch({ body, reason: options.reason }); return this.client.proxy
.webhooks(webhookId)
.patch({ body, reason: options.reason })
.then(webhook => new Webhook(this.client, webhook));
} }
/** /**