ぽんこつ呼ばわりされたときはリアクションを変えるように

This commit is contained in:
syuilo 2018-09-19 08:52:06 +09:00
parent 9cfb9abdcd
commit bde4086bac
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
3 changed files with 42 additions and 23 deletions

View file

@ -152,6 +152,36 @@ export default class 藍 {
private onMention = (msg: MessageLike) => {
console.log(`mention received: ${msg.id}`);
const context = !msg.isMessage && msg.replyId == null ? null : this.contexts.findOne(msg.isMessage ? {
isMessage: true,
userId: msg.userId
} : {
isMessage: false,
noteId: msg.replyId
});
let reaction = 'love';
if (context != null) {
const module = this.modules.find(m => m.name == context.module);
const res = module.onReplyThisModule(msg, context.data);
if (res != null && typeof res === 'object') {
reaction = res.reaction;
}
} else {
let res: ReturnType<IModule['onMention']>;
this.modules.filter(m => m.hasOwnProperty('onMention')).some(m => {
res = m.onMention(msg);
return res === true || typeof res === 'object';
});
if (res != null && typeof res === 'object') {
reaction = res.reaction;
}
}
setTimeout(() => {
if (msg.isMessage) {
// 既読にする
@ -162,27 +192,10 @@ export default class 藍 {
// リアクションする
this.api('notes/reactions/create', {
noteId: msg.id,
reaction: 'love'
reaction: reaction
});
}
}, 1000);
const context = !msg.isMessage && msg.replyId == null ? null : this.contexts.findOne(msg.isMessage ? {
isMessage: true,
userId: msg.userId
} : {
isMessage: false,
noteId: msg.replyId
});
if (context != null) {
const module = this.modules.find(m => m.name == context.module);
module.onReplyThisModule(msg, context.data);
} else {
this.modules.filter(m => m.hasOwnProperty('onMention')).some(m => {
return m.onMention(msg);
});
}
}
public post = async (param: any) => {

View file

@ -4,7 +4,11 @@ import MessageLike from './message-like';
export default interface IModule {
name: string;
install?: (ai: ) => void;
onMention?: (msg: MessageLike) => boolean;
onMention?: (msg: MessageLike) => boolean | Result;
onLocalNote?: (note: any) => void;
onReplyThisModule?: (msg: MessageLike, data?: any) => void;
onReplyThisModule?: (msg: MessageLike, data?: any) => void | Result;
}
export type Result = {
reaction: string;
};

View file

@ -1,5 +1,5 @@
import from '../../ai';
import IModule from '../../module';
import IModule, { Result } from '../../module';
import MessageLike from '../../message-like';
import serifs from '../../serifs';
import Friend from '../../friend';
@ -304,12 +304,14 @@ export default class CoreModule implements IModule {
return true;
}
private ponkotu = (msg: MessageLike): boolean => {
private ponkotu = (msg: MessageLike): boolean |Result => {
if (!msg.includes(['ぽんこつ'])) return false;
msg.friend.decLove();
return true;
return {
reaction: 'angry'
};
}
public onReplyThisModule = (msg: MessageLike, data: any) => {