再起動の取り消しを実装するなど

This commit is contained in:
syuilo 2018-08-11 21:28:17 +09:00
parent b54e5aaf80
commit ae4127d19e
7 changed files with 43 additions and 9 deletions

View file

@ -9,6 +9,10 @@ export default class MessageLike {
return this.messageOrNote.id; return this.messageOrNote.id;
} }
public get user() {
return this.messageOrNote.user;
}
public get userId() { public get userId() {
return this.messageOrNote.userId; return this.messageOrNote.userId;
} }

View file

@ -122,7 +122,7 @@ export default class EmojiModule implements IModule {
public install = (ai: ) => { } public install = (ai: ) => { }
public onMention = (msg: MessageLike) => { 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 hand = hands[Math.floor(Math.random() * hands.length)];
const face = faces[Math.floor(Math.random() * faces.length)]; const face = faces[Math.floor(Math.random() * faces.length)];
const emoji = Array.isArray(hand) ? hand[0] + face + hand[1] : hand + face + hand; const emoji = Array.isArray(hand) ? hand[0] + face + hand[1] : hand + face + hand;

View file

@ -28,7 +28,7 @@ export default class EmojiModule implements IModule {
public install = (ai: ) => { } public install = (ai: ) => { }
public onMention = (msg: MessageLike) => { public onMention = (msg: MessageLike) => {
if (msg.text && msg.text.indexOf('占') > -1) { if (msg.text && msg.text.includes('占')) {
const date = new Date(); const date = new Date();
const seed = `${date.getFullYear()}/${date.getMonth()}/${date.getDay()}@${msg.userId}`; const seed = `${date.getFullYear()}/${date.getMonth()}/${date.getDay()}@${msg.userId}`;
const rng = seedrandom(seed); const rng = seedrandom(seed);

View file

@ -6,7 +6,7 @@ export default class PingModule implements IModule {
public install = (ai: ) => { } public install = (ai: ) => { }
public onMention = (msg: MessageLike) => { public onMention = (msg: MessageLike) => {
if (msg.text && msg.text.indexOf('ping') > -1) { if (msg.text && msg.text.includes('ping')) {
msg.reply('PONG!'); msg.reply('PONG!');
return true; return true;
} else { } else {

View file

@ -38,7 +38,7 @@ export default class ReversiModule implements IModule {
} }
public onMention = (msg: MessageLike) => { public onMention = (msg: MessageLike) => {
if (msg.text && msg.text.indexOf('リバーシ') > -1) { if (msg.text && msg.text.includes('リバーシ')) {
if (config.reversiEnabled) { if (config.reversiEnabled) {
msg.reply(serifs.REVERSI_OK); msg.reply(serifs.REVERSI_OK);

View file

@ -4,14 +4,15 @@ import 藍 from '../../ai';
import IModule from '../../module'; import IModule from '../../module';
import serifs from '../../serifs'; import serifs from '../../serifs';
import config from '../../config'; import config from '../../config';
import MessageLike from '../../message-like';
const ReconnectingWebSocket = require('../../../node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js'); const ReconnectingWebSocket = require('../../../node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js');
export default class ServerModule implements IModule { export default class ServerModule implements IModule {
private ai: ; private ai: ;
private connection?: any; private connection?: any;
private rebootScheduled = false; private preventScheduleReboot = false;
private rebootTimer: any; private rebootTimer: NodeJS.Timer;
private rebootTimerSub: any; private rebootTimerSub: NodeJS.Timer;
public install = (ai: ) => { public install = (ai: ) => {
this.ai = ai; this.ai = ai;
@ -59,9 +60,9 @@ export default class ServerModule implements IModule {
} }
private scheduleReboot = () => { private scheduleReboot = () => {
if (this.rebootScheduled) return; if (this.preventScheduleReboot) return;
this.rebootScheduled = true; this.preventScheduleReboot = true;
this.ai.post({ this.ai.post({
text: serifs.REBOOT_SCHEDULED text: serifs.REBOOT_SCHEDULED
@ -78,4 +79,28 @@ export default class ServerModule implements IModule {
}); });
}, 1000 * 50); }, 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;
}
}
} }

View file

@ -20,6 +20,11 @@ export default {
REBOOT: 'では、まもなくサーバーを再起動します!', REBOOT: 'では、まもなくサーバーを再起動します!',
REBOOT_DETAIL: '(私も再起動に巻き込まれちゃうので、サーバーの再起動が完了したことのお知らせはできません...)', REBOOT_DETAIL: '(私も再起動に巻き込まれちゃうので、サーバーの再起動が完了したことのお知らせはできません...)',
REBOOT_CANCEL_REQUESTED_ACCEPT: 'わかりました。再起動の予定を取り消しました!',
REBOOT_CANCEL_REQUESTED_REJECT: 'ごめんなさい、再起動の取り消しは管理者のみが行えます...',
REBOOT_CANCELED: '再起動が取り消されました。お騒がせしました',
/** /**
* *
*/ */