From 0b8e1a0519d06cba707a19daef01fe41b47f10dc Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Thu, 25 Sep 2025 10:01:05 +0900 Subject: [PATCH] feat: mention --- src/data.ts | 13 +++++++++++++ src/main.ts | 25 +++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/data.ts diff --git a/src/data.ts b/src/data.ts new file mode 100644 index 0000000..ae18bfd --- /dev/null +++ b/src/data.ts @@ -0,0 +1,13 @@ +export const nameMap = new Map([ + // 運営 + ["KOBAYASHI Yuki / 小林", "502798784959479808"], + ["Yasumura Takuya / 安村拓也", "1225332719068643424"], + ["SHIBAYAMAKeiichiro", "660420646261489674"], + ["MANABEKaichi", "1119186793099710514"], + ["Ryuhei TAKANAKA", "905761740665528370"], + ["Hiroki Oya / 大矢宏輝", "735679928007131213"], + ["中村渉吾 (Shogo Nakamura)", "703588743738687488"], + + // 運営ではないけど運営タスクに名前のある人 + ["川端 悠斗", "943071631167860756"], +]); diff --git a/src/main.ts b/src/main.ts index 6840c3a..78cd973 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,5 @@ import * as v from "valibot"; +import { nameMap } from "./data.ts"; import { queryNotion, retry, webhook } from "./io.ts"; import { NotionFetchResponse, type Task } from "./validator.ts"; @@ -36,19 +37,31 @@ const query = { ], }; -function formatTask(task: Task) { +function formatTask(task: Task): string { const due = task.properties.期日?.date.start; const title = task.properties.タイトル?.title.map((title) => title.plain_text).join(""); - const assignee = task.properties.担当者?.people.map((person) => person.name).join(" / @"); + const assignees = task.properties.担当者?.people.map( + (person): { success: true; id: string } | { success: false; display: string } => { + if (!person.name) return { success: false, display: "-" }; + const d_id = nameMap.get(person.name); + if (!d_id) return { success: false, display: person.name }; + return { success: true, id: d_id }; + }, + ); + + const assignee = assignees + ?.map((a) => { + if (a.success) return `<@${a.id}>`; + return `@${a.display}`; + }) + .join(" "); if (!assignee) { return `・【${due}】${title} (担当者不在)`; } - return `・【${due}】${title} @${assignee}`; + return `・【${due}】${title} ${assignee}`; } -/** - - @throws on NetworkError and ParseError - */ + async function main() { const res = await queryNotion(query); const json = v.parse(NotionFetchResponse, await res.json());