diff --git a/packages/common/package.json b/packages/common/package.json index 51aa644..efe83b8 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/common", - "version": "0.0.1", + "version": "0.0.2", "main": "./dist/index.js", "module": "./dist/index.mjs", "type": "module", diff --git a/packages/core/package.json b/packages/core/package.json index 6f77ec1..14ec09e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/core", - "version": "3.0.0", + "version": "3.0.1", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -23,9 +23,9 @@ } }, "dependencies": { - "@biscuitland/common": "^0.0.1", - "@biscuitland/rest": "^3.0.0", - "@biscuitland/ws": "^3.0.0", + "@biscuitland/common": "^0.0.2", + "@biscuitland/rest": "^3.0.1", + "@biscuitland/ws": "^3.0.1", "eventemitter2": "^6.4.9" }, "devDependencies": { diff --git a/packages/core/src/utils/types.ts b/packages/core/src/utils/types.ts new file mode 100644 index 0000000..d692ca6 --- /dev/null +++ b/packages/core/src/utils/types.ts @@ -0,0 +1,18 @@ +import type { ImageFormat } from '@biscuitland/common'; + +export type EditNickname = { nick?: string; reason?: string }; + +/** + * @link https://discord.com/developers/docs/reference#image-formatting + */ +export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096; +export type ImageOptions = { + format?: ImageFormat; + size?: ImageSize; +}; + +export enum ThreadTypes { + AnnouncementThread = 10, + PublicThread = 11, + PrivateThread = 12 +} diff --git a/packages/core/src/utils/utils.ts b/packages/core/src/utils/utils.ts new file mode 100644 index 0000000..6113b42 --- /dev/null +++ b/packages/core/src/utils/utils.ts @@ -0,0 +1,60 @@ +import { ReplaceRegex } from '@biscuitland/common'; +import { DiscordEpoch } from '@biscuitland/common'; +import { ImageFormat } from '@biscuitland/common'; +import type { ImageSize } from './types'; + +/** + * Convert a timestamp to a snowflake. + * @param timestamp The timestamp to convert. + * @returns The snowflake. + */ +export function snowflakeToTimestamp(id: string): number { + return (Number(id) >> 22) + DiscordEpoch; +} + +/** + * Format an image URL. + * @param url The URL to format. + * @param size The size of the image. + * @param format The format of the image. + * @returns The formatted URL. + */ +export function formatImageURL(url: string, size: ImageSize = 128, format?: ImageFormat): string { + return `${url}.${format ?? (url.includes('/a_') ? 'gif' : 'jpg')}?size=${size}`; +} + +/** + * Get the bot ID from a token. + * @param token The token to get the bot ID from. + * @returns The bot ID. + * @warning Discord staff has mentioned this may not be stable forever xd. + */ +export function getBotIdFromToken(token: string): string { + return Buffer.from(token.split('.')[0], 'base64').toString('ascii'); +} + +/** + * Convert an object to a URLSearchParams object. + * @param obj The object to convert. + * @returns The URLSearchParams object. + */ +export function objectToParams(obj: object): URLSearchParams { + const query = new URLSearchParams(); + for (const [key, value] of Object.entries(obj)) { + if (!value) continue; + query.append(ReplaceRegex.camel(key), String(value)); + } + + return query; +} + +/** + * Get the channel link from a channel ID and guild ID. + * + * @param channelId The channel ID. + * @param guildId The guild ID. + * @returns The channel link. + */ +export function channelLink(channelId: string, guildId?: string) { + return `https://discord.com/channels/${guildId ?? '@me'}/${channelId}`; +} diff --git a/packages/helpers/package.json b/packages/helpers/package.json index c012823..326dc47 100644 --- a/packages/helpers/package.json +++ b/packages/helpers/package.json @@ -1,75 +1,75 @@ { - "name": "@biscuitland/helpers", - "version": "3.0.0", - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "files": [ - "dist/**" - ], - "scripts": { - "build": "tsup", - "clean": "rm -rf dist && rm -rf .turbo", - "dev": "tsup --watch" - }, - "exports": { - "./package.json": "./package.json", - ".": { - "import": { - "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" - }, - "require": "./dist/index.js" - } - }, - "dependencies": { - "@biscuitland/common": "^0.0.1" - }, - "devDependencies": { - "@types/node": "^18.7.14", - "tsup": "^6.1.3" - }, - "license": "Apache-2.0", - "author": "Yuzuru ", - "contributors": [ - { - "name": "Yuzuru", - "url": "https://github.com/yuzudev", - "author": true - }, - { - "name": "miia", - "url": "https://github.com/dragurimu" - }, - { - "name": "n128", - "url": "https://github.com/nicolito128" - }, - { - "name": "socram03", - "url": "https://github.com/socram03" - }, - { - "name": "Drylozu", - "url": "https://github.com/Drylozu" - } - ], - "homepage": "https://biscuitjs.com", - "repository": { - "type": "git", - "url": "git+https://github.com/oasisjs/biscuit.git" - }, - "bugs": { - "url": "https://github.com/oasisjs/biscuit" - }, - "keywords": [ - "api", - "discord", - "bots", - "typescript", - "botdev" - ], - "publishConfig": { - "access": "public" - } -} \ No newline at end of file + "name": "@biscuitland/helpers", + "version": "3.0.1", + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist/**" + ], + "scripts": { + "build": "tsup", + "clean": "rm -rf dist && rm -rf .turbo", + "dev": "tsup --watch" + }, + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.mjs" + }, + "require": "./dist/index.js" + } + }, + "dependencies": { + "@biscuitland/common": "^0.0.2" + }, + "devDependencies": { + "@types/node": "^18.7.14", + "tsup": "^6.1.3" + }, + "license": "Apache-2.0", + "author": "Yuzuru ", + "contributors": [ + { + "name": "Yuzuru", + "url": "https://github.com/yuzudev", + "author": true + }, + { + "name": "miia", + "url": "https://github.com/dragurimu" + }, + { + "name": "n128", + "url": "https://github.com/nicolito128" + }, + { + "name": "socram03", + "url": "https://github.com/socram03" + }, + { + "name": "Drylozu", + "url": "https://github.com/Drylozu" + } + ], + "homepage": "https://biscuitjs.com", + "repository": { + "type": "git", + "url": "git+https://github.com/oasisjs/biscuit.git" + }, + "bugs": { + "url": "https://github.com/oasisjs/biscuit" + }, + "keywords": [ + "api", + "discord", + "bots", + "typescript", + "botdev" + ], + "publishConfig": { + "access": "public" + } +} diff --git a/packages/rest/package.json b/packages/rest/package.json index eb0c5d8..4439e9a 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/rest", - "version": "3.0.0", + "version": "3.0.1", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", diff --git a/packages/ws/package.json b/packages/ws/package.json index 3781cf8..6a5bcf2 100644 --- a/packages/ws/package.json +++ b/packages/ws/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/ws", - "version": "3.0.0", + "version": "3.0.1", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", @@ -24,8 +24,8 @@ } }, "dependencies": { - "@biscuitland/common": "^0.0.1", - "@biscuitland/rest": "^3.0.0", + "@biscuitland/common": "^0.0.2", + "@biscuitland/rest": "^3.0.1", "ws": "^8.13.0" }, "devDependencies": { diff --git a/packages/ws/src/shard/Shard.ts b/packages/ws/src/shard/Shard.ts index 1997a9f..1201361 100644 --- a/packages/ws/src/shard/Shard.ts +++ b/packages/ws/src/shard/Shard.ts @@ -105,6 +105,7 @@ export class Shard { else this.offlineSendQueue.push(resolve); }); } + return; } /** Close the socket connection to discord if present. */ @@ -575,8 +576,8 @@ export class Shard { } /** This function communicates with the management process, in order to know whether its free to identify. When this function resolves, this means that the shard is allowed to send an identify payload to discord. */ - async requestIdentify(): Promise {} + async requestIdentify(): Promise { } /** This function communicates with the management process, in order to tell it can identify the next shard. */ - async shardIsReady(): Promise {} + async shardIsReady(): Promise { } }