diff --git a/src/modules/timer/index.ts b/src/modules/timer/index.ts index bf74ee2..71fe1c4 100644 --- a/src/modules/timer/index.ts +++ b/src/modules/timer/index.ts @@ -12,29 +12,31 @@ export default class TimerModule implements IModule { } public onMention = (msg: MessageLike) => { - const seconds = (msg.text || '').match(/([0-9]+)秒/); - const minutes = (msg.text || '').match(/([0-9]+)分/); - const hours = (msg.text || '').match(/([0-9]+)時間/); - const timeStr = seconds || minutes || hours; + const secondsQuery = (msg.text || '').match(/([0-9]+)秒/); + const minutesQuery = (msg.text || '').match(/([0-9]+)分/); + const hoursQuery = (msg.text || '').match(/([0-9]+)時間/); - if (timeStr) { - const num = parseInt(timeStr[1], 10); + const seconds = secondsQuery ? parseInt(secondsQuery[1], 10) : 0; + const minutes = minutesQuery ? parseInt(minutesQuery[1], 10) : 0; + const hours = hoursQuery ? parseInt(hoursQuery[1], 10) : 0; - if (num <= 0) { + if (secondsQuery || minutesQuery || hoursQuery) { + if ((seconds + minutes + hours) == 0) { msg.reply(serifs.timer.invalid); return true; } else { msg.reply(serifs.timer.set); const time = - seconds ? 1000 * num : - minutes ? 1000 * 60 * num : - hours ? 1000 * 60 * 60 * num * 1000 : - null; + (1000 * seconds) + + (1000 * 60 * minutes) + + (1000 * 60 * 60 * hours); + + const str = `${hours ? hoursQuery[0] : ''}${minutes ? minutesQuery[0] : ''}${seconds ? secondsQuery[0] : ''}`; setTimeout(() => { this.ai.sendMessage(msg.userId, { - text: serifs.timer.notify.replace('{time}', timeStr[0]) + text: serifs.timer.notify.replace('{time}', str) }); }, time);