From 54510fb0c2b70aa3f4ebd00b91f25fef874f293c Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Mon, 3 Jun 2024 19:55:52 -0400 Subject: updated the readme and added example for lua scripting --- README.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 8573246..d74d7a0 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,10 @@ webirc password to use. webirc address to use. +### plugins + +A list of plugins to load:`plugins = ["./plugins/rss.lua", "./plugins/test.lua"]` + ## Custom Commands Custom commands let you define a command that does a SQL query to the database and performs the given task. Here's an example: @@ -525,6 +529,89 @@ go mod vendor go build ``` +### Plugins and Scripting + +milla can be extended with plugins. The plugins are written in lua and are loaded at runtime. The plugins are loaded after an IRC connection has been made.
+ +An example plugin is provided under `plugins/rss.lua`.
+ +```yaml +rssfeeds: + - name: "one" + url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCaiL2GDNpLYH6Wokkk1VNcg" + - name: "two" + url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCd26IHBHcbtxD7pUdnIgiCw" + - name: "three" + url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCS4FAVeYW_IaZqAbqhlvxlA" +``` + +```lua +local milla = require("milla") +local yaml = require("yaml") +local http = require("http") +local xmlpath = require("xmlpath") + +local function read_file(file) + local f = assert(io.open(file, "rb")) + local content = f:read("*all") + f:close() + return content +end + +local function get_rss_feed() + local yaml_config = read_file("./plugins/rss.yaml") + local config = yaml.parse(yaml_config) + local titles = {} + local author_names = {} + local uris = {} + local rss_feed_list = {} + + for _, v in pairs(config.rssfeeds) do + local response, err = http.request("GET", v.url) + local node, err = xmlpath.loadxml(response.body) + + local path, err = xmlpath.compile("//entry/title") + local iterator = path:iter(node) + for _, match in ipairs(iterator) do + table.insert(titles, match:string()) + end + + path, err = xmlpath.compile("//entry/author/name") + iterator = path:iter(node) + for _, match in ipairs(iterator) do + table.insert(author_names, match:string()) + end + + path, err = xmlpath.compile("//entry/author/uri") + iterator = path:iter(node) + for _, match in ipairs(iterator) do + table.insert(uris, match:string()) + end + end + + for i = 1, #titles do + table.insert(rss_feed_list, + author_names[i] .. ": " .. titles[i] .. " -- " .. uris[i]) + end + + return rss_feed_list +end + +local function rss_feed() + local rss_feeds = get_rss_feed() + for _, v in pairs(rss_feeds) do milla.send_message(v, "#rssfeed") end +end + +rss_feed() +``` +More of milla's functionality will be available over time.
' + +The following libraries are loaded by milla by default: +* [gluaxmlpath](https://github.com/ailncode/gluaxmlpath) +* [gluahttp](https://github.com/cjoudrey/gluahttp) +* [gluayaml](https://github.com/kohkimakimoto/gluayaml) +* [gluasocket](https://gitlab.com/megalithic-llc/gluasocket) + ## FAQ - I end up with color escape sequences getting printed at the end of a line/begging of the next line. What gives? -- cgit v1.2.3