Isaac 95f76716ed
feat: #206 convert to interactions (buttons and application commands) (#238)
* feat: make command handler slash command-ready

Only `help` and `settings` commands work so far

* feat(commands): finish new settings command

* fix(settings): convert `roles` and `ping` to an array

* fix(commands): make `add` a slash command

* fix(commands): make `blacklist` a slash command

* fix(commands): remove URLs from `help` command

* Add weblate badge and overview image

* Update sponsors

* sqlite things

* imrpovements

* update eslint rules

* (⚠ untested) close command

* fix: default locale for getting command option names

* Update README.md

* Update README.md

* Update README.md

* update new command to slash commands and fix close command

* fixes and improvements

* fix: closing a ticket when the creator has left

* Revert "fix: closing a ticket when the creator has left"

This reverts commit afc40ae17077782e344fd8cee03a089966c2347e.

* fix: closing a ticket when the creator has left

* fix: localisation issues in settings command

* fix: delete category channel

* New button and select panels + updated message panels

Includes new options for panel embed message image and thumbnail

Co-Authored-By: Puneet Gopinath <baalkrshna@gmail.com>
Co-Authored-By: thevisuales <6569806+thevisuales@users.noreply.github.com>

* Finish converting to buttons, added close button

Co-Authored-By: Puneet Gopinath <baalkrshna@gmail.com>
Co-Authored-By: thevisuales <6569806+thevisuales@users.noreply.github.com>

* fully convert to slash commands

* re-add "... has created a ticket" message

* locales

* fix add and remove commands

* fix remove command

* fix stats command

* eslint

Co-authored-by: Puneet Gopinath <baalkrshna@gmail.com>
Co-authored-by: thevisuales <6569806+thevisuales@users.noreply.github.com>
2021-09-24 15:32:36 +01:00

73 lines
1.9 KiB
JavaScript

const { Sequelize } = require('sequelize');
const fs = require('fs');
const { path } = require('../utils/fs');
const types = require('./dialects');
module.exports = async client => {
const {
DB_TYPE,
DB_HOST,
DB_PORT,
DB_USER,
DB_PASS,
DB_NAME
} = process.env;
const type = (DB_TYPE || 'sqlite').toLowerCase();
const supported = Object.keys(types);
if (!supported.includes(type)) {
client.log.error(new Error(`DB_TYPE (${type}) is not a valid type`));
return process.exit();
}
try {
types[type].packages.forEach(pkg => require(pkg));
} catch {
const required = types[type].packages.map(i => `"${i}"`).join(' and ');
client.log.error(new Error(`Please install the package(s) for your selected database type: ${required}`));
return process.exit();
}
let sequelize;
if (type === 'sqlite') {
client.log.info('Using SQLite storage');
sequelize = new Sequelize({
dialect: types[type].dialect,
logging: text => client.log.debug(text),
storage: path('./user/database.sqlite')
});
client.config.defaults.log_messages = false;
client.log.warn('Message logging is disabled due to insufficient database');
} else {
client.log.info(`Connecting to ${types[type].name} database...`);
sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASS, {
dialect: types[type].dialect,
host: DB_HOST,
logging: text => client.log.debug(text),
port: DB_PORT
});
}
try {
await sequelize.authenticate();
client.log.success('Connected to database successfully');
} catch (error) {
client.log.warn('Failed to connect to database');
client.log.error(error);
return process.exit();
}
const models = fs.readdirSync(path('./src/database/models'))
.filter(filename => filename.endsWith('.model.js'));
for (const model of models) {
require(`./models/${model}`)(client, sequelize);
}
await sequelize.sync({ alter: true });
return sequelize;
};