2026.4.0-beta.0 #12

Merged
last2014 merged 11 commits from develop into main 2026-05-03 05:28:47 +00:00
6 changed files with 69 additions and 17 deletions
Showing only changes of commit c0df3d7344 - Show all commits
+14 -2
View File
@@ -1,10 +1,22 @@
command:
# コマンド処理の間隔(分) number
# 自然数のみが有効です。
interval: 10
weather:
splits: 4
earthquake:
# 地震発生情報を投稿することに必要な最大震度 number
# 例: 30を指定すると、最大震度が震度3以上の地震発生情報のみを投稿します。
# 10(震度1), 20(震度2), 30(震度3), 40(震度4), 45(震度5弱), 50(震度5強), 55(震度6弱), 60(震度6強), 70(震度7)が有効です。
requireMaxScale: 30
# 最大震度が不明な地震発生情報を投稿するかどうか boolean
canUnknownMaxScale: true
# 過去のデバッグ用データを使用して地震情報を配信するかどうか boolean
# デバッグ用途のみで使用してください。
useHistoryData: false
uwuzu:
# APIトークン string
# とくに理由がない限り、全権限を与えてください。
token: API_TOKEN
# uwuzuサーバーのorigin string
origin: https://uwuzu.example.com
# デバッグモードにするかどうか boolean
debug: false
+18
View File
@@ -64,6 +64,7 @@ const processMessage = async (message: any) => {
try {
const scaleMessages: Record<string, string> = {
"-1": "不明",
"0": "震度0",
"10": "震度1",
"20": "震度2",
"30": "震度3",
@@ -85,6 +86,23 @@ const processMessage = async (message: any) => {
{
console.log("地震発生情報を受信しました");
if (
(message.earthquake.maxScale === -1 ||
message.earthquake.maxScale === undefined) &&
!config.earthquake.canUnknownMaxScale
) {
console.log("最大震度が不明であり、最大震度が不明な場合の投稿が許可されていないため、スキップします");
break;
}
if (
message.earthquake.maxScale !== -1 &&
message.earthquake.maxScale < config.earthquake.requireMaxScale
) {
console.log("投稿に必要な最大震度に満たないため、スキップします");
break;
}
const domesticTsunamiMessages: Record<string, string> = {
"None": "😌この地震による**国内**の津波の心配はありません。",
"Unknown": "😕この地震による**国内**の***津波情報は***不明です。",
+3 -2
View File
@@ -1,6 +1,6 @@
import client from "@/lib/client";
import config from "@/lib/config";
import initI18n from "@/lib/i18n";
import Memory from "@/lib/memory";
import i18next from "i18next";
import { readFileSync } from "node:fs";
import { EOL } from "node:os";
@@ -84,7 +84,8 @@ if (!isMainThread && workerData === "scheduledWeatherNotice") {
export async function weatherReply(uniqid: string) {
// インデックス
const splitCount = config.weather.splits;
const mem = Memory.memory;
const splitCount = Math.round(3100 / mem.max_length);
const total = cityList.length;
const chunkSizes = Array(splitCount).fill(0).map((_, i) =>
Math.floor((total + i) / splitCount)
+2 -2
View File
@@ -1,7 +1,7 @@
import { schedule } from "node-cron";
import { readFileSync } from "node:fs";
import config from "@/lib/config";
import { initUserID } from "@/lib/memory";
import { initData } from "@/lib/memory";
import { styleText } from "node:util";
import { Worker } from "node:worker_threads";
@@ -18,7 +18,7 @@ try {
}
console.log();
await initUserID();
await initData();
new Worker(`${import.meta.dirname}/feature/earthquakeNotice.js`);
+13 -4
View File
@@ -7,12 +7,21 @@ const schema = z.object({
command: z.object({
interval: z.number().int().positive(),
}),
weather: z.object({
splits: z.number().int().positive(),
}),
earthquake: z.object({
requireMaxScale: z.union([
z.literal(10),
z.literal(20),
z.literal(30),
z.literal(40),
z.literal(45),
z.literal(50),
z.literal(55),
z.literal(60),
z.literal(70),
]),
canUnknownMaxScale: z.boolean(),
useHistoryData: z.boolean(),
}).optional(),
}),
uwuzu: z.object({
token: z.string().length(64),
origin: z.string().refine(data => {
+19 -7
View File
@@ -14,6 +14,7 @@ class MemoryClass {
lastReadMention: "",
lastReadReply: "",
userid: "",
max_length: 0,
}));
}
@@ -32,15 +33,26 @@ class MemoryClass {
const Memory = new MemoryClass();
export const initUserID = async () => {
const response = await client.request("me/");
export const initData = async () => {
await Promise.all([
(async () => {
const response = await client.request("me/");
if (!response.success)
throw new Error("meの取得に失敗しました");
if (!response.success)
throw new Error("meの取得に失敗しました");
const mem = Memory.memory;
mem.userid = response.userid;
Memory.memory = mem;
const mem = Memory.memory;
mem.userid = response.userid;
Memory.memory = mem;
})(),
(async () => {
const response = await client.request("serverinfo-api");
const mem = Memory.memory;
mem.max_length = response.server_info.max_ueuse_length;
Memory.memory = mem;
})(),
]);
}
export default Memory;