From cca9c7bc03590791e91f3c7aaa54226708933c49 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Aug 2018 11:14:06 +0900 Subject: [PATCH] Improve AI --- src/modules/server/index.ts | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/modules/server/index.ts b/src/modules/server/index.ts index 641e56e..12fc9ff 100644 --- a/src/modules/server/index.ts +++ b/src/modules/server/index.ts @@ -95,6 +95,8 @@ export default class ServerModule implements IModule { this.ai.post({ text: reason == 'cpu' ? serifs.REBOOT_SCHEDULED_CPU : serifs.REBOOT_SCHEDULED_MEM + }).then(post => { + this.ai.subscribeReply(this, 'reboot', false, post.id); }); this.rebootTimer = setTimeout(() => { @@ -109,6 +111,26 @@ export default class ServerModule implements IModule { }, 1000 * 50); } + public onReplyThisModule = (msg: MessageLike) => { + if (msg.text == null) return; + + if (msg.text.includes('やめ')) { + if (msg.user.isAdmin) { + msg.reply(serifs.REBOOT_CANCEL_REQUESTED_ACCEPT); + + this.ai.post({ + text: serifs.REBOOT_CANCELED + }); + + this.cancelReboot(); + } else { + msg.reply(serifs.REBOOT_CANCEL_REQUESTED_REJECT); + } + } + + this.ai.unsubscribeReply(this, 'reboot'); + } + public onMention = (msg: MessageLike) => { if (msg.text && msg.text.includes('再起動しないで')) { if (msg.user.isAdmin) { @@ -118,12 +140,7 @@ export default class ServerModule implements IModule { text: serifs.REBOOT_CANCELED }); - clearTimeout(this.rebootTimer); - clearTimeout(this.rebootTimerSub); - - setTimeout(() => { - this.preventScheduleReboot = false; - }, 1000 * 60 * 3); + this.cancelReboot(); } else { msg.reply(serifs.REBOOT_CANCEL_REQUESTED_REJECT); } @@ -132,4 +149,14 @@ export default class ServerModule implements IModule { return false; } } + + private cancelReboot = () => { + clearTimeout(this.rebootTimer); + clearTimeout(this.rebootTimerSub); + + // 10分間延期 + setTimeout(() => { + this.preventScheduleReboot = false; + }, 1000 * 60 * 10); + } }