v7.0(unconfirmed)をリリース

This commit is contained in:
2025-08-01 18:57:15 +09:00
parent 50db83cc8c
commit dc67845bc8
17 changed files with 317 additions and 115 deletions
+16
View File
@@ -0,0 +1,16 @@
import { unlinkSync } from "fs";
export default function logsDelete() {
console.log("ログを削除中します");
try {
unlinkSync("logs/boot.json");
unlinkSync("logs/version.txt");
console.log("ログファイルを削除しました");
console.log("----------------");
} catch (err) {
console.log("ログファイルの削除中にエラーが発生しました:\n", err);
process.exit();
}
}
+7
View File
@@ -0,0 +1,7 @@
import logsDelete from "./logsDel.js";
import packageLockJsonDelete from "./packageLockDel.js";
import npmInstall from "./npmInstall.js";
logsDelete();
packageLockJsonDelete();
npmInstall();
+23
View File
@@ -0,0 +1,23 @@
import { execSync } from "child_process";
export default function npmInstall() {
// npm install実行
console.log("npm installを実行します");
try {
const npmInstall = execSync("npm install");
console.log("----");
console.log("$ npm install");
console.log(npmInstall.toString());
console.log("----");
console.log("npm installを実行しました");
} catch (err) {
console.log("npm installの実行中にエラーが発生しました:\n", err);
process.exit();
}
console.log("初期化が完了しました");
process.exit();
}
+15
View File
@@ -0,0 +1,15 @@
import { unlinkSync } from "fs";
export default function packageLockJsonDelete() {
console.log("package-lock.jsonを削除します");
try {
unlinkSync("package-lock.json");
console.log("package-lock.jsonを削除しました");
console.log("----------------");
} catch (err) {
console.log("package-lock.jsonの削除中にエラーが発生しました:\n", err);
process.exit();
}
}
+32
View File
@@ -0,0 +1,32 @@
import { ueuse } from "types/types.js";
import config from "../../config.js";
export default async function Follow(data: ueuse) {
const followReq = await fetch(`https://${config.uwuzu.host}/api/users/follow/`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
userid: data.account.userid,
}),
});
const followRes = await followReq.json();
console.log("フォロー: ", followRes);
const noticeReq = await fetch(`https://${config.uwuzu.host}/api/ueuse/create/`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
text: `
${data.account.username}さんをフォローしました
`,
replyid: data.uniqid,
}),
});
const noticeRes = await noticeReq.json();
console.log("フォロー通知: ", noticeRes);
}
+114
View File
@@ -0,0 +1,114 @@
import * as fs from "fs";
import config from "../../config.js";
import type { ueuse } from "types/types.js";
const initialFile: Array<string> = [];
// コマンド読み込み
import Follow from "./follow.js";
import UnFollow from "./unfollow.js";
import Weather from "./weather.js";
// 初期化
if (!fs.existsSync("logs/alreadyCommands.json")) {
fs.writeFileSync(
"logs/alreadyCommands.json",
JSON.stringify(initialFile),
"utf-8",
);
}
// 対応済みユーズ一覧
const alreadyCommands: Array<string> = JSON.parse(fs.readFileSync("alreadyCommands.json", "utf-8"));
function cutAfterChar(str: string, char: string) {
const index = str.indexOf(char);
if (index === -1) {
return "";
}
return str.substring(index + 1);
}
async function Reply(text: string, reply: string) {
const req = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
text: text,
replyid: reply,
}),
});
const res = await req.json();
return res;
}
function alreadyAdd(data: string) {
alreadyCommands[alreadyCommands.length] = data;
fs.writeFileSync(
"logs/alreadyCommands.json",
JSON.stringify(alreadyCommands),
"utf-8",
);
}
export default async function Commands() {
const mentions: Array<ueuse> = await (await fetch(
`https://${config.uwuzu.host}/api/ueuse/mentions/`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
}),
}
)).json();
console.log("----------------");
console.log("コマンド処理");
for (let i = 0; i < mentions.length; i++) {
const data = mentions[i];
// 除外ユーズ
if (alreadyCommands.indexOf(data.uniqid) !== -1) {
break;
}
if (data.text.charAt(0) === "!") {
break;
}
// コマンド処理
console.log("--------");
const commandName = cutAfterChar(data.text, "/");
switch (commandName) {
case "follow":
alreadyAdd(data.uniqid);
Follow(data);
break;
case "unfollow":
alreadyAdd(data.uniqid);
UnFollow(data);
break;
case "weather":
alreadyAdd(data.uniqid);
Weather(data);
break;
default:
alreadyAdd(data.uniqid);
const reply = await Reply(`
不明なコマンドです。
コマンド実行を除外する場合は1文字目に\`!\`を入れてください。
`, data.uniqid);
console.log("未対応コマンド: ", reply);
break;
}
}
}
+31
View File
@@ -0,0 +1,31 @@
import { ueuse } from "types/types.js";
import config from "../../config.js";
export default async function UnFollow(data: ueuse) {
const unfollowReq = await fetch(`https://${config.uwuzu.host}/api/users/unfollow/`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
userid: data.account.userid,
}),
});
const unfollowRes = await unfollowReq.json();
console.log("フォロー解除: ", unfollowRes);
const noticeReq = await fetch(`https://${config.uwuzu.host}/api/ueuse/create/`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
text: `
${data.account.username}さんをフォロー解除しました
`,
replyid: data.uniqid,
}),
});
const noticeRes = await noticeReq.json();
console.log("フォロー解除通知: ", noticeRes);
}
+6
View File
@@ -0,0 +1,6 @@
import { weatherReply } from "scripts/weatherNotice";
import { ueuse } from "types/types.js";
export default function Weather(data: ueuse) {
weatherReply(data.uniqid);
}
-44
View File
@@ -1,44 +0,0 @@
import type * as types from "types/types";
import config from "../../config.js";
export default async function followBack() {
console.log("----------------");
// フォロワーを取得
const resMe = await fetch(
`https://${config.uwuzu.host}/api/me/`,
{
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
}),
},
);
const meData: types.meApi = await resMe.json();
const followers = meData.follower;
// フォロー
for (let i = 0; i < followers.length; i++) {
const followerItem = followers[i];
setTimeout(async () => {
const resFollow = await fetch(
`https://${config.uwuzu.host}/api/users/follow/`,
{
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
userid: followerItem,
}),
},
);
const followData: types.followApi = await resFollow.json();
console.log(`フォロー:${JSON.stringify(followData)}`);
}, 100);
}
}
-7
View File
@@ -1,7 +0,0 @@
import followBack from "./follow.js";
import unFollowBack from "./unfollow.js";
export default function follows() {
unFollowBack();
followBack();
}
-34
View File
@@ -1,34 +0,0 @@
import config from "../../config.js";
import { meApi } from "types/types.js";
export default async function unFollowBack() {
const profile: meApi = await
(await fetch(`https://${config.uwuzu.host}/api/me/`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
})
})).json();
for (let i = 0; i < profile.followee.length; i++) {
const followUser = profile.followee[i];
if (
profile.follower.indexOf(followUser) === -1
) {
setTimeout(async () => {
const req = await fetch(`https://${config.uwuzu.host}/api/users/unfollow/`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
userId: followUser,
}),
});
const res = await req.text();
console.log(`フォロー解除: ${res}`)
}, 100);
}
}
}
+6 -3
View File
@@ -4,7 +4,7 @@ import type * as types from "types/types.js";
import config from "../config.js";
export default async function weatherNotice() {
export async function weatherNotice() {
console.log("----------------");
// 仮投稿
@@ -26,7 +26,10 @@ export default async function weatherNotice() {
console.log(`天気仮投稿:${JSON.stringify(ueuseData)}`);
weatherReply(ueuseData.uniqid);
}
export async function weatherReply(uniqid: string) {
// インデックス
const splitCount = config.weather.splitCount;
const total = cityList.length;
@@ -109,13 +112,13 @@ export default async function weatherNotice() {
body: JSON.stringify({
token: config.uwuzu.apiToken,
text: weatherResults[i],
replyid: ueuseData.uniqid
replyid: uniqid,
}),
},
);
const replyData: types.ueuseCreateApi = await resReply.json();
console.log(`天気投稿${JSON.stringify(replyData)}`);
console.log(`天気返信${JSON.stringify(replyData)}`);
}
}