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

@ -18,6 +18,7 @@
"autobind-decorator": "2.4.0",
"canvas": "2.6.1",
"chalk": "4.1.0",
"emoji-regex": "9.0.0",
"lokijs": "1.5.11",
"mecab-async": "0.1.2",
"misskey-reversi": "0.0.5",

View file

@ -13,6 +13,7 @@ import BirthdayModule from './modules/birthday';
import ReversiModule from './modules/reversi';
import PingModule from './modules/ping';
import EmojiModule from './modules/emoji';
import EmojiReactModule from './modules/emoji-react';
import FortuneModule from './modules/fortune';
import GuessingGameModule from './modules/guessing-game';
import KazutoriModule from './modules/kazutori';
@ -57,6 +58,7 @@ promiseRetry(retry => {
// 藍起動
new (account, [
new EmojiModule(),
new EmojiReactModule(),
new FortuneModule(),
new GuessingGameModule(),
new KazutoriModule(),

4
src/misskey/note.ts Normal file
View file

@ -0,0 +1,4 @@
export type Note = {
id: string;
text: string | null;
};

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;
}
}
}

View file

@ -5,6 +5,7 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": false,
"experimentalDecorators": true,
"sourceMap": false,
"target": "es2017",