From 1195867b2c42a6f2d036bb54fc3d46a86828bc7f Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 3 Jan 2021 14:50:17 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A6=AA=E6=84=9B=E5=BA=A6=E3=82=B7=E3=82=B9?= =?UTF-8?q?=E3=83=86=E3=83=A0=E3=81=AE=E5=B0=8F=E3=81=95=E3=81=AA=E6=94=B9?= =?UTF-8?q?=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai.ts | 21 +++++++++++++++++++++ src/friend.ts | 17 ++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) 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