import {unescape} from 'html-escaper'; import fetchRetry from "fetch-retry"; import { appendFileSync } from "fs"; import credentials from "./credentials.json" assert { type: 'json' }; import Bot from "./Bot.js"; import { getPostDataById, getNewPixivPosts } from "./pixiv.js"; process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; global.fetch = fetchRetry(global.fetch); var mikubot = new Bot({ url: "https://mikuobsession.net", app: credentials.app, username: credentials.accounts[0].username, password: credentials.accounts[0].password }); var mikubot_nsfw = new Bot({ url: "https://mikuobsession.net", app: credentials.app, username: credentials.accounts[1].username, password: credentials.accounts[1].password }); await mikubot.login(); await mikubot_nsfw.login(); var newPosts = await getNewPixivPosts("初音ミク"); for (let post of newPosts) { let bot = post.xRestrict ? mikubot_nsfw : mikubot; let url = `https://www.pixiv.net/en/artworks/${post.id}`; try { let {images, illust} = await getPostDataById(post.id); let date = new Date(illust.createDate); let dateString = date.toLocaleDateString("en-US", {timeZone: "JST", month: "long", day: "numeric", year: "numeric"}); let timeString = date.toLocaleTimeString("en-US", {timeZone: "JST", hour12: true, hour: "numeric", "minute": "numeric"}); let status = `${illust.title} / ${illust.userName} / ${dateString} ${timeString}
${unescape(illust.description)}
${illust.aiType == 2 ? `#AIgenerated ` : ''}${post.tags.map(tag => `#${tag}`).join(" ")}
${url}
https://www.pixiv.net/en/users/${illust.userId}`; if (images.length > 4) { status += `
⚠ There are ${images.length} images.`; } if (illust.illustType == 2) { status += `
⚠ This is ugoria, you have to view on Pixiv.`; } await bot.post({ status, content_type: "text/html", files: images, sensitive: Boolean(post.xRestrict), visibility: "public" }); appendFileSync(`known_ids/初音ミク.txt`, "\n" + post.id); } catch(error) { console.error(error.stack); await bot.post({ status: `${url}\n#error\n${error.stack}`, visibility: "public" }); } }