noticeUwuzu v6.0@uwuzu1.5.4

This commit is contained in:
2025-07-26 21:28:07 +09:00
parent 3955d91978
commit 724e18ba3b
20 changed files with 268 additions and 120 deletions
+7 -50
View File
@@ -1,11 +1,8 @@
import WebSocket from "ws";
import { differenceInMinutes, subMinutes } from "date-fns";
import sendMail from "../src/mailer.js";
import config from "../config.js";
let rateLimit: Date | null = null;
class P2PEarthquakeClient {
private ws: WebSocket | null = null;
private reconnectInterval: number = config.earthquake.reconnectTimes;
@@ -75,10 +72,6 @@ class P2PEarthquakeClient {
console.log("緊急地震速報を受信しました");
this.executeEventFunc(message);
break;
case 555: // 地域情報更新情報
console.log("地域情報更新を受信しました");
this.executeEventFunc(message);
break;
default:
console.log(`未対応の情報を受信しました(コード: ${message.code})`);
break;
@@ -208,7 +201,7 @@ async function event(earthquakeInfo: any): Promise<void> {
let magnitude: string = "マグニチュード:";
if (
earthquakeInfo.earthquake.hypocenter.magnitude !== -1 ||
earthquakeInfo.earthquake.hypocenter.magnitude != -1 ||
earthquakeInfo.earthquake.hypocenter.magnitude === undefined
) {
magnitude += "マグニチュードの情報はありません";
@@ -262,7 +255,7 @@ async function event(earthquakeInfo: any): Promise<void> {
}
if (
earthquakeInfo.earthquake.maxScale === -1 &&
earthquakeInfo.earthquake.maxScale == -1 &&
earthquakeInfo.earthquake.maxScale === undefined
) {
maxScale = "最大震度情報なし";
@@ -346,7 +339,7 @@ async function event(earthquakeInfo: any): Promise<void> {
if (
earthquakeInfo.earthquake.hypocenter.depth !== null ||
earthquakeInfo.earthquake.hypocenter.depth !== undefined ||
earthquakeInfo.earthquake.hypocenter.depth !== -1
earthquakeInfo.earthquake.hypocenter.depth != -1
) {
if (earthquakeInfo.earthquake.hypocenter.depth === 0) {
depth = "深さ:ごく浅い";
@@ -361,9 +354,9 @@ async function event(earthquakeInfo: any): Promise<void> {
if(
earthquakeInfo.earthquake.hypocenter.magnitude !== null ||
earthquakeInfo.earthquake.hypocenter.magnitude !== undefined ||
earthquakeInfo.earthquake.hypocenter.magnitude !== -1
earthquakeInfo.earthquake.hypocenter.magnitude != -1
) {
magnitude = `マグニチュード:${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
magnitude = `マグニチュード:M${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
}
ueuse(`
@@ -378,49 +371,13 @@ async function event(earthquakeInfo: any): Promise<void> {
国内の津波:${domesticTsunami}
`);
}
// 地域情報更新の場合
else if (earthquakeInfo.code === 555) {
if (rateLimit === null) {
rateLimit = subMinutes(new Date(), config.earthquake.rateLimit + 15);
}
// 対象地域マッピング
const areaMaps: any = await areaMap();
const areaNames: Array<string> = Array.from(
new Set(
earthquakeInfo.areas
.map((i: any) => {
return areaMaps[i.id];
})
.filter(Boolean),
),
);
const areas = areaNames.join("・");
if (Math.abs(differenceInMinutes(rateLimit, new Date())) >= config.earthquake.rateLimit) {
ueuse(`
==地震情報==
【地域情報更新】
時刻:${earthquakeInfo.time}
対象地域:${areas}
`);
rateLimit = new Date();
} else {
console.log("レート制限に満たしていないため投稿されませんでした");
return;
}
}
}
async function ueuse(text: string) {
const res = await fetch(`https://${config.uwuzuServer}/api/ueuse/create`, {
const res = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
method: "POST",
body: JSON.stringify({
token: config.apiToken,
token: config.uwuzu.apiToken,
text: text,
}),
});
@@ -1,13 +1,13 @@
import type * as types from "types/types";
import config from "../config.js";
import config from "../../config.js";
export default async function followBack() {
console.log("----------------");
// フォロワーを取得
const resMe = await fetch(
`https://${config.uwuzuServer}/api/me?token=${config.apiToken}`,
`https://${config.uwuzu.host}/api/me?token=${config.uwuzu.apiToken}`,
{
method: "GET",
// uwuzu v1.5.4で/api/meのPOSTが死んでいるため簡易的にGET
@@ -25,11 +25,11 @@ export default async function followBack() {
const followerItem = followers[i];
const resFollow = await fetch(
`https://${config.uwuzuServer}/api/users/follow`,
`https://${config.uwuzu.host}/api/users/follow`,
{
method: "POST",
body: JSON.stringify({
token: config.apiToken,
token: config.uwuzu.apiToken,
userid: followerItem,
}),
},
+7
View File
@@ -0,0 +1,7 @@
import followBack from "./follow.js";
import unFollowBack from "./unfollow.js";
export default function follows() {
unFollowBack();
followBack();
}
+27
View File
@@ -0,0 +1,27 @@
import config from "../../config.js";
import { meApi } from "types/types.js";
export default async function unFollowBack() {
const profile: meApi = await
(await fetch(`https://${config.uwuzu.host}/api/me`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
})
})).json();
profile.followee.forEach(async (followUser: string) => {
if (
profile.follower[followUser] === undefined ||
profile.follower[followUser] === null
) {
await fetch(`https://${config.uwuzu.host}/api/users/unfollow`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
userId: followUser,
}),
})
}
});
}
+18 -21
View File
@@ -1,29 +1,26 @@
import * as fs from "fs";
import { format, isAfter } from "date-fns";
import { parse } from "date-fns/fp";
import { isBefore } from "date-fns/fp";
import config from "../config.js";
import sendMail from "../src/mailer.js";
const formatParse = parse(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")
// 初期化
if (fs.existsSync("iolog.json") === false) {
fs.writeFileSync("iolog.json", JSON.stringify({
start: format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"),
stop: "",
}), "utf-8");
}
export default function successExit() {
const iolog = JSON.parse(fs.readFileSync("iolog.json", "utf-8"));
// 初期化
if (!fs.existsSync("logs/boot.json")) {
fs.writeFileSync("logs/boot.json", JSON.stringify({
start: new Date(),
stop: "",
}), "utf-8");
}
const iolog = JSON.parse(fs.readFileSync("logs/boot.json", "utf-8"));
if (config.emergency.function) {
// 前回の終了確認
const start = formatParse(iolog.start);
const stop = formatParse(iolog.stop);
const start = iolog.start;
const stop = iolog.stop;
if (isAfter(start, stop)) {
if (isBefore(start, stop)) {
console.log("前回の終了が適切でない可能性があります");
if (config.emergency.mail.function) {
@@ -48,15 +45,15 @@ export default function successExit() {
}
// 起動時に起動時刻を保存
iolog.start = format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
fs.writeFileSync("iolog.json", JSON.stringify(iolog), "utf-8");
iolog.start = new Date();
fs.writeFileSync("logs/boot.json", JSON.stringify(iolog), "utf-8");
// 終了時に終了時刻を保存
process.on("exit", () => {
const iolog = JSON.parse(fs.readFileSync("iolog.json", "utf-8"));
iolog.stop = format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
const iolog = JSON.parse(fs.readFileSync("logs/boot.json", "utf-8"));
iolog.stop = new Date();
fs.writeFileSync("iolog.json", JSON.stringify(iolog), "utf-8");
fs.writeFileSync("logs/boot.json", JSON.stringify(iolog), "utf-8");
});
}
+2 -2
View File
@@ -28,11 +28,11 @@ export default async function timeNotice() {
} else {
// 投稿
const resUeuse = await fetch(
`https://${config.uwuzuServer}/api/ueuse/create`,
`https://${config.uwuzu.host}/api/ueuse/create`,
{
method: "POST",
body: JSON.stringify({
token: config.apiToken,
token: config.uwuzu.apiToken,
text: `${format(new Date(), "HH:mm")}になりました`,
}),
},
+4 -4
View File
@@ -9,11 +9,11 @@ export default async function weatherNotice() {
// 仮投稿
const resUeuse = await fetch(
`https://${config.uwuzuServer}/api/ueuse/create`,
`https://${config.uwuzu.host}/api/ueuse/create`,
{
method: "POST",
body: JSON.stringify({
token: config.apiToken,
token: config.uwuzu.apiToken,
text: `
本日の天気
※タイムラインが埋まるため返信に記載しています
@@ -103,11 +103,11 @@ export default async function weatherNotice() {
// 分割投稿
for (let i = 0; i < splitCount; i++) {
const resReply = await fetch(
`https://${config.uwuzuServer}/api/ueuse/create`,
`https://${config.uwuzu.host}/api/ueuse/create`,
{
method: "POST",
body: JSON.stringify({
token: config.apiToken,
token: config.uwuzu.apiToken,
text: weatherResults[i],
replyid: ueuseData.uniqid
}),