mirror of
https://github.com/syuilo/ai.git
synced 2025-03-25 21:12:56 +00:00
いい?と聞くとやっていいかどうかをリアクションする機能の追加
This commit is contained in:
parent
c63341d8a6
commit
1a68e6970f
2 changed files with 50 additions and 0 deletions
|
@ -16,6 +16,7 @@ import TalkModule from './modules/talk';
|
||||||
import BirthdayModule from './modules/birthday';
|
import BirthdayModule from './modules/birthday';
|
||||||
import ReversiModule from './modules/reversi';
|
import ReversiModule from './modules/reversi';
|
||||||
import PingModule from './modules/ping';
|
import PingModule from './modules/ping';
|
||||||
|
import okngModule from './modules/okng';
|
||||||
import EmojiModule from './modules/emoji';
|
import EmojiModule from './modules/emoji';
|
||||||
import EmojiReactModule from './modules/emoji-react';
|
import EmojiReactModule from './modules/emoji-react';
|
||||||
import FortuneModule from './modules/fortune';
|
import FortuneModule from './modules/fortune';
|
||||||
|
@ -69,6 +70,7 @@ promiseRetry(retry => {
|
||||||
// 藍起動
|
// 藍起動
|
||||||
new 藍(account, [
|
new 藍(account, [
|
||||||
new CoreModule(),
|
new CoreModule(),
|
||||||
|
new okngModule(),
|
||||||
new EmojiModule(),
|
new EmojiModule(),
|
||||||
new EmojiReactModule(),
|
new EmojiReactModule(),
|
||||||
new FortuneModule(),
|
new FortuneModule(),
|
||||||
|
|
48
src/modules/okng/index.ts
Normal file
48
src/modules/okng/index.ts
Normal 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:');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue