2018-08-11 06:26:25 +00:00
|
|
|
import 藍 from './ai';
|
2018-08-12 14:03:00 +00:00
|
|
|
const delay = require('timeout-as-promise');
|
2018-08-11 01:42:06 +00:00
|
|
|
|
|
|
|
export default class MessageLike {
|
|
|
|
private ai: 藍;
|
|
|
|
private messageOrNote: any;
|
|
|
|
public isMessage: boolean;
|
|
|
|
|
|
|
|
public get id() {
|
|
|
|
return this.messageOrNote.id;
|
|
|
|
}
|
|
|
|
|
2018-08-11 12:28:17 +00:00
|
|
|
public get user() {
|
|
|
|
return this.messageOrNote.user;
|
|
|
|
}
|
|
|
|
|
2018-08-11 01:42:06 +00:00
|
|
|
public get userId() {
|
|
|
|
return this.messageOrNote.userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get text() {
|
|
|
|
return this.messageOrNote.text;
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:00 +00:00
|
|
|
public get replyId() {
|
|
|
|
return this.messageOrNote.replyId;
|
|
|
|
}
|
|
|
|
|
2018-08-27 10:04:09 +00:00
|
|
|
public friend: ReturnType<藍['friends']['findOne']>;
|
|
|
|
|
2018-08-11 01:42:06 +00:00
|
|
|
constructor(ai: 藍, messageOrNote: any, isMessage: boolean) {
|
|
|
|
this.ai = ai;
|
|
|
|
this.messageOrNote = messageOrNote;
|
|
|
|
this.isMessage = isMessage;
|
2018-08-27 10:04:09 +00:00
|
|
|
|
|
|
|
this.friend = this.ai.friends.findOne({
|
|
|
|
userId: this.userId
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.friend == null) {
|
|
|
|
this.friend = this.ai.friends.insertOne({
|
|
|
|
userId: this.userId
|
|
|
|
});
|
|
|
|
}
|
2018-08-11 01:42:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:00 +00:00
|
|
|
public reply = async (text: string, cw?: string) => {
|
2018-08-11 03:34:24 +00:00
|
|
|
console.log(`sending reply of ${this.id} ...`);
|
|
|
|
|
2018-08-12 14:03:00 +00:00
|
|
|
await delay(2000);
|
|
|
|
|
|
|
|
if (this.isMessage) {
|
|
|
|
return await this.ai.sendMessage(this.messageOrNote.userId, {
|
|
|
|
text: text
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return await this.ai.post({
|
|
|
|
replyId: this.messageOrNote.id,
|
|
|
|
text: text,
|
|
|
|
cw: cw
|
|
|
|
});
|
|
|
|
}
|
2018-08-11 01:42:06 +00:00
|
|
|
}
|
|
|
|
}
|