|
@@ -0,0 +1,76 @@
|
|
|
+const html = require("node-html-parser");
|
|
|
+const axios = require("axios");
|
|
|
+const db = require("../../db.js");
|
|
|
+
|
|
|
+const kissDiaryRoot = "https://com3d2.world/r18/notices.php";
|
|
|
+
|
|
|
+async function aggregate() {
|
|
|
+ let lastDiary = db.get("latestCom3D2WorldDiaryEntry").value();
|
|
|
+
|
|
|
+ try {
|
|
|
+ let mainPageRes = await axios.get(kissDiaryRoot);
|
|
|
+
|
|
|
+ if(mainPageRes.status != 200)
|
|
|
+ return [];
|
|
|
+
|
|
|
+ let rootNode = html.parse(mainPageRes.data, {
|
|
|
+ pre: true,
|
|
|
+ script: false,
|
|
|
+ style: false
|
|
|
+ });
|
|
|
+
|
|
|
+ let diaryEntries = rootNode.querySelectorAll("div.frame a");
|
|
|
+
|
|
|
+ if(!diaryEntries) {
|
|
|
+ console.log("[COM3D2 WORLD BLOG] Failed to find listing!");
|
|
|
+ }
|
|
|
+
|
|
|
+ let result = [];
|
|
|
+ let latestEntry = lastDiary;
|
|
|
+
|
|
|
+ for(let a of diaryEntries) {
|
|
|
+ if(!a.rawAttributes.id)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ let id = +a.rawAttributes.id;
|
|
|
+
|
|
|
+ if(id <= lastDiary)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if(id > latestEntry)
|
|
|
+ latestEntry = id;
|
|
|
+
|
|
|
+ let diaryLink = `${kissDiaryRoot}?no=${id}`;
|
|
|
+ let res = await axios.get(diaryLink);
|
|
|
+ if(res.status != 200)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ let node = html.parse(res.data, {
|
|
|
+ pre: true,
|
|
|
+ script: false,
|
|
|
+ style: false
|
|
|
+ });
|
|
|
+
|
|
|
+ let title = node.querySelector("div.frame div.notice_title th");
|
|
|
+ let contents = node.querySelectorAll("div.frame div")[1];
|
|
|
+
|
|
|
+ result.push({
|
|
|
+ id: `com3d2-world-notices-${id}`,
|
|
|
+ link: diaryLink,
|
|
|
+ title: title.text,
|
|
|
+ author: "com3d2.world",
|
|
|
+ contents: contents.outerHTML,
|
|
|
+ embedColor: 0xa39869
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ db.set("latestCom3D2WorldDiaryEntry", latestEntry).write();
|
|
|
+ return result;
|
|
|
+ } catch(err) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ aggregate: aggregate
|
|
|
+};
|