型の調整

This commit is contained in:
takejohn 2024-03-30 17:53:58 +09:00
parent d463a0db30
commit b2ab6778b0
2 changed files with 6 additions and 10 deletions

View file

@ -1,6 +1,8 @@
export type Note = { export type Note = {
id: string; id: string;
text: string | null; text: string | null;
cw: string | null;
userId: string;
reply: any | null; reply: any | null;
poll?: { poll?: {
choices: { choices: {

View file

@ -5,12 +5,7 @@ import config from '@/config.js';
import serifs from '@/serifs.js'; import serifs from '@/serifs.js';
import { mecab } from './mecab.js'; import { mecab } from './mecab.js';
import from '@/ai.js'; import from '@/ai.js';
import { Note } from '@/misskey/note.js';
type LocalTimeline = {
userId: string;
text: string | null;
cw: string | null;
}[];
function kanaToHira(str: string) { function kanaToHira(str: string) {
return str.replace(/[\u30a1-\u30f6]/g, match => { return str.replace(/[\u30a1-\u30f6]/g, match => {
@ -48,11 +43,11 @@ class Installed extends InstalledModule {
@bindThis @bindThis
private async learn() { private async learn() {
const tl = await this.ai.api<LocalTimeline>('notes/local-timeline', { const tl = await this.ai.api<Note[]>('notes/local-timeline', {
limit: 30 limit: 30
}); });
const interestedNotes = tl.filter(note => const interestedNotes = tl.filter((note): note is Note & { text: string } =>
note.userId !== this.ai.account.id && note.userId !== this.ai.account.id &&
note.text != null && note.text != null &&
note.cw == null); note.cw == null);
@ -60,8 +55,7 @@ class Installed extends InstalledModule {
let keywords: string[][] = []; let keywords: string[][] = [];
for (const note of interestedNotes) { for (const note of interestedNotes) {
// TODO: note.text に null チェックが必要? const tokens = await mecab(note.text, config.mecab, config.mecabDic);
const tokens = await mecab(note.text as string, config.mecab, config.mecabDic);
const keywordsInThisNote = tokens.filter(token => token[2] == '固有名詞' && token[8] != null); const keywordsInThisNote = tokens.filter(token => token[2] == '固有名詞' && token[8] != null);
keywords = keywords.concat(keywordsInThisNote); keywords = keywords.concat(keywordsInThisNote);
} }