Del: noticeUwuzuのAA / Del: worker_threadsを廃止 / FIx: client.tsでパスが誤っている問題 / Chg: Collapseのアップデートに反映

This commit is contained in:
2026-05-27 05:53:38 +09:00
parent 6b35112d1e
commit 0fe88a36ab
5 changed files with 62 additions and 71 deletions
-5
View File
@@ -1,5 +0,0 @@
# # ###### ##### ### ###### ####### # # # # # # ###### # #
## # # # # # # # # # # # # # # # # #
# ## # # # # # # ####### # # # # # # # # ## # #
# ## # # # # # # # # # # # # # # #
# # ###### # ### ###### ####### ###### # # ###### ###### ######
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "earthquake-bot-for-mtweet",
"version": "1.0.2",
"version": "1.0.3",
"type": "module",
"main": "dist/index.js",
"scripts": {
+4 -2
View File
@@ -6,7 +6,8 @@ import { EOL } from "node:os";
import { WebSocket } from "ws";
import generateImage from "@/earthquake/generateImage";
if (config.earthquake?.useHistoryData) {
export default function earthquake() {
if (config.earthquake?.useHistoryData) {
console.log("過去の地震情報を配信します");
const history = JSON.parse(readFileSync(`${import.meta.dirname}/../../260420.json`, "utf-8"));
history.reverse();
@@ -16,7 +17,7 @@ if (config.earthquake?.useHistoryData) {
processMessage(history[i]);
i++;
}, 10 * 1000);
} else {
} else {
const connect = () => {
const WEBSOCKET_URL = config.debug
? "wss://api-realtime-sandbox.p2pquake.net/v2/ws"
@@ -59,6 +60,7 @@ if (config.earthquake?.useHistoryData) {
}
connect();
}
}
const processMessage = async (message: any) => {
+2 -3
View File
@@ -1,10 +1,9 @@
import { readFileSync } from "node:fs";
import config from "@/lib/config";
import { styleText } from "node:util";
import { Worker } from "node:worker_threads";
import earthquake from "@/earthquake";
try {
console.log(readFileSync(`${import.meta.dirname}/../asciiart.txt`, "utf-8"));
console.log(JSON.parse(readFileSync(`${import.meta.dirname}/../package.json`, "utf-8")).version);
if (config.debug) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
@@ -16,7 +15,7 @@ try {
}
console.log();
new Worker(`${import.meta.dirname}/earthquake/index.js`);
earthquake();
console.log("Botが起動しました");
} catch (err: any) {
+11 -16
View File
@@ -11,18 +11,18 @@ type SuccessPosted<T = string> = {
post: {
id: T;
content: string;
zone: "normal" | string;
zone: "normal" | "free";
created_at: string;
};
};
}
const BASE_URL = "https://collapse.jp/api/v3/bot";
const BASE_URL = "https://collapse.jp/api/v3/bot/";
export const createPost = async (data: {
text: string;
zone?: "normal" | string;
replyTarget?: "all" | string;
zone?: "normal" | "free";
replyTarget?: "all" | "followers" | "mutual" | "mentioned" | "none";
replyid?: string;
images?: [Blob, string][];
}, title: string) => {
@@ -78,30 +78,25 @@ export const createPost = async (data: {
const replyid = data.replyid === undefined && firstUniqid !== ""
? firstUniqid
: data.replyid;
const reply = replyid !== undefined
? `/${replyid}/reply`
: "";
const url = new URL(`/posts${reply}`, BASE_URL);
const body = new FormData();
body.append("content", data.text);
if (!replyid) {
body.append("zone", data.zone ?? "normal");
body.append("reply_restriction", data.replyTarget ?? "all");
if (replyid) {
body.append("reply_to_id", replyid);
}
if (data.images) {
data.images.forEach(img => body.append("images", img[0], img[1]));
}
const req = await fetch(url, {
const req = await fetch(new URL("posts", BASE_URL), {
method: "POST",
body: JSON.stringify({
content: data.text,
zone: data.zone ?? "normal",
reply_restriction: data.replyTarget ?? "all",
}),
body,
headers: {
"Authorization": `Bearer ${config.mtweet.token}`,
"Content-Type": "application/json",
"X-Idempotency-Key": String(process.hrtime.bigint()),
},
});
@@ -114,7 +109,7 @@ export const createPost = async (data: {
break;
}
console.warn(`${title}の投稿に失敗しました (試行 ${attempt}/${config.post.maxRetries}):`, res.error.message);
console.warn(`${title}の投稿に失敗しました (試行 ${attempt}/${config.post.maxRetries}):`, `${res.error.message}(${res.error.code})`);
if (attempt < config.post.maxRetries) {
const interval = res.error.details?.retry_after
? res.error.details.retry_after * 1000