Improve AI

This commit is contained in:
syuilo 2018-08-13 11:14:06 +09:00
parent 97ff5cae05
commit cca9c7bc03

View file

@ -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);
}
}