This commit is contained in:
MARCROCK22 2023-06-01 18:47:24 -04:00 committed by GitHub
parent 87cdad0b03
commit 88d687d697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 164 additions and 85 deletions

View File

@ -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",

View File

@ -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": {

View File

@ -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
}

View File

@ -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}`;
}

View File

@ -1,6 +1,6 @@
{
"name": "@biscuitland/helpers",
"version": "3.0.0",
"version": "3.0.1",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
@ -23,7 +23,7 @@
}
},
"dependencies": {
"@biscuitland/common": "^0.0.1"
"@biscuitland/common": "^0.0.2"
},
"devDependencies": {
"@types/node": "^18.7.14",

View File

@ -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",

View File

@ -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": {

View File

@ -105,6 +105,7 @@ export class Shard {
else this.offlineSendQueue.push(resolve);
});
}
return;
}
/** Close the socket connection to discord if present. */