mirror of
https://github.com/syuilo/ai.git
synced 2024-11-24 22:01:07 +00:00
Add emoji-react module
This commit is contained in:
parent
ecba11b654
commit
e3c89fa069
|
@ -18,6 +18,7 @@
|
||||||
"autobind-decorator": "2.4.0",
|
"autobind-decorator": "2.4.0",
|
||||||
"canvas": "2.6.1",
|
"canvas": "2.6.1",
|
||||||
"chalk": "4.1.0",
|
"chalk": "4.1.0",
|
||||||
|
"emoji-regex": "9.0.0",
|
||||||
"lokijs": "1.5.11",
|
"lokijs": "1.5.11",
|
||||||
"mecab-async": "0.1.2",
|
"mecab-async": "0.1.2",
|
||||||
"misskey-reversi": "0.0.5",
|
"misskey-reversi": "0.0.5",
|
||||||
|
|
|
@ -13,6 +13,7 @@ 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 EmojiModule from './modules/emoji';
|
import EmojiModule from './modules/emoji';
|
||||||
|
import EmojiReactModule from './modules/emoji-react';
|
||||||
import FortuneModule from './modules/fortune';
|
import FortuneModule from './modules/fortune';
|
||||||
import GuessingGameModule from './modules/guessing-game';
|
import GuessingGameModule from './modules/guessing-game';
|
||||||
import KazutoriModule from './modules/kazutori';
|
import KazutoriModule from './modules/kazutori';
|
||||||
|
@ -57,6 +58,7 @@ promiseRetry(retry => {
|
||||||
// 藍起動
|
// 藍起動
|
||||||
new 藍(account, [
|
new 藍(account, [
|
||||||
new EmojiModule(),
|
new EmojiModule(),
|
||||||
|
new EmojiReactModule(),
|
||||||
new FortuneModule(),
|
new FortuneModule(),
|
||||||
new GuessingGameModule(),
|
new GuessingGameModule(),
|
||||||
new KazutoriModule(),
|
new KazutoriModule(),
|
||||||
|
|
4
src/misskey/note.ts
Normal file
4
src/misskey/note.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export type Note = {
|
||||||
|
id: string;
|
||||||
|
text: string | null;
|
||||||
|
};
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noImplicitThis": true,
|
"noImplicitThis": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"strictNullChecks": false,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"target": "es2017",
|
"target": "es2017",
|
||||||
|
|
Loading…
Reference in a new issue