Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f14999be13 | |||
| 6ec9831ed4 | |||
| 718e97ed45 | |||
| f6f7030d8c |
@@ -12,6 +12,13 @@ Automatic notification bot for uwuzu
|
||||
- Earthquake occurs
|
||||
- Tsunami forecast
|
||||
- Weather notification
|
||||
- Commands that users can use freely
|
||||
- About BOT
|
||||
- Command Help
|
||||
- Report to the operator
|
||||
- Follow back
|
||||
- Unfollow
|
||||
- Weather Repost
|
||||
- Startup requirements check
|
||||
- Check package existence
|
||||
- Required package version check
|
||||
|
||||
+16
-10
@@ -1,35 +1,41 @@
|
||||
import * as fs from "fs";
|
||||
import config from "../config.js";
|
||||
import { readFileSync, writeFileSync, existsSync } from "fs";
|
||||
|
||||
export default async function VersionCheck() {
|
||||
const nowVersion: string = JSON.parse(fs.readFileSync("package.json", "utf-8")).version;
|
||||
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
|
||||
|
||||
// 初期化
|
||||
if (!fs.existsSync("logs/version.txt")) {
|
||||
fs.writeFileSync(
|
||||
if (!existsSync("logs/version.txt")) {
|
||||
writeFileSync(
|
||||
"logs/version.txt",
|
||||
nowVersion,
|
||||
packageJson.version,
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
// 最終起動バージョン取得
|
||||
const oldVersion = fs.readFileSync("logs/version.txt", "utf-8");
|
||||
const oldVersion = readFileSync("logs/version.txt", "utf-8");
|
||||
|
||||
if (oldVersion !== nowVersion) {
|
||||
if (oldVersion !== packageJson.version) {
|
||||
try {
|
||||
fs.writeFileSync(
|
||||
writeFileSync(
|
||||
"logs/version.txt",
|
||||
nowVersion,
|
||||
packageJson.version,
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const releaseUrl = `${packageJson.repository.url}/releases/tag/${packageJson.tag}`;
|
||||
|
||||
await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
text: `${nowVersion}にBOTがアップデートされました!`,
|
||||
text: `
|
||||
${packageJson.version}にBOTがアップデートされました!
|
||||
リリース内容:${releaseUrl}
|
||||
`,
|
||||
}),
|
||||
cache: "no-store",
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("アップデート通知にエラーが発生しました: ", err);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
+18
-3
@@ -17,6 +17,7 @@ const config: configTypes = {
|
||||
areasCsvUrl: "https://raw.githubusercontent.com/p2pquake/epsp-specifications/master/epsp-area.csv", // 対象地域CSVファイルのURL
|
||||
maxScaleMin: 30, // 地震発生の際の最低震度(10-70)
|
||||
},
|
||||
// 天気お知らせ設定
|
||||
weather: {
|
||||
splitCount: 4, // 返信の分割数
|
||||
},
|
||||
@@ -24,6 +25,7 @@ const config: configTypes = {
|
||||
// 緊急時設定
|
||||
emergency: {
|
||||
function: true, // 緊急時のコンソール表示
|
||||
report: false, // reportコマンド
|
||||
mail: {
|
||||
function: true, // 緊急時のメール送信
|
||||
host: "smtp.example.com", // SMTPサーバー
|
||||
@@ -34,10 +36,23 @@ const config: configTypes = {
|
||||
to: "admin@noticeuwuzu.example.com", // 緊急時メール送信先(配列可)
|
||||
},
|
||||
},
|
||||
// 規約等
|
||||
legal: {
|
||||
terms: `
|
||||
`, // 利用規約
|
||||
privacy: `
|
||||
`, // プライバシーポリシー
|
||||
},
|
||||
// 管理者情報設定
|
||||
admin: {
|
||||
name: "あどみん", // BOT管理者名
|
||||
showMail: true, // メールアドレスを公開するか(emergency.mail.toが使用されます)
|
||||
},
|
||||
// uwuzuサーバー設定
|
||||
uwuzu: {
|
||||
apiToken: "TOKEN_EXAMPLE",
|
||||
clientToken: "TOKEN_EXAMPLE",
|
||||
host: "uwuzu.example.com",
|
||||
apiToken: "TOKEN_EXAMPLE", // APIトークン
|
||||
clientToken: "TOKEN_EXAMPLE", // クライアントトークン(任意)
|
||||
host: "uwuzu.example.com", // サーバーホスト(HTTPSである必要があります)
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -11,13 +11,16 @@ import * as cron from "node-cron";
|
||||
import timeNotice from "./scripts/timeNotice.js";
|
||||
import { weatherNotice } from "./scripts/weatherNotice.js";
|
||||
import earthquakeNotice from "./scripts/earthquakeNotice.js";
|
||||
import birthdayNotice from "./scripts/birthdayNotice.js";
|
||||
import Commands from "./scripts/commands/main.js";
|
||||
import BirthdayDataSet from "./scripts/birthdayDataSet.js";
|
||||
|
||||
// その他機能
|
||||
import asciiArt from "./scripts/asciiart.js";
|
||||
asciiArt();
|
||||
import successExit from "./scripts/successExit.js";
|
||||
successExit();
|
||||
BirthdayDataSet();
|
||||
|
||||
// 地震情報観測開始
|
||||
earthquakeNotice();
|
||||
@@ -34,7 +37,10 @@ cron.schedule('*/10 * * * *', () => {
|
||||
|
||||
// 天気お知らせ(毎日7:00)
|
||||
cron.schedule("0 7 * * *", () => {
|
||||
weatherNotice();
|
||||
setTimeout(() => {
|
||||
weatherNotice();
|
||||
birthdayNotice();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
// 起動表示
|
||||
|
||||
+11
-2
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "notice-uwuzu",
|
||||
"version": "v7.1(LTS)@uwuzu1.5.4",
|
||||
"version": "v7.3@uwuzu1.5.4",
|
||||
"tag": "v7.3",
|
||||
"description": "Notice Bot for uwuzu",
|
||||
"main": "dist/main.js",
|
||||
"scripts": {
|
||||
@@ -10,20 +11,28 @@
|
||||
"dev": "tsx main.ts",
|
||||
"clean": "tsc && node dist/scripts/clean/main.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.last2014.com/last2014/noticeUwuzu"
|
||||
},
|
||||
"keywords": [
|
||||
"uwuzu",
|
||||
"bot",
|
||||
"cron",
|
||||
"notice",
|
||||
"mail",
|
||||
"weather",
|
||||
"time",
|
||||
"earthquake"
|
||||
"earthquake",
|
||||
"command",
|
||||
"commands"
|
||||
],
|
||||
"author": {
|
||||
"name": "Last2014",
|
||||
"url": "https://last2014.com",
|
||||
"email": "info@last2014.com"
|
||||
},
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { existsSync, writeFileSync } from "fs";
|
||||
|
||||
const initialData = {} as
|
||||
{ [key: string]: string | undefined };
|
||||
|
||||
export default function BirthdayDataSet() {
|
||||
if (!existsSync("data/birthdays.json")) {
|
||||
writeFileSync(
|
||||
"data/birthdays.json",
|
||||
JSON.stringify(initialData),
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { readFileSync } from "fs";
|
||||
import { isSameDay, format, differenceInYears } from "date-fns/fp";
|
||||
import config from "../config.js";
|
||||
|
||||
export default async function birthdayNotice() {
|
||||
// 読み込み
|
||||
const birthdays: { [key: string]: string | undefined } =
|
||||
JSON.parse(readFileSync("data/birthdays.json", "utf-8"));
|
||||
|
||||
// 配列化
|
||||
const birthdaysIndex: string[] = Object.entries(birthdays)
|
||||
.map(([key, value]) => value)
|
||||
.filter(value => value !== undefined) as string[];
|
||||
|
||||
// 初期値
|
||||
const resultInitial: string = `
|
||||
【今日誕生日の人】\n`;
|
||||
|
||||
let result = resultInitial;
|
||||
|
||||
for (let i = 0; i < Object.keys(birthdays).length; i++) {
|
||||
const birthday = format(birthdaysIndex[i], "yyyy/MM/dd")
|
||||
|
||||
if (isSameDay(birthday, new Date())) {
|
||||
const age = differenceInYears(new Date(), birthday);
|
||||
|
||||
const req = await fetch(`https://${config.uwuzu.host}/api/users/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
userid: Object.keys(birthdays)[i],
|
||||
}),
|
||||
});
|
||||
|
||||
const res = await req.json();
|
||||
|
||||
result+= `${res.username}さん(${age}歳)\n`
|
||||
}
|
||||
}
|
||||
|
||||
if (result === resultInitial) {
|
||||
return;
|
||||
}
|
||||
|
||||
const req = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
text: result,
|
||||
}),
|
||||
});
|
||||
|
||||
const res = await req.json();
|
||||
|
||||
console.log("誕生日お知らせ:", res);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import { readFileSync, writeFileSync, existsSync } from "fs";
|
||||
import { parse, isValid } from 'date-fns/fp';
|
||||
import { Reply } from "./main.js";
|
||||
|
||||
function normalizedString(Str: string) {
|
||||
return Str.replace(/[\u3000-\u303F]+/g, ' ')
|
||||
.replace(/[\uFF01-\uFF0F]+/g, '0-9')
|
||||
.replace(/[\u3001-\u3002]+/g, '/');
|
||||
}
|
||||
|
||||
function isValidDateString(dateString: string) {
|
||||
const normalizedStr = normalizedString(dateString);
|
||||
|
||||
const regex = /^\d{4}\/\d{2}\/\d{2}$/;
|
||||
if (!regex.test(normalizedStr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parseString = parse(new Date(), 'yyyy/MM/dd');
|
||||
return isValid(parseString(normalizedStr));
|
||||
}
|
||||
|
||||
export default function Birthday(data: ueuse) {
|
||||
// 読み込み
|
||||
const birthdays: { [key: string]: string | undefined } =
|
||||
JSON.parse(readFileSync("data/birthdays.json", "utf-8"));
|
||||
|
||||
if (
|
||||
(data.abi === "none" ||
|
||||
data.abi === "") &&
|
||||
birthdays[data.account.userid] === undefined
|
||||
) {
|
||||
Reply(`
|
||||
追記に誕生日を入力してください
|
||||
(このユーズはもう利用できません。他のユーズで\`/birthday\`をまたご利用ください。)
|
||||
`, data.uniqid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
data.abi === "delete" &&
|
||||
birthdays[data.account.userid] !== undefined
|
||||
) {
|
||||
birthdays[data.account.userid] = undefined;
|
||||
writeFileSync(
|
||||
"data/birthdays.json",
|
||||
JSON.stringify(birthdays),
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
Reply(`
|
||||
誕生日のデータを削除しました
|
||||
`, data.uniqid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
data.abi === "delete" &&
|
||||
birthdays[data.account.userid] === undefined
|
||||
) {
|
||||
Reply(`
|
||||
誕生日のデータが存在しないため削除できません
|
||||
`, data.uniqid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidDateString(data.abi)) {
|
||||
Reply(`
|
||||
誕生日の形式が違います。
|
||||
yyyy/MM/ddの形式で入力してください。
|
||||
スラッシュ・数字は全角での使用が可能です。
|
||||
(このユーズはもう利用できません。他のユーズで\`/birthday\`をまたご利用ください。)
|
||||
`, data.uniqid);
|
||||
return;
|
||||
}
|
||||
|
||||
birthdays[data.account.userid] = normalizedString(data.abi);
|
||||
writeFileSync(
|
||||
"data/birthdays.json",
|
||||
JSON.stringify(birthdays),
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
Reply(`
|
||||
${data.account.username}さんの誕生日を${normalizedString(data.abi)}に設定しました
|
||||
`, data.uniqid);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import config from "../../config.js";
|
||||
import { Reply } from "./main.js";
|
||||
|
||||
export default async function Follow(data: ueuse) {
|
||||
const followReq = await fetch(`https://${config.uwuzu.host}/api/users/follow`, {
|
||||
@@ -8,6 +9,7 @@ export default async function Follow(data: ueuse) {
|
||||
token: config.uwuzu.apiToken,
|
||||
userid: data.account.userid,
|
||||
}),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const followRes = await followReq.json();
|
||||
@@ -15,18 +17,9 @@ export default async function Follow(data: ueuse) {
|
||||
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 notice = await Reply(`
|
||||
${data.account.username}さんをフォローしました
|
||||
`, data.uniqid);
|
||||
|
||||
const noticeRes = await noticeReq.json();
|
||||
|
||||
console.log("フォロー通知: ", noticeRes);
|
||||
console.log("フォロー通知: ", notice);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import { readFileSync } from "fs";
|
||||
import { Reply } from "./main.js";
|
||||
|
||||
const helpsMin = {
|
||||
"info": "このBOTについての概要を返信するコマンドです。",
|
||||
"help": "コマンドの概要を返信します。追記に\`/\`抜きのコマンド名を入力することでそのコマンドの詳細(フル)を返信します。",
|
||||
"follow": "コマンド送信者をフォローします。",
|
||||
"unfollow": "コマンド送信者をフォロー解除します。",
|
||||
"weather": "天気を返信します。",
|
||||
"report": "運営者に不具合などを報告します。",
|
||||
"birthday": "誕生日を設定・削除できます。",
|
||||
"legal privacy": "プライバシーポリシーを返信します。",
|
||||
} as { [key: string]: string };
|
||||
|
||||
const helpsFull = {
|
||||
"info": `
|
||||
このBOTについての概要を返信するコマンドです。
|
||||
バージョン、開発者などが確認できます。
|
||||
`,
|
||||
"help": `
|
||||
このコマンドです。コマンドの概要を返信します。
|
||||
追記に\`/\`抜きのコマンド名を入力することでそのコマンドの詳細(フル)を返信します。
|
||||
`,
|
||||
"follow": `
|
||||
コマンドを送信したユーザーをフォローします。
|
||||
既にフォローされているユーザーも使用できます。
|
||||
`,
|
||||
"unfollow": `
|
||||
コマンドを送信したユーザーをフォロー解除します。
|
||||
既にフォローされていないユーザーも使用できます。
|
||||
`,
|
||||
"weather": `
|
||||
天気を返信します。
|
||||
毎日7:00の天気を再投稿するわけではなく、
|
||||
再取得して返信します。
|
||||
`,
|
||||
"report": `
|
||||
不具合などを運営者にメールで報告できます。
|
||||
運営者によって有効化されていないと使用できません。
|
||||
\`/report\`を使用してそのユーズの追記に内容を入力することで使用できます。
|
||||
`,
|
||||
"birthday": `
|
||||
誕生日を設定できます。
|
||||
設定された誕生日の7:00に祝われます。
|
||||
追記にyyyy/MM/ddの形式で誕生日を入力することで誕生日を設定できます。
|
||||
また、追記に\`delete\`と入力することで誕生日のデータを削除できます。
|
||||
`,
|
||||
"legal privacy": `
|
||||
プライバシーポリシーを返信します。
|
||||
`,
|
||||
} as { [key: string]: string };
|
||||
|
||||
export default async function Help(data: ueuse) {
|
||||
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
|
||||
|
||||
if (
|
||||
data.abi === "none" ||
|
||||
data.abi === ""
|
||||
) {
|
||||
const helpMsg =
|
||||
Object.entries(helpsMin)
|
||||
.map(([command, message]) =>
|
||||
`\`/${command}\`:${message}`
|
||||
).join('\n');
|
||||
|
||||
const ueuse = await Reply(`
|
||||
${helpMsg}
|
||||
BOTの概要は\`/info\`をご利用ください。
|
||||
Wikiを見る:${packageJson.repository.url}/wiki
|
||||
`, data.uniqid);
|
||||
|
||||
console.log("ヘルプ:", ueuse);
|
||||
} else {
|
||||
const ueuse = await Reply(`
|
||||
${helpsFull[data.abi]}
|
||||
機能を見る:${packageJson.repository.url}/wiki
|
||||
`, data.uniqid);
|
||||
|
||||
console.log("ヘルプ:", ueuse);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import { readFileSync } from "fs";
|
||||
import { Reply } from "./main.js";
|
||||
import config from "../../config.js";
|
||||
|
||||
export default async function Info(data: ueuse) {
|
||||
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
|
||||
const releaseUrl = `${packageJson.repository.url}/releases/tag/${packageJson.tag}`;
|
||||
|
||||
let editor = "";
|
||||
|
||||
if (packageJson.author.name !== "Last2014") {
|
||||
editor = `\nEdited by ${packageJson.author.name}`;
|
||||
}
|
||||
|
||||
let adminMail;
|
||||
|
||||
if (
|
||||
config.admin.showMail &&
|
||||
config.emergency.mail.to !== undefined
|
||||
) {
|
||||
adminMail = config.emergency.mail.to;
|
||||
} else if (
|
||||
config.admin.showMail &&
|
||||
config.emergency.mail.to === undefined
|
||||
) {
|
||||
adminMail = "未設定";
|
||||
} else {
|
||||
adminMail = "非公開";
|
||||
}
|
||||
|
||||
let isReport;
|
||||
|
||||
if (config.emergency.report) {
|
||||
isReport = "有効";
|
||||
} else {
|
||||
isReport = "無効";
|
||||
}
|
||||
|
||||
const ueuse = await Reply(`
|
||||
【BOTについて】
|
||||
このBOTはオープンソースソフトウェアであるnoticeUwuzuを利用して運営されています。
|
||||
noticeUwuzuはApache License 2.0によって保護されています。
|
||||
ライセンスに違反して使用した場合は著作権法違反となります。
|
||||
バージョン:${packageJson.version}
|
||||
リリース詳細:${releaseUrl}
|
||||
|
||||
【運営者情報】
|
||||
運営者名:${config.admin.name}
|
||||
メールアドレス:${adminMail}
|
||||
報告機能(\`/report\`):${isReport}
|
||||
|
||||
|
||||
【関連コマンド】
|
||||
コマンドのヘルプをお探しですか?
|
||||
\`/help\`をご利用ください。
|
||||
|
||||
運営者へ報告が必要ですか?
|
||||
\`/report\`をご利用ください。
|
||||
|
||||
プライバシーポリシーをお探しですか?
|
||||
\`/legal privacy\`をご利用ください。
|
||||
|
||||
|
||||
【クレジット】
|
||||
Created by Last2014${editor}
|
||||
`, data.uniqid);
|
||||
|
||||
console.log("概要:", ueuse);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import { Reply } from "../main.js";
|
||||
import config from "../../../config.js";
|
||||
|
||||
export default function PrivacyPolicy(data: ueuse) {
|
||||
Reply(config.legal.privacy, data.uniqid);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import { Reply } from "../main.js";
|
||||
import config from "../../../config.js";
|
||||
|
||||
export default function Terms(data: ueuse) {
|
||||
Reply(config.legal.terms, data.uniqid);
|
||||
}
|
||||
@@ -5,9 +5,15 @@ import type { ueuse } from "types/types.js";
|
||||
const initialFile: Array<string> = [];
|
||||
|
||||
// コマンド読み込み
|
||||
import Info from "./info.js";
|
||||
import Follow from "./follow.js";
|
||||
import UnFollow from "./unfollow.js";
|
||||
import Weather from "./weather.js";
|
||||
import Help from "./help.js";
|
||||
import Report from "./report.js";
|
||||
import Birthday from "./birthday.js";
|
||||
import Terms from "./legal/terms.js"
|
||||
import PrivacyPolicy from "./legal/privacy.js";
|
||||
|
||||
// 初期化
|
||||
if (!fs.existsSync("logs/alreadyCommands.json")) {
|
||||
@@ -31,7 +37,7 @@ function cutAfterChar(str: string, char: string) {
|
||||
return str.substring(index + 1);
|
||||
}
|
||||
|
||||
async function Reply(text: string, reply: string) {
|
||||
export async function Reply(text: string, reply: string) {
|
||||
const req = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
@@ -39,6 +45,7 @@ async function Reply(text: string, reply: string) {
|
||||
text: text,
|
||||
replyid: reply,
|
||||
}),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const res = await req.json();
|
||||
@@ -63,6 +70,7 @@ export default async function Commands() {
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
}),
|
||||
cache: "no-store",
|
||||
}
|
||||
);
|
||||
|
||||
@@ -79,7 +87,11 @@ export default async function Commands() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (data.text.charAt(0) === "!") {
|
||||
if (
|
||||
data.text.charAt(0) === "!" ||
|
||||
data.text.charAt(0) === "!" ||
|
||||
data.abi === "ignore"
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -88,22 +100,39 @@ export default async function Commands() {
|
||||
|
||||
const commandName = cutAfterChar(data.text, "/");
|
||||
|
||||
alreadyAdd(data.uniqid);
|
||||
|
||||
switch (commandName) {
|
||||
case "":
|
||||
break;
|
||||
case "info":
|
||||
Info(data);
|
||||
break;
|
||||
case "help":
|
||||
Help(data);
|
||||
break;
|
||||
case "legal terms":
|
||||
Terms(data);
|
||||
break;
|
||||
case "legal privacy":
|
||||
PrivacyPolicy(data);
|
||||
break;
|
||||
case "report":
|
||||
Report(data);
|
||||
break;
|
||||
case "follow":
|
||||
alreadyAdd(data.uniqid);
|
||||
Follow(data);
|
||||
break;
|
||||
case "unfollow":
|
||||
alreadyAdd(data.uniqid);
|
||||
UnFollow(data);
|
||||
break;
|
||||
case "weather":
|
||||
alreadyAdd(data.uniqid);
|
||||
Weather(data);
|
||||
break;
|
||||
case "birthday":
|
||||
Birthday(data);
|
||||
break;
|
||||
default:
|
||||
alreadyAdd(data.uniqid);
|
||||
|
||||
const reply = await Reply(`
|
||||
不明なコマンドです。
|
||||
コマンド実行を除外する場合は1文字目に\`!\`を入れてください。
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import { Reply } from "./main.js";
|
||||
import config from "../../config.js";
|
||||
import sendMail from "../../src/mailer.js";
|
||||
|
||||
export default async function Report(data: ueuse) {
|
||||
if (
|
||||
data.abi === "none" ||
|
||||
data.abi === ""
|
||||
) {
|
||||
console.log("報告(内容なし):", await Reply(`
|
||||
追記に内容を記入してください。
|
||||
(このユーズはもう利用できません。他のユーズで\`/report\`をまたご利用ください。)
|
||||
`, data.uniqid));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.emergency.mail.function) {
|
||||
console.log("報告(メールオフ):", await Reply(`
|
||||
BOTの運営者によってメール送信機能が無効化されています。
|
||||
そのため報告機能はご利用いただけません。
|
||||
`, data.uniqid));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.emergency.report) {
|
||||
console.log("報告(機能オフ):", await Reply(`
|
||||
BOTの運営者によって報告機能が無効化されています。
|
||||
そのため報告機能はご利用いただけません。
|
||||
`, data.uniqid));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
sendMail({
|
||||
to: config.emergency.mail.to,
|
||||
subject: "【報告】BOT利用者からの報告",
|
||||
text: `
|
||||
※noticeUwuzu自動送信によるメールです
|
||||
【報告】
|
||||
BOT管理者さん、noticeUwuzu自動送信メールです。
|
||||
@${data.account.userid}@${config.uwuzu.host}から/reportコマンドを利用した報告がありました。
|
||||
報告元ユーズ:https://${config.uwuzu.host}/!${data.uniqid}
|
||||
下記が内容となります。
|
||||
${data.abi}
|
||||
`,
|
||||
});
|
||||
|
||||
console.log("報告(完了):", await Reply(`
|
||||
報告が完了しました。
|
||||
運営者は報告者、ユーズのURL、内容を確認できます。
|
||||
場合によっては運営者、BOTからブロックされる可能性があります。
|
||||
`, data.uniqid));
|
||||
|
||||
return;
|
||||
} catch (err) {
|
||||
console.log("/reportエラー:", err);
|
||||
|
||||
console.log("報告(エラー):", await Reply(`
|
||||
報告に失敗しました。
|
||||
`, data.uniqid));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ueuse } from "types/types.js";
|
||||
import config from "../../config.js";
|
||||
import { Reply } from "./main.js";
|
||||
|
||||
export default async function UnFollow(data: ueuse) {
|
||||
const unfollowReq = await fetch(`https://${config.uwuzu.host}/api/users/unfollow`, {
|
||||
@@ -8,24 +9,17 @@ export default async function UnFollow(data: ueuse) {
|
||||
token: config.uwuzu.apiToken,
|
||||
userid: data.account.userid,
|
||||
}),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
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();
|
||||
const notice = await Reply(`
|
||||
${data.account.username}さんをフォロー解除しました
|
||||
`, data.uniqid);
|
||||
|
||||
console.log("フォロー解除通知: ", noticeRes);
|
||||
console.log("フォロー解除通知: ", notice);
|
||||
}
|
||||
|
||||
+20
-10
@@ -2,7 +2,6 @@ import WebSocket from "ws";
|
||||
import sendMail from "../src/mailer.js";
|
||||
|
||||
import config from "../config.js";
|
||||
import { max } from "date-fns/fp";
|
||||
|
||||
class P2PEarthquakeClient {
|
||||
private ws: WebSocket | null = null;
|
||||
@@ -74,7 +73,7 @@ class P2PEarthquakeClient {
|
||||
event(message);
|
||||
} else {
|
||||
console.log(`未対応の情報を受信しました(コード: ${message.code})`);
|
||||
console.log(`受信メッセージ:${message}`);
|
||||
console.log("受信メッセージ:", message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +137,7 @@ async function areaMap(): Promise<Record<number, string>> {
|
||||
|
||||
// 情報受信
|
||||
async function event(earthquakeInfo: any): Promise<void> {
|
||||
console.log(`受信メッセージ:${earthquakeInfo}`);
|
||||
console.log("受信メッセージ:", earthquakeInfo);
|
||||
// ----処理----
|
||||
|
||||
// 緊急地震速報の場合
|
||||
@@ -290,12 +289,12 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
to: config.emergency.mail.to,
|
||||
subject: "【警告】震度6強以上の地震を受信しました",
|
||||
text: `
|
||||
※noticeUwuzu自動送信によるメールです
|
||||
【警告】
|
||||
BOT管理者さん、noticeUwuzu自動送信メールです。
|
||||
震度6強以上の地震を受信したため警告メールが送信されました。
|
||||
物理、システム的にサーバーがダウンする可能性があります。
|
||||
ご自身の身をお守りください。
|
||||
※noticeUwuzu自動送信によるメールです
|
||||
【警告】
|
||||
BOT管理者さん、noticeUwuzu自動送信メールです。
|
||||
震度6強以上の地震を受信したため警告メールが送信されました。
|
||||
物理、システム的にサーバーがダウンする可能性があります。
|
||||
ご自身の身をお守りください。
|
||||
`
|
||||
});
|
||||
|
||||
@@ -315,6 +314,8 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
),
|
||||
);
|
||||
areas = `対象地域:${areaNames.join("・")}`;
|
||||
} else {
|
||||
areas = "対象地域:不明";
|
||||
}
|
||||
|
||||
// 詳細
|
||||
@@ -325,6 +326,8 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
earthquakeInfo.comments.freeFormComment !== undefined
|
||||
) {
|
||||
description = `この地震について:${earthquakeInfo.comments.freeFormComment}`;
|
||||
} else {
|
||||
description = "";
|
||||
}
|
||||
|
||||
// 深さ
|
||||
@@ -341,6 +344,8 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
} else {
|
||||
depth = `深さ:${String(earthquakeInfo.earthquake.hypocenter.depth)}km`;
|
||||
}
|
||||
} else {
|
||||
depth = "深さ:不明";
|
||||
}
|
||||
|
||||
// マグニチュード
|
||||
@@ -351,10 +356,12 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude !== undefined
|
||||
) {
|
||||
if (earthquakeInfo.earthquake.hypocenter.magnitude === -1) {
|
||||
depth = "マグニチュード:不明";
|
||||
magnitude = "マグニチュード:不明";
|
||||
} else {
|
||||
magnitude = `マグニチュード:M${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
|
||||
}
|
||||
} else {
|
||||
magnitude = "マグニチュード:不明";
|
||||
}
|
||||
|
||||
ueuse(`
|
||||
@@ -418,6 +425,8 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
immediate = "### 津波が直ちに襲来します";
|
||||
} else if (!data.immediate) {
|
||||
immediate = "津波は直ちには襲来しません";
|
||||
} else {
|
||||
immediate = "津波の襲来が直後かの情報がありません";
|
||||
}
|
||||
|
||||
// 第1波
|
||||
@@ -482,6 +491,7 @@ async function ueuse(text: string) {
|
||||
token: config.uwuzu.apiToken,
|
||||
text: text,
|
||||
}),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const resData = await res.json();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as fs from "fs";
|
||||
import { isBefore } from "date-fns/fp";
|
||||
import { isAfter } from "date-fns";
|
||||
|
||||
import config from "../config.js";
|
||||
import sendMail from "../src/mailer.js";
|
||||
@@ -20,7 +20,7 @@ export default function successExit() {
|
||||
const start = iolog.start;
|
||||
const stop = iolog.stop;
|
||||
|
||||
if (isBefore(start, stop)) {
|
||||
if (isAfter(start, stop)) {
|
||||
console.log("前回の終了が適切でない可能性があります");
|
||||
|
||||
if (config.emergency.mail.function) {
|
||||
|
||||
@@ -35,6 +35,7 @@ export default async function timeNotice() {
|
||||
token: config.uwuzu.apiToken,
|
||||
text: `${format(new Date(), "HH:mm")}になりました`,
|
||||
}),
|
||||
cache: "no-store",
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ export async function weatherNotice() {
|
||||
※タイムラインが埋まるため返信に記載しています
|
||||
`,
|
||||
}),
|
||||
cache: "no-store",
|
||||
},
|
||||
);
|
||||
|
||||
@@ -114,6 +115,7 @@ export async function weatherReply(uniqid: string) {
|
||||
text: weatherResults[i],
|
||||
replyid: uniqid,
|
||||
}),
|
||||
cache: "no-store",
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Vendored
+18
-5
@@ -19,18 +19,29 @@ interface timeTypes {
|
||||
}
|
||||
|
||||
interface emergencyMailTypes {
|
||||
function: Boolean;
|
||||
host: string | undefined;
|
||||
function: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
user: string;
|
||||
password: string;
|
||||
secure: Boolean;
|
||||
to: string;
|
||||
secure: boolean;
|
||||
to: string | string[];
|
||||
}
|
||||
|
||||
interface emergencyTypes {
|
||||
function: Boolean;
|
||||
function: boolean;
|
||||
mail: emergencyMailTypes;
|
||||
report: boolean;
|
||||
}
|
||||
|
||||
interface legalTypes {
|
||||
terms: string;
|
||||
privacy: string;
|
||||
}
|
||||
|
||||
interface adminTypes {
|
||||
name: string;
|
||||
showMail: boolean;
|
||||
}
|
||||
|
||||
interface uwuzuTypes {
|
||||
@@ -45,5 +56,7 @@ export interface configTypes {
|
||||
weather: weatherTypes;
|
||||
|
||||
emergency: emergencyTypes;
|
||||
legal: legalTypes;
|
||||
admin: adminTypes;
|
||||
uwuzu: uwuzuTypes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user