Database improvements

This commit is contained in:
Isaac 2021-05-30 20:39:14 +01:00
parent c91a8c5b0c
commit 461d535102
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
7 changed files with 25 additions and 30 deletions

View File

@ -9,14 +9,13 @@
![Discord Tickets](https://ik.imagekit.io/eartharoid/discord-tickets/wordmark/gradient_HTC7nqZr9.png) ![Discord Tickets](https://ik.imagekit.io/eartharoid/discord-tickets/wordmark/gradient_HTC7nqZr9.png)
An open-source ticket management bot for Discord - a free alternative to the premium and white-label plans of other popular ticketing bots. An open-source ticket management bot for Discord - a free alternative to the premium and white-label plans of other popular ticketing bots.
## What is this? ## What is this?
Discord Tickets is a Discord bot for creating and managing "support ticket" channels. It is a free and open-source alternative to the popular paid "premium" and "white-label" ticketing bots, such as [Ticket Tool](https://tickettool.xyz/), [TicketsBot](https://ticketsbot.net/), [Tickety](https://tickety.net/), [Helper.gg](https://helper.gg/), [Helper](https://helper.wtf), and others. Discord Tickets is a Discord bot for creating and managing ticket channels. It is a free and open-source alternative to the paid "premium" and "white-label" plans of popular ticketing bots, such as [Ticket Tool](https://tickettool.xyz/), [TicketsBot](https://ticketsbot.net/), [Tickety](https://tickety.net/), [Helper.gg](https://helper.gg/), [Helper](https://helper.wtf), and others.
Discord Tickets is feature-rich and much more customisable than many of the bots mentioned above. As it is intended for self-hosting, the bot can have your community or company's logo, for free. Discord Tickets is feature-rich and much more customisable than many of the bots mentioned above. As it is intended for self-hosting, the bot can have your community/company's logo, for free.
Although intended for use in a single Discord server, the bot can also function in multiple servers at once if you run more than one community. Although intended for use in a single Discord server, the bot can also function in multiple servers at once if you run more than one community.
@ -26,7 +25,7 @@ Discord Tickets is packed full of features, many of which were suggested by its
- Create a plugin for it, if you can code JavaScript - Create a plugin for it, if you can code JavaScript
- Request someone else to make a plugin - Request someone else to make a plugin
- [Submit a feature request](https://github.com/discord-tickets/.github/blob/main/.github/CONTRIBUTING.md#submitting-a-feature-request) if you think many other users would benefit from it - [Submit a feature request](https://github.com/discord-tickets/.github/blob/main//CONTRIBUTING.md#submitting-a-feature-request) if you think many other users would benefit from it
Here's some of the things that makes Discord Tickets awesome: Here's some of the things that makes Discord Tickets awesome:
@ -35,31 +34,22 @@ Some messages can be configured for each server and for each ticket category. Ev
You can also configure the functionality of the bot to your liking and add commands with plugins. You can also configure the functionality of the bot to your liking and add commands with plugins.
2. **Localisable** 2. **Localisable**
If the bot hasn't already been translated to your (community's) language, you can [translate](https://github.com/discord-tickets/.github/blob/main/.github/CONTRIBUTING.md#translating) it yourself. If the bot hasn't already been translated to your (community's) language, you can [translate](https://github.com/discord-tickets/.github/blob/main//CONTRIBUTING.md#translating) it yourself.
Plugin authors are encouraged to support multiple languages as well. Plugin authors are encouraged to support multiple languages as well.
3. **Multiple ticket categories** 3. **Multiple ticket categories**
Each ticket category has its own settings for messages and the support team roles. There's also multiple methods of creating a ticket. Each ticket category has its own settings for messages and the support team roles. There's also multiple methods of creating a ticket.
4. **A beautiful ticket archives portal** 4. **A beautiful ticket archives portal**
Add the official [Discord Tickets-Portal](https://github.com/discord-tickets/portal) plugin for an instant ticket archives website. **\[COMING SOON\] :** Add the official [Discord Tickets Portal](https://github.com/discord-tickets/portal) plugin for an instant ticket archives website.
5. **Plugin support** 1. **Open-source and self-hosted**
Developers can add a lot of functionality to Discord Tickets without modifying the source code by creating plugins. Plugins can listen for client and ticket events, create commands, and more. [Discord Tickets-Portal](https://github.com/discord-tickets/portal) is an example of what can be done with plugins. It's yours, you have full control.
6. **Open-source and self-hosted** 6. **Supports multiple databases**
It's yours.
7. **Supports multiple databases**
Discord Tickets uses [Sequelize](https://github.com/sequelize/sequelize) to allow you to choose from SQLite, MySQL, MariaDB, PostgreSQL, or MSSQL for your database, with very little setup. Discord Tickets uses [Sequelize](https://github.com/sequelize/sequelize) to allow you to choose from SQLite, MySQL, MariaDB, PostgreSQL, or MSSQL for your database, with very little setup.
If you choose SQLite, which is the default as it is the easiest, you don't need to do anything! If you choose to use another database (recommended), you only need to install the package(s) with NPM and create the database. All of the database tables are created automatically, regardless of which database type you use. If you choose SQLite, which is the default as it is the easiest, you don't need to do anything! If you choose to use another database (recommended), you only need to install the package(s) with NPM and create the database. All of the database tables are created automatically, regardless of which database type you use.
### Screenshots
![The opening message of a ticket channel](https://i.imgur.com/2T5eSH0.png)
<!-- -->
> screenshot of a panel
## Getting started ## Getting started
| [**Host it yourself**](https://discordtickets.app/installation) | [**Fully managed hosting**](https://discordtickets.app/hosting) | [**Public test bot**](https://discord.com/oauth2/authorize?permissions=8&scope=applications.commands%20bot&client_id=475371285531066368) | | [**Host it yourself**](https://discordtickets.app/installation) | [**Fully managed hosting**](https://discordtickets.app/hosting) | [**Public test bot**](https://discord.com/oauth2/authorize?permissions=8&scope=applications.commands%20bot&client_id=475371285531066368) |
@ -79,7 +69,7 @@ If the [documentation](https://discordtickets.app) leaves you with questions, yo
## Contributing ## Contributing
For contributing instructions, or to find out all of the ways you can contribute, read [CONTRIBUTING.md](https://github.com/discord-tickets/.github/blob/main/.github/CONTRIBUTING.md). All contributions are welcome and encouraged, but please [read the information](https://github.com/discord-tickets/.github/blob/main/.github/CONTRIBUTING.md) given before doing so. For contributing instructions, or to find out all of the ways you can contribute, read [CONTRIBUTING.md](https://github.com/discord-tickets/.github/blob/main//CONTRIBUTING.md). All contributions are welcome and encouraged, but please [read the information](https://github.com/discord-tickets/.github/blob/main//CONTRIBUTING.md) given before doing so.
## Contributors ## Contributors

View File

@ -59,7 +59,7 @@ module.exports = class BlacklistCommand extends Command {
id = role.id; id = role.id;
} else if (/\d{17,19}/.test(input)) { } else if (/\d{17,19}/.test(input)) {
id = input; id = input;
} else if (settings.blacklist?.length === 0) { } else if (settings.blacklist.length === 0) {
return await message.channel.send( return await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
@ -69,7 +69,7 @@ module.exports = class BlacklistCommand extends Command {
); );
} else { } else {
// list blacklisted members // list blacklisted members
const blacklist = settings.blacklist?.map(element => { const blacklist = settings.blacklist.map(element => {
const is_role = message.guild.roles.cache.has(element); const is_role = message.guild.roles.cache.has(element);
if (is_role) return `» <@&${element}> (\`${element}\`)`; if (is_role) return `» <@&${element}> (\`${element}\`)`;
else return `» <@${element}> (\`${element}\`)`; else return `» <@${element}> (\`${element}\`)`;
@ -85,7 +85,7 @@ module.exports = class BlacklistCommand extends Command {
const is_role = role !== undefined || message.guild.roles.cache.has(id); const is_role = role !== undefined || message.guild.roles.cache.has(id);
const member_or_role = is_role ? 'role' : 'member'; const member_or_role = is_role ? 'role' : 'member';
const index = settings.blacklist?.findIndex(element => element === id); const index = settings.blacklist.findIndex(element => element === id);
const new_blacklist = [...settings.blacklist]; const new_blacklist = [...settings.blacklist];

View File

@ -66,7 +66,7 @@ module.exports = async client => {
require(`./models/${model}`)(client, sequelize); require(`./models/${model}`)(client, sequelize);
} }
sequelize.sync({ alter: { drop: false } }); await sequelize.sync({ alter: { drop: false } });
return sequelize; return sequelize;
}; };

View File

@ -4,6 +4,14 @@ module.exports = ({ config }, sequelize) => {
sequelize.define('Guild', { sequelize.define('Guild', {
blacklist: { blacklist: {
defaultValue: [], defaultValue: [],
get() {
const raw_value = this.getDataValue('blacklist');
return raw_value
? typeof raw_value === 'string'
? JSON.parse(raw_value)
: raw_value
: null;
},
type: DataTypes.JSON type: DataTypes.JSON
}, },
colour: { colour: {

View File

@ -2,7 +2,6 @@ const { DataTypes } = require('sequelize');
module.exports = (_client, sequelize) => { module.exports = (_client, sequelize) => {
const { DB_TABLE_PREFIX } = process.env; const { DB_TABLE_PREFIX } = process.env;
sequelize.define('Message', { sequelize.define('Message', {
author: { author: {
allowNull: false, allowNull: false,
type: DataTypes.CHAR(19) type: DataTypes.CHAR(19)

View File

@ -37,10 +37,10 @@ module.exports = class MessageReactionAddEventListener extends EventListener {
const channel = r.message.channel; const channel = r.message.channel;
const member = await guild.members.fetch(u.id); const member = await guild.members.fetch(u.id);
if (settings.blacklist?.includes(u.id)) { if (settings.blacklist.includes(u.id)) {
return this.client.log.info(`Ignoring blacklisted member ${u.tag}`); return this.client.log.info(`Ignoring blacklisted member ${u.tag}`);
} else { } else {
settings.blacklist?.forEach(element => { settings.blacklist.forEach(element => {
if (guild.roles.cache.has(element) && member.roles.cache.has(element)) { if (guild.roles.cache.has(element) && member.roles.cache.has(element)) {
return this.client.log.info(`Ignoring member ${u.tag} with blacklisted role`); return this.client.log.info(`Ignoring member ${u.tag} with blacklisted role`);
} }

View File

@ -87,14 +87,12 @@ module.exports = class CommandManager {
const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name)); const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name));
if (!cmd) return; if (!cmd) return;
if (typeof settings.blacklist === 'string') settings.blacklist = JSON.parse(settings.blacklist);
let is_blacklisted = false; let is_blacklisted = false;
if (settings.blacklist?.includes(message.author.id)) { if (settings.blacklist.includes(message.author.id)) {
is_blacklisted = true; is_blacklisted = true;
this.client.log.info(`Ignoring blacklisted member ${message.author.tag}`); this.client.log.info(`Ignoring blacklisted member ${message.author.tag}`);
} else { } else {
settings.blacklist?.forEach(element => { settings.blacklist.forEach(element => {
if (message.guild.roles.cache.has(element) && message.member.roles.cache.has(element)) { if (message.guild.roles.cache.has(element) && message.member.roles.cache.has(element)) {
is_blacklisted = true; is_blacklisted = true;
this.client.log.info(`Ignoring member ${message.author.tag} with blacklisted role`); this.client.log.info(`Ignoring member ${message.author.tag} with blacklisted role`);