This commit is contained in:
2025-06-29 18:56:27 +09:00
parent 761af6eafc
commit 5bd251f6eb
7 changed files with 185 additions and 66 deletions
+40
View File
@@ -0,0 +1,40 @@
import * as dotenv from "dotenv";
import type * as types from "../types";
dotenv.config();
export default async function followBack() {
// uwuzu.netで/api/meのPOSTが死んでいるため簡易的にGET
const resMe = await fetch(
`https://${process.env.SERVER}/api/me?token=${process.env.TOKEN}`,
{
method: "GET",
},
);
const meData: types.meApi = await resMe.json();
console.log(meData);
const followers: Array<string> = meData.follower;
for (let i = 0; i < followers.length; i++) {
const followerItem = followers[i];
const resFollow = await fetch(
`https://${process.env.SERVER}/api/users/follow`,
{
method: "POST",
body: JSON.stringify({
token: process.env.TOKEN,
userid: followerItem,
}),
},
);
const followData: types.followApi = await resFollow.json();
console.log(JSON.stringify(followData));
}
}
+25
View File
@@ -0,0 +1,25 @@
import * as dotenv from "dotenv";
import { format } from "date-fns";
import type * as types from "../types";
dotenv.config();
export default async function timeNotice() {
const now = format(new Date(), "HH:mm");
const resUeuse = await fetch(
`https://${process.env.SERVER}/api/ueuse/create`,
{
method: "POST",
body: JSON.stringify({
token: process.env.TOKEN,
text: `${now}になりました`,
}),
},
);
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
console.log(JSON.stringify(ueuseData));
}
+50
View File
@@ -0,0 +1,50 @@
import * as dotenv from "dotenv";
import { cityList } from "../src/weatherId.js";
import type * as types from "../types";
dotenv.config();
export default async function weatherNotice() {
let weatherResults: string = "";
for (const [cityId, cityName] of Object.entries(cityList)) {
const res = await fetch(
`https://weather.tsukumijima.net/api/forecast/city/${cityId}`,
);
const data = await res.json();
const today = data.forecasts[0];
const weather = today.telop ?? "取得できませんでした";
const maxTemp = today.temperature.max?.celsius ?? "取得できませんでした";
const minTemp = today.temperature.min?.celsius ?? "取得できませんでした";
const chanceOfRain = data.chanceOfRain?.["T06_12"] ?? "取得できませんでした";
weatherResults = weatherResults +
`${cityName}\n
天気:${weather}\n
最高気温:${maxTemp}\n
最低気温:${minTemp}\n
降水確率:${chanceOfRain}
`;
}
// 返信用ユーズ
const resUeuse = await fetch(
`https://${process.env.SERVER}/api/ueuse/create`,
{
method: "POST",
body: JSON.stringify({
token: process.env.TOKEN,
text: `
# 本日の天気\n
${weatherResults}
`,
}),
},
);
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
console.log(JSON.stringify(ueuseData));
}