Chg: 最大震度が投稿に必要な値に満たない場合のコンソール表示を変更 / Feat: 返信ではないユーズの自主的な文字数制限
This commit is contained in:
@@ -33,5 +33,11 @@ ueuse:
|
|||||||
# 再試行の間隔(ミリ秒) number
|
# 再試行の間隔(ミリ秒) number
|
||||||
# 正数のみが有効です。
|
# 正数のみが有効です。
|
||||||
retryInterval: 1000
|
retryInterval: 1000
|
||||||
|
# 公開されたユーズの自主規制文字数 number
|
||||||
|
# 返信ではない(公開された)ユーズで使用する自主的な文字数制限です。
|
||||||
|
# 返信では、サーバーの設定に従います。
|
||||||
|
# 0にすると、返信ではないユーズでもサーバーの設定に従います。
|
||||||
|
# 0以上の整数が有効です。
|
||||||
|
maxLengthWithPublic: 512
|
||||||
# デバッグモードにするかどうか boolean
|
# デバッグモードにするかどうか boolean
|
||||||
debug: false
|
debug: false
|
||||||
@@ -116,7 +116,7 @@ const processMessage = async (message: any) => {
|
|||||||
message.earthquake.maxScale !== -1 &&
|
message.earthquake.maxScale !== -1 &&
|
||||||
message.earthquake.maxScale < config.earthquake.requireMaxScale
|
message.earthquake.maxScale < config.earthquake.requireMaxScale
|
||||||
) {
|
) {
|
||||||
console.log("投稿に必要な最大震度に満たないため、スキップします");
|
console.log(`最大震度(${scaleMessages[message.earthquake.maxScale]})が投稿に必要な値(${scaleMessages[config.earthquake.requireMaxScale]})に満たないため、スキップします`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ const processMessage = async (message: any) => {
|
|||||||
.sort((a, b) => b[1].scale - a[1].scale)
|
.sort((a, b) => b[1].scale - a[1].scale)
|
||||||
.map(([label, { prefs }]) => {
|
.map(([label, { prefs }]) => {
|
||||||
const prefLines = Object.entries(prefs)
|
const prefLines = Object.entries(prefs)
|
||||||
.map(([pref, addrs]) => `${pref}: ${addrs.join("・")}`)
|
.map(([pref, addrs]) => `**${pref}:** ${addrs.join("・")}`)
|
||||||
.join(EOL);
|
.join(EOL);
|
||||||
|
|
||||||
return `【${label}】${EOL}${prefLines}`;
|
return `【${label}】${EOL}${prefLines}`;
|
||||||
@@ -281,7 +281,7 @@ const processMessage = async (message: any) => {
|
|||||||
? `から${scaleMessages[String(Math.floor(area.scaleTo))]}`
|
? `から${scaleMessages[String(Math.floor(area.scaleTo))]}`
|
||||||
: ""),
|
: ""),
|
||||||
kind: kindMessages[area.kindCode] ?? "😕主要動の***到達予想は***ありません。",
|
kind: kindMessages[area.kindCode] ?? "😕主要動の***到達予想は***ありません。",
|
||||||
arrivalTime: area.arrivalTime !== undefined
|
arrivalTime: typeof area.arrivalTime === "string" && area.arrivalTime !== ""
|
||||||
? format(new Date(area.arrivalTime), "yyyy年M月d日 H:mm:ss")
|
? format(new Date(area.arrivalTime), "yyyy年M月d日 H:mm:ss")
|
||||||
: "不明",
|
: "不明",
|
||||||
}) + EOL.repeat(2);
|
}) + EOL.repeat(2);
|
||||||
@@ -306,7 +306,7 @@ const processMessage = async (message: any) => {
|
|||||||
magnitude: message.earthquake.hypocenter.magnitude === undefined ||
|
magnitude: message.earthquake.hypocenter.magnitude === undefined ||
|
||||||
message.earthquake.hypocenter.magnitude === -1
|
message.earthquake.hypocenter.magnitude === -1
|
||||||
? "不明"
|
? "不明"
|
||||||
: `M${message.earthquake.hypocenter.magnitude}`,
|
: `M${message.earthquake.hypocenter.magnitude.toFixed(1)}`,
|
||||||
areas: areasMsg !== ""
|
areas: areasMsg !== ""
|
||||||
? EOL.repeat(2) + areasMsg.trim()
|
? EOL.repeat(2) + areasMsg.trim()
|
||||||
: "",
|
: "",
|
||||||
|
|||||||
+13
-2
@@ -15,7 +15,6 @@ export default client;
|
|||||||
|
|
||||||
export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: string) => {
|
export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: string) => {
|
||||||
const mem = Memory.memory;
|
const mem = Memory.memory;
|
||||||
const maxLength = mem.max_length;
|
|
||||||
const excessedMessage = "👉返信に続きがあります。";
|
const excessedMessage = "👉返信に続きがあります。";
|
||||||
|
|
||||||
let lines = data.text.split(EOL);
|
let lines = data.text.split(EOL);
|
||||||
@@ -26,7 +25,13 @@ export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: s
|
|||||||
count++;
|
count++;
|
||||||
let currentText = "";
|
let currentText = "";
|
||||||
|
|
||||||
const limit = maxLength - (excessedMessage.length + EOL.length * 2);
|
const currentMaxLength = (data.replyid !== undefined || firstUniqid !== "")
|
||||||
|
? mem.max_length
|
||||||
|
: config.ueuse.maxLengthWithPublic === 0
|
||||||
|
? mem.max_length
|
||||||
|
: config.ueuse.maxLengthWithPublic;
|
||||||
|
|
||||||
|
const limit = currentMaxLength - (excessedMessage.length + EOL.length * 2);
|
||||||
|
|
||||||
while (lines.length > 0) {
|
while (lines.length > 0) {
|
||||||
const nextLine = lines[0];
|
const nextLine = lines[0];
|
||||||
@@ -50,6 +55,8 @@ export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentText = currentText.trimEnd();
|
||||||
|
|
||||||
if (lines.length > 0) {
|
if (lines.length > 0) {
|
||||||
currentText += EOL.repeat(2) + excessedMessage;
|
currentText += EOL.repeat(2) + excessedMessage;
|
||||||
}
|
}
|
||||||
@@ -87,5 +94,9 @@ export const createUeuse = async (data: ApiMap["ueuse/create"]["body"], title: s
|
|||||||
firstUniqid = postedUniqid;
|
firstUniqid = postedUniqid;
|
||||||
|
|
||||||
console.log(`${title}を投稿(${count}):`, postedUniqid);
|
console.log(`${title}を投稿(${count}):`, postedUniqid);
|
||||||
|
|
||||||
|
while (lines.length > 0 && lines[0]?.trim() === "") {
|
||||||
|
lines.shift();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,7 @@ const schema = z.object({
|
|||||||
ueuse: z.object({
|
ueuse: z.object({
|
||||||
maxRetries: z.number().int().positive(),
|
maxRetries: z.number().int().positive(),
|
||||||
retryInterval: z.number().positive(),
|
retryInterval: z.number().positive(),
|
||||||
|
maxLengthWithPublic: z.number().int().nonnegative(),
|
||||||
}),
|
}),
|
||||||
debug: z.boolean().optional(),
|
debug: z.boolean().optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user