Compare commits

...

3 Commits

10 changed files with 240 additions and 22 deletions
+2
View File
@@ -0,0 +1,2 @@
TOKEN=
SERVER=
+2 -1
View File
@@ -1,4 +1,5 @@
/dist/
/.env*
/.env
/.env.local
/node_modules/
/package-lock.json
+19
View File
@@ -0,0 +1,19 @@
# uwuzuお知らせBOT
# uwuzuお知らせBOTについて
uwuzuで動作するお知らせBOTです。
# .env形式
`.env.example`をご覧ください。
# サーバー起動
```
npm install
npm run build
npm run start
```
※Node.js・npmがインストールされている必要があります。
+13 -16
View File
@@ -1,22 +1,19 @@
import * as cron from "node-cron";
import * as dotenv from "dotenv";
import { format } from "date-fns";
dotenv.config();
import timeNotice from "./scripts/timeNotice.js";
import weatherNotice from "./scripts/weatherNotice.js";
async function ueuse() {
const now = format(new Date(), "HH:mm");
console.log(now);
const res = await fetch(`https://${process.env.SERVER}/api/ueuse/create`, {
method: "POST",
body: JSON.stringify({
token: process.env.TOKEN,
text: `日本時間${now}になりました`,
}),
});
}
import followBack from "./scripts/followBack.js";
// 時報・フォローバック(毎時)
cron.schedule("0 * * * *", () => {
ueuse();
timeNotice();
followBack();
});
// 天気お知らせ(毎日7:00)
cron.schedule("0 7 * * *", () => {
weatherNotice();
});
console.log("サーバーが起動しました");
+7 -5
View File
@@ -1,10 +1,12 @@
{
"name": "timenoticeuwuzu",
"version": "v1.0@uwuzu1.5.4",
"description": "@TimeNotice@uwuzu.netの中身",
"name": "noticeuwuzu",
"version": "v2.0@uwuzu1.5.4",
"description": "uwuzu Notice Bot",
"main": "dist/main.js",
"scripts": {
"start": "node ."
"start": "node .",
"build": "tsc",
"dev": "tsx main.ts"
},
"keywords": [
"uwuzu",
@@ -28,7 +30,7 @@
"date-fns": "^4.1.0",
"dotenv": "^17.0.0",
"node-cron": "^4.1.1",
"ts-node": "^10.9.2",
"tsx": "^4.20.3",
"typescript": "^5.8.3"
}
}
+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));
}
+49
View File
@@ -0,0 +1,49 @@
export const cityList: { [cityId: string]: string } = {
"016010": "札幌",
"020010": "青森",
"030010": "盛岡",
"040010": "仙台",
"050010": "秋田",
"060010": "山形",
"070010": "福島",
"080010": "水戸",
"090010": "宇都宮",
"100010": "前橋",
"110010": "さいたま",
"120010": "千葉",
"130010": "東京",
"140010": "横浜",
"150010": "新潟",
"160010": "富山",
"170010": "金沢",
"180010": "福井",
"190010": "甲府",
"200010": "長野",
"210010": "岐阜",
"220010": "静岡",
"230010": "名古屋",
"240010": "津",
"250010": "大津",
"260010": "京都",
"270000": "大阪",
"280010": "神戸",
"290010": "奈良",
"300010": "和歌山",
"310010": "鳥取",
"320010": "松江",
"330010": "岡山",
"340010": "広島",
"350010": "山口",
"360010": "徳島",
"370000": "高松",
"380010": "松山",
"390010": "高知",
"400010": "福岡",
"410010": "佐賀",
"420010": "長崎",
"430010": "熊本",
"440010": "大分",
"450010": "宮崎",
"460010": "鹿児島",
"471010": "那覇",
};
Vendored
+33
View File
@@ -0,0 +1,33 @@
export interface Role {
name: string;
color: string;
effect: string;
id: string;
}
export interface meApi {
username: string;
userid: string;
profile: string;
user_icon: string;
user_header: string;
registered_date: string;
followee: Array;
followee_cnt: number;
follower: Array;
follower_cnt: number;
ueuse_cnt: number;
isBot: Boolean;
isAdmin: Boolean;
role: Role[];
language: String;
}
export interface ueuseCreateApi {
uniqid: string;
userid: string;
}
export interface followApi {
userid: string;
}