Skip to content

Commit

Permalink
chore: make requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Oct 14, 2022
1 parent 330334b commit f8c3dc3
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 195 deletions.
28 changes: 12 additions & 16 deletions packages/core/src/api/bot.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import type { REST } from '@discordjs/rest';
import { makeURLSearchParams } from '@discordjs/rest';
import type {
APIDMChannel,
APIPartialGuild,
APIUser,
RESTGetAPICurrentUserGuildsQuery,
RESTPatchAPICurrentUserJSONBody,
RESTPatchAPIGuildMemberJSONBody,
RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
import { makeURLSearchParams, type REST } from '@discordjs/rest';
import {
Routes,
type APIGuildMember,
type APIDMChannel,
type APIPartialGuild,
type APIUser,
type RESTGetAPICurrentUserGuildsQuery,
type RESTPatchAPICurrentUserJSONBody,
type RESTPatchAPIGuildMemberJSONBody,
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
} from 'discord-api-types/v10';
import { Routes, type APIGuildMember } from 'discord-api-types/v10';

export class BotsAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Returns the user object of the requester's account
Expand Down
47 changes: 16 additions & 31 deletions packages/core/src/api/channel.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
import type { REST } from '@discordjs/rest';
import { makeURLSearchParams } from '@discordjs/rest';
import type {
APIChannel,
APIFollowedChannel,
APIInvite,
APIMessage,
RESTGetAPIChannelUsersThreadsArchivedResult,
RESTPatchAPIChannelJSONBody,
RESTPostAPIChannelInviteJSONBody,
import { makeURLSearchParams, type REST } from '@discordjs/rest';
import {
Routes,
type APIChannel,
type APIFollowedChannel,
type APIInvite,
type APIMessage,
type RESTGetAPIChannelUsersThreadsArchivedResult,
type RESTPatchAPIChannelJSONBody,
type RESTPostAPIChannelInviteJSONBody,
type RESTGetAPIChannelMessagesQuery,
type RESTGetAPIChannelThreadsArchivedQuery,
} from 'discord-api-types/v10';
import { Routes } from 'discord-api-types/v10';

export interface GetChannelMessagesOptions {
after?: string;
around?: string;
before?: string;
limit?: number;
}

export interface FetchThreadsOptions {
before?: string;
limit?: number;
}

export class ChannelsAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Fetches a channel
Expand Down Expand Up @@ -66,7 +51,7 @@ export class ChannelsAPI {
* @param channelId - The id of the channel to fetch messages from
* @param options - The options to use when fetching messages
*/
public async messages(channelId: string, options?: GetChannelMessagesOptions) {
public async getMessages(channelId: string, options: RESTGetAPIChannelMessagesQuery = {}) {
return (await this.rest.get(Routes.channelMessages(channelId), {
query: makeURLSearchParams(options as Record<string, unknown>),
})) as APIMessage[];
Expand Down Expand Up @@ -155,7 +140,7 @@ export class ChannelsAPI {
public async getArchivedThreads(
channelId: string,
archivedStatus: 'private' | 'public',
options?: FetchThreadsOptions,
options: RESTGetAPIChannelThreadsArchivedQuery = {},
) {
return (await this.rest.get(Routes.channelThreads(channelId, archivedStatus), {
query: makeURLSearchParams(options as Record<string, unknown>),
Expand All @@ -168,7 +153,7 @@ export class ChannelsAPI {
* @param channelId - The id of the channel to fetch joined archived threads from
* @param options - The options to use when fetching joined archived threads
*/
public async getJoinedPrivateArchivedThreads(channelId: string, options: FetchThreadsOptions = {}) {
public async getJoinedPrivateArchivedThreads(channelId: string, options: RESTGetAPIChannelThreadsArchivedQuery = {}) {
return (await this.rest.get(Routes.channelJoinedArchivedThreads(channelId), {
query: makeURLSearchParams(options as Record<string, unknown>),
})) as RESTGetAPIChannelUsersThreadsArchivedResult;
Expand Down
109 changes: 52 additions & 57 deletions packages/core/src/api/guild.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,58 @@
/* eslint-disable jsdoc/check-param-names */
import type { Buffer } from 'node:buffer';
import type { REST } from '@discordjs/rest';
import { makeURLSearchParams } from '@discordjs/rest';
import type {
APIAuditLog,
APIBan,
APIChannel,
APIEmoji,
APIGuild,
APIGuildIntegration,
APIGuildMember,
APIGuildPreview,
APIGuildScheduledEvent,
APIGuildWelcomeScreen,
APIGuildWidget,
APIGuildWidgetSettings,
APIInvite,
APIRole,
APISticker,
APITemplate,
APIThreadChannel,
APIVoiceRegion,
GuildMFALevel,
GuildWidgetStyle,
RESTGetAPIAuditLogQuery,
RESTGetAPIGuildMembersQuery,
RESTGetAPIGuildPruneCountResult,
RESTGetAPIGuildScheduledEventQuery,
RESTGetAPIGuildScheduledEventsQuery,
RESTGetAPIGuildScheduledEventUsersQuery,
RESTGetAPIGuildVanityUrlResult,
RESTPatchAPIGuildChannelPositionsJSONBody,
RESTPatchAPIGuildEmojiJSONBody,
RESTPatchAPIGuildJSONBody,
RESTPatchAPIGuildRoleJSONBody,
RESTPatchAPIGuildRolePositionsJSONBody,
RESTPatchAPIGuildScheduledEventJSONBody,
RESTPatchAPIGuildStickerJSONBody,
RESTPatchAPIGuildTemplateJSONBody,
RESTPatchAPIGuildVoiceStateUserJSONBody,
RESTPatchAPIGuildWelcomeScreenJSONBody,
RESTPatchAPIGuildWidgetSettingsJSONBody,
RESTPostAPIGuildChannelJSONBody,
RESTPostAPIGuildEmojiJSONBody,
RESTPostAPIGuildPruneJSONBody,
RESTPostAPIGuildRoleJSONBody,
RESTPostAPIGuildScheduledEventJSONBody,
RESTPostAPIGuildsJSONBody,
RESTPostAPIGuildTemplatesJSONBody,
RESTPutAPIGuildBanJSONBody,
import { makeURLSearchParams, type REST } from '@discordjs/rest';
import {
Routes,
type APIAuditLog,
type APIBan,
type APIChannel,
type APIEmoji,
type APIGuild,
type APIGuildIntegration,
type APIGuildMember,
type APIGuildPreview,
type APIGuildScheduledEvent,
type APIGuildWelcomeScreen,
type APIGuildWidget,
type APIGuildWidgetSettings,
type APIInvite,
type APIRole,
type APISticker,
type APITemplate,
type APIThreadChannel,
type APIVoiceRegion,
type GuildMFALevel,
type GuildWidgetStyle,
type RESTGetAPIAuditLogQuery,
type RESTGetAPIGuildMembersQuery,
type RESTGetAPIGuildPruneCountResult,
type RESTGetAPIGuildScheduledEventQuery,
type RESTGetAPIGuildScheduledEventsQuery,
type RESTGetAPIGuildScheduledEventUsersQuery,
type RESTGetAPIGuildVanityUrlResult,
type RESTPatchAPIGuildChannelPositionsJSONBody,
type RESTPatchAPIGuildEmojiJSONBody,
type RESTPatchAPIGuildJSONBody,
type RESTPatchAPIGuildRoleJSONBody,
type RESTPatchAPIGuildRolePositionsJSONBody,
type RESTPatchAPIGuildScheduledEventJSONBody,
type RESTPatchAPIGuildStickerJSONBody,
type RESTPatchAPIGuildTemplateJSONBody,
type RESTPatchAPIGuildVoiceStateUserJSONBody,
type RESTPatchAPIGuildWelcomeScreenJSONBody,
type RESTPatchAPIGuildWidgetSettingsJSONBody,
type RESTPostAPIGuildChannelJSONBody,
type RESTPostAPIGuildEmojiJSONBody,
type RESTPostAPIGuildPruneJSONBody,
type RESTPostAPIGuildRoleJSONBody,
type RESTPostAPIGuildScheduledEventJSONBody,
type RESTPostAPIGuildsJSONBody,
type RESTPostAPIGuildTemplatesJSONBody,
type RESTPutAPIGuildBanJSONBody,
} from 'discord-api-types/v10';
import { Routes } from 'discord-api-types/v10';

export class GuildsAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Fetches a guild
Expand Down Expand Up @@ -194,7 +189,7 @@ export class GuildsAPI {
* @param reason - The reason for banning the user
* @returns
*/
public async ban(guildId: string, userId: string, options?: RESTPutAPIGuildBanJSONBody, reason?: string) {
public async ban(guildId: string, userId: string, options: RESTPutAPIGuildBanJSONBody = {}, reason?: string) {
return this.rest.put(Routes.guildBan(guildId, userId), {
reason,
body: options,
Expand Down Expand Up @@ -311,7 +306,7 @@ export class GuildsAPI {
* @param options - The options for pruning members
* @param reason - The reason for pruning members
*/
public async beginPrune(guildId: string, options?: RESTPostAPIGuildPruneJSONBody, reason?: string) {
public async beginPrune(guildId: string, options: RESTPostAPIGuildPruneJSONBody = {}, reason?: string) {
return (await this.rest.post(Routes.guildPrune(guildId), {
body: options,
reason,
Expand Down
14 changes: 4 additions & 10 deletions packages/core/src/api/guildMember.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import type { REST } from '@discordjs/rest';
import { makeURLSearchParams } from '@discordjs/rest';
import type { APIGuildMember, RESTPatchAPIGuildMemberJSONBody } from 'discord-api-types/v10';
import { Routes } from 'discord-api-types/v10';
import { makeURLSearchParams, type REST } from '@discordjs/rest';
import { Routes, type APIGuildMember, type RESTPatchAPIGuildMemberJSONBody } from 'discord-api-types/v10';

export class GuildMembersAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Fetches a guild member
Expand Down Expand Up @@ -41,7 +35,7 @@ export class GuildMembersAPI {
* @param options - The options to use when editing the guild member
* @param reason - The reason for editing this guild member
*/
public async edit(guildId: string, userId: string, options?: RESTPatchAPIGuildMemberJSONBody, reason?: string) {
public async edit(guildId: string, userId: string, options: RESTPatchAPIGuildMemberJSONBody = {}, reason?: string) {
return (await this.rest.patch(Routes.guildMember(guildId, userId), {
reason,
body: options,
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/api/guildTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import type { REST } from '@discordjs/rest';
import type { APITemplate, RESTPostAPITemplateCreateGuildJSONBody } from 'discord-api-types/v10';
import { Routes } from 'discord-api-types/v10';
import { Routes, type APITemplate, type RESTPostAPITemplateCreateGuildJSONBody } from 'discord-api-types/v10';

export class GuildTemplatesAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Fetches a guild template
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class API {

public readonly webhooks: WebhooksAPI;

public constructor(rest: REST) {
public constructor(public readonly rest: REST) {
this.bots = new BotsAPI(rest);
this.channels = new ChannelsAPI(rest);
this.guilds = new GuildsAPI(rest);
Expand Down
22 changes: 8 additions & 14 deletions packages/core/src/api/interactions.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import type { RawFile, REST } from '@discordjs/rest';
import type {
APIInteraction,
APIInteractionResponseCallbackData,
APIMessage,
APIModalInteractionResponseCallbackData,
import {
Routes,
InteractionResponseType,
type APIInteraction,
type APIInteractionResponseCallbackData,
type APIMessage,
type APIModalInteractionResponseCallbackData,
} from 'discord-api-types/v10';
import { Routes, InteractionResponseType } from 'discord-api-types/v10';
import type { WebhooksAPI } from './webhook.js';

export class InteractionsAPI {
private readonly rest: REST;

private readonly webhooks: WebhooksAPI;

public constructor(rest: REST, webhooks: WebhooksAPI) {
this.rest = rest;
this.webhooks = webhooks;
}
public constructor(private readonly rest: REST, private readonly webhooks: WebhooksAPI) {}

/**
* Replies to an interaction
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/api/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import type { REST } from '@discordjs/rest';
import { Routes, type APIInvite } from 'discord-api-types/v10';

export class InvitesAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Fetches an invite
Expand Down
21 changes: 8 additions & 13 deletions packages/core/src/api/message.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import type { RawFile, REST } from '@discordjs/rest';
import { makeURLSearchParams } from '@discordjs/rest';
import type {
APIMessage,
APIUser,
RESTGetAPIChannelMessageReactionUsersQuery,
RESTPostAPIChannelMessageJSONBody,
import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest';
import {
Routes,
type APIMessage,
type APIUser,
type RESTGetAPIChannelMessageReactionUsersQuery,
type RESTPostAPIChannelMessageJSONBody,
} from 'discord-api-types/v10';
import { Routes } from 'discord-api-types/v10';

export class MessagesAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Sends a message in a channel
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/api/sticker.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import type { REST } from '@discordjs/rest';
import type { RESTGetNitroStickerPacksResult } from 'discord-api-types/v10';
import { Routes, type APISticker } from 'discord-api-types/v10';
import { Routes, type APISticker, type RESTGetNitroStickerPacksResult } from 'discord-api-types/v10';

export class StickersAPI {
private readonly rest: REST;

public constructor(rest: REST) {
this.rest = rest;
}
public constructor(private readonly rest: REST) {}

/**
* Fetches all of the nitro sticker packs
Expand Down
Loading

0 comments on commit f8c3dc3

Please sign in to comment.