diff --git a/src/ai.ts b/src/ai.ts index 90cb9a1..11018c8 100644 --- a/src/ai.ts +++ b/src/ai.ts @@ -172,6 +172,11 @@ export default class 藍 { if (data.userId == this.account.id) return; // 自分は弾く this.onReceiveMessage(new Message(this, data, true)); }); + + // 通知 + mainStream.on('notification', data => { + this.onNotification(data); + }); //#endregion // Install modules @@ -277,6 +282,22 @@ export default class 藍 { } } + @autobind + private onNotification(notification: any) { + switch (notification.type) { + // リアクションされたら親愛度を少し上げる + // TODO: リアクション取り消しをよしなにハンドリングする + case 'reaction': { + const friend = new Friend(this, { user: notification.user }); + friend.incLove(0.1); + break; + } + + default: + break; + } + } + @autobind private crawleTimer() { const timers = this.timers.find(); diff --git a/src/friend.ts b/src/friend.ts index 679ecd3..69e7b97 100644 --- a/src/friend.ts +++ b/src/friend.ts @@ -101,7 +101,7 @@ export default class Friend { } @autobind - public incLove() { + public incLove(amount = 1) { const today = getDate(); if (this.doc.lastLoveIncrementedAt != today) { @@ -112,20 +112,25 @@ export default class Friend { if (this.doc.lastLoveIncrementedAt == today && (this.doc.todayLoveIncrements || 0) >= 3) return; if (this.doc.love == null) this.doc.love = 0; - this.doc.love++; + this.doc.love += amount; // 最大 100 if (this.doc.love > 100) this.doc.love = 100; this.doc.lastLoveIncrementedAt = today; - this.doc.todayLoveIncrements = (this.doc.todayLoveIncrements || 0) + 1; + this.doc.todayLoveIncrements = (this.doc.todayLoveIncrements || 0) + amount; this.save(); + + this.ai.log(`💗 ${this.userId} +${amount}`); } @autobind - public decLove() { + public decLove(amount = 1) { + // 親愛度MAXなら下げない + if (this.doc.love === 100) return; + if (this.doc.love == null) this.doc.love = 0; - this.doc.love--; + this.doc.love -= amount; // 最低 -30 if (this.doc.love < -30) this.doc.love = -30; @@ -136,6 +141,8 @@ export default class Friend { } this.save(); + + this.ai.log(`💢 ${this.userId} -${amount}`); } @autobind