feat: Add @discordjs/core (#8736)

* feat: add @discordjs/core

* chore: lint

* chore: add all gateway events

* chore: add the rest of the rest routes

* chore: cleanup gateway

* chore: rename gateway to client

* chore: rename gateway to client

* fix: don't spread unless we need to

* refactor: use classes and make requested changes

* chore: show shardId on emit

* chore: add interface for intrinsic props

* refactor: scope dispatch data instead of spreading

* chore: add utility for uploading files for messages and interactions

* feat: finish up form data handling

* chore: add readme

* chore: update api-extractor stuff

* chore: bump deps

* chore: make requested changes

* chore: make requested changes

* Update package.json

* chore: make requested changes

* fix: add missing interaction responses

* chore: make some requested changes

* chore: remove `return await`

* chore: use autoModeration instead of automod

* refactor: use snowflakes and -types results

* chore: sort imports, fix return type on editUserVoiceState

* chore: rename bots to users

* feat: add automod dispatch events

* refactor: move templates and members into guild

* fix: use users instead of bots in api class

* chore: imports

* chore: make requested changes

* fix: don't make files required on interaction replies

* fix: rename sendMessage to createMessage

* feat: add application command routes

* feat: add webhook.execute overloads and options to invites.get

* chore: use create prefixes

* chore: seperate interaction params

* chore: use Id

* chore: make requested changes

* chore: make requested changes

* chore: make requested changes

* chore: for -> from

* Apply suggestions from code review

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* Update packages/core/README.md

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* chore: make requested changes

* chore: update -types

* chore: bump vitest

* fix: sticker uploading

* fix: lockfile

* chore: make requested changes

* chore: make requested changes

* Update packages/core/src/api/applicationCommands.ts

Co-authored-by: Almeida <almeidx@pm.me>

* Apply suggestions from code review

Co-authored-by: Aura Román <kyradiscord@gmail.com>

* Update packages/core/README.md

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

Co-authored-by: almeidx <almeidx@pm.me>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Aura Román <kyradiscord@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Suneet Tipirneni
2022-11-27 16:23:13 -05:00
committed by GitHub
parent 12553da135
commit 2127b32d26
33 changed files with 2979 additions and 2 deletions

View File

@@ -0,0 +1,112 @@
import { makeURLSearchParams, type REST } from '@discordjs/rest';
import {
Routes,
type RESTGetAPICurrentUserGuildsQuery,
type RESTGetAPICurrentUserGuildsResult,
type RESTGetAPICurrentUserResult,
type RESTGetAPIUserResult,
type RESTGetCurrentUserGuildMemberResult,
type RESTPatchAPICurrentUserJSONBody,
type RESTPatchAPICurrentUserResult,
type RESTPatchAPIGuildMemberJSONBody,
type RESTPatchAPIGuildMemberResult,
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
type RESTPatchAPIGuildVoiceStateCurrentMemberResult,
type RESTPostAPICurrentUserCreateDMChannelResult,
type Snowflake,
} from 'discord-api-types/v10';
export class UsersAPI {
public constructor(private readonly rest: REST) {}
/**
* Fetches a user by their id
*
* @param userId - The id of the user to fetch
*/
public async get(userId: Snowflake) {
return this.rest.get(Routes.user(userId)) as Promise<RESTGetAPIUserResult>;
}
/**
* Returns the user object of the requester's account
*/
public async getCurrent() {
return this.rest.get(Routes.user('@me')) as Promise<RESTGetAPICurrentUserResult>;
}
/**
* Returns a list of partial guild objects the current user is a member of
*
* @param options - The options to use when fetching the current user's guilds
*/
public async getGuilds(options: RESTGetAPICurrentUserGuildsQuery = {}) {
return this.rest.get(Routes.userGuilds(), {
query: makeURLSearchParams(options as Record<string, unknown>),
}) as Promise<RESTGetAPICurrentUserGuildsResult>;
}
/**
* Leaves the guild with the given id
*
* @param guildId - The id of the guild
*/
public async leaveGuild(guildId: Snowflake) {
await this.rest.delete(Routes.userGuild(guildId));
}
/**
* Edits the current user
*
* @param user - The new data for the current user
*/
public async edit(user: RESTPatchAPICurrentUserJSONBody) {
return this.rest.patch(Routes.user('@me'), { body: user }) as Promise<RESTPatchAPICurrentUserResult>;
}
/**
* Fetches the guild member for the current user
*
* @param guildId - The id of the guild
*/
public async getGuildMember(guildId: Snowflake) {
return this.rest.get(Routes.userGuildMember(guildId)) as Promise<RESTGetCurrentUserGuildMemberResult>;
}
/**
* Edits the guild member for the current user
*
* @param guildId - The id of the guild
* @param member - The new data for the guild member
* @param reason - The reason for editing this guild member
*/
public async editGuildMember(guildId: Snowflake, member: RESTPatchAPIGuildMemberJSONBody = {}, reason?: string) {
return this.rest.patch(Routes.guildMember(guildId, '@me'), {
reason,
body: member,
}) as Promise<RESTPatchAPIGuildMemberResult>;
}
/**
* Sets the voice state for the current user
*
* @param guildId - The id of the guild
* @param options - The options to use when setting the voice state
*/
public async setVoiceState(guildId: Snowflake, options: RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody = {}) {
return this.rest.patch(Routes.guildVoiceState(guildId, '@me'), {
body: options,
}) as Promise<RESTPatchAPIGuildVoiceStateCurrentMemberResult>;
}
/**
* Opens a new DM channel with a user
*
* @param userId - The id of the user to open a DM channel with
*/
public async createDM(userId: Snowflake) {
return this.rest.post(Routes.userChannels(), {
body: { recipient_id: userId },
}) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>;
}
}