いい?と聞くとやっていいかどうかをリアクションする機能の追加

This commit is contained in:
na2na-p 2022-02-17 15:33:25 +09:00
parent c63341d8a6
commit 1a68e6970f
2 changed files with 50 additions and 0 deletions

View file

@ -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(),

48
src/modules/okng/index.ts Normal file
View file

@ -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<Stream['useSharedConnection']>;
@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:');
}
}
}
}