mirror of
https://github.com/nullnyat/NullcatChan.git
synced 2025-08-07 23:53:52 +09:00
Add emoji-react module
This commit is contained in:
57
src/modules/emoji-react/index.ts
Normal file
57
src/modules/emoji-react/index.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user