Add emoji-react module

This commit is contained in:
syuilo
2020-08-23 12:15:11 +09:00
parent ecba11b654
commit e3c89fa069
5 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,57 @@
import autobind from 'autobind-decorator';
const emojiRegex = require('emoji-regex');
import { Note } from '../../misskey/note';
import Module from '../../module';
import Stream from '../../stream';
export default class extends Module {
public readonly name = 'emoji-react';
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.text == null) return;
const customEmojis = note.text.match(/:([^\n:]+?):/g);
if (customEmojis) {
// カスタム絵文字が複数種類ある場合はキャンセル
if (!customEmojis.every((val, i, arr) => val === arr[0])) return;
this.log(`Custom emoji detected - ${customEmojis[0]}`);
setTimeout(() => {
this.ai.api('notes/reactions/create', {
noteId: note.id,
reaction: customEmojis[0]
});
}, 2000);
return;
}
const emojis = note.text.match(emojiRegex());
if (emojis) {
// 絵文字が複数種類ある場合はキャンセル
if (!emojis.every((val, i, arr) => val === arr[0])) return;
this.log(`Emoji detected - ${emojis[0]}`);
setTimeout(() => {
this.ai.api('notes/reactions/create', {
noteId: note.id,
reaction: emojis[0]
});
}, 2000);
return;
}
}
}