Feat: ユーズの再試行 / Feat: ユーズの文字数制限回避 / Feat: ユーズ送信関数 / Chg: weatherNotice.tsのマジックナンバーに命名
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import client from "@/lib/client";
|
||||
import config from "@/lib/config";
|
||||
import initI18n from "@/lib/i18n";
|
||||
import Memory from "@/lib/memory";
|
||||
import i18next from "i18next";
|
||||
@@ -61,12 +62,27 @@ if (!isMainThread && workerData === "scheduledWeatherNotice") {
|
||||
console.log("天気予報の投稿を行います");
|
||||
|
||||
try {
|
||||
const provisionalUeuse = await client.request("ueuse/create", {
|
||||
text: i18next.t("weatherProvisional"),
|
||||
});
|
||||
let provisionalUeuse;
|
||||
let success = false;
|
||||
|
||||
if (!provisionalUeuse.success) {
|
||||
console.error("天気仮投稿に失敗しました:", provisionalUeuse.error_code);
|
||||
for (let attempt = 1; attempt <= config.ueuse.maxRetries; attempt++) {
|
||||
provisionalUeuse = await client.request("ueuse/create", {
|
||||
text: i18next.t("weatherProvisional"),
|
||||
});
|
||||
|
||||
if (provisionalUeuse.success) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
console.warn(`天気仮投稿に失敗しました (試行 ${attempt}/${config.ueuse.maxRetries}):`, provisionalUeuse.error_code);
|
||||
if (attempt < config.ueuse.maxRetries) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
if (!success || !provisionalUeuse?.success) {
|
||||
console.error("天気仮投稿の全試行に失敗したため、終了します。");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -84,8 +100,9 @@ if (!isMainThread && workerData === "scheduledWeatherNotice") {
|
||||
|
||||
export async function weatherReply(uniqid: string) {
|
||||
// インデックス
|
||||
const aboutFullLength = 3100;
|
||||
const mem = Memory.memory;
|
||||
const splitCount = Math.round(3100 / mem.max_length);
|
||||
const splitCount = Math.round(aboutFullLength / mem.max_length);
|
||||
const total = cityList.length;
|
||||
const chunkSizes = Array(splitCount).fill(0).map((_, i) =>
|
||||
Math.floor((total + i) / splitCount)
|
||||
@@ -149,13 +166,29 @@ export async function weatherReply(uniqid: string) {
|
||||
|
||||
// 分割投稿
|
||||
for (let i = 0; i < splitCount; i++) {
|
||||
const replyUeuse = await client.request("ueuse/create", {
|
||||
text: weatherResults[i].trim(),
|
||||
replyid: uniqid,
|
||||
});
|
||||
let replyUeuse;
|
||||
let success = false;
|
||||
|
||||
if (!replyUeuse.success) {
|
||||
console.error("天気返信に失敗しました:", replyUeuse.error_code);
|
||||
for (let attempt = 1; attempt <= config.ueuse.maxRetries; attempt++) {
|
||||
replyUeuse = await client.request("ueuse/create", {
|
||||
text: weatherResults[i].trim(),
|
||||
replyid: uniqid,
|
||||
});
|
||||
|
||||
if (replyUeuse.success) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
|
||||
console.warn(`天気返信に失敗しました (試行 ${attempt}/${config.ueuse.maxRetries}):`, replyUeuse.error_code);
|
||||
if (attempt < config.ueuse.maxRetries) {
|
||||
await new Promise(resolve => setTimeout(resolve, config.ueuse.retryInterval));
|
||||
}
|
||||
}
|
||||
|
||||
if (!success || !replyUeuse?.success) {
|
||||
console.error("天気返信の全試行に失敗したため、終了します。");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("天気返信:", replyUeuse.uniqid);
|
||||
|
||||
Reference in New Issue
Block a user