-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initialize project * feat: setup changeset * chore: add changeset * feat: implement what-is-dis package * feat: add simple bot with bun for example * feat: add more user and role input * remove low-level discord package and use discord.js instead * feat: add type-safe for choices * feat: add customizable internal logger * chore: add debug logger * chore: add more logger * fix attachment bug * docs: update README.md * chore: remove changeset file * docs: update README.md * feat: add ci and release workflow * docs: update README.md * Create proud-seals-share.md * chore: fix script * Update .changeset/proud-seals-share.md
- Loading branch information
1 parent
d785d70
commit c210c4b
Showing
43 changed files
with
2,506 additions
and
3,509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": ["@changesets/changelog-github", { "repo": "softnetics/what-is-dis" }], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@softnetics/what-is-dis": major | ||
--- | ||
|
||
First Major Release! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@internal/project-config/eslint/base') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Continuous Integration | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 40 | ||
concurrency: | ||
group: ci-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
name: Checkout | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: dtinth/setup-github-actions-caching-for-turbo@v1 | ||
|
||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- name: Setup node with cache | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: pnpm | ||
|
||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Run lint | ||
run: pnpm lint --parallel | ||
|
||
- name: Run build | ||
run: pnpm build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Release with reusable workflows | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
actions: read | ||
checks: read | ||
contents: write | ||
deployments: read | ||
issues: write | ||
discussions: read | ||
packages: write | ||
pull-requests: write | ||
repository-projects: read | ||
security-events: read | ||
statuses: read | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
release: | ||
uses: softnetics/workflows/.github/workflows/release-packages.yaml@main | ||
with: | ||
before-publish: pnpm build | ||
package-manager: pnpm | ||
secrets: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ coverage | |
.next/ | ||
out/ | ||
build | ||
dist | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@internal/project-config/prettier/base') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
{ | ||
"eslint.workingDirectories": [ | ||
{ | ||
"mode": "auto" | ||
} | ||
] | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"javascript.preferences.importModuleSpecifier": "shortest", | ||
"typescript.format.enable": true, | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"[prisma]": { | ||
"editor.defaultFormatter": "Prisma.prisma" | ||
}, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Softnetics | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,123 @@ | ||
# Turborepo starter | ||
# What Is Dis <!-- omit in toc --> | ||
|
||
This is an official starter Turborepo. | ||
Typescript Discord bot framework aims to be a simple and easy to use framework for creating discord bots. It is built on top of [discord.js](https://discord.js.org/#/) | ||
|
||
## Using this example | ||
# Table of Contents <!-- omit in toc --> | ||
|
||
Run the following command: | ||
# Installation | ||
|
||
```sh | ||
npx create-turbo@latest | ||
```bash | ||
npm install discord.js @softnetics/what-is-dis | ||
# Or | ||
yarn add discord.js @softnetics/what-is-dis | ||
# Or | ||
pnpm add discord.js @softnetics/what-is-dis | ||
# Or | ||
bun add discord.js @softnetics/what-is-dis | ||
``` | ||
|
||
## What's inside? | ||
|
||
This Turborepo includes the following packages/apps: | ||
|
||
### Apps and Packages | ||
|
||
- `docs`: a [Next.js](https://nextjs.org/) app | ||
- `web`: another [Next.js](https://nextjs.org/) app | ||
- `ui`: a stub React component library shared by both `web` and `docs` applications | ||
- `eslint-config-custom`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`) | ||
- `tsconfig`: `tsconfig.json`s used throughout the monorepo | ||
|
||
Each package/app is 100% [TypeScript](https://www.typescriptlang.org/). | ||
|
||
### Utilities | ||
|
||
This Turborepo has some additional tools already setup for you: | ||
|
||
- [TypeScript](https://www.typescriptlang.org/) for static type checking | ||
- [ESLint](https://eslint.org/) for code linting | ||
- [Prettier](https://prettier.io) for code formatting | ||
|
||
### Build | ||
|
||
To build all apps and packages, run the following command: | ||
|
||
``` | ||
cd my-turborepo | ||
pnpm build | ||
# Usage | ||
|
||
```ts | ||
import { GatewayIntentBits } from '@discordjs/core' | ||
import { DiscordBot, defineSlashCommandBasic } from '@softnetics/what-is-dis' | ||
|
||
const pingCommand = defineSlashCommandBasic({ | ||
name: 'ping', | ||
description: 'Ping!', | ||
options: { | ||
message: { | ||
type: 'string', | ||
description: 'Message to echo back', | ||
choices: [ | ||
{ name: 'Hello', value: 'hello' }, | ||
{ name: 'World', value: 'world' }, | ||
], | ||
}, | ||
to: { | ||
type: 'user', | ||
description: 'User to ping', | ||
required: true, | ||
}, | ||
}, | ||
execute: async ({ interaction, body, logger }) => { | ||
const message = body.message // Type: "hello" | "world" | undefined | ||
const user = body.to // Type: string (user id) | ||
logger.info(`Received /ping command with message: ${message} and user: ${user}`) | ||
await interaction.reply({ | ||
content: `Pong! ${message} <@${user}>`, | ||
}) | ||
}, | ||
}) | ||
|
||
// Create a discord bot instance | ||
const bot = new DiscordBot({ | ||
clientId: environment.DISCORD_CLIENT_ID, | ||
token: environment.DISCORD_TOKEN, | ||
intents: [ | ||
GatewayIntentBits.Guilds, | ||
GatewayIntentBits.GuildMessages, | ||
GatewayIntentBits.MessageContent, | ||
], | ||
// If this value is set, the bot will only register commands in this guild. It's useful for development. | ||
developmentGuildId: environment.DISCORD_DEVELOPMENT_GUILD_ID, | ||
// If this value is set to true, the bot will delete the commands before registering them for `developmentGuildId`. | ||
refreshCommands: true, | ||
// Add more slash commands here | ||
slashCommands: [pingCommand], | ||
// Customized logger | ||
loggerOptions: { | ||
level: 'debug', | ||
}, | ||
// This function will be called when the bot is ready | ||
onReady: ({ logger }) => { | ||
logger.info('Try to excecute /ping command!') | ||
}, | ||
// This function will be called before the bot shuts down | ||
onShutDown: async ({ logger }) => { | ||
logger.info('Bot is shutting down!') | ||
}, | ||
}) | ||
|
||
// Register the given slash commands and listen for the event | ||
bot.listen() | ||
``` | ||
|
||
### Develop | ||
# Examples | ||
|
||
To develop all apps and packages, run the following command: | ||
You can find examples in the [examples](./examples) folder. | ||
|
||
``` | ||
cd my-turborepo | ||
pnpm dev | ||
``` | ||
|
||
### Remote Caching | ||
|
||
Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines. | ||
|
||
By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands: | ||
- [Ping-pong discord bot](./examples/bun-simple-bot/) | ||
|
||
``` | ||
cd my-turborepo | ||
npx turbo login | ||
``` | ||
|
||
This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview). | ||
# Features | ||
|
||
Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo: | ||
- [x] Slash commands | ||
- Input types | ||
- [x] Subcommands | ||
- [ ] 🚧 Subcommand groups | ||
- [x] String | ||
- [x] Integer | ||
- [x] Boolean | ||
- [x] User | ||
- [x] Channel | ||
- [x] Role | ||
- [x] Mentionable | ||
- [x] Number | ||
- [x] Attachment | ||
- [ ] 🚧 Message command with prefix | ||
- [ ] 🚧 Message components | ||
- [ ] 🚧 [Action Rows](https://discordjs.guide/message-components/action-rows.html) | ||
- [ ] 🚧 [Buttons](https://discordjs.guide/message-components/buttons.html) | ||
- [ ] 🚧 [Select menus](https://discordjs.guide/message-components/select-menus.html) | ||
- [ ] 🚧 Other components | ||
- [ ] 🚧 [Modal](https://discordjs.guide/interactions/modals.html#building-and-responding-with-modals) | ||
- [ ] 🚧 [Context Menu](https://discordjs.guide/interactions/context-menus.html) | ||
- [ ] 🚧 Emoji reactions | ||
|
||
``` | ||
npx turbo link | ||
``` | ||
# Contributing | ||
|
||
## Useful Links | ||
WIP | ||
|
||
Learn more about the power of Turborepo: | ||
# License | ||
|
||
- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks) | ||
- [Caching](https://turbo.build/repo/docs/core-concepts/caching) | ||
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) | ||
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering) | ||
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration) | ||
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference) | ||
[MIT](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DISCORD_TOKEN= | ||
DISCORD_CLIENT_ID= | ||
DISCORD_DEVELOPMENT_GUILD_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@example/bun-simple-bot", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "bun --watch src/index.ts" | ||
}, | ||
"devDependencies": { | ||
"@internal/project-config": "workspace:^" | ||
}, | ||
"dependencies": { | ||
"@discordjs/core": "^1.0.1", | ||
"@softnetics/what-is-dis": "workspace:^", | ||
"dotenv": "^16.3.1", | ||
"znv": "^0.4.0", | ||
"zod": "^3.22.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { parseEnv, z } from 'znv' | ||
|
||
export const environment = parseEnv(process.env, { | ||
DISCORD_TOKEN: z.string(), | ||
DISCORD_CLIENT_ID: z.string(), | ||
DISCORD_DEVELOPMENT_GUILD_ID: z.string(), | ||
}) |
Oops, something went wrong.