diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c382addc8..77746a261 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,15 @@ // Set *default* container specific settings.json values on container create. "settings": { - "terminal.integrated.shell.linux": "/bin/bash" + "terminal.integrated.shell.linux": "/bin/bash", + "deno.enable": true, + "deno.lint": true, + "editor.defaultFormatter": "denoland.vscode-deno", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": true, + "source.fixAll": true + } }, // Add the IDs of extensions you want installed when the container is created. @@ -20,4 +28,4 @@ // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. // "remoteUser": "vscode" -} \ No newline at end of file +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6bf456c31..4c31dcf43 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,10 +13,8 @@ jobs: deno-version: ${{ matrix.deno }} - name: Cache dependencies run: deno cache mod.ts - - name: Run local tests - run: TEST_TYPE=local deno test --allow-env - - name: Run API tests + - name: Run test script if: github.ref == 'refs/heads/master' - run: TEST_TYPE=api deno test --allow-net --allow-env + run: deno test --allow-net --allow-env env: DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} diff --git a/.gitignore b/.gitignore index f82cdf33a..33cbff9b6 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,10 @@ public/ .idea/ # Windows -desktop.ini \ No newline at end of file +desktop.ini + +# Visual Studio Code +.vscode/* +!.vscode/tasks.json +!.vscode/launch.json +*.code-workspace diff --git a/.vscode/settings.json b/.vscode/settings.json index e15e7fd59..088bb67d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,6 @@ { "deno.enable": true, "deno.lint": true, - "deno.unstable": true, "editor.defaultFormatter": "denoland.vscode-deno", "editor.formatOnSave": true, "editor.codeActionsOnSave": { diff --git a/README.md b/README.md index 1759d3482..ef5bd5094 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,22 @@ Discordeno follows [Semantic Versioning](https://semver.org/) ![Lint](https://github.com/discordeno/discordeno/workflows/Lint/badge.svg) ![Test](https://github.com/discordeno/discordeno/workflows/Test/badge.svg) +## Table of contents + +- [Features](#features) +- [Getting Started](#getting-started) + - [Minimal Example](#minimal-example) + - [Boilerplates](#boilerplates) +- [Links](#links) +- [Contributing](#contributing) + ## Features - **Secure & stable**: Discordeno is actively maintained to ensure great performance and convenience. Moreover, it internally checks all missing permissions before forwarding a request to the Discord API so that the client - does not get globally-banned by Discord. + does not get + [globally-banned by Discord](https://discord.com/developers/docs/topics/rate-limits#invalid-request-limit). - **Simple, Efficient, & Lightweight**: Discordeno is simplistic, easy-to-use, versatile while being efficient and lightweight. Follows [Convention Over Configuration](https://en.wikipedia.org/wiki/Convention_over_configuration) @@ -64,7 +74,7 @@ unofficial boilerplates: (official)](https://github.com/discordeno/slash-commands-boilerplate) - [Add Your Own!](https://github.com/discordeno/discordeno/pulls) -## Useful Links +## Links - [Website](https://discordeno.mod.land) - [Documentation](https://doc.deno.land/https/deno.land/x/discordeno/mod.ts) @@ -74,7 +84,3 @@ unofficial boilerplates: We appreciate your help! Before contributing, please read the [Contributing Guide](https://github.com/discordeno/discordeno/blob/master/.github/CONTRIBUTING.md). - -### License - -[License can be found here](https://github.com/discordeno/discordeno/blob/master/LICENSE) diff --git a/docs/src/README.md b/docs/src/README.md index 20afdd20f..fbdc3ec3f 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -54,5 +54,5 @@ resources: - [TypeScript Crash Course by Traversy Media](https://www.youtube.com/watch?v=rAy_3SIqT-E) -There is always more resources... Take your time and don't fret! Come back when +There are always more resources... Take your time and don't fret! Come back when you are ready, we can't wait to see what your Discordeno created bot does! diff --git a/docs/src/faq.md b/docs/src/faq.md index 04ecfcc44..e8bfdf840 100644 --- a/docs/src/faq.md +++ b/docs/src/faq.md @@ -21,13 +21,14 @@ of it's code! A breaking change in typings is a breaking change for the library! ## How Stable Is Discordeno? -One of the biggest issues with almost every library(I have used) is stability. -None of the libraries gave much love and attention to TypeScript developers the -way it deserves. Sometimes TypeScript projects would break because breaking -changes to typings did not make a MAJOR bump so TypeScript bots in production -would break. Sometimes I was personally maintaing the typings because no one -else was for that lib. Some libs were pre 1.0 and didn't even have a stable -branch/version where I would not have to worry about breaking changes. +One of the biggest issues with almost every library (that I have used) is +stability. None of the libraries gave much love and attention to TypeScript +developers the way it deserves. Sometimes TypeScript projects would break +because breaking changes to typings did not make a MAJOR bump so TypeScript bots +in production would break. Sometimes I was personally maintaining the typings +because no one else was for that lib. Some libs were pre 1.0 and didn't even +have a stable branch/version where I would not have to worry about breaking +changes. This is why I made it one of my foundational goals of this library to have the best stability for TypeScript developers. No matter how small, a breaking change diff --git a/src/api/structures/guild.ts b/src/api/structures/guild.ts index bffd97546..f1cc711cb 100644 --- a/src/api/structures/guild.ts +++ b/src/api/structures/guild.ts @@ -146,7 +146,7 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) { ); await Promise.all(channels.map(async (channel) => { - const channelStruct = await structures.createChannel(channel); + const channelStruct = await structures.createChannel(channel, rest.id); return cacheHandlers.set("channels", channelStruct.id, channelStruct); })); diff --git a/src/util/permissions.ts b/src/util/permissions.ts index 97a97ac27..8579cb99b 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -52,15 +52,15 @@ export async function botHasPermission( guildID: string, permissions: Permission[], ) { - const member = await cacheHandlers.get("members", botID); - if (!member) return false; - const guild = await cacheHandlers.get("guilds", guildID); if (!guild) return false; // Check if the bot is the owner of the guild, if it is, returns true if (guild.ownerID === botID) return true; + const member = await cacheHandlers.get("members", botID); + if (!member) return false; + // The everyone role is not in member.roles const permissionBits = [...member.guilds.get(guildID)?.roles || [], guild.id] .map((id) => guild.roles.get(id)!) diff --git a/test/mod.test.ts b/test/mod.test.ts index 15fca7706..9ba38479a 100644 --- a/test/mod.test.ts +++ b/test/mod.test.ts @@ -13,6 +13,7 @@ import { cache, Channel, channelOverwriteHasPermission, + closeWS, createGuildChannel, createGuildRole, createServer, @@ -36,7 +37,6 @@ import { export const defaultTestOptions: Partial = { sanitizeOps: false, sanitizeResources: false, - ignore: Deno.env.get("TEST_TYPE") !== "api", }; // Temporary data @@ -59,14 +59,6 @@ Deno.test({ intents: ["GUILD_MESSAGES", "GUILDS"], }); - eventHandlers.ready = () => { - if (cache.guilds.size >= 10) { - cache.guilds.map((guild) => - guild.ownerID === botID && deleteServer(guild.id) - ); - } - }; - // Delay the execution by 5 seconds await delay(5000); @@ -348,8 +340,9 @@ Deno.test({ // Forcefully exit the Deno process once all tests are done. Deno.test({ - name: "exit the process forcefully after all the tests are done\n", + name: "[main] close the websocket connection", fn() { - Deno.exit(); + closeWS(); }, + ...defaultTestOptions, });