Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9fb2e10
chore: remove yarn
e-enes Apr 16, 2024
4703473
chore: updated .gitignore
e-enes Apr 16, 2024
ac5153b
refactor: base project
e-enes Apr 17, 2024
75989d2
chore: added commit message validation
e-enes Apr 17, 2024
298a7fc
docs: added license
e-enes Apr 17, 2024
3417d69
fix: updated main entry
e-enes Apr 17, 2024
32e7b4e
feat: added config (env & orm)
e-enes Apr 17, 2024
36186d6
feat: added custom logger and updated some stuff
e-enes Apr 17, 2024
eb82566
chore: updated dependencies
e-enes Apr 17, 2024
536c07d
chore: updated paths alias
e-enes Apr 17, 2024
6483800
chore: updated commit msg
e-enes Apr 17, 2024
9bba374
refactor: updated routes and controllers
e-enes Apr 19, 2024
fe7a7d9
refactor: split express app and updated prod
e-enes Apr 19, 2024
b7e4a36
refactor: updated auth
e-enes Apr 19, 2024
5d02017
refactor: updated auth middleware
e-enes Apr 20, 2024
f04209e
fix: switched to lowercase
e-enes Apr 20, 2024
429c241
style: updated print width
e-enes Apr 20, 2024
c8a06d7
fix: updated enum keys
e-enes Apr 20, 2024
5b0d628
refactor: updated entity
e-enes Apr 20, 2024
0c81889
feat: added controller for v1
e-enes Apr 20, 2024
463c5f6
fix: added body type and updated auth middleware
e-enes Apr 21, 2024
13ff1fb
fix: file extension
e-enes Apr 21, 2024
440ba87
refactor: added payment controller and updated entity
e-enes Apr 21, 2024
5133961
refactor: added email controller
e-enes Apr 21, 2024
1301dee
refactor: added vote controller
e-enes Apr 21, 2024
a52e9a3
refactor: added integration controller and updated some stuff
e-enes Apr 21, 2024
ba81a93
fix: switched to modern function
e-enes Apr 21, 2024
abc691a
feat: added rate limit
e-enes Apr 23, 2024
9ddab86
feat: added token rate limit
e-enes Apr 23, 2024
3891216
fix: triple database management
chaun14 Apr 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
# Environnement (dev | prod)
ENVIRONNEMENT=prod
# Bot Identifier
BOT_ID=

#Votes
TOPGG_VOTE_WEBHOOK=topggWebhookKeyHere
VCODES_VOTE_WEBHOOK=vCodesWebhookKeyHere
DLIST_VOTE_WEBHOOK=dlistWebhookKeyHere
WUMPUSSTORE_VOTE_WEBHOOK=wumpusStoreWebhookKeyHere
# payments
TEBEX_KEY=putyourtebexencryptionkeyhere
# Server port
PORT=

# internal api key
# Rate Limit IP
RATE_LIMIT_IP_ACCESS= # default 100
RATE_LIMIT_IP_TIME= # default 15m

# Rate Limit Token
RATE_LIMIT_TOKEN_ACCESS= # default 100
RATE_LIMIT_TOKEN_TIME= # default 15m

# Voting webhook URLs for various services
TOPGG_VOTE_WEBHOOK=
VCODES_VOTE_WEBHOOK=
DLIST_VOTE_WEBHOOK=
WUMPUSSTORE_VOTE_WEBHOOK=

# Tebex payment API key
TEBEX_API_KEY=

# Internal API key for secured access
INTERNAL_API_KEY=

# emails
# SendGrid API key for sending emails
SENDGRID_API_KEY=

# integrations
DC_API_KEY=
# DoubleCounter integration API key
DC_API_KEY=

# Configuration for Prod DB
PROD_DB_HOST=localhost
PROD_DB_PORT=3306
PROD_DB_USERNAME=root
PROD_DB_PASSWORD=password
PROD_DB_DATABASE=bot

# Configuration for Dashboard DB
DASH_DB_HOST=localhost
DASH_DB_PORT=3306
DASH_DB_USERNAME=root
DASH_DB_PASSWORD=password
DASH_DB_DATABASE=dash

# Configuration for Bot DB
BOT_DB_HOST=localhost
BOT_DB_PORT=3306
BOT_DB_USERNAME=root
BOT_DB_PASSWORD=password
BOT_DB_DATABASE=bot
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "prettier"],
"ignorePatterns": ["bin", "node_modules"],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1, "ignoredNodes": ["PropertyDefinition"] }],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"no-case-declarations": "off",
"prettier/prettier": "error",
"@typescript-eslint/no-explicit-any": "off"
},
"env": {
"es2021": true,
"node": true
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ typings/
# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
Expand Down Expand Up @@ -103,6 +100,12 @@ dist
# TernJS port file
.tern-port

# JetBrains
.idea/

# VSCode
.vscode/

# custom
bin/*
ormconfig.json
bin/
ormconfig.json
21 changes: 21 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

commit_msg=$(cat "$1")

types="feat|fix|refactor|docs|style|test|chore|ci|perf|revert"

if ! echo "$commit_msg" | grep -Eq "^($types)"; then
echo ""
echo "ERROR: Missing or incorrect commit type."
echo "The commit message must start with one of the following types: $types"
echo ""
exit 1
fi

if ! echo "$commit_msg" | grep -Eq ": [a-z].{2,75}$"; then
echo ""
echo "ERROR: Missing or incorrect commit description."
echo "The commit description must be written in lowercase and be between 3 and 75 characters long."
echo ""
exit 1
fi
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

npm run lint:staged
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"useTabs": false,
"trailingComma": "es5",
"singleQuote": false,
"printWidth": 120,
"tabWidth": 2,
"endOfLine": "lf"
}
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2021-2024 chaun14

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
96 changes: 96 additions & 0 deletions config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const { env } = process;

export enum Environments {
DEVELOPMENT,
PRODUCTION,
}

const parseRateLimitTime = (timeValue?: string) => {
if (!timeValue) return 15 * 60 * 1000;

const unit = timeValue.slice(-1);
const time = Number(timeValue.slice(0, -1));

console.log(unit);

switch (unit) {
case "h":
return time * 60 * 60 * 1000;
case "m":
return time * 60 * 1000;
case "s":
return time * 1000;
default:
throw new Error(`Unexpected unit for RATE_LIMIT_TIMEt: ${unit}. Accepted unit: 'h', 'm' and 's'`);
}
};

const config = {
// Bot Id
botId: env.BOT_ID,

// Rate limit
rateLimit: {
ip: {
max: env.RATE_LIMIT_IP_ACCESS ? Number(env.RATE_LIMIT_IP_TIME) : 100,
time: parseRateLimitTime(env.RATE_LIMIT_IP_TIME),
},
token: {
max: env.RATE_LIMIT_TOKEN_ACCESS ? Number(env.RATE_LIMIT_TOKEN_TIME) : 100,
time: parseRateLimitTime(env.RATE_LIMIT_TOKEN_TIME),
},
},

// Port number for the server
port: env.PORT,

// Environment type (development || production)
environment: env.NODE_ENV === "production" ? Environments.PRODUCTION : Environments.DEVELOPMENT,

// Webhook configurations for votes
voteWebhooks: {
topgg: env.TOPGG_VOTE_WEBHOOK,
vcodes: env.VCODES_VOTE_WEBHOOK,
dlist: env.DLIST_VOTE_WEBHOOK,
wumpus: env.WUMPUSSTORE_VOTE_WEBHOOK,
},

// Tebex payment API key
tebexKey: env.TEBEX_API_KEY,

// Internal API key for secured access
internalApiKey: env.INTERNAL_API_KEY,

// SendGrid API key for sending emails
sendgridApiKey: env.SENDGRID_API_KEY,

// DoubleCounter integration API key
dcApiKey: env.DC_API_KEY,

// Database configurations
databases: {
dash: {
host: env.DASH_DB_HOST,
port: Number(env.DASH_DB_PORT),
username: env.DASH_DB_USERNAME,
password: env.DASH_DB_PASSWORD,
database: env.DASH_DB_DATABASE,
},
bot: {
host: env.BOT_DB_HOST,
port: Number(env.BOT_DB_PORT),
username: env.BOT_DB_USERNAME,
password: env.BOT_DB_PASSWORD,
database: env.BOT_DB_DATABASE,
},
prod: {
host: env.PROD_DB_HOST,
port: Number(env.PROD_DB_PORT),
username: env.PROD_DB_USERNAME,
password: env.PROD_DB_PASSWORD,
database: env.PROD_DB_DATABASE,
},
},
};

export default config;
34 changes: 34 additions & 0 deletions config/ormconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { DataSource, DataSourceOptions } from "typeorm";

import Applications from "@entity/dash/Applications.js";
import Payments from "@entity/dash/Payments.js";
import PremiumPlans from "@entity/dash/PremiumPlans.js";
import PremiumServices from "@entity/dash/PremiumServices.js";
import Votes from "@entity/dash/Votes.js";
import CustomInvites from "@entity/bot/CustomInvites.js";
import GuildSettings from "@entity/bot/GuildSettings.js";
import Joins from "@entity/bot/Joins.js";

const entities: { dash: object[]; bot: object[]; prod: object[] } = {
dash: [Applications, Payments, PremiumPlans, PremiumServices, Votes],
bot: [CustomInvites, GuildSettings, Joins],
prod: [CustomInvites, GuildSettings, Joins],
};

import config from "@config";

const createDataSourceOptions = (name: string): DataSourceOptions => ({
type: "mysql",
host: config.databases[name]["host"]!,
port: config.databases[name]["port"]!,
username: config.databases[name]["username"]!,
password: config.databases[name]["password"]!,
database: config.databases[name]["database"]!,
synchronize: false,
logging: ["error", "warn"],
entities: entities[name],
});

export const dashDataSource = new DataSource(createDataSourceOptions("dash"));
export const customBotDataSource = new DataSource(createDataSourceOptions("bot"));
export const prodbotDataSource = new DataSource(createDataSourceOptions("prod"));
23 changes: 0 additions & 23 deletions ormconfig.example.json

This file was deleted.

Loading