refactor: init codebase

This commit is contained in:
xHyroM 2023-04-03 16:33:23 +02:00
parent 6afd498fb5
commit 79dcde2f86
No known key found for this signature in database
GPG key ID: BE0423F386C436AA
18 changed files with 1247 additions and 1034 deletions

49
.gitignore vendored
View file

@ -1,9 +1,5 @@
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node
# My
wrangler.toml
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,node
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,node
### Node ###
# Logs
@ -62,6 +58,9 @@ web_modules/
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
@ -77,10 +76,12 @@ web_modules/
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
# dotenv environment variable files
.env
.env.test
.env.production
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
@ -103,6 +104,12 @@ dist
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
@ -130,9 +137,29 @@ dist
.webpack/
# Optional stylelint cache
.stylelintcache
# SvelteKit build / generate output
.svelte-kit
# End of https://www.toptal.com/developers/gitignore/api/node
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,node
.turbo

12
.vscode/settings.json vendored
View file

@ -1,10 +1,8 @@
{
"liveServer.settings.port": 5501,
"liveSassCompile.settings.formats": [
{
"format": "expanded",
"extensionName": ".css",
"savePath": "/packages/website/styles/css"
"[typescript]": {
"editor.defaultFormatter": "rome.rome"
},
"[javascript]": {
"editor.defaultFormatter": "rome.rome"
}
]
}

View file

@ -1,7 +1,46 @@
<div align="center">
<h1>Discord Roles Bot</h1>
</div>
<h1 align="center">
<br>
<img src="https://github.com/xHyroM/website/blob/main/src/assets/logo.png?raw=true" alt="Hyro" width="256">
<br>
</h1>
<h4 align="center">Source code for Roles Bot, a discord bot.</h4>
<p align="center">
<a href="https://discord.gg/kFPKmEKeMS/" alt="Discord">
<img src="https://img.shields.io/discord/1046534628577640528?label=discord&style=for-the-badge&color=2fbfc4"/>
</a>
</p>
## Informations
Discord bot for reaction roles that works with [Cloudflare Workers](https://workers.cloudflare.com/).
You can add the bot to your server, just click [here](https://discord.com/api/oauth2/authorize?client_id=923267906941370368&permissions=268435456&scope=bot%20applications.commands).
## Setup
1. Clone this repository: `git clone https://github.com/xHyroM/roles-bot.git`
2. Navigate to the project directory: `cd roles-bot`
3. Install the dependencies: `pnpm install`
## Usage
- To run the development server: `pnpm run dev`
- To build the project for production: `pnpm run build`
- To preview the production build of website: `pnpm run preview`
- To deploy bot to CF workers: `pnpm run deploy`
## Contributing
To contribute to this project, please follow the [standard Git workflow](https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository#The-Standard-Git-Workflow) and [CONTRIBUTING](./CONTRIBUTING.md).
1. Fork this repository
2. Create a new branch for your changes: `git checkout -b my-feature`
3. Commit your changes: `git commit -am "Add my feature"`
4. Push the branch: `git push origin my-feature`
5. Open a pull request
## License
This project is licensed under the [MIT License](./LICENSE).

View file

@ -1,24 +1,22 @@
{
"name": "roles-bot",
"version": "1.0.0",
"main": "dist/worker.mjs",
"type": "module",
"description": "",
"main": "index.js",
"scripts": {
"build": "node scripts/build.mjs",
"dev": "miniflare --watch --debug --port 8787",
"publish": "cross-env NODE_ENV=production wrangler publish"
"build": "turbo run build",
"dev": "turbo run dev",
"preview": "turbo run preview",
"deploy": "turbo run deploy",
"test": "turbo run test",
"lint": "rome check .",
"format": "rome format --write ."
},
"keywords": [],
"author": "xHyroM",
"license": "MIT",
"packageManager": "pnpm@8.1.0",
"devDependencies": {
"@cloudflare/workers-types": "^3.17.0",
"@types/jest": "^29.1.2",
"discord-api-types": "^0.37.14",
"esbuild": "^0.15.11",
"eslint": "^8.25.0",
"jest": "^29.2.0",
"miniflare": "^2.10.0",
"typescript": "^4.8.4"
"rome": "^12.0.0"
}
}

21
packages/bot/LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Jozef Steinhübl
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.

7
packages/bot/README.md Normal file
View file

@ -0,0 +1,7 @@
<div align="center">
<h1>Discord Roles Bot</h1>
</div>
Discord bot for reaction roles that works with [Cloudflare Workers](https://workers.cloudflare.com/).
You can add the bot to your server, just click [here](https://discord.com/api/oauth2/authorize?client_id=923267906941370368&permissions=268435456&scope=bot%20applications.commands).

24
packages/bot/package.json Normal file
View file

@ -0,0 +1,24 @@
{
"name": "roles-bot",
"version": "1.0.0",
"main": "dist/worker.mjs",
"type": "module",
"scripts": {
"build": "node scripts/build.mjs",
"dev": "miniflare --watch --debug --port 8787",
"deploy": "cross-env NODE_ENV=production wrangler publish"
},
"keywords": [],
"author": "xHyroM",
"license": "MIT",
"devDependencies": {
"@cloudflare/workers-types": "^3.17.0",
"@types/jest": "^29.1.2",
"discord-api-types": "^0.37.14",
"esbuild": "^0.15.11",
"eslint": "^8.25.0",
"jest": "^29.2.0",
"miniflare": "^2.10.0",
"typescript": "^4.8.4"
}
}

View file

@ -0,0 +1,38 @@
import esbuild from "esbuild";
import { rmSync, existsSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
if (existsSync(join(__dirname, "..", "dist")))
rmSync(join(__dirname, "..", "dist"), { recursive: true });
const watch = process.argv.includes("--watch");
const dev = process.argv.includes("--dev");
Promise.all([
esbuild.build({
bundle: true,
logLevel: "info",
format: "esm",
mainFields: ["browser", "module", "main"],
platform: "neutral",
target: "es2020",
entryPoints: ["./src/index.ts"],
outfile: "./dist/worker.mjs",
sourcemap: dev,
charset: "utf8",
minify: !dev,
watch: watch,
}),
])
.catch((err) => {
console.error("Roles Bot failed to build");
console.error(err.message);
})
.then(() => {
console.log(
watch ? "Waiting for your changes..." : "Roles Bot has been built",
);
});

View file

@ -0,0 +1,6 @@
export default {
fetch: (request: Request) => {
console.log(request);
return new Response("asda");
},
};

View file

@ -1,7 +1,7 @@
name = "roles-bot"
type = "javascript"
account_id = ""
workers_dev = true
account_id = "294bee38d448e390dab3757215c63f03"
compatibility_date = "2022-07-12"
[build]
command = "pnpm build"

File diff suppressed because it is too large Load diff

2
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,2 @@
packages:
- "packages/*"

12
rome.json Normal file
View file

@ -0,0 +1,12 @@
{
"$schema": "./node_modules/rome/configuration_schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}

View file

@ -1,34 +0,0 @@
import esbuild from 'esbuild';
import { rmSync, existsSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
if (existsSync(join(__dirname, '..', 'dist')))
rmSync(join(__dirname, '..', 'dist'), { recursive: true });
const watch = process.argv.includes('--watch');
const dev = process.argv.includes('--dev');
Promise.all([
esbuild.build({
bundle: true,
logLevel: 'info',
format: 'esm',
mainFields: ['browser', 'module', 'main'],
platform: 'neutral',
target: 'es2020',
entryPoints: ['./src/index.ts'],
outfile: './dist/worker.mjs',
sourcemap: dev,
charset: 'utf8',
minify: !dev,
watch: watch
})
]).catch(err => {
console.error('Roles Bot failed to build');
console.error(err.message);
}).then(() =>{
console.log(watch ? 'Waiting for your changes...' : 'Roles Bot has been built');
});

View file

@ -1,6 +0,0 @@
export default {
fetch: (request: Request) => {
console.log(request);
return new Response('asda');
}
}

21
turbo.json Normal file
View file

@ -0,0 +1,21 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist"]
},
"dev": {
"outputs": ["dist"]
},
"preview": {
"outputs": ["dist"]
},
"deploy": {
"dependsOn": ["build", "test", "lint"]
},
"test": {
"dependsOn": ["^build"]
}
}
}