型を作成・コードの整形・フォローバック機能作成(使用未定)・README作成・.env.example作成・ts-node廃止tsx移行
This commit is contained in:
parent
4aa58eb55d
commit
f3cc634bb9
|
@ -0,0 +1,2 @@
|
|||
TOKEN=
|
||||
SERVER=
|
|
@ -1,4 +1,5 @@
|
|||
/dist/
|
||||
/.env*
|
||||
/.env
|
||||
/.env.local
|
||||
/node_modules/
|
||||
/package-lock.json
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# uwuzu時報BOT
|
||||
|
||||
# なにこれ
|
||||
|
||||
uwuzuの時報BOT。
|
||||
1時間おきに投稿する。
|
||||
タイムゾーンはサーバー依存。
|
||||
|
||||
# .envは?
|
||||
|
||||
.env.example見て
|
||||
|
||||
# サーバー起動
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
npm run start
|
||||
```
|
47
main.ts
47
main.ts
|
@ -2,21 +2,64 @@ import * as cron from "node-cron";
|
|||
import * as dotenv from "dotenv";
|
||||
import { format } from "date-fns";
|
||||
|
||||
import type * as type from "./types";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
async function ueuse() {
|
||||
const now = format(new Date(), "HH:mm");
|
||||
console.log(now);
|
||||
|
||||
const res = await fetch(`https://${process.env.SERVER}/api/ueuse/create`, {
|
||||
const resUeuse = await fetch(
|
||||
`https://${process.env.SERVER}/api/ueuse/create`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
text: `${now}になりました`,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const ueuseData: type.ueuseCreateApi = await resUeuse.json();
|
||||
|
||||
console.log(JSON.stringify(ueuseData));
|
||||
}
|
||||
|
||||
async function follow() {
|
||||
const resMe = await fetch(`https://${process.env.SERVER}/api/me`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
text: `日本時間${now}になりました`,
|
||||
}),
|
||||
});
|
||||
|
||||
const meData: type.meApi = await resMe.json();
|
||||
|
||||
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: type.followApi = await resFollow.json();
|
||||
|
||||
console.log(JSON.stringify(followData));
|
||||
}
|
||||
}
|
||||
|
||||
cron.schedule("0 * * * *", () => {
|
||||
ueuse();
|
||||
});
|
||||
|
||||
console.log("サーバーが起動しました");
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
{
|
||||
"name": "timenoticeuwuzu",
|
||||
"version": "v1.0@uwuzu1.5.4",
|
||||
"version": "v1.1@uwuzu1.5.4",
|
||||
"description": "@TimeNotice@uwuzu.netの中身",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue