From b2ab6778b04c8546672a242d934ac2399c041d2f Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:53:58 +0900 Subject: [PATCH] =?UTF-8?q?=E5=9E=8B=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/misskey/note.ts | 2 ++ src/modules/keyword/index.ts | 14 ++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/misskey/note.ts b/src/misskey/note.ts index 7aa0aff..f426677 100644 --- a/src/misskey/note.ts +++ b/src/misskey/note.ts @@ -1,6 +1,8 @@ export type Note = { id: string; text: string | null; + cw: string | null; + userId: string; reply: any | null; poll?: { choices: { diff --git a/src/modules/keyword/index.ts b/src/modules/keyword/index.ts index 3b6d42c..ac88a01 100644 --- a/src/modules/keyword/index.ts +++ b/src/modules/keyword/index.ts @@ -5,12 +5,7 @@ import config from '@/config.js'; import serifs from '@/serifs.js'; import { mecab } from './mecab.js'; import 藍 from '@/ai.js'; - -type LocalTimeline = { - userId: string; - text: string | null; - cw: string | null; -}[]; +import { Note } from '@/misskey/note.js'; function kanaToHira(str: string) { return str.replace(/[\u30a1-\u30f6]/g, match => { @@ -48,11 +43,11 @@ class Installed extends InstalledModule { @bindThis private async learn() { - const tl = await this.ai.api('notes/local-timeline', { + const tl = await this.ai.api('notes/local-timeline', { limit: 30 }); - const interestedNotes = tl.filter(note => + const interestedNotes = tl.filter((note): note is Note & { text: string } => note.userId !== this.ai.account.id && note.text != null && note.cw == null); @@ -60,8 +55,7 @@ class Installed extends InstalledModule { let keywords: string[][] = []; for (const note of interestedNotes) { - // TODO: note.text に null チェックが必要? - const tokens = await mecab(note.text as string, config.mecab, config.mecabDic); + const tokens = await mecab(note.text, config.mecab, config.mecabDic); const keywordsInThisNote = tokens.filter(token => token[2] == '固有名詞' && token[8] != null); keywords = keywords.concat(keywordsInThisNote); }