Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins! #30

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Plugins! #30

wants to merge 6 commits into from

Conversation

QtFuta
Copy link
Contributor

@QtFuta QtFuta commented Jan 17, 2023

Work for #5 and (possible duplicate) #29

Created a base system to have plugins :D

Plugins will be located in backend/plugins, they need to be added to the index.mjs file so expanse can read them.
Comments with an example were included :P

I required the plugins to have some functions that expanse will call at some point.
The current ones are:

  • getId() to identify the plugin (ideally would be unique for future usages)
  • receiveItem(item) for the plugin to process items that are saved in the DB, regardless of from which user it came from
  • receiveUserItem(user, category, item, config) for the plugin to process items of a user.
  • getAvailableConfig() for future usage to be able to template a config screen for the user.

An example of how it works can be found in my fork for ImgBB :3

So, this is a base implementation, there is some stuff that I want to improve/implement:

  • Currently plugins will be called for all new items and for all users, there needs to be a way to let the user decide which items they want to let the plugin process.
    This is where the uniqueness of getId() will be in play.
  • Allow users to configure the plugin, since in the example in my fork I'm only processing items that have been saved, but user might want to dynamically update this and would be different for each user.
    This is where getAvailableConfig() to get an object with the possible properties to configure plus possible values and more stuff to create a dynamic form for the user.
    Also in here the DB will need to be updated with a new table to store the plugin configuration for each user, then it'll be sent as the last parameter of receiveUserItem

I need help with something! 😓
In my fork I'm using SQLite, so can someone please test that the function get_items(ids) works well with postgres?

Checks if object has a function.
Plugins receive what items are actually new to the DB,
and new ones to the user.
Provide more functionality than snoowrap classes.
Include a function to let them initialize.
@QtFuta
Copy link
Contributor Author

QtFuta commented Jan 18, 2023

Improved it a bit 😅

Now the item it's a custom own for expanse, and the item from reddit (snoowrap) is a property of it.
This will allow us add more functionality that plugins might have in common.
For example, I added a way to know if a post is text, image, gif, video or a link 😃

Also included a way to defer plugin initialization in case is needed for expanse to initialize something first.
This way we can ensure that expanse is ready before the plugins start (for example in my fork I need to wait for dotenv to load the variables)

My fork has been updated with the example usage of this 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant