2026.4.0-alpha.0
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
import client from "@/lib/client";
|
||||
import Memory from "@/lib/memory";
|
||||
import ueuseModule from "better-uwuzu-sdk/types/1.6.8/types/modules/ueuse";
|
||||
import i18next from "i18next";
|
||||
import weatherCommand from "@/feature/command/weather";
|
||||
import helpCommand from "@/feature/command/help";
|
||||
import followCommand from "@/feature/command/follow";
|
||||
import unfollowCommand from "@/feature/command/unfollow";
|
||||
import miqCommand from "./miq";
|
||||
|
||||
export default async function commandExecute() {
|
||||
let ueuses: ueuseModule[] = [];
|
||||
|
||||
{
|
||||
const response = await client.request("me/notification/", {
|
||||
limit: 20,
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
for (const notification of response.data) {
|
||||
if (notification.category !== "reply")
|
||||
break;
|
||||
|
||||
if (!notification.valueid) {
|
||||
console.warn("返信通知にvalueidが存在しないため、スキップします");
|
||||
break;
|
||||
}
|
||||
|
||||
const ueuseResponse = await client.request("ueuse/get", {
|
||||
uniqid: notification.valueid,
|
||||
});
|
||||
|
||||
if (!ueuseResponse.success || !ueuseResponse.data[0]) {
|
||||
console.warn("返信通知からユーズを参照できないため、スキップします");
|
||||
break;
|
||||
}
|
||||
|
||||
ueuses.push(ueuseResponse.data[0]);
|
||||
}
|
||||
} else {
|
||||
console.warn("返信通知の取得に失敗しましたが、続行します");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const response = await client.request("ueuse/mentions", {
|
||||
limit: 20,
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
ueuses.push(...response.data);
|
||||
} else {
|
||||
console.warn("メンションの取得に失敗しましたが、続行します");
|
||||
}
|
||||
}
|
||||
|
||||
ueuses = [...new Set(ueuses)];
|
||||
|
||||
for (const ueuse of ueuses) {
|
||||
const repliedUeuse = (Memory.memory["repliedUeuse"] as string[]);
|
||||
|
||||
if (repliedUeuse.includes(ueuse.uniqid)) {
|
||||
console.log("既に応答しているため、スキップします");
|
||||
break;
|
||||
}
|
||||
|
||||
const mem = Memory.memory;
|
||||
let text = ueuse.text;
|
||||
text = text.replace(`@${mem.userid}`, "");
|
||||
text = text.trim();
|
||||
|
||||
const rows = text.split(/\r\n|\r|\n/).map(row => row.trim());
|
||||
const commandRow = rows.filter(row => row.startsWith("/"))[0];
|
||||
|
||||
if (!commandRow || commandRow === "") {
|
||||
console.warn("コマンドが本文から参照できません");
|
||||
|
||||
const response = await client.request("ueuse/create", {
|
||||
text: i18next.t("commandNotFound"),
|
||||
replyid: ueuse.uniqid,
|
||||
});
|
||||
|
||||
if (!response.success)
|
||||
console.warn("ユーズの作成に失敗しました:", response.error_code);
|
||||
break;
|
||||
}
|
||||
|
||||
const args = commandRow.replace("/", "").split(" ");
|
||||
|
||||
switch (args[0]) {
|
||||
case "help":
|
||||
await helpCommand(ueuse, args);
|
||||
break;
|
||||
case "weather":
|
||||
await weatherCommand(ueuse);
|
||||
break;
|
||||
case "follow":
|
||||
await followCommand(ueuse);
|
||||
break;
|
||||
case "unfollow":
|
||||
await unfollowCommand(ueuse);
|
||||
break;
|
||||
case "miq":
|
||||
await miqCommand(ueuse, args);
|
||||
break;
|
||||
default:
|
||||
console.warn("不明なコマンドが入力されました:", args[0]);
|
||||
|
||||
const response = await client.request("ueuse/create", {
|
||||
text: i18next.t("unknownCommand", { command: args[0] }),
|
||||
replyid: ueuse.uniqid,
|
||||
});
|
||||
|
||||
if (!response.success)
|
||||
console.warn("ユーズの作成に失敗しました:", response.error_code);
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
const repliedUeuse = (Memory.memory["repliedUeuse"] as string[]);
|
||||
repliedUeuse.push(ueuse.uniqid);
|
||||
const mem = Memory.memory;
|
||||
mem["repliedUeuse"] = repliedUeuse;
|
||||
Memory.memory = mem;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user