Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pukimaa committed Nov 6, 2023
0 parents commit 8ccb6dc
Show file tree
Hide file tree
Showing 42 changed files with 1,283 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DISCORD_TOKEN=""
APPLICATION_ID=""
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"root": true,
"extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
"parserOptions": {
"project": ["./tsconfig.eslint.json"]
},
"ignorePatterns": ["dist/*"]
}
31 changes: 31 additions & 0 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Crowdin Action

on:
# Uncomment to run on every push to master, this is recommended but turned off by default, in case you haven't set up your Crowdin project yet
# push:
# branches: [master]
workflow_dispatch:

jobs:
synchronize-with-crowdin:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: crowdin action
uses: crowdin/github-action@v1
with:
upload_translations: true
download_translations: true
auto_approve_imported: true
create_pull_request: true
skip_untranslated_strings: true
crowdin_branch_name: 'BRANCH_IN_CROWDIN'
commit_message: 'i18n: update crowdin translations'
env:
# Add these secrets to your repository's secrets
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
bot.log
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 120,
"useTabs": true,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"endOfLine": "lf"
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"i18n-ally.localesPaths": [
"src/locales"
],
"i18n-ally.keystyle": "nested"
}
19 changes: 19 additions & 0 deletions .vscode/tako.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Slash Command Template": {
"scope": "javascript,typescript",
"body": [
"import { SlashCommandBuilder } from 'discord.js';",
"import type { Command } from '../index.ts';",
"",
"export default {",
"data: new SlashCommandBuilder()",
".setName('NAME')",
".setDescription('DESC')",
".toJSON(),",
"async execute(interaction) {},",
"} satisfies Command;"

],
"description": "Template for a slash command. Be sure to save after inserting, to format the code."
}
}
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2023 Jaron Ain

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.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# TypeScript Discord Bot Template

This is a template for creating a Discord bot using TypeScript and the Bun framework. Please note that the documentation isn't really written yet and you should come with some technical knowledge about the tech used here or at least know how to read their documentations.

## Prerequisites
- [Bun](https://bun.sh)
- A database compatible with [Prisma](https://prisma.io). The schema file is currently set for [PostgreSQL](https://www.postgresql.org/).

## Getting Started

1. Clone this repository.
2. Install dependencies with `bun install`.
3. Create a `.env` file with your Discord bot token and any other necessary configuration variables as outlined in `.env.example`
4. If you want automatic uploads and downloads to Crowdin, check out `.github/workflows/crowdin.yml`!

## Database
You can just import `prisma` from `src/database.ts` to get access to the fully typesafe database.

## Translation
Import `i18next` from `src/i18n.ts` to get an i18next object that is already fully equipped with all the translations in `src/locales`. It's recommended to use the *i18n Ally* extension by Lokalise for a nice integration into VS Code, in order to check if your translations exist.

## Scripts
You can run these scripts by using `bun run ` as a prefix.

`commit`: Commit your changes using commitizen

`format`: Lint and attempt to autofix all your files. It's recommended to use a Prettier ESLint Plugin for your Editor or to create a GitHub Workflow or similiar to lint everything.

`deploy`: Deploy/Sync the application commands (Slash-Commands) if the regular sync command does not work.

`start`: Start the bot.

`dev`: Start the bot with hot-reloading on file changes.

## Features

- Bun instead of Node for way faster code execution
- TypeScript support, to prevent errors before going into production
- Reliable translation with i18next and Crowdin Support
- Consistency using custom helpers and a robust configuration system.

## To-Do
- [ ] Better logging
- [ ] Documentation for a foolproof setup

## Contributing

Contributions are welcome! Please open an issue or pull request for any requests, changes or additions.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
Binary file added bun.lockb
Binary file not shown.
34 changes: 34 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const config = {
// Activates dev mode, which will only sync commands to the dev guild and will log debug logs
dev: true,
// Main guild is currently unused, while the dev guild is used for syncing commands just with the guild
guilds: {
main: '884046271176912917',
dev: '884046271176912917',
},
// The devs of the bot, used for dev only commands. Input the IDs of the devs here in a string.
devs: [''],
colors: {
primary: 0x299ba3,
accent: 0x5bd79d,
green: 0x40b056,
yellow: 0xf0e34c,
red: 0xea4d4d,
},
emojis: {
ping: '🏓',
success: '✅',
error: '❌',
pagination: {
first: '⏮️',
previous: '◀️',
next: '▶️',
last: '⏭️',
},
} as const,
// It's recommended to store API URLs in here, so you can easily change them later
apis: {
},
};

export default config;
127 changes: 127 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#
# Your Crowdin credentials
#
"project_id_env": CROWDIN_PROJECT_ID
"api_token_env": CROWDIN_PERSONAL_TOKEN
"base_path": "."
"base_url": "https://api.crowdin.com"

#
# Choose file structure in Crowdin
# e.g. true or false
#
"preserve_hierarchy": true

#
# Files configuration
#
files: [
{
#
# Source files filter
# e.g. "/resources/en/*.json"
#
"source": "/src/locales/en/*.json",

#
# Where translations will be placed
# e.g. "/resources/%two_letters_code%/%original_file_name%"
#
"translation": "/src/locales/%two_letters_code%/%original_file_name%",

#
# Files or directories for ignore
# e.g. ["/**/?.txt", "/**/[0-9].txt", "/**/*\?*.txt"]
#
# "ignore": [],

#
# The dest allows you to specify a file name in Crowdin
# e.g. "/messages.json"
#
# "dest": "",

#
# File type
# e.g. "json"
#
"type": "i18next_json",

#
# The parameter "update_option" is optional. If it is not set, after the files update the translations for changed strings will be removed. Use to fix typos and for minor changes in the source strings
# e.g. "update_as_unapproved" or "update_without_changes"
#
# "update_option": "",

#
# Start block (for XML only)
#

#
# Defines whether to translate tags attributes.
# e.g. 0 or 1 (Default is 1)
#
# "translate_attributes": 1,

#
# Defines whether to translate texts placed inside the tags.
# e.g. 0 or 1 (Default is 1)
#
# "translate_content": 1,

#
# This is an array of strings, where each item is the XPaths to DOM element that should be imported
# e.g. ["/content/text", "/content/text[@value]"]
#
# "translatable_elements": [],

#
# Defines whether to split long texts into smaller text segments
# e.g. 0 or 1 (Default is 1)
#
# "content_segmentation": 1,

#
# End block (for XML only)
#

#
# Start .properties block
#

#
# Defines whether single quote should be escaped by another single quote or backslash in exported translations
# e.g. 0 or 1 or 2 or 3 (Default is 3)
# 0 - do not escape single quote;
# 1 - escape single quote by another single quote;
# 2 - escape single quote by backslash;
# 3 - escape single quote by another single quote only in strings containing variables ( {0} ).
#
# "escape_quotes": 3,

#
# Defines whether any special characters (=, :, ! and #) should be escaped by backslash in exported translations.
# e.g. 0 or 1 (Default is 0)
# 0 - do not escape special characters
# 1 - escape special characters by a backslash
#
# "escape_special_characters": 0
#

#
# End .properties block
#

#
# Does the first line contain header?
# e.g. true or false
#
# "first_line_contains_header": true,

#
# for spreadsheets
# e.g. "identifier,source_phrase,context,uk,ru,fr"
#
# "scheme": "",
}
]
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "tako-bun",
"version": "0.0.1-alpha.3",
"private": true,
"type": "module",
"scripts": {
"commit": "cz",
"lint": "prettier --check . && eslint ./src --ext .ts --format=pretty",
"deploy": "bun src/util/deploy.ts",
"format": "prettier --write . && eslint ./src --ext .ts --fix --format=pretty",
"start": "bun src/index.ts",
"dev": "bunx nodemon --exec bun src/index.ts"
},
"dependencies": {
"@discordjs/core": "^1.0.1",
"@prisma/client": "5.4.2",
"discord.js": "^14.13.0",
"i18next": "^23.5.1",
"i18next-fs-backend": "^2.2.0",
"is-language-code": "^5.0.9",
"prisma": "^5.4.2",
"tslog": "^4.9.2",
"uwuifier": "^4.0.5"
},
"devDependencies": {
"@sapphire/ts-config": "^5.0.0",
"@types/node": "^20.8.6",
"bun-types": "^1.0.6",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.51.0",
"eslint-config-neon": "^0.1.57",
"eslint-formatter-pretty": "^5.0.0",
"typescript": "^5.2.2"
},
"nodemon": {
"ext": "js,mjs,cjs,json,ts"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
16 changes: 16 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Guild {
id String @id @unique
language String @default("en")
}
Loading

0 comments on commit 8ccb6dc

Please sign in to comment.