Improve timer

This commit is contained in:
syuilo 2018-08-26 09:12:48 +09:00
parent ac3abc0210
commit 1dc0bf27e9

View file

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