From 59631f2facdda38498f56084853d546e6530c838 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 28 Oct 2023 13:25:09 +0000 Subject: [PATCH] format --- packages/bot/src/commandOptionsParser.ts | 2 +- packages/bot/src/transformers/member.ts | 4 +-- .../bot/src/transformers/reverse/index.ts | 1 - packages/bot/src/transformers/role.ts | 8 ++--- .../transformers/toggles/ToggleBitfield.ts | 4 +-- packages/bot/src/transformers/toggles/role.ts | 4 +-- packages/bot/src/utils.ts | 2 +- packages/discordeno/bin/disocrdeno.js | 0 packages/rest/src/invalidBucket.ts | 12 ++++++-- packages/rest/tests/e2e/message.spec.ts | 30 +++++++++---------- packages/rest/tests/e2e/user.spec.ts | 2 +- packages/utils/src/bucket.ts | 2 +- packages/utils/tests/bucket.spec.ts | 24 +++++++-------- website/docs/beginner/env.md | 19 +++++------- website/docs/bigbot/step-3-gateway.md | 2 +- website/docs/examples/deno.md | 22 +++++++------- website/src/components/home/faq/index.tsx | 6 ++-- 17 files changed, 74 insertions(+), 70 deletions(-) mode change 100644 => 100755 packages/discordeno/bin/disocrdeno.js diff --git a/packages/bot/src/commandOptionsParser.ts b/packages/bot/src/commandOptionsParser.ts index 938496b9a..3c550c0ca 100644 --- a/packages/bot/src/commandOptionsParser.ts +++ b/packages/bot/src/commandOptionsParser.ts @@ -27,7 +27,7 @@ export function commandOptionsParser(interaction: Interaction, options?: Interac break case ApplicationCommandOptionTypes.Attachment: args[option.name] = interaction.data.resolved?.attachments?.get(BigInt(option.value!)) - break; + break case ApplicationCommandOptionTypes.Mentionable: // Mentionable are roles or users args[option.name] = interaction.data.resolved?.roles?.get(BigInt(option.value!)) ?? { diff --git a/packages/bot/src/transformers/member.ts b/packages/bot/src/transformers/member.ts index 1761515ab..eb50a5603 100644 --- a/packages/bot/src/transformers/member.ts +++ b/packages/bot/src/transformers/member.ts @@ -21,8 +21,8 @@ export function transformMember(bot: Bot, payload: DiscordMember, guildId: BigSt const member: Member = Object.create(baseMember) const props = bot.transformers.desiredProperties.member - if (userId && props.id) member.id = typeof userId === "string" ? bot.transformers.snowflake(userId) : userId - if (guildId && props.guildId) member.guildId = typeof guildId === "string" ? bot.transformers.snowflake(guildId) : guildId + if (userId && props.id) member.id = typeof userId === 'string' ? bot.transformers.snowflake(userId) : userId + if (guildId && props.guildId) member.guildId = typeof guildId === 'string' ? bot.transformers.snowflake(guildId) : guildId if (payload.user && props.user) member.user = bot.transformers.user(bot, payload.user) if (payload.nick && props.nick) member.nick = payload.nick if (payload.roles && props.roles) member.roles = payload.roles.map((id) => bot.transformers.snowflake(id)) diff --git a/packages/bot/src/transformers/reverse/index.ts b/packages/bot/src/transformers/reverse/index.ts index 27cd33208..f6e9be5a3 100644 --- a/packages/bot/src/transformers/reverse/index.ts +++ b/packages/bot/src/transformers/reverse/index.ts @@ -17,4 +17,3 @@ export * from './member.js' export * from './presence.js' export * from './team.js' export * from './widgetSettings.js' - diff --git a/packages/bot/src/transformers/role.ts b/packages/bot/src/transformers/role.ts index a9b143549..fca3d86a5 100644 --- a/packages/bot/src/transformers/role.ts +++ b/packages/bot/src/transformers/role.ts @@ -32,11 +32,11 @@ const baseRole: Partial & BaseRole = { }, /** Whether this role is available for purchase. */ get availableForPurchase() { - return !!this.toggles?.has('availableForPurchase'); + return !!this.toggles?.has('availableForPurchase') }, /** Whether this is a guild's linked role. */ get guildConnections() { - return !!this.toggles?.has('guildConnections'); + return !!this.toggles?.has('guildConnections') }, } @@ -111,8 +111,8 @@ export interface Role extends BaseRole { managed: boolean /** Whether this role is mentionable */ mentionable: boolean - /** - * Use role.tags + /** + * Use role.tags * @deprecated this is not deprecated, but this is here to prevent users from using this as this is an internal value open to breaking changes. */ internalTags?: { diff --git a/packages/bot/src/transformers/toggles/ToggleBitfield.ts b/packages/bot/src/transformers/toggles/ToggleBitfield.ts index 6777ab373..1fde6d986 100644 --- a/packages/bot/src/transformers/toggles/ToggleBitfield.ts +++ b/packages/bot/src/transformers/toggles/ToggleBitfield.ts @@ -23,7 +23,7 @@ export class ToggleBitfield { } toJSON(): number { - return this.bitfield; + return this.bitfield } } @@ -52,6 +52,6 @@ export class ToggleBitfieldBigint { } toJSON(): string { - return this.bitfield.toString(); + return this.bitfield.toString() } } diff --git a/packages/bot/src/transformers/toggles/role.ts b/packages/bot/src/transformers/toggles/role.ts index 99182eea3..fe52c9cb7 100644 --- a/packages/bot/src/transformers/toggles/role.ts +++ b/packages/bot/src/transformers/toggles/role.ts @@ -55,12 +55,12 @@ export class RoleToggles extends ToggleBitfield { /** Whether this role is available for purchase. */ get availableForPurchase(): boolean { - return this.has('availableForPurchase'); + return this.has('availableForPurchase') } /** Whether this is a guild's linked role. */ get guildConnections(): boolean { - return this.has('guildConnections'); + return this.has('guildConnections') } /** Checks whether or not the permissions exist in this */ diff --git a/packages/bot/src/utils.ts b/packages/bot/src/utils.ts index c7c2ec052..7ed94fe2d 100644 --- a/packages/bot/src/utils.ts +++ b/packages/bot/src/utils.ts @@ -10,4 +10,4 @@ export function bigintToSnowflake(snowflake: BigString): string { export function snowflakeToTimestamp(id: bigint): number { return Number(id / 4194304n + 1420070400000n) -} \ No newline at end of file +} diff --git a/packages/discordeno/bin/disocrdeno.js b/packages/discordeno/bin/disocrdeno.js old mode 100644 new mode 100755 diff --git a/packages/rest/src/invalidBucket.ts b/packages/rest/src/invalidBucket.ts index e2effd61f..7a9bbdbce 100644 --- a/packages/rest/src/invalidBucket.ts +++ b/packages/rest/src/invalidBucket.ts @@ -55,10 +55,18 @@ export function createInvalidRequestBucket(options: InvalidRequestBucketOptions) bucket.processing = true while (bucket.waiting.length > 0) { - logger.info(`[InvalidBucket] processing waiting queue while loop ran with ${bucket.waiting.length} pending requests to be made. ${JSON.stringify(bucket)}`) + logger.info( + `[InvalidBucket] processing waiting queue while loop ran with ${bucket.waiting.length} pending requests to be made. ${JSON.stringify( + bucket, + )}`, + ) if (!bucket.isRequestAllowed() && bucket.resetAt !== undefined) { - logger.warn(`[InvalidBucket] processing waiting queue is now paused until more requests are available. ${bucket.waiting.length} pending requests. ${JSON.stringify(bucket)}`) + logger.warn( + `[InvalidBucket] processing waiting queue is now paused until more requests are available. ${ + bucket.waiting.length + } pending requests. ${JSON.stringify(bucket)}`, + ) await delay(bucket.resetAt - Date.now()) } diff --git a/packages/rest/tests/e2e/message.spec.ts b/packages/rest/tests/e2e/message.spec.ts index fdc7959f0..2eb624647 100644 --- a/packages/rest/tests/e2e/message.spec.ts +++ b/packages/rest/tests/e2e/message.spec.ts @@ -43,8 +43,8 @@ describe('Send a message', () => { expect(attachment.filename).to.be.equal('gamer') }) - it ('With a file attachment', async () => { - const txtFile = new Blob(['hello world'], { type: 'text/plain' }); + it('With a file attachment', async () => { + const txtFile = new Blob(['hello world'], { type: 'text/plain' }) const fileMsg = await rest.sendMessage(e2ecache.channel.id, { content: '222', @@ -54,15 +54,15 @@ describe('Send a message', () => { blob: txtFile, }, ], - }); + }) - expect(fileMsg.id).not.equals(undefined); - expect(fileMsg.content).equals('222'); - expect(fileMsg.attachments.length).equals(1); - expect(fileMsg.attachments.at(0)?.filename).equals('application.txt'); - expect(fileMsg.attachments.at(0)?.size).equals(11); + expect(fileMsg.id).not.equals(undefined) + expect(fileMsg.content).equals('222') + expect(fileMsg.attachments.length).equals(1) + expect(fileMsg.attachments.at(0)?.filename).equals('application.txt') + expect(fileMsg.attachments.at(0)?.size).equals(11) - const txtFile2 = new Blob(['hello world edit'], { type: 'text/plain' }); + const txtFile2 = new Blob(['hello world edit'], { type: 'text/plain' }) const edited = await rest.editMessage(e2ecache.channel.id, fileMsg.id, { content: '222 edit', @@ -72,13 +72,13 @@ describe('Send a message', () => { blob: txtFile2, }, ], - }); + }) - expect(edited.id).not.equals(undefined); - expect(edited.content).equals('222 edit'); - expect(edited.attachments.length).equals(1); - expect(edited.attachments.at(0)?.filename).equals('application_edit.txt'); - expect(edited.attachments.at(0)?.size).equals(16); + expect(edited.id).not.equals(undefined) + expect(edited.content).equals('222 edit') + expect(edited.attachments.length).equals(1) + expect(edited.attachments.at(0)?.filename).equals('application_edit.txt') + expect(edited.attachments.at(0)?.size).equals(16) }) }) diff --git a/packages/rest/tests/e2e/user.spec.ts b/packages/rest/tests/e2e/user.spec.ts index 2ec8b3b36..2154dab70 100644 --- a/packages/rest/tests/e2e/user.spec.ts +++ b/packages/rest/tests/e2e/user.spec.ts @@ -32,7 +32,7 @@ describe('Get a user from the api', () => { }) it('Has a valid discriminator', () => { - expect(user.discriminator.length).to.be.oneOf([1,4]) + expect(user.discriminator.length).to.be.oneOf([1, 4]) }) it('Has been camelized', () => { diff --git a/packages/utils/src/bucket.ts b/packages/utils/src/bucket.ts index c23a61e75..f762952d9 100644 --- a/packages/utils/src/bucket.ts +++ b/packages/utils/src/bucket.ts @@ -37,7 +37,7 @@ export class LeakyBucket implements LeakyBucketOptions { this.refillsAt = undefined // Reset the timeoutId clearTimeout(this.timeoutId) - this.timeoutId = undefined; + this.timeoutId = undefined if (this.used > 0) { this.timeoutId = setTimeout(() => { diff --git a/packages/utils/tests/bucket.spec.ts b/packages/utils/tests/bucket.spec.ts index 98ac27037..fb4b72709 100644 --- a/packages/utils/tests/bucket.spec.ts +++ b/packages/utils/tests/bucket.spec.ts @@ -170,18 +170,18 @@ describe('bucket.ts', () => { expect(bucket.used).equals(1) }) - describe('remaining', () => { - it("should be 0 even used too many", () => { - const bucket = new LeakyBucket({ - max: 1, - refillInterval: 500, - refillAmount: 1, + describe('remaining', () => { + it('should be 0 even used too many', () => { + const bucket = new LeakyBucket({ + max: 1, + refillInterval: 500, + refillAmount: 1, + }) + // max is < used + bucket.used = 2 + expect(bucket.remaining).equals(0) }) - // max is < used - bucket.used = 2; - expect(bucket.remaining).equals(0); }) - }) it("Don't process queue twice", () => { const bucket = new LeakyBucket({ @@ -190,9 +190,9 @@ describe('bucket.ts', () => { refillAmount: 1, }) // fake processing - bucket.processing = true; + bucket.processing = true // request when already processing - bucket.processQueue(); + bucket.processQueue() }) }) }) diff --git a/website/docs/beginner/env.md b/website/docs/beginner/env.md index 63eb29d8b..6bc045a75 100644 --- a/website/docs/beginner/env.md +++ b/website/docs/beginner/env.md @@ -11,7 +11,6 @@ Before you can set up a `.env` file with TypeScript in Node.js, you need to inst `npm install dotenv @types/dotenv --save-dev` - ## Step 2: Create a .env File 1. Create a new file named `.env` in the root directory of your project. @@ -19,28 +18,26 @@ Before you can set up a `.env` file with TypeScript in Node.js, you need to inst VAR_NAME=value - For example: ```js -DB_HOST=localhost -DB_USER=admin -DB_PASS=password123 +DB_HOST = localhost +DB_USER = admin +DB_PASS = password123 ``` - ## Step 3: Load Environment Variables 1. In your TypeScript file, import the `dotenv` package: ```ts -import dotenv from 'dotenv'; +import dotenv from 'dotenv' ``` 2. Call the config method of the dotenv package to load the environment variables from the .env file: ```ts -dotenv.config(); +dotenv.config() ``` ## Step 4: Access Environment Variables @@ -48,9 +45,9 @@ dotenv.config(); You can now access your environment variables using the process.env object. For example: ```ts -const dbHost = process.env.DB_HOST; -const dbUser = process.env.DB_USER; -const dbPass = process.env.DB_PASS; +const dbHost = process.env.DB_HOST +const dbUser = process.env.DB_USER +const dbPass = process.env.DB_PASS ``` And that's it! You have now set up a .env file with TypeScript in Node.js and can access your environment variables in your code. diff --git a/website/docs/bigbot/step-3-gateway.md b/website/docs/bigbot/step-3-gateway.md index 94dc9dc3c..8d54d108a 100644 --- a/website/docs/bigbot/step-3-gateway.md +++ b/website/docs/bigbot/step-3-gateway.md @@ -149,7 +149,7 @@ GATEWAY.tellWorkerToIdentify = async function (workerId, shardId, bucketId) { method: 'POST', headers: { authorization: process.env.AUTHORIZATION, - "Content-type": "application/json", + 'Content-type': 'application/json', }, body: JSON.stringify({ type: 'IDENTIFY_SHARD', shardId }), }) diff --git a/website/docs/examples/deno.md b/website/docs/examples/deno.md index 922dd6304..97bde18e5 100644 --- a/website/docs/examples/deno.md +++ b/website/docs/examples/deno.md @@ -13,26 +13,24 @@ To do it you can use a workaround provided here: https://nest.land/package/katsu You would use it like this. ```ts -import { load } from "https://x.nest.land/Yenv@1.0.0/mod.ts"; +import { load } from 'https://x.nest.land/Yenv@1.0.0/mod.ts' // Import it like this. There might be a newer version of this fix later, but I would not expect much changes. -import { fixGatewayWebsocket } from "https://x.nest.land/katsura@1.3.9/src/discordenoFixes/gatewaySocket.ts"; -import { createBot } from "npm:@discordeno/bot@19.0.0-next.5c42bdd"; +import { fixGatewayWebsocket } from 'https://x.nest.land/katsura@1.3.9/src/discordenoFixes/gatewaySocket.ts' +import { createBot } from 'npm:@discordeno/bot@19.0.0-next.5c42bdd' const env = await load({ token: /[M-Z][A-Za-z\d]{23}\.[\w-]{6}\.[\w-]{27}/, -}); - +}) const bot = createBot({ token: env.token, events: { - ready: (data) => console.log(`Shard ${data.shardId} ready`) - } -}); + ready: data => console.log(`Shard ${data.shardId} ready`), + }, +}) // Use this function with the gateway managerr -fixGatewayWebsocket(bot.gateway); +fixGatewayWebsocket(bot.gateway) -await bot.start(); - -``` \ No newline at end of file +await bot.start() +``` diff --git a/website/src/components/home/faq/index.tsx b/website/src/components/home/faq/index.tsx index 5747e0b1a..ffd0aa9b5 100644 --- a/website/src/components/home/faq/index.tsx +++ b/website/src/components/home/faq/index.tsx @@ -58,12 +58,14 @@ const questions = [ }, { question: "Why doesn't Discordeno use classes like other libraries?", - answer: "Generally, Discordeno does not use classes. Instead, Discordeno uses plain JavaScript objects to define commands, events, and other components. However, in certain cases where it makes sense, we do use classes. This design choice was made to keep the library lightweight and simple and to allow for more flexible and dynamic code, as components can be easily modified and extended at runtime. While classes can be useful in some cases, Discordeno has chosen to use a more functional approach.", + answer: + 'Generally, Discordeno does not use classes. Instead, Discordeno uses plain JavaScript objects to define commands, events, and other components. However, in certain cases where it makes sense, we do use classes. This design choice was made to keep the library lightweight and simple and to allow for more flexible and dynamic code, as components can be easily modified and extended at runtime. While classes can be useful in some cases, Discordeno has chosen to use a more functional approach.', defaultExpanded: false, }, { question: 'Can I still use classes in my bot with Discordeno?', - answer: "Yes! While Discordeno itself does not use classes, you can still use classes in your own code by using one of the many libraries or frameworks that provide class-based abstractions on top of Discordeno. Some examples of such libraries include the Discordeno.js which provides a very similar framework and API to Discord.js, or the Sinf library that provides a similar API to Eris library. These libraries provide classes and other abstractions that can help simplify the development of your bot, while still leveraging the power and flexibility of Discordeno's underlying object-based API. Make sure to check the documentation of these libraries for more information on how to use them in your bot.", + answer: + "Yes! While Discordeno itself does not use classes, you can still use classes in your own code by using one of the many libraries or frameworks that provide class-based abstractions on top of Discordeno. Some examples of such libraries include the Discordeno.js which provides a very similar framework and API to Discord.js, or the Sinf library that provides a similar API to Eris library. These libraries provide classes and other abstractions that can help simplify the development of your bot, while still leveraging the power and flexibility of Discordeno's underlying object-based API. Make sure to check the documentation of these libraries for more information on how to use them in your bot.", defaultExpanded: false, }, ]