mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-17 09:23:07 +02:00
Start making
Start on the basic structure, database stuff
This commit is contained in:
parent
828d4af22d
commit
f44e9080e5
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,4 +7,5 @@ site/
|
||||
# files
|
||||
.env
|
||||
user/config.js
|
||||
user/database.sqlite
|
||||
*.code-workspace
|
||||
|
@ -1,4 +1,7 @@
|
||||
# Please download from [releases](https://github.com/eartharoid/DiscordTickets/releases) or [v2 branch](https://github.com/eartharoid/DiscordTickets/tree/v2) - master branch is currently a work in progress
|
||||
|
||||
https://discord.com/oauth2/authorize?permissions=8&scope=applications.commands%20bot&client_id=...
|
||||
|
||||
# DiscordTickets
|
||||
|
||||
[![Run on Repl.it](https://repl.it/badge/github/eartharoid/DiscordTickets)](https://repl.it/github/eartharoid/DiscordTickets) [![GitHub issues](https://img.shields.io/github/issues/eartharoid/DiscordTickets?style=flat-square)](https://github.com/eartharoid/DiscordTickets/issues) [![GitHub stars](https://img.shields.io/github/stars/eartharoid/DiscordTickets?style=flat-square)](https://github.com/eartharoid/DiscordTickets/stargazers) [![GitHub forks](https://img.shields.io/github/forks/eartharoid/DiscordTickets?style=flat-square)](https://github.com/eartharoid/DiscordTickets/network) [![GitHub license](https://img.shields.io/github/license/eartharoid/DiscordTickets?style=flat-square)](https://github.com/eartharoid/DiscordTickets/blob/master/LICENSE) ![Codacy grade](https://img.shields.io/codacy/grade/14e6851c85444424b75b8bc3f93e93db?logo=codacy&style=flat-square) [![Discord support server](https://discordapp.com/api/guilds/451745464480432129/embed.png?style=shield)](https://discord.gg/pXc9vyC)
|
||||
|
@ -1,5 +1,6 @@
|
||||
DISCORD_TOKEN=
|
||||
|
||||
DB_TYPE=sqlite
|
||||
DB_HOST=
|
||||
DB_NAME=
|
||||
DB_USER=
|
||||
|
@ -1,2 +1,16 @@
|
||||
{% extends "base.html" %}
|
||||
{% block announce %}{% include "announce.html" ignore missing %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ super() }}
|
||||
<footer class="sponsorship">
|
||||
<hr>
|
||||
<a href="https://github.com/eartharoid/DiscordTickets/?sponsor=1" title="Donate to support this project">
|
||||
<span class="twemoji heart-throb-hover">
|
||||
{% set icon = "octicons/heart-fill-16" %}
|
||||
{% include ".icons/" ~ icon ~ ".svg" %}
|
||||
</span>
|
||||
</a>
|
||||
<hr>
|
||||
</footer>
|
||||
{% endblock %}
|
53
package.json
53
package.json
@ -4,31 +4,6 @@
|
||||
"private": true,
|
||||
"description": "An open-source & self-hosted Discord bot for ticket management.",
|
||||
"main": "src/index.js",
|
||||
"dependencies": {
|
||||
"@eartharoid/dtf": "^1.0.8",
|
||||
"boxen": "^5.0.0",
|
||||
"discord.js": "^12.5.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"leekslazylogger": "^2.0.7",
|
||||
"n-readlines": "^1.0.1",
|
||||
"node-fetch": "^2.6.1",
|
||||
"sequelize": "^6.5.0",
|
||||
"terminal-link": "^2.1.1",
|
||||
"to-time-monthsfork": "^1.1.3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"sqlite3": "^5.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"mysql2": "2.x",
|
||||
"mariadb": "2.x",
|
||||
"pg": "8.x",
|
||||
"tedious": "11.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.19.0",
|
||||
"nodemon": "^2.0.7"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node src/",
|
||||
"test": "echo \"Nothing to test! Run with 'npm start'\" && exit 1"
|
||||
@ -50,6 +25,30 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/eartharoid/DiscordTickets/issues"
|
||||
},
|
||||
"homepage": "https://github.com/eartharoid/DiscordTickets/#readme",
|
||||
"funding": "https://github.com/eartharoid/DiscordTickets/?sponsor=1"
|
||||
"homepage": "https://discordtickets.eartharoid.me",
|
||||
"funding": "https://github.com/eartharoid/DiscordTickets/?sponsor=1",
|
||||
"dependencies": {
|
||||
"@eartharoid/i18n": "^0.0.1",
|
||||
"discord.js": "^12.5.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"keyv": "^4.0.3",
|
||||
"leekslazylogger": "^2.0.7",
|
||||
"node-fetch": "^2.6.1",
|
||||
"terminal-link": "^2.1.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@keyv/sqlite": "^2.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@keyv/mongo": "^1.1.0",
|
||||
"@keyv/mysql": "^1.1.4",
|
||||
"@keyv/postgres": "^1.0.16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@keyv/mongo": "^1.1.0",
|
||||
"@keyv/mysql": "^1.1.4",
|
||||
"@keyv/postgres": "^1.0.16",
|
||||
"eslint": "^7.20.0",
|
||||
"nodemon": "^2.0.7"
|
||||
}
|
||||
}
|
||||
|
945
pnpm-lock.yaml
945
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
73
src/index.js
73
src/index.js
@ -1,22 +1,87 @@
|
||||
/**
|
||||
* DiscordTickets
|
||||
* Copyright (C) 2021 Isaac Saunders
|
||||
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*
|
||||
* @name @eartharoid/discordtickets
|
||||
* @description An open-source & self-hosted Discord bot for ticket management.
|
||||
* @copyright 2021 Isaac Saunders
|
||||
* @license GNU-GPLv3
|
||||
*/
|
||||
|
||||
const node_version = Number(process.versions.node.split('.')[0]);
|
||||
if (node_version < 14) return console.log(`Error: DiscordTickets does not work on Node v${node_version}. Please upgrade to v14 or above.`);
|
||||
const { version } = require('../package.json');
|
||||
|
||||
const fs = require('fs');
|
||||
const { path } = require('./utils/fs');
|
||||
if (!fs.existsSync(path('./.env'))) return console.log('Please make a copy of \'example.env\' called \'.env\'');
|
||||
if (!fs.existsSync(path('./user/config.js'))) return console.log('Please make a copy of \'example.config.js\' called \'config.js\'');
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
const config = require('../user/config');
|
||||
|
||||
const Logger = require('leekslazylogger');
|
||||
const log = new Logger({
|
||||
name: 'DiscordTickets by eartharoid',
|
||||
debug: config.debug,
|
||||
logToFile: config.logs.enabled,
|
||||
keepFor: config.logs.keep_for
|
||||
});
|
||||
|
||||
|
||||
const terminalLink = require('terminal-link');
|
||||
log.report = error => {
|
||||
let report = [
|
||||
'<< Issue report >>',
|
||||
'Please include this information if you ask for help about the following error!',
|
||||
`Support server: ${terminalLink('go.eartharoid.me/discord', 'https://go.eartharoid.me/discord')}`,
|
||||
`Node.JS version: ${process.versions.node.split('.')}`,
|
||||
`Bot version: ${version}`,
|
||||
`Platform: ${process.platform}`
|
||||
];
|
||||
log.warn(report.join('\n'));
|
||||
if (error) log.error(error);
|
||||
};
|
||||
|
||||
const { Client } = require('discord.js');
|
||||
class Bot extends Client {
|
||||
constructor() {
|
||||
super({
|
||||
autoReconnect: true,
|
||||
});
|
||||
|
||||
Object.assign(this, {
|
||||
config,
|
||||
db: require('./modules/database')(log),
|
||||
log,
|
||||
});
|
||||
|
||||
this.log.info('Connecting to Discord API');
|
||||
|
||||
this.login();
|
||||
}
|
||||
}
|
||||
|
||||
new Bot();
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
log.report();
|
||||
log.warn('An error was not caught');
|
||||
if (error instanceof Error) log.warn(`Uncaught ${error.name}: ${error}`);
|
||||
log.error(error);
|
||||
});
|
||||
|
||||
|
71
src/modules/database.js
Normal file
71
src/modules/database.js
Normal file
@ -0,0 +1,71 @@
|
||||
const Keyv = require('keyv');
|
||||
|
||||
const { homepage } = require('../../package.json');
|
||||
const { path } = require('../utils/fs');
|
||||
|
||||
const types = {
|
||||
sqlite: 'sqlite',
|
||||
mysql: 'mysql',
|
||||
mongo: 'mongo',
|
||||
mongodb: 'mongo',
|
||||
postgre: 'postgres',
|
||||
postgres: 'postgres',
|
||||
postgresql: 'postgres',
|
||||
};
|
||||
|
||||
const supported = Object.keys(types);
|
||||
|
||||
module.exports = (log) => {
|
||||
|
||||
let type = (process.env.DB_TYPE || 'sqlite').toLowerCase();
|
||||
|
||||
if (!supported.includes(type)) {
|
||||
log.report('Invalid database type');
|
||||
throw new Error('DB_TYPE is not valid type');
|
||||
}
|
||||
|
||||
try {
|
||||
require(`@keyv/${types[type]}`);
|
||||
} catch {
|
||||
log.report('Specified database type is not installed');
|
||||
throw new Error(`"@keyv/${types[type]}" is not installed, please install is manually`);
|
||||
}
|
||||
|
||||
const {
|
||||
DB_HOST,
|
||||
DB_USER,
|
||||
DB_PASS,
|
||||
DB_NAME
|
||||
} = process.env;
|
||||
let database;
|
||||
|
||||
switch (type) {
|
||||
case 'mysql':
|
||||
database = `mysql://${DB_USER}:${DB_PASS}@${DB_HOST}/${DB_NAME}`;
|
||||
break;
|
||||
case 'mongo':
|
||||
case 'mongodb':
|
||||
database = `mongodb://${DB_USER}:${DB_PASS}@${DB_HOST}/${DB_NAME}`;
|
||||
break;
|
||||
case 'postgre':
|
||||
case 'postgres':
|
||||
case 'postgresql':
|
||||
database = `postgresql://${DB_USER}:${DB_PASS}@${DB_HOST}/${DB_NAME}`;
|
||||
break;
|
||||
default: // sqlite
|
||||
database = `sqlite://${path('./user/database.sqlite')}`;
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
servers: new Keyv(database, {
|
||||
namespace: 'servers'
|
||||
}),
|
||||
tickets: new Keyv(database, {
|
||||
namespace: 'tickets'
|
||||
}),
|
||||
messages: new Keyv(database, {
|
||||
namespace: 'messages'
|
||||
})
|
||||
};
|
||||
};
|
5
src/utils/fs.js
Normal file
5
src/utils/fs.js
Normal file
@ -0,0 +1,5 @@
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
path: path => join(__dirname, '../../', path),
|
||||
};
|
@ -23,9 +23,6 @@
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
storage: {
|
||||
type: 'sqlite'
|
||||
},
|
||||
portal: {
|
||||
enabled: true,
|
||||
host: 'https://tickets.eartharoid.me'
|
||||
|
@ -23,9 +23,6 @@
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
storage: {
|
||||
type: 'sqlite'
|
||||
},
|
||||
portal: {
|
||||
enabled: false,
|
||||
host: 'https://tickets.example.com'
|
||||
|
0
user/plugins/.gitkeep
Normal file
0
user/plugins/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user