mirror of
https://github.com/syuilo/ai.git
synced 2024-11-24 22:01:07 +00:00
Improve timer
This commit is contained in:
parent
ac3abc0210
commit
1dc0bf27e9
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue