podaboutlist / linkfix-for-discord

LinkFix brings link embeds back to your Discord server! Simply post Twitter, Instagram, TikTok, or Reddit links and LinkFix will reply with a rich media embed.
https://discord.com/application-directory/385950397493280805
GNU Affero General Public License v3.0
16 stars 4 forks source link

feature: implement PostgreSQL for storage of per-server settings #19

Open RalphORama opened 9 months ago

RalphORama commented 9 months ago

Summary

As LinkFix gets added to more servers, several people have reached out requesting features that would require per-server configuration. We need to store those configurations.

Methodology

Firstly, I am going to try to avoid using ORMs as much as possible. the pg package offers the ability to execute raw queries which should be good enough for our requirements. If, in the future, the database gets more complicated, I wouldn't have an issue moving to something like Sequelize.

Secondly, I want LinkFix to store as little data as possible. I think we shouldn't create records for guilds until someone in the guild actually sets configuration options. This keeps us in the clear for crap like GDPR, plus I personally believe in data privacy myself and don't want to become a vector of attack for other people.

Database Structire

https://dbdiagram.io/d/LinkFix-658b15e289dea6279992fb74

Screenshot 2023-12-31 at 2 43 45 AM

To-Do

After we move into production:

shoegaze commented 4 months ago

Add permission checks - admins only?

It's possible to set permissions for a command using SlashCommandBuilder#setDefaultMemberPermissions(): https://discordjs.guide/slash-commands/permissions.html#member-permissions

e.g.

new SlashCommandBuilder()
  .setName(...)
  // ...
  .setDefaultMemberPermissions(PermissionFlagsBits.Administrator)

should make the command admin-only.

shoegaze commented 4 months ago

Should settings.guild be an FK (with REFERENCES guilds(id))? Additionally, should it have ON DELETE CASCADE so that the settings rows are deleted when /forget is run? (Or should we keep the rows so that we can restore settings on /configure ?)

Also FYI: guilds.id is a bigint while settings.guild is an integer