From 35e85ba628d97cdc50189ae646811795a7e4da23 Mon Sep 17 00:00:00 2001 From: socram03 Date: Mon, 5 Jun 2023 09:05:01 +0000 Subject: [PATCH] chore: fixes update --- README.md | 41 ++++++++++------------- packages/core/README.md | 8 ++--- packages/core/package.json | 2 +- packages/core/src/managers/MainManager.ts | 12 +++---- packages/core/src/session.ts | 8 ++++- packages/helpers/README.md | 4 +-- packages/helpers/package.json | 2 +- packages/rest/package.json | 2 +- packages/ws/README.md | 24 ++++++++----- packages/ws/package.json | 2 +- 10 files changed, 56 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 688ae9f..a4cee95 100644 --- a/README.md +++ b/README.md @@ -28,37 +28,34 @@ The Proxy object enables dynamic, flexible and efficient calls to the API, it is ## Example bot (TS/JS) -```js +```ts import { Session } from '@biscuitland/core'; import { GatewayIntentBits, InteractionType, InteractionResponseType } from '@biscuitland/common'; const session = new Session({ - intents: GatewayIntentBits.Guilds, - token: 'your token goes here' + intents: GatewayIntentBits.Guilds, + token: 'your token goes here' }); -const commands = [{ +const commands = [ + { name: 'ping', description: 'Replies with pong!' -}]; + } +]; -session.on('READY', (payload) => { - const username = payload.user.username; - console.log('I\'m ready! logged in as %s', username); - - const [shardId, _shardCount] = payload.shard ?? [0, 0]; - - if (shardId === 0) session.managers.application.bulkCommands(session.applicationId!, commands); +session.once('READY', (payload) => { + const username = payload.user.username; + console.log('Logged in as: %s', username); + session.managers.applications.bulkCommands(session.applicationId, commands); }); session.on('INTERACTION_CREATE', (interaction) => { - if (interaction.type !== InteractionType.ApplicationCommand) return; - session.managers.interaction.reply(interaction.id, interaction.token, { - body: { - type: InteractionResponseType.ChannelMessageWithSource, - data: { content: 'pong!' } - } - }); + if (interaction.type !== InteractionType.ApplicationCommand) return; + session.managers.interactions.reply(interaction.id, interaction.token, { + type: InteractionResponseType.ChannelMessageWithSource, + data: { content: 'pong!' } + }); }); session.start(); @@ -68,8 +65,4 @@ session.start(); * [Website](https://biscuitjs.com/) * [Documentation](https://docs.biscuitjs.com/) * [Discord](https://discord.gg/XNw2RZFzaP) -* [core](https://www.npmjs.com/package/@biscuitland/core) | [api-types](https://www.npmjs.com/package/@biscuitland/api-types) | [cache](https://www.npmjs.com/package/@biscuitland/cache) | [rest](https://www.npmjs.com/package/@biscuitland/rest) | [ws](https://www.npmjs.com/package/@biscuitland/ws) | [helpers](https://www.npmjs.com/package/@biscuitland/helpers) - -## Known issues: -- node18 is required to run the library, however --experimental-fetch flag should work on node16+ -- no optimal way to deliver a webspec bun version to the registry (#50) +* [core](https://www.npmjs.com/package/@biscuitland/core) | [rest](https://www.npmjs.com/package/@biscuitland/rest) | [ws](https://www.npmjs.com/package/@biscuitland/ws) | [helpers](https://www.npmjs.com/package/@biscuitland/helpers) diff --git a/packages/core/README.md b/packages/core/README.md index e7c4f0b..1c808ab 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -15,14 +15,14 @@ yarn add @biscuitland/core ### Example bot `project/index.js`: -```js +```ts import { Session } from '@biscuitland/core'; -import { GatewayIntentBits } from "discord-api-types/v10"; +import { GatewayIntentBits } from '@biscuitland/common'; const session = new Session({ token: 'your token', intents: GatewayIntentBits.Guilds }); -session.events.on('READY', (payload) => { - console.log('Logged in as:', payload.user.username); +session.on('READY', (payload, shardId) => { + console.log('Logged in as: %s in shard #%s', payload.user.username, shardId); }); session.start(); diff --git a/packages/core/package.json b/packages/core/package.json index 0090c77..4247c3b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/core", - "version": "3.0.2", + "version": "3.0.3", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", diff --git a/packages/core/src/managers/MainManager.ts b/packages/core/src/managers/MainManager.ts index de336e0..1211942 100644 --- a/packages/core/src/managers/MainManager.ts +++ b/packages/core/src/managers/MainManager.ts @@ -13,16 +13,16 @@ export class MainManager { this.guilds = new GuildManager(this.session); this.members = new MemberManager(this.session); this.channels = new ChannelManager(this.session); - this.application = new ApplicationManager(this.session); - this.interaction = new InteractionManager(this.session); - this.webhook = new WebhookManager(this.session); + this.applications = new ApplicationManager(this.session); + this.interactions = new InteractionManager(this.session); + this.webhooks = new WebhookManager(this.session); } users: UserManager; guilds: GuildManager; members: MemberManager; channels: ChannelManager; - application: ApplicationManager; - interaction: InteractionManager; - webhook: WebhookManager; + applications: ApplicationManager; + interactions: InteractionManager; + webhooks: WebhookManager; } diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index 9079784..3db1a9c 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -86,7 +86,7 @@ export class Session extends EventEmitter2 { ctx.gateway = new GatewayManager({ token: this.options.token, intents: this.options.intents ?? 0, - connection: this.options.defaultGatewayOptions?.connection ?? (await this.rest.get('/gateway/bot')), + connection: this.options.defaultGatewayOptions?.connection ?? (await this.api.gateway.bot.get()), async handlePayload(shard, data) { const { t, d } = data; if (!(t && d)) return; @@ -95,6 +95,12 @@ export class Session extends EventEmitter2 { ...this.options.defaultGatewayOptions }); + ctx.once('READY', (payload) => { + const { user, application } = payload; + this.botId = user.id; + this.applicationId = application.id; + }); + await ctx.gateway.spawnShards(); } } diff --git a/packages/helpers/README.md b/packages/helpers/README.md index ee985bf..8a49d07 100644 --- a/packages/helpers/README.md +++ b/packages/helpers/README.md @@ -17,5 +17,5 @@ yarn add @biscuitland/helpers ## Links * [Website](https://biscuitjs.com/) * [Documentation](https://docs.biscuitjs.com/) -* [Discord](https://discord.gg/XNw2RZFzaP) -* [core](https://www.npmjs.com/package/@biscuitland/core) | [api-types](https://www.npmjs.com/package/@biscuitland/api-types) | [cache](https://www.npmjs.com/package/@biscuitland/cache) | [rest](https://www.npmjs.com/package/@biscuitland/rest) | [ws](https://www.npmjs.com/package/@biscuitland/ws) +* [Discord](https://discord.gg/XNw2RZFzaP) +* [core](https://www.npmjs.com/package/@biscuitland/core) | [rest](https://www.npmjs.com/package/@biscuitland/rest) | [ws](https://www.npmjs.com/package/@biscuitland/ws) \ No newline at end of file diff --git a/packages/helpers/package.json b/packages/helpers/package.json index f2781be..d468055 100644 --- a/packages/helpers/package.json +++ b/packages/helpers/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/helpers", - "version": "3.0.4", + "version": "3.0.5", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", diff --git a/packages/rest/package.json b/packages/rest/package.json index 53224cf..26b4845 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/rest", - "version": "3.0.2", + "version": "3.0.3", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", diff --git a/packages/ws/README.md b/packages/ws/README.md index 5392428..d61623d 100644 --- a/packages/ws/README.md +++ b/packages/ws/README.md @@ -23,21 +23,29 @@ yarn add @biscuitland/ws ## Example ```ts -import { GatewayManager } from '@biscuitland/ws'; -import { BiscuitREST } from '@biscuitland/rest'; -import { GatewayIntentBits, Routes} from '@biscuitland/common'; +import { GatewayManager } from "@biscuitland/ws"; +import { BiscuitREST, Router } from "@biscuitland/rest"; +import { GatewayIntentBits } from "@biscuitland/common"; const intents = GatewayIntentBits.Guilds; -const token = 'your token goes here'; +const token = "your token goes here"; const rest = new BiscuitREST({ token }); +const api = new Router(rest).createProxy(); (async () => { - const connection = await rest.get(Routes.gatewayBot()) + const connection = await api.gateway.bot.get(); - // gateway bot code ↓ - const ws = new GatewayManager({ token, intents, connection }); + // gateway bot code ↓ + const ws = new GatewayManager({ + token, + intents, + connection, + async handlePayload(shardId, payload) { + console.log("Received payload on shard #%s", shardId, payload); + }, + }); - await ws.spawnShards(); + await ws.spawnShards(); })(); ``` diff --git a/packages/ws/package.json b/packages/ws/package.json index 164f314..c18b931 100644 --- a/packages/ws/package.json +++ b/packages/ws/package.json @@ -1,6 +1,6 @@ { "name": "@biscuitland/ws", - "version": "3.0.2", + "version": "3.0.3", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts",