From 1a68e6970fcb0bbbef612d760fd20a8a19fdd447 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Thu, 17 Feb 2022 15:33:25 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=84=E3=81=84=EF=BC=9F=E3=81=A8=E8=81=9E?= =?UTF-8?q?=E3=81=8F=E3=81=A8=E3=82=84=E3=81=A3=E3=81=A6=E3=81=84=E3=81=84?= =?UTF-8?q?=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B=E3=82=92=E3=83=AA=E3=82=A2?= =?UTF-8?q?=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=99=E3=82=8B=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 ++ src/modules/okng/index.ts | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/modules/okng/index.ts diff --git a/src/index.ts b/src/index.ts index 5ecb258..b61f300 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ import TalkModule from './modules/talk'; import BirthdayModule from './modules/birthday'; import ReversiModule from './modules/reversi'; import PingModule from './modules/ping'; +import okngModule from './modules/okng'; import EmojiModule from './modules/emoji'; import EmojiReactModule from './modules/emoji-react'; import FortuneModule from './modules/fortune'; @@ -69,6 +70,7 @@ promiseRetry(retry => { // 藍起動 new 藍(account, [ new CoreModule(), + new okngModule(), new EmojiModule(), new EmojiReactModule(), new FortuneModule(), diff --git a/src/modules/okng/index.ts b/src/modules/okng/index.ts new file mode 100644 index 0000000..ac07655 --- /dev/null +++ b/src/modules/okng/index.ts @@ -0,0 +1,48 @@ +import autobind from 'autobind-decorator'; +import { parse } from 'twemoji-parser'; +const delay = require('timeout-as-promise'); + +import { Note } from '@/misskey/note'; +import Module from '@/module'; +import Stream from '@/stream'; +import includes from '@/utils/includes'; + +export default class extends Module { + public readonly name = 'okng'; + + private htl: ReturnType; + + @autobind + public install() { + this.htl = this.ai.connection.useSharedConnection('homeTimeline'); + this.htl.on('note', this.onNote); + + return {}; + } + + @autobind + private async onNote(note: Note) { + if (note.reply != null) return; + if (note.text == null) return; + if (note.text.includes('@')) return; // (自分または他人問わず)メンションっぽかったらreject + + const react = async (reaction: string, immediate = false) => { + if (!immediate) { + await delay(1500); + } + this.ai.api('notes/reactions/create', { + noteId: note.id, + reaction: reaction + }); + }; + + if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) { + // 50%の確率で":dame:"または":yattare:"を返す + if (Math.random() < 0.5) { + return react(':dame:'); + } else { + return react(':yattare:'); + } + } + } +}