Compare commits
No commits in common. "c8a91e54e2e341360f50fae23fb66d03686ff106" and "f2f4a012a3d942affeff83c4ee4122e5247fdeed" have entirely different histories.
c8a91e54e2
...
f2f4a012a3
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,5 +2,5 @@ credentials.json
|
||||
known_ids
|
||||
logindata
|
||||
._*
|
||||
*.txt
|
||||
output.txt
|
||||
node_modules
|
||||
|
9
Bot.js
9
Bot.js
@ -18,12 +18,11 @@ export default class Bot {
|
||||
form.append("grant_type", "password");
|
||||
form.append("username", this.username);
|
||||
form.append("password", this.password);
|
||||
var res = await fetch(this.url + "/oauth/token", {
|
||||
var data = await fetch(this.url + "/oauth/token", {
|
||||
method: "POST",
|
||||
body: form
|
||||
});
|
||||
if (!res.ok) throw new Error("HTTP "+ res.status);
|
||||
this.loginData = await res.json();
|
||||
}).then(res => res.json());
|
||||
this.loginData = data;
|
||||
writeFileSync(`logindata/${this.username}.json`, JSON.stringify(this.loginData));
|
||||
}
|
||||
|
||||
@ -47,7 +46,6 @@ export default class Bot {
|
||||
"Authorization": `${this.loginData.token_type} ${this.loginData.access_token}`
|
||||
}
|
||||
});
|
||||
if (!res.ok) throw new Error("HTTP "+ res.status);
|
||||
var json = await res.json();
|
||||
console.log("posted", res.status, json.uri || json);
|
||||
return json;
|
||||
@ -63,7 +61,6 @@ export default class Bot {
|
||||
"Authorization": `${this.loginData.token_type} ${this.loginData.access_token}`
|
||||
}
|
||||
});
|
||||
if (!res.ok) throw new Error("HTTP "+ res.status);
|
||||
var json = await res.json();
|
||||
console.log("uploaded file", res.status, json.url);
|
||||
return json;
|
||||
|
25
index.js
25
index.js
@ -1,12 +1,9 @@
|
||||
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",
|
||||
@ -29,15 +26,17 @@ await mikubot_nsfw.login();
|
||||
|
||||
var newPosts = await getNewPixivPosts("初音ミク");
|
||||
|
||||
for (let post of newPosts) {
|
||||
posts: for (let post of newPosts) {
|
||||
let bot = post.xRestrict ? mikubot_nsfw : mikubot;
|
||||
let url = `https://www.pixiv.net/en/artworks/${post.id}`;
|
||||
let attempts = 0, error;
|
||||
do {
|
||||
attempts++;
|
||||
if (attempts > 1) console.log("attempt", attempts);
|
||||
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"}) + " JST";
|
||||
let status = `<b>${illust.title}</b> / ${illust.userName} / ${dateString} ${timeString}<br>${unescape(illust.description)}<br>${illust.aiType == 2 ? `#AIgenerated ` : ''}${post.tags.map(tag => `#${tag}`).join(" ")}<br>${url}<br>https://www.pixiv.net/en/users/${illust.userId}`;
|
||||
let date = new Date(illust.createDate).toLocaleString("en-US", {timeZone: "JST", month: "long", day: "numeric", year: "numeric"});
|
||||
let status = `<b>${illust.title}</b> / ${illust.userName} / ${date}<br>${unescape(illust.description)}<br>${illust.aiType == 2 ? `#AIgenerated ` : ''}${post.tags.map(tag => `#${tag}`).join(" ")}<br>${url}<br>https://www.pixiv.net/en/users/${illust.userId}`;
|
||||
if (images.length > 4) {
|
||||
status += `<br>⚠ There are ${images.length} images.`;
|
||||
}
|
||||
@ -48,12 +47,14 @@ for (let post of newPosts) {
|
||||
sensitive: Boolean(post.xRestrict),
|
||||
visibility: "public"
|
||||
});
|
||||
appendFileSync(`known_ids/初音ミク.txt`, "\n" + post.id);
|
||||
} catch(error) {
|
||||
console.error(error.stack);
|
||||
continue posts;
|
||||
} catch(e) {
|
||||
console.error(e.stack);
|
||||
error = e;
|
||||
}
|
||||
} while (attempts < 3)
|
||||
await bot.post({
|
||||
status: `${url}\n#error\n${error.stack}`,
|
||||
visibility: "public"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
11
package-lock.json
generated
11
package-lock.json
generated
@ -5,15 +5,9 @@
|
||||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"fetch-retry": "^6.0.0",
|
||||
"html-escaper": "^3.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/fetch-retry": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fetch-retry/-/fetch-retry-6.0.0.tgz",
|
||||
"integrity": "sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag=="
|
||||
},
|
||||
"node_modules/html-escaper": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
|
||||
@ -21,11 +15,6 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"fetch-retry": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fetch-retry/-/fetch-retry-6.0.0.tgz",
|
||||
"integrity": "sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag=="
|
||||
},
|
||||
"html-escaper": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"fetch-retry": "^6.0.0",
|
||||
"html-escaper": "^3.0.3"
|
||||
}
|
||||
}
|
||||
|
8
pixiv.js
8
pixiv.js
@ -21,7 +21,8 @@ export async function getNewPixivPosts(tag = "初音ミク") {
|
||||
}
|
||||
}).then(res => res.json());
|
||||
if (data.error) {
|
||||
throw new Error(JSON.stringify(data));
|
||||
console.error(data);
|
||||
break;
|
||||
}
|
||||
|
||||
for (let post of data.body.illustManga.data) {
|
||||
@ -35,8 +36,7 @@ export async function getNewPixivPosts(tag = "初音ミク") {
|
||||
await sleep(1);
|
||||
}
|
||||
|
||||
return newPosts.reverse();
|
||||
/*return {
|
||||
return {
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
},
|
||||
@ -47,7 +47,7 @@ export async function getNewPixivPosts(tag = "初音ミク") {
|
||||
}
|
||||
return {value, done: !Boolean(value)}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
async function sleep(seconds) {
|
||||
|
Loading…
Reference in New Issue
Block a user