2026.4.0-beta.0 #12
+14
-2
@@ -1,10 +1,22 @@
|
|||||||
command:
|
command:
|
||||||
|
# コマンド処理の間隔(分) number
|
||||||
|
# 自然数のみが有効です。
|
||||||
interval: 10
|
interval: 10
|
||||||
weather:
|
|
||||||
splits: 4
|
|
||||||
earthquake:
|
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
|
useHistoryData: false
|
||||||
uwuzu:
|
uwuzu:
|
||||||
|
# APIトークン string
|
||||||
|
# とくに理由がない限り、全権限を与えてください。
|
||||||
token: API_TOKEN
|
token: API_TOKEN
|
||||||
|
# uwuzuサーバーのorigin string
|
||||||
origin: https://uwuzu.example.com
|
origin: https://uwuzu.example.com
|
||||||
|
# デバッグモードにするかどうか boolean
|
||||||
debug: false
|
debug: false
|
||||||
@@ -64,6 +64,7 @@ const processMessage = async (message: any) => {
|
|||||||
try {
|
try {
|
||||||
const scaleMessages: Record<string, string> = {
|
const scaleMessages: Record<string, string> = {
|
||||||
"-1": "不明",
|
"-1": "不明",
|
||||||
|
"0": "震度0",
|
||||||
"10": "震度1",
|
"10": "震度1",
|
||||||
"20": "震度2",
|
"20": "震度2",
|
||||||
"30": "震度3",
|
"30": "震度3",
|
||||||
@@ -85,6 +86,23 @@ const processMessage = async (message: any) => {
|
|||||||
{
|
{
|
||||||
console.log("地震発生情報を受信しました");
|
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> = {
|
const domesticTsunamiMessages: Record<string, string> = {
|
||||||
"None": "😌この地震による**国内**の津波の心配はありません。",
|
"None": "😌この地震による**国内**の津波の心配はありません。",
|
||||||
"Unknown": "😕この地震による**国内**の***津波情報は***不明です。",
|
"Unknown": "😕この地震による**国内**の***津波情報は***不明です。",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import client from "@/lib/client";
|
import client from "@/lib/client";
|
||||||
import config from "@/lib/config";
|
|
||||||
import initI18n from "@/lib/i18n";
|
import initI18n from "@/lib/i18n";
|
||||||
|
import Memory from "@/lib/memory";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import { EOL } from "node:os";
|
import { EOL } from "node:os";
|
||||||
@@ -84,7 +84,8 @@ if (!isMainThread && workerData === "scheduledWeatherNotice") {
|
|||||||
|
|
||||||
export async function weatherReply(uniqid: string) {
|
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 total = cityList.length;
|
||||||
const chunkSizes = Array(splitCount).fill(0).map((_, i) =>
|
const chunkSizes = Array(splitCount).fill(0).map((_, i) =>
|
||||||
Math.floor((total + i) / splitCount)
|
Math.floor((total + i) / splitCount)
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
import { schedule } from "node-cron";
|
import { schedule } from "node-cron";
|
||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import config from "@/lib/config";
|
import config from "@/lib/config";
|
||||||
import { initUserID } from "@/lib/memory";
|
import { initData } from "@/lib/memory";
|
||||||
import { styleText } from "node:util";
|
import { styleText } from "node:util";
|
||||||
import { Worker } from "node:worker_threads";
|
import { Worker } from "node:worker_threads";
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ try {
|
|||||||
}
|
}
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
await initUserID();
|
await initData();
|
||||||
|
|
||||||
new Worker(`${import.meta.dirname}/feature/earthquakeNotice.js`);
|
new Worker(`${import.meta.dirname}/feature/earthquakeNotice.js`);
|
||||||
|
|
||||||
|
|||||||
+13
-4
@@ -7,12 +7,21 @@ const schema = z.object({
|
|||||||
command: z.object({
|
command: z.object({
|
||||||
interval: z.number().int().positive(),
|
interval: z.number().int().positive(),
|
||||||
}),
|
}),
|
||||||
weather: z.object({
|
|
||||||
splits: z.number().int().positive(),
|
|
||||||
}),
|
|
||||||
earthquake: z.object({
|
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(),
|
useHistoryData: z.boolean(),
|
||||||
}).optional(),
|
}),
|
||||||
uwuzu: z.object({
|
uwuzu: z.object({
|
||||||
token: z.string().length(64),
|
token: z.string().length(64),
|
||||||
origin: z.string().refine(data => {
|
origin: z.string().refine(data => {
|
||||||
|
|||||||
+13
-1
@@ -14,6 +14,7 @@ class MemoryClass {
|
|||||||
lastReadMention: "",
|
lastReadMention: "",
|
||||||
lastReadReply: "",
|
lastReadReply: "",
|
||||||
userid: "",
|
userid: "",
|
||||||
|
max_length: 0,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +33,9 @@ class MemoryClass {
|
|||||||
|
|
||||||
const Memory = new MemoryClass();
|
const Memory = new MemoryClass();
|
||||||
|
|
||||||
export const initUserID = async () => {
|
export const initData = async () => {
|
||||||
|
await Promise.all([
|
||||||
|
(async () => {
|
||||||
const response = await client.request("me/");
|
const response = await client.request("me/");
|
||||||
|
|
||||||
if (!response.success)
|
if (!response.success)
|
||||||
@@ -41,6 +44,15 @@ export const initUserID = async () => {
|
|||||||
const mem = Memory.memory;
|
const mem = Memory.memory;
|
||||||
mem.userid = response.userid;
|
mem.userid = response.userid;
|
||||||
Memory.memory = mem;
|
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;
|
export default Memory;
|
||||||
Reference in New Issue
Block a user