Plugin system
CatAsk uses Lua for plugins, and its own plugin system that uses lupa to make them work (LuaPluginManager
in utils.py
).
Keep in mind that the plugin system is still in a beta stage, so bugs will happen
Plugin overview
A plugin file usually consists of:
- a
metadata
table - a
socialLinks
table - calls to supported Flask functions (currently
flask.route()
andflask.modify_template()
)
Metadata and social links
It's recommended to set the plugin's metadata using a metadata
table:
metadata = {
name = "Plugin name",
version = "1.2.10",
author = "author",
description = "A plugin"
}
You can also use a socialLinks
table to display links to various social profiles:
socialLinks = {
bluesky = "https://bsky.app/profile/mystie.dev",
git = "https://example.com/author/plugin",
website = "https://example.com",
discord = "https://discord.com/invite/author",
mastodon = "https://social.example.com/@author",
reddit = "https://reddit.com/u/author",
twitter = "https://bsky.app/profile/author.example.com"
}
Allowed services: git, bluesky, fediverse, website, homepage, twitter, discord, instagram, mastodon, reddit, github, gitlab, medium, substack
Functions
flask.route()
Syntax
flask.route(rule, {
methods = { "GET", "POST", "PATCH", ... },
endpoint = endpoint,
login_required = false|true
})(function()
return "Return value"
end)
Example usage
local methods = { "GET", "POST" }
local return_msg = [[
Hello world!
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
]]
flask.route("/my_route", {
methods = methods,
endpoint = "myEndpoint",
login_required = true
})(function()
return return_msg
end)
flask.modify_template()
Syntax
Available modifiers: insert_before, insert_after, replaceExample usage
local marker = [[<div id="response-container"></div>]]
local content = [[
<script>console.log("Plugin loaded!")</script>
]]
flask.modify_template("template/path.html", "insert_after", marker, content)
Example plugin
metadata = {
name = "Plugin name",
version = "1.8.3",
author = "Author",
description = "A plugin"
}
socialLinks = {
bluesky = "https://bsky.app/profile/mystie.dev",
git = "https://example.com/author/plugin",
website = "https://example.com",
discord = "https://discord.com/invite/author",
mastodon = "https://social.example.com/@author",
reddit = "https://reddit.com/u/author",
twitter = "https://bsky.app/profile/author.example.com"
}
flask.route("/plugin_route", {
methods = { "GET", "POST" },
endpoint = "pluginRoute",
auth_required = true
})(function()
return "This is a plugin route"
end)
local marker = [[<div id="response-container"></div>]]
local content = [[
<script>console.log("Plugin loaded!")</script>
]]
flask.modify_template("admin/base.html", "insert_after", marker, content)