@@ -558,8 +558,7 @@ rssfeeds:
558
558
url: "https://www.youtube.com/feeds/videos.xml?channel_id=UCS4FAVeYW_IaZqAbqhlvxlA"
559
559
` ` `
560
560
561
- ` ` ` lua
562
- local milla = require("milla")
561
+ ` local milla = require("milla")
563
562
local yaml = require("yaml")
564
563
local http = require("http")
565
564
local xmlpath = require("xmlpath")
@@ -571,35 +570,64 @@ local function read_file(file)
571
570
return content
572
571
end
573
572
574
- local function get_rss_feed()
573
+ local function sleep(n) os.execute("sleep " .. tonumber(n)) end
574
+
575
+ local function get_config()
575
576
local yaml_config = read_file("./plugins/rss.yaml")
576
577
local config = yaml.parse(yaml_config)
578
+ return config
579
+ end
580
+
581
+ local function get_rss_feed(config)
577
582
local titles = {}
578
583
local author_names = {}
579
584
local uris = {}
580
585
local rss_feed_list = {}
581
586
582
587
for _, v in pairs(config.rssfeeds) do
583
588
local response, err = http.request("GET", v.url)
589
+ if err ~= nil then
590
+ milla.send_message(err, "")
591
+ goto continue
592
+ end
584
593
local node, err = xmlpath.loadxml(response.body)
594
+ if err ~= nil then
595
+ milla.send_message(err, "")
596
+ goto continue
597
+ end
585
598
586
599
local path, err = xmlpath.compile("//entry/title")
600
+ if err ~= nil then
601
+ milla.send_message(err, "")
602
+ goto continue
603
+ end
587
604
local iterator = path:iter(node)
588
605
for _, match in ipairs(iterator) do
589
606
table.insert(titles, match:string())
590
607
end
591
608
592
609
path, err = xmlpath.compile("//entry/author/name")
610
+ -- local path, err = xmlpath.compile("//entry/title")
611
+ if err ~= nil then
612
+ milla.send_message(err, "")
613
+ goto continue
614
+ end
593
615
iterator = path:iter(node)
594
616
for _, match in ipairs(iterator) do
595
617
table.insert(author_names, match:string())
596
618
end
597
619
598
620
path, err = xmlpath.compile("//entry/author/uri")
621
+ -- local path, err = xmlpath.compile("//entry/title")
622
+ if err ~= nil then
623
+ milla.send_message(err, "")
624
+ goto continue
625
+ end
599
626
iterator = path:iter(node)
600
627
for _, match in ipairs(iterator) do
601
628
table.insert(uris, match:string())
602
629
end
630
+ ::continue::
603
631
end
604
632
605
633
for i = 1, #titles do
@@ -611,11 +639,16 @@ local function get_rss_feed()
611
639
end
612
640
613
641
local function rss_feed()
614
- local rss_feeds = get_rss_feed()
615
- for _, v in pairs(rss_feeds) do milla.send_message(v, "#rssfeed") end
642
+ local config = get_config()
643
+ while true do
644
+ for _, v in pairs(get_rss_feed(config)) do
645
+ milla.send_message(v, config.channel)
646
+ sleep(config.period)
647
+ end
648
+ end
616
649
end
617
650
618
- rss_feed()
651
+ r ` ` lua
619
652
` ` `
620
653
621
654
` ` ` lua
0 commit comments