Skip to content

Commit

Permalink
Add config example & DB schema
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Oct 31, 2023
1 parent cbb6db0 commit 4eec9f4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"es2022": true
},
"plugins": ["unicorn", "sonarjs"],
"ignorePatterns": ["util/temp.js", "public/toasts/toastNotification.js"],
"rules": {
"array-bracket-spacing": 2,
"array-callback-return": 2,
Expand Down Expand Up @@ -61,7 +60,7 @@
"no-unreachable": 1,
"no-unreachable-loop": 2,
"no-unsafe-finally": 2,
"no-unused-vars": [2, { "argsIgnorePattern": "args|next", "varsIgnorePattern": "_|updateSlashcommands|updateLinkedroles" }],
"no-unused-vars": [2, { "argsIgnorePattern": "next", "varsIgnorePattern": "_" }],
"no-useless-computed-key": 2,
"no-useless-rename": 2,
"no-useless-escape": 2,
Expand Down
16 changes: 16 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"botId": "1168822115810672711",
"botSecret": "",
"botToken": "",

"port": 25527,

"userAgent": "DiscordBot (https://disgithook.tomatenkuchen.com, v1.0.0)",

"db": {
"host": "",
"user": "",
"password": "",
"database": ""
}
}
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const { db } = require("../config.json")

const mysql = require("mysql2")
const mainDB = mysql.createPool(db)
const pool = mainDB.promise()
const { port } = require("./config.json")
const pool = require("./util/setupDB.js")

const express = require("express")
const app = express()
app.listen(port)

// - Dashboard -

Expand All @@ -23,9 +21,12 @@ app.get("/auth/logout", (req, res) => {
// - Hooks -

const hookFunc = async (req, res) => {
const [rows] = await pool.query("SELECT * FROM `hook` WHERE `id` = ?", [req.params.id])
console.log(rows)

if (rows.length == 0) return res.sendStatus(404)

res.sendStatus(204)
}
app.get("/hook/:id/:secret", hookFunc)
app.post("/hook/:id/:secret", hookFunc)

app.listen(25527)
2 changes: 1 addition & 1 deletion util/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports.getUserGuilds = async token => {
return json
}

module.exports.getAccessToken = async (userId, tokens, bot) => {
module.exports.getAccessToken = async (userId, tokens) => {
if (Date.now() > tokens.expires_at) {
const body = new URLSearchParams({
client_id: botId,
Expand Down
32 changes: 32 additions & 0 deletions util/setupDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { db } = require("../config.json")

const mysql = require("mysql2")
const mainDB = mysql.createPool(db)

const pool = mainDB.promise()
module.exports = pool

// hook schema: id secret guild webhook? channel? name? avatar? message
pool.query(
"CREATE TABLE IF NOT EXISTS `hook` (" +
"`id` VARCHAR(8) NOT NULL PRIMARY KEY," +
"`secret` VARCHAR(64) NOT NULL," +
"`guild` VARCHAR(21) NOT NULL," +
"`webhook` VARCHAR(128) NOT NULL," +
"`channel` VARCHAR(21) NOT NULL," +
"`name` VARCHAR(32) NOT NULL," +
"`avatar` VARCHAR(512) NOT NULL," +
"`message` VARCHAR(10240) NOT NULL" +
")"
)

// user schema: user token access refresh expires
pool.query(
"CREATE TABLE IF NOT EXISTS `user` (" +
"`id` VARCHAR(21) NOT NULL PRIMARY KEY," +
"`token` VARCHAR(64) NOT NULL," +
"`access` VARCHAR(64) NOT NULL," +
"`refresh` VARCHAR(64) NOT NULL," +
"`expires` BIGINT NOT NULL" +
")"
)

0 comments on commit 4eec9f4

Please sign in to comment.