From ae4127d19eecfe94c09868b091a9e8b39416684e Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 11 Aug 2018 21:28:17 +0900 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E8=B5=B7=E5=8B=95=E3=81=AE=E5=8F=96?= =?UTF-8?q?=E3=82=8A=E6=B6=88=E3=81=97=E3=82=92=E5=AE=9F=E8=A3=85=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=81=AA=E3=81=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/message-like.ts | 4 ++++ src/modules/emoji/index.ts | 2 +- src/modules/fortune/index.ts | 2 +- src/modules/ping/index.ts | 2 +- src/modules/reversi/index.ts | 2 +- src/modules/server/index.ts | 35 ++++++++++++++++++++++++++++++----- src/serifs.ts | 5 +++++ 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/message-like.ts b/src/message-like.ts index 6b2947c..b1d68bc 100644 --- a/src/message-like.ts +++ b/src/message-like.ts @@ -9,6 +9,10 @@ export default class MessageLike { return this.messageOrNote.id; } + public get user() { + return this.messageOrNote.user; + } + public get userId() { return this.messageOrNote.userId; } diff --git a/src/modules/emoji/index.ts b/src/modules/emoji/index.ts index 74a1209..7ea2fa9 100644 --- a/src/modules/emoji/index.ts +++ b/src/modules/emoji/index.ts @@ -122,7 +122,7 @@ export default class EmojiModule implements IModule { public install = (ai: 藍) => { } public onMention = (msg: MessageLike) => { - if (msg.text && msg.text.indexOf('絵文字') > -1) { + if (msg.text && msg.text.includes('絵文字')) { const hand = hands[Math.floor(Math.random() * hands.length)]; const face = faces[Math.floor(Math.random() * faces.length)]; const emoji = Array.isArray(hand) ? hand[0] + face + hand[1] : hand + face + hand; diff --git a/src/modules/fortune/index.ts b/src/modules/fortune/index.ts index cf1e705..e72b77d 100644 --- a/src/modules/fortune/index.ts +++ b/src/modules/fortune/index.ts @@ -28,7 +28,7 @@ export default class EmojiModule implements IModule { public install = (ai: 藍) => { } public onMention = (msg: MessageLike) => { - if (msg.text && msg.text.indexOf('占') > -1) { + if (msg.text && msg.text.includes('占')) { const date = new Date(); const seed = `${date.getFullYear()}/${date.getMonth()}/${date.getDay()}@${msg.userId}`; const rng = seedrandom(seed); diff --git a/src/modules/ping/index.ts b/src/modules/ping/index.ts index 0dee2c4..3fac725 100644 --- a/src/modules/ping/index.ts +++ b/src/modules/ping/index.ts @@ -6,7 +6,7 @@ export default class PingModule implements IModule { public install = (ai: 藍) => { } public onMention = (msg: MessageLike) => { - if (msg.text && msg.text.indexOf('ping') > -1) { + if (msg.text && msg.text.includes('ping')) { msg.reply('PONG!'); return true; } else { diff --git a/src/modules/reversi/index.ts b/src/modules/reversi/index.ts index ae8c00b..882b84b 100644 --- a/src/modules/reversi/index.ts +++ b/src/modules/reversi/index.ts @@ -38,7 +38,7 @@ export default class ReversiModule implements IModule { } public onMention = (msg: MessageLike) => { - if (msg.text && msg.text.indexOf('リバーシ') > -1) { + if (msg.text && msg.text.includes('リバーシ')) { if (config.reversiEnabled) { msg.reply(serifs.REVERSI_OK); diff --git a/src/modules/server/index.ts b/src/modules/server/index.ts index 8a67fc5..d52d627 100644 --- a/src/modules/server/index.ts +++ b/src/modules/server/index.ts @@ -4,14 +4,15 @@ import 藍 from '../../ai'; import IModule from '../../module'; import serifs from '../../serifs'; import config from '../../config'; +import MessageLike from '../../message-like'; const ReconnectingWebSocket = require('../../../node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js'); export default class ServerModule implements IModule { private ai: 藍; private connection?: any; - private rebootScheduled = false; - private rebootTimer: any; - private rebootTimerSub: any; + private preventScheduleReboot = false; + private rebootTimer: NodeJS.Timer; + private rebootTimerSub: NodeJS.Timer; public install = (ai: 藍) => { this.ai = ai; @@ -59,9 +60,9 @@ export default class ServerModule implements IModule { } private scheduleReboot = () => { - if (this.rebootScheduled) return; + if (this.preventScheduleReboot) return; - this.rebootScheduled = true; + this.preventScheduleReboot = true; this.ai.post({ text: serifs.REBOOT_SCHEDULED @@ -78,4 +79,28 @@ export default class ServerModule implements IModule { }); }, 1000 * 50); } + + public onMention = (msg: MessageLike) => { + if (msg.text && msg.text.includes('再起動しないで')) { + if (msg.user.isAdmin) { + msg.reply(serifs.REBOOT_CANCEL_REQUESTED_ACCEPT); + + this.ai.post({ + text: serifs.REBOOT_CANCELED + }); + + clearTimeout(this.rebootTimer); + clearTimeout(this.rebootTimerSub); + + setTimeout(() => { + this.preventScheduleReboot = false; + }, 1000 * 60 * 3); + } else { + msg.reply(serifs.REBOOT_CANCEL_REQUESTED_REJECT); + } + return true; + } else { + return false; + } + } } diff --git a/src/serifs.ts b/src/serifs.ts index ae23a2b..dc3b7bc 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -20,6 +20,11 @@ export default { REBOOT: 'では、まもなくサーバーを再起動します!', REBOOT_DETAIL: '(私も再起動に巻き込まれちゃうので、サーバーの再起動が完了したことのお知らせはできません...)', + REBOOT_CANCEL_REQUESTED_ACCEPT: 'わかりました。再起動の予定を取り消しました!', + REBOOT_CANCEL_REQUESTED_REJECT: 'ごめんなさい、再起動の取り消しは管理者のみが行えます...', + + REBOOT_CANCELED: '再起動が取り消されました。お騒がせしました', + /** * 絵文字生成 */