Michael-J-Scofield / discord-anti-spam

A simple discord anti spam node.js module to prevent spam on your discord server
MIT License
146 stars 53 forks source link

Add the ability to update configuration on runtime #152

Closed anselal closed 2 years ago

anselal commented 2 years ago

It would be nice to be able to update the configuration on runtime. Since we instantiate an object we could add a function to update all the properties on runtime. Also getters/setters for each individual property would be a nice addition.

Is this something you could easily add ? I am not very handy with JS but i could give a hand if needed

Scraayp commented 2 years ago

I will look into it for the next update

Scraayp commented 2 years ago

I'm thinking about creating a update function.

const AntiSpam = require("discord-anti-spam");
const antiSpam = new AntiSpam({
  // Anti spam options
});

antiSpam.update({
// new options
)};

I just need to figure out how we gonna add it into the multiple guild option.

anselal commented 2 years ago

I didn't study the multiple guild option yet, but there should be a property for a guildId I guess, or not?

Scraayp commented 2 years ago

Yes, but the problem is I can add it as the options for guild with id. But then everytime restarting the bot will result in removing cache so also the guild options! Which were updated by the update function

anselal commented 2 years ago

The options should be initialised either with hardcoded default values which restarting the bot won't affect those, or if you change the options on runtime the user must have a way to save the new options (json/db). So this is won't be a problem.

Besides that, restarting the bot for no obvious reason is a no no.

You can update/add/edit/remove bot commands without restarting the bot.

My bot is up and running for almost 3 months and I update it every week without restarting it...

Scraayp commented 2 years ago

As I removed the abillity to add guild options. This became way easier, I'm gonna work on the system in #159. You can help if you want.

MasonStooksbury commented 2 years ago

I accomplished this by initializing the antiSpam object with "let" instead of "const". Then I could make a command that would allow you to reassign antiSpam to a new AntiSpam object with new settings. Seems to be working so far.

That being said, very excited for an update options method instead!