diff --git a/README.md b/README.md index 86c9934..16a40b0 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,6 @@ Cordis is cut up in the form of multiple packages/libraries: - [`@cordis/redis-store`](https://github.com/cordis-lib/cordis/tree/main/libs/redis-store) - A Redis implementation of `@cordis/store` - [`@cordis/rest`](https://github.com/cordis-lib/cordis/tree/main/libs/rest) - Tooling for making HTTP requests to Discord, with rate limiting handling - [`@cordis/routers`](https://github.com/cordis-lib/cordis/tree/main/libs/routers) - Make API requests with ease using simple dynamic JavaScript property accessing -- [`@cordis/snowflake`](https://github.com/cordis-lib/cordis/tree/main/libs/snowflake) - A simple snowflake structure for destructuring Discord IDs into relevant information - [`@cordis/store`](https://github.com/cordis-lib/cordis/tree/main/libs/store) - A simple map-like interface for holding key-value pairs - ships with an in-memory implementation # Contributing diff --git a/libs/common/src/functions/functions.test.ts b/libs/common/src/functions/functions.test.ts index 4045a06..4820d65 100644 --- a/libs/common/src/functions/functions.test.ts +++ b/libs/common/src/functions/functions.test.ts @@ -1,5 +1,4 @@ -import { getMissingProps, halt, isPromise, keyMirror, makeDiscordCdnUrl } from './'; -import { CordisUtilTypeError, CordisUtilRangeError } from '../error'; +import { getMissingProps, halt, isPromise, keyMirror } from './'; test('get missing props', () => { const obj = { one: 1, two: 2 }; @@ -37,39 +36,3 @@ describe('is promise', () => { test('key mirror', () => { expect(keyMirror(['b'])).toStrictEqual({ b: 'b' }); }); - -describe('make discord cdn url', () => { - describe('invalid options handling', () => { - test('invalid format', () => { - const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; - // @ts-expect-error Intentionally invalid format - expect(() => makeDiscordCdnUrl(root, { format: 'asdf' })).toThrow(CordisUtilTypeError); - }); - - test('invalid size', () => { - const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; - // @ts-expect-error Intentionally invalid size - expect(() => makeDiscordCdnUrl(root, { size: 1 })).toThrow(CordisUtilRangeError); - }); - }); - - test('defaults using an image', () => { - const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; - expect(makeDiscordCdnUrl(root)).toBe(`${root}.webp`); - }); - - test('defaults using a gif', () => { - const root = 'a_bbab2f9b0bcecf438b4810c67798bfca'; - expect(makeDiscordCdnUrl(root)).toBe(`${root}.gif`); - }); - - test('non-dynamic with a gif', () => { - const root = 'a_bbab2f9b0bcecf438b4810c67798bfca'; - expect(makeDiscordCdnUrl(root, { dynamic: false })).toBe(`${root}.webp`); - }); - - test('valid custom size', () => { - const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; - expect(makeDiscordCdnUrl(root, { size: 16 })).toBe(`${root}.webp?size=16`); - }); -}); diff --git a/libs/common/src/functions/index.ts b/libs/common/src/functions/index.ts index 741e5a5..1afe3e1 100644 --- a/libs/common/src/functions/index.ts +++ b/libs/common/src/functions/index.ts @@ -2,4 +2,3 @@ export * from './getMissingProps'; export * from './halt'; export * from './isPromise'; export * from './keyMirror'; -export * from './makeDiscordCdnUrl'; diff --git a/libs/rest/src/RestManager.ts b/libs/rest/src/RestManager.ts index 55ecc9f..c5b88a1 100644 --- a/libs/rest/src/RestManager.ts +++ b/libs/rest/src/RestManager.ts @@ -205,7 +205,7 @@ export class RestManager extends EventEmitter { * @param options Other options for the request */ /* istanbul ignore next */ - public post(path: string, options: { data: D; reason?: string; files?: File[] }): Promise { - return this.make({ path, method: 'post', ...options }); + public post(path: string, options: { data: D; reason?: string; files?: File[]; query?: Q }): Promise { + return this.make({ path, method: 'post', ...options }); } } diff --git a/libs/routers/src/IRouter.ts b/libs/routers/src/IRouter.ts index b41b072..505f8a9 100644 --- a/libs/routers/src/IRouter.ts +++ b/libs/routers/src/IRouter.ts @@ -5,5 +5,5 @@ export type IRouter = { delete(options?: { data?: D; reason?: string }): Promise; patch(options: { data: D; reason?: string }): Promise; put(options?: { data?: D; reason?: string }): Promise; - post(options: { data: D; reason?: string; files?: File[] }): Promise; + post(options: { data: D; reason?: string; files?: File[]; query?: Q }): Promise; } & { [key: string]: IRouter }; diff --git a/libs/snowflake/README.md b/libs/util/README.md similarity index 68% rename from libs/snowflake/README.md rename to libs/util/README.md index b63496b..b689125 100644 --- a/libs/snowflake/README.md +++ b/libs/util/README.md @@ -1,15 +1,15 @@ -# `@cordis/snowflake` +# `@cordis/util` [![GitHub](https://img.shields.io/badge/License-Apache%202.0-yellow.svg)](https://github.com/cordis-lib/cordis/blob/main/LICENSE) -[![npm](https://img.shields.io/npm/v/@cordis/snowflake?color=crimson&logo=npm)](https://www.npmjs.com/package/@cordis/snowflake) +[![npm](https://img.shields.io/npm/v/@cordis/util?color=crimson&logo=npm)](https://www.npmjs.com/package/@cordis/util) [![TypeScript](https://github.com/cordis-lib/cordis/actions/workflows/quality.yml/badge.svg)](https://github.com/cordis-lib/cordis/actions/workflows/quality.yml) -Simple package for destructuring (Twitter) Discord snowflakes. +Helper methods and structures for Cordis ## Installation -- `npm install @cordis/snowflake` -- `pnpm install @cordis/snowflake` -- `yarn add @cordis/snowflake` +- `npm install @cordis/util` +- `pnpm install @cordis/util` +- `yarn add @cordis/util` ## Documentation You can find documentation for the whole project over at https://cordis.js.org diff --git a/libs/snowflake/package.json b/libs/util/package.json similarity index 80% rename from libs/snowflake/package.json rename to libs/util/package.json index 2f4e15a..54de92e 100644 --- a/libs/snowflake/package.json +++ b/libs/util/package.json @@ -1,9 +1,9 @@ { - "name": "@cordis/snowflake", - "description": "Utility structure for dealing with Discord snowflakes", + "name": "@cordis/util", + "version": "0.1.7", + "description": "Helper methods and structures for Cordis", "main": "./dist/index.js", "types": "./types/index.d.ts", - "version": "0.1.7", "scripts": { "lint": "eslint src --ext .ts", "build": "tsc" @@ -24,7 +24,7 @@ "Holo-Buckshot (https://github.com/Holo-Buckshot)", "Nico (https://github.com/zaida04)" ], - "author": "didinele", + "author": "Zaid \"Nico\"", "bugs": { "url": "https://github.com/cordis-lib/cordis/issues" }, @@ -34,6 +34,8 @@ "typescript": "^4.2.2" }, "dependencies": { + "@cordis/rest": "workspace:^0.1.6", + "@cordis/error": "workspace:^0.1.6", "tslib": "^2.1.0" } } diff --git a/libs/snowflake/src/index.test.ts b/libs/util/src/Snowflake.test.ts similarity index 94% rename from libs/snowflake/src/index.test.ts rename to libs/util/src/Snowflake.test.ts index f593c08..c380108 100644 --- a/libs/snowflake/src/index.test.ts +++ b/libs/util/src/Snowflake.test.ts @@ -1,4 +1,4 @@ -import { Snowflake, getCreationData } from './'; +import { Snowflake, getCreationData } from './Snowflake'; const ID = '223703707118731264'; const CREATED_AT = 1473405519991; diff --git a/libs/snowflake/src/index.ts b/libs/util/src/Snowflake.ts similarity index 100% rename from libs/snowflake/src/index.ts rename to libs/util/src/Snowflake.ts diff --git a/libs/util/src/embed.test.ts b/libs/util/src/embed.test.ts new file mode 100644 index 0000000..2273846 --- /dev/null +++ b/libs/util/src/embed.test.ts @@ -0,0 +1,80 @@ +import { buildEmbed } from './embed'; + +test('Dataless value checks', () => { + const embed1 = buildEmbed({}); + expect(embed1.author).toBe(undefined); + expect(embed1.color).toBe(undefined); + expect(embed1.description).toBe(undefined); + expect(embed1.footer).toBe(undefined); + expect(embed1.fields).toStrictEqual([]); + expect(embed1.image).toBe(undefined); + expect(embed1.provider).toBe(undefined); + expect(embed1.thumbnail).toBe(undefined); + expect(embed1.timestamp).toBe(undefined); + expect(embed1.title).toBe(undefined); + expect(embed1.author).toBe(undefined); + expect(embed1.url).toBe(undefined); + expect(embed1.video).toBe(undefined); +}); + +test('Data value checks', () => { + const date = new Date('2021-03-08T14:40:27.875Z'); + const color = 16753920; + + let embed2 = buildEmbed({ + title: 'testing title!', + description: 'testing description', + url: 'https://google.com', + color, + fields: [], + thumbnail: { + url: 'https://google.com' + }, + image: { + url: 'https://lh3.googleusercontent.com/proxy/K6J0xWzyfl729xgnZLj55qd5L0us_QN7m5MbcQgV09xP-HVw8Z_iJDwpXexcy87ZkHHrins6rMFwPahgPI-VI_il_gedMlBD7IIll_0e4AZNBg' + }, + author: { + name: 'Test Author' + }, + footer: { + text: 'Test Footer' + } + }).setTimestamp(date.getTime()); + + expect(embed2.timestamp).toBe(date.toString()); + expect(embed2.color).toBe(color); + expect(embed2.fields).toStrictEqual([]); + + embed2 = embed2 + .setAuthor('testing_author_3') + .setColor(16753920) + .setDescription('I am testing changing descriptions') + .setFooter('bing bong', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ') + .setImage('https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058') + .setThumbnail('https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058') + .setTitle('Never gonna give you up') + .setURL('http://yahoo.com') + .addFields({ name: 'never gonna', value: 'let you down', inline: true }, { name: 'never gonna run around and', value: 'desert you' }); + + expect(embed2.toJSON()).toMatchObject({ + title: 'Never gonna give you up', + description: 'I am testing changing descriptions', + url: 'http://yahoo.com', + color: 16753920, + fields: [{ name: 'never gonna', value: 'let you down', inline: true }, { name: 'never gonna run around and', value: 'desert you' }], + thumbnail: { + url: 'https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058' + }, + image: { + url: 'https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058' + }, + author: { + name: 'testing_author_3' + }, + type: 'rich', + footer: { + text: 'bing bong', + icon_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' + } + }); +}); diff --git a/libs/util/src/embed.ts b/libs/util/src/embed.ts new file mode 100644 index 0000000..56fc85d --- /dev/null +++ b/libs/util/src/embed.ts @@ -0,0 +1,43 @@ +import { APIEmbed, APIEmbedField, EmbedType } from 'discord-api-types/v8'; + +export const buildEmbed = (embedData: Partial = {}) => { + embedData.fields ??= []; + embedData.type = EmbedType.Rich; + + return { + ...Object.freeze(embedData), + toJSON: () => embedData, + + setAuthor(name: string, url?: string, icon_url?: string, proxy_icon_url?: string) { + return buildEmbed({ ...this, author: { name, url, icon_url, proxy_icon_url } }); + }, + setColor(color: number) { + return buildEmbed({ ...this, color }); + }, + setDescription(description: string) { + return buildEmbed({ ...this, description }); + }, + setFooter(text: string, icon_url?: string, proxy_icon_url?: string) { + return buildEmbed({ ...this, footer: { text, icon_url, proxy_icon_url } }); + }, + setImage(url: string, proxy_url?: string, height?: number, width?: number) { + return buildEmbed({ ...this, image: { url, proxy_url, height, width } }); + }, + setThumbnail(url: string, proxy_url?: string, height?: number, width?: number) { + return buildEmbed({ ...this, thumbnail: { url, proxy_url, height, width } }); + }, + setTitle(title: string) { + return buildEmbed({ ...this, title }); + }, + setURL(url: string) { + return buildEmbed({ ...this, url }); + }, + setTimestamp(timestamp: Date | number = new Date()) { + if (typeof timestamp === 'number') timestamp = new Date(timestamp); + return buildEmbed({ ...this, timestamp: timestamp.toString() }); + }, + addFields(...data: APIEmbedField[]) { + return buildEmbed({ ...this, fields: embedData.fields?.concat(data) ?? data }); + } + }; +}; diff --git a/libs/common/src/error.ts b/libs/util/src/error.ts similarity index 100% rename from libs/common/src/error.ts rename to libs/util/src/error.ts diff --git a/libs/util/src/index.ts b/libs/util/src/index.ts new file mode 100644 index 0000000..b7bffc0 --- /dev/null +++ b/libs/util/src/index.ts @@ -0,0 +1,4 @@ +export * from './embed'; +export * from './makeDiscordCdnUrl'; +export * from './restUtils'; +export * from './Snowflake'; diff --git a/libs/util/src/makeDiscordCdnUrl.test.ts b/libs/util/src/makeDiscordCdnUrl.test.ts new file mode 100644 index 0000000..ae44552 --- /dev/null +++ b/libs/util/src/makeDiscordCdnUrl.test.ts @@ -0,0 +1,36 @@ +import { makeDiscordCdnUrl } from './'; +import { CordisUtilTypeError, CordisUtilRangeError } from './error'; + +describe('invalid options handling', () => { + test('invalid format', () => { + const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; + // @ts-expect-error Intentionally invalid format + expect(() => makeDiscordCdnUrl(root, { format: 'asdf' })).toThrow(CordisUtilTypeError); + }); + + test('invalid size', () => { + const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; + // @ts-expect-error Intentionally invalid size + expect(() => makeDiscordCdnUrl(root, { size: 1 })).toThrow(CordisUtilRangeError); + }); +}); + +test('defaults using an image', () => { + const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; + expect(makeDiscordCdnUrl(root)).toBe(`${root}.webp`); +}); + +test('defaults using a gif', () => { + const root = 'a_bbab2f9b0bcecf438b4810c67798bfca'; + expect(makeDiscordCdnUrl(root)).toBe(`${root}.gif`); +}); + +test('non-dynamic with a gif', () => { + const root = 'a_bbab2f9b0bcecf438b4810c67798bfca'; + expect(makeDiscordCdnUrl(root, { dynamic: false })).toBe(`${root}.webp`); +}); + +test('valid custom size', () => { + const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; + expect(makeDiscordCdnUrl(root, { size: 16 })).toBe(`${root}.webp?size=16`); +}); diff --git a/libs/common/src/functions/makeDiscordCdnUrl.ts b/libs/util/src/makeDiscordCdnUrl.ts similarity index 94% rename from libs/common/src/functions/makeDiscordCdnUrl.ts rename to libs/util/src/makeDiscordCdnUrl.ts index 5dc9c6e..466aae1 100644 --- a/libs/common/src/functions/makeDiscordCdnUrl.ts +++ b/libs/util/src/makeDiscordCdnUrl.ts @@ -1,4 +1,4 @@ -import { CordisUtilTypeError, CordisUtilRangeError } from '../error'; +import { CordisUtilTypeError, CordisUtilRangeError } from './error'; /** * Valid image formats diff --git a/libs/util/src/restUtils.ts b/libs/util/src/restUtils.ts new file mode 100644 index 0000000..774285e --- /dev/null +++ b/libs/util/src/restUtils.ts @@ -0,0 +1,232 @@ +/* istanbul ignore file */ + +import { Routes } from 'discord-api-types/v8'; +import type { RestManager } from '@cordis/rest'; +// eslint-disable-next-line no-duplicate-imports +import type { + Snowflake, + APIAuditLog, + APIChannel, + APIGuildPreview, + APIMessage, + APIWebhook, + RESTDeleteAPIChannelAllMessageReactionsResult, + RESTDeleteAPIChannelMessageOwnReaction, + RESTDeleteAPIChannelMessageReactionResult, + RESTDeleteAPIChannelMessageUserReactionResult, + RESTDeleteAPIChannelPermissionResult, + RESTDeleteAPIChannelPinResult, + RESTDeleteAPICurrentUserGuildResult, + RESTDeleteAPIGuildBanResult, + RESTDeleteAPIGuildEmojiResult, + RESTDeleteAPIGuildIntegrationResult, + RESTDeleteAPIGuildMemberResult, + RESTDeleteAPIGuildMemberRoleResult, + RESTDeleteAPIGuildResult, + RESTDeleteAPIGuildRoleResult, + RESTDeleteAPIGuildTemplateResult, + RESTDeleteAPIInviteResult, + RESTDeleteAPIWebhookResult, + RESTGetAPIAuditLogQuery, + RESTGetAPIChannelInvitesResult, + RESTGetAPIChannelMessageResult, + RESTGetAPIChannelMessagesQuery, + RESTGetAPIChannelMessagesResult, + RESTGetAPIChannelPinsResult, + RESTGetAPIChannelWebhooksResult, + RESTGetAPICurrentUserConnectionsResult, + RESTGetAPICurrentUserResult, + RESTGetAPIGuildBanResult, + RESTGetAPIGuildBansResult, + RESTGetAPIGuildChannelsResult, + RESTGetAPIGuildEmojiResult, + RESTGetAPIGuildEmojisResult, + RESTGetAPIGuildIntegrationsResult, + RESTGetAPIGuildInvitesResult, + RESTGetAPIGuildMemberResult, + RESTGetAPIGuildPruneCountQuery, + RESTGetAPIGuildPruneCountResult, + RESTGetAPIGuildResult, + RESTGetAPIGuildRolesResult, + RESTGetAPIGuildTemplatesResult, + RESTGetAPIGuildVanityUrlResult, + RESTGetAPIGuildVoiceRegionsResult, + RESTGetAPIGuildWidgetImageQuery, + RESTGetAPIGuildWidgetImageResult, + RESTGetAPIGuildWidgetJSONResult, + RESTGetAPIInviteResult, + RESTGetAPITemplateResult, + RESTGetAPIUserResult, + RESTGetAPIWebhookResult, + RESTPatchAPIChannelJSONBody, + RESTPatchAPIChannelMessageJSONBody, + RESTPatchAPIChannelMessageResult, + RESTPatchAPIChannelResult, + RESTPatchAPICurrentGuildMemberNicknameJSONBody, + RESTPatchAPICurrentGuildMemberNicknameResult, + RESTPatchAPICurrentUserJSONBody, + RESTPatchAPICurrentUserResult, + RESTPatchAPIGuildEmojiJSONBody, + RESTPatchAPIGuildEmojiResult, + RESTPatchAPIGuildIntegrationJSONBody, + RESTPatchAPIGuildIntegrationResult, + RESTPatchAPIGuildJSONBody, + RESTPatchAPIGuildMemberJSONBody, + RESTPatchAPIGuildMemberResult, + RESTPatchAPIGuildResult, + RESTPatchAPIGuildRoleJSONBody, + RESTPatchAPIGuildRolePositionsJSONBody, + RESTPatchAPIGuildRolePositionsResult, + RESTPatchAPIGuildRoleResult, + RESTPatchAPIGuildTemplateJSONBody, + RESTPatchAPIGuildTemplateResult, + RESTPatchAPIGuildWidgetSettingsJSONBody, + RESTPatchAPIGuildWidgetSettingsResult, + RESTPatchAPIWebhookJSONBody, + RESTPatchAPIWebhookResult, + RESTPatchAPIWebhookWithTokenJSONBody, + RESTPatchAPIWebhookWithTokenMessageJSONBody, + RESTPostAPIChannelFollowersJSONBody, + RESTPostAPIChannelFollowersResult, + RESTPostAPIChannelInviteJSONBody, + RESTPostAPIChannelInviteResult, + RESTPostAPIChannelMessageCrosspostResult, + RESTPostAPIChannelMessageJSONBody, + RESTPostAPIChannelMessageResult, + RESTPostAPIChannelMessagesBulkDeleteJSONBody, + RESTPostAPIChannelMessagesBulkDeleteResult, + RESTPostAPIChannelTypingResult, + RESTPostAPIChannelWebhookJSONBody, + RESTPostAPICurrentUserCreateDMChannelJSONBody, + RESTPostAPICurrentUserCreateDMChannelResult, + RESTPostAPIGuildChannelJSONBody, + RESTPostAPIGuildChannelResult, + RESTPostAPIGuildEmojiJSONBody, + RESTPostAPIGuildEmojiResult, + RESTPostAPIGuildIntegrationJSONBody, + RESTPostAPIGuildIntegrationResult, + RESTPostAPIGuildIntegrationSyncResult, + RESTPostAPIGuildPruneJSONBody, + RESTPostAPIGuildPruneResult, + RESTPostAPIGuildRoleJSONBody, + RESTPostAPIGuildRoleResult, + RESTPostAPIGuildTemplatesJSONBody, + RESTPostAPIGuildTemplatesResult, + RESTPostAPIGuildsJSONBody, + RESTPostAPIGuildsResult, + RESTPostAPITemplateCreateGuildJSONBody, + RESTPostAPITemplateCreateGuildResult, + RESTPostAPIWebhookWithTokenGitHubQuery, + RESTPostAPIWebhookWithTokenGitHubResult, + RESTPostAPIWebhookWithTokenGitHubWaitResult, + RESTPostAPIWebhookWithTokenJSONBody, + RESTPostAPIWebhookWithTokenResult, + RESTPostAPIWebhookWithTokenSlackQuery, + RESTPostAPIWebhookWithTokenSlackResult, + RESTPostAPIWebhookWithTokenSlackWaitResult, + RESTPutAPIChannelMessageReactionResult, + RESTPutAPIChannelPermissionJSONBody, + RESTPutAPIChannelPermissionResult, + RESTPutAPIGuildBanJSONBody, + RESTPutAPIGuildBanResult, + RESTPutAPIGuildMemberJSONBody, + RESTPutAPIGuildMemberResult, + RESTPutAPIGuildMemberRoleResult, + RESTPutAPIGuildTemplateSyncResult +} from 'discord-api-types/v8'; + +interface webhookIdOrToken { webhookID: Snowflake; webhookToken?: string } + +export const makeRestUtils = (rest: RestManager) => ({ + createGuild: (data: RESTPostAPIGuildsJSONBody) => rest.post(Routes.guilds(), { data }), + fetchGuild: (...args: Parameters) => rest.get(Routes.guild(...args)), + fetchGuildPreview: (...args: Parameters) => rest.get(Routes.guildPreview(...args)), + editGuild: (guildID: Snowflake, data: RESTPatchAPIGuildJSONBody) => rest.patch(Routes.guild(guildID), { data }), + deleteGuild: (...args: Parameters) => rest.delete(Routes.guild(...args)), + fetchGuildChannels: (...args: Parameters) => rest.get(Routes.guildChannels(...args)), + createGuildChannel: (guildID: Snowflake, data: RESTPostAPIGuildChannelJSONBody) => rest.post(Routes.guildChannels(guildID), { data }), + fetchGuildMember: (...args: Parameters) => rest.get(Routes.guildMember(...args)), + addGuildMember: (guildID: Snowflake, userID: Snowflake, data: RESTPutAPIGuildMemberJSONBody) => rest.put(Routes.guildMember(guildID, userID), { data }), + editGuildMember: (guildID: Snowflake, userID: Snowflake, data: RESTPatchAPIGuildMemberJSONBody) => rest.patch(Routes.guildMember(guildID, userID), { data }), + setMeNickname: (guildID: Snowflake, data: RESTPatchAPICurrentGuildMemberNicknameJSONBody) => rest.patch(Routes.guildCurrentMemberNickname(guildID), { data }), + addRole: (...args: Parameters) => rest.put(Routes.guildMemberRole(...args)), + removeRole: (...args: Parameters) => rest.delete(Routes.guildMemberRole(...args)), + kickMember: (...args: Parameters) => rest.delete(Routes.guildMember(...args)), + fetchGuildBans: (...args: Parameters) => rest.get(Routes.guildBans(...args)), + fetchGuildBan: (...args: Parameters) => rest.get(Routes.guildBan(...args)), + banMember: (guildID: Snowflake, userID: Snowflake, data: RESTPutAPIGuildBanJSONBody) => rest.put(Routes.guildBan(guildID, userID), { data }), + unbanMember: (guildID: Snowflake, userID: Snowflake) => rest.delete(Routes.guildBan(guildID, userID)), + fetchRoles: (...args: Parameters) => rest.get(Routes.guildMemberRole(...args)), + createRole: (guildID: Snowflake, data: RESTPostAPIGuildRoleJSONBody) => rest.post(Routes.guildRoles(guildID), { data }), + setRolePosition: (guildID: Snowflake, data: RESTPatchAPIGuildRolePositionsJSONBody) => rest.patch(Routes.guildRoles(guildID), { data }), + editRole: (guildID: Snowflake, roleID: Snowflake, data: RESTPatchAPIGuildRoleJSONBody) => rest.patch(Routes.guildRole(guildID, roleID), { data }), + deleteRole: (...args: Parameters) => rest.delete(Routes.guildRole(...args)), + pruneGuild: (guildID: Snowflake, data: RESTPostAPIGuildPruneJSONBody) => rest.post(Routes.guildPrune(guildID), { data }), + getPredictedPruneResult: (guildID: Snowflake, options: RESTGetAPIGuildPruneCountQuery) => rest.get(Routes.guildPrune(guildID), { query: options }), + fetchGuildVoiceRegions: (...args: Parameters) => rest.get(Routes.guildVoiceRegions(...args)), + fetchGuildInvites: (...args: Parameters) => rest.get(Routes.guildInvites(...args)), + fetchGuildIntegration: (...args: Parameters) => rest.get(Routes.guildIntegrations(...args)), + createGuildIntegration: (guildID: Snowflake, data: RESTPostAPIGuildIntegrationJSONBody) => rest.post(Routes.guildIntegrations(guildID), { data }), + editGuildIntegration: (guildID: Snowflake, integrationID: Snowflake, data: RESTPatchAPIGuildIntegrationJSONBody) => rest.patch(Routes.guildIntegration(guildID, integrationID), { data }), + deleteGuildIntegration: (...args: Parameters) => rest.delete(Routes.guildIntegration(...args)), + syncGuildIntegration: (...args: Parameters) => rest.post(Routes.guildIntegrationSync(...args), { data: null }), + fetchGuildWidgetSettings: (...args: Parameters) => rest.get(Routes.guildWidgetSettings(...args)), + fetchGuildWidget: (...args: Parameters) => rest.get(Routes.guildWidgetImage(...args)), + editGuildWidget: (guildID: Snowflake, data: RESTPatchAPIGuildWidgetSettingsJSONBody) => rest.patch(Routes.guildWidgetSettings(guildID), { data }), + fetchGuildVanityURL: (...args: Parameters) => rest.get(Routes.guildVanityUrl(...args)), + fetchGuildWidgetImage: (guildID: Snowflake, options: RESTGetAPIGuildWidgetImageQuery) => rest.get(Routes.guildWidgetImage(guildID), { query: options }), + fetchChannel: (...args: Parameters) => rest.get(Routes.channel(...args)), + editChannel: (channelID: Snowflake, data: RESTPatchAPIChannelJSONBody) => rest.patch(Routes.channel(channelID), { data }), + deleteChannel: (...args: Parameters) => rest.delete(Routes.channel(...args)), + fetchChannelMessages: (...args: Parameters) => rest.get(Routes.channelMessages(...args)), + fetchChannelMessage: (...args: Parameters) => rest.get(Routes.channelMessage(...args)), + sendMessage: (channelID: Snowflake, data: RESTPostAPIChannelMessageJSONBody) => rest.post(Routes.channelMessages(channelID), { data }), + crosspostMessage: (channelID: Snowflake, messageID: Snowflake) => rest.post(Routes.channelMessageCrosspost(channelID, messageID), { data: null }), + addReaction: (...args: Parameters) => rest.put(Routes.channelMessageReaction(...args)), + deleteUserReaction: (channelID: Snowflake, messageID: Snowflake, emoji: Snowflake | string, userID?: Snowflake) => userID ? rest.delete(Routes.channelMessageUserReaction(channelID, messageID, emoji, userID)) : rest.delete(Routes.channelMessageOwnReaction(channelID, messageID, emoji)), + deleteAllMessageReactions: (...args: Parameters) => rest.delete(Routes.channelMessageAllReactions(...args)), + deleteAllEmoteReaction: (...args: Parameters) => rest.delete(Routes.channelMessageReaction(...args)), + fetchMessageReactions: (channelID: Snowflake, messageID: Snowflake, emoji: Snowflake | string, options: RESTGetAPIChannelMessagesQuery) => rest.get(Routes.channelMessageReaction(channelID, messageID, emoji), { query: options }), + editMessage: (channelID: Snowflake, messageID: Snowflake, data: RESTPatchAPIChannelMessageJSONBody) => rest.patch(Routes.channelMessage(channelID, messageID), { data }), + deleteMessage: (...args: Parameters) => rest.delete(Routes.channelMessage(...args)), + bulkDeleteMessages: (channelID: Snowflake, data: RESTPostAPIChannelMessagesBulkDeleteJSONBody) => rest.post(Routes.channelBulkDelete(channelID), { data }), + editChannelPermissions: (channelID: Snowflake, owerwriteID: Snowflake, data: RESTPutAPIChannelPermissionJSONBody) => rest.put(Routes.channelPermission(channelID, owerwriteID), { data }), + deleteChannelPermissions: (...args: Parameters) => rest.delete(Routes.channelPermission(...args)), + fetchChannelInvites: (...args: Parameters) => rest.get(Routes.channelInvites(...args)), + createChannelInvite: (channelID: Snowflake, data: RESTPostAPIChannelInviteJSONBody) => rest.post(Routes.channelInvites(channelID), { data }), + followNewsChannel: (channelID: Snowflake, data: RESTPostAPIChannelFollowersJSONBody) => rest.post(Routes.channelFollowers(channelID), { data }), + startTyping: (...args: Parameters) => rest.get(Routes.channelTyping(...args)), + fetchPinnedChannelMessages: (...args: Parameters) => rest.get(Routes.channelPins(...args)), + deletePinnedChannelMessage: (...args: Parameters) => rest.delete(Routes.channelPin(...args)), + addPinnedChannelMessage: (...args: Parameters) => rest.put(Routes.channelPin(...args)), + fetchAuditLogs: (guildID: Snowflake, options?: RESTGetAPIAuditLogQuery) => rest.get(Routes.guildAuditLog(guildID), { query: options }), + fetchInvite: (...args: Parameters) => rest.get(Routes.invite(...args)), + deleteInvite: (...args: Parameters) => rest.delete(Routes.invite(...args)), + createWebhook: (channelID: Snowflake, data: RESTPostAPIChannelWebhookJSONBody) => rest.post(Routes.channelWebhooks(channelID), { data }), + fetchWebhooks: (...args: Parameters) => rest.get(Routes.channelWebhooks(...args)), + fetchWebhook: (...args: Parameters) => rest.get(Routes.webhook(...args)), + editWebhook: ({ webhookID, webhookToken }: webhookIdOrToken, data: RESTPatchAPIWebhookJSONBody | RESTPatchAPIWebhookWithTokenJSONBody) => rest.patch(Routes.webhook(webhookID, webhookToken), { data }), + deleteWebhook: ({ webhookID, webhookToken }: webhookIdOrToken) => rest.delete(Routes.webhook(webhookID, webhookToken)), + sendWebhookMessage: (webhookID: Snowflake, webhookToken: string, data: RESTPostAPIWebhookWithTokenJSONBody) => rest.post(Routes.webhook(webhookID, webhookToken), { data }), + editWebhookMessage: (webhookID: Snowflake, webhookToken: string, messageID: Snowflake, data: RESTPatchAPIWebhookWithTokenMessageJSONBody) => rest.patch(Routes.webhookMessage(webhookID, webhookToken, messageID), { data }), + fetchGuildEmojis: (...args: Parameters) => rest.get(Routes.guildEmojis(...args)), + fetchGuildEmoji: (...args: Parameters) => rest.get(Routes.guildEmoji(...args)), + createGuildEmoji: (guildID: Snowflake, data: RESTPostAPIGuildEmojiJSONBody) => rest.post(Routes.guildEmojis(guildID), { data }), + editGuildEmoji: (guildID: Snowflake, emojiID: Snowflake, data: RESTPatchAPIGuildEmojiJSONBody) => rest.patch(Routes.guildEmoji(guildID, emojiID), { data }), + deleteGuildEmoji: (...args: Parameters) => rest.delete(Routes.guildEmoji(...args)), + fetchMe: () => rest.get(Routes.user()), + fetchUser: (userID?: Snowflake | null) => rest.get(Routes.user(userID ?? undefined)), + editMe: (data: RESTPatchAPICurrentUserJSONBody) => rest.patch(Routes.user(), { data }), + leaveGuild: (...args: Parameters) => rest.delete(Routes.guild(...args)), + createDM: (data: RESTPostAPICurrentUserCreateDMChannelJSONBody) => rest.post(Routes.userChannels(), { data }), + getUserConnections: () => rest.get(Routes.userConnections()), + fetchTemplate: (...args: Parameters) => rest.get(Routes.template(...args)), + createGuildFromTemplate: (guildID: Snowflake, data: RESTPostAPITemplateCreateGuildJSONBody) => rest.post(Routes.template(guildID), { data }), + fetchGuildTemplates: (...args: Parameters) => rest.get(Routes.guildTemplates(...args)), + createGuildTemplate: (guildID: Snowflake, data: RESTPostAPIGuildTemplatesJSONBody) => rest.post(Routes.guildTemplates(guildID), { data }), + executeSlackWebhook: (webhookID: Snowflake, webhookToken: string, options: RESTPostAPIWebhookWithTokenSlackQuery) => rest.post(Routes.webhookPlatform(webhookID, webhookToken, 'slack'), { data: null, query: options }), + executeGithubWebhook: (webhookID: Snowflake, webhookToken: string, options: RESTPostAPIWebhookWithTokenGitHubQuery) => rest.post(Routes.webhookPlatform(webhookID, webhookToken, 'github'), { data: null, query: options }), + syncGuildTemplate: (guildID: Snowflake, templateCode: string) => rest.put(Routes.guildTemplate(guildID, templateCode)), + editGuildTemplate: (guildID: Snowflake, templateCode: string, data: RESTPatchAPIGuildTemplateJSONBody) => rest.patch(Routes.guildTemplate(guildID, templateCode), { data }), + deleteGuildTemplate: (...args: Parameters) => rest.delete(Routes.guildTemplate(...args)) +}); diff --git a/libs/snowflake/tsconfig.json b/libs/util/tsconfig.json similarity index 100% rename from libs/snowflake/tsconfig.json rename to libs/util/tsconfig.json diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 55594e6..ba0e601 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -210,25 +210,29 @@ importers: '@types/node': ^14.14.31 tslib: ^2.1.0 typescript: ^4.2.2 - libs/snowflake: + libs/store: dependencies: + '@cordis/error': link:../error tslib: 2.1.0 devDependencies: '@types/node': 14.14.31 typescript: 4.2.2 specifiers: + '@cordis/error': workspace:^0.1.7 '@types/node': ^14.14.31 tslib: ^2.1.0 typescript: ^4.2.2 - libs/store: + libs/util: dependencies: '@cordis/error': link:../error + '@cordis/rest': link:../rest tslib: 2.1.0 devDependencies: '@types/node': 14.14.31 typescript: 4.2.2 specifiers: - '@cordis/error': workspace:^0.1.7 + '@cordis/error': workspace:^0.1.6 + '@cordis/rest': workspace:^0.1.6 '@types/node': ^14.14.31 tslib: ^2.1.0 typescript: ^4.2.2