mirror of
https://github.com/nullnyat/NullcatChan.git
synced 2025-07-02 09:49:59 +09:00
nanka iroiro
This commit is contained in:
47
src/modules/timer/index.ts
Normal file
47
src/modules/timer/index.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import 藍 from '../../ai';
|
||||
import IModule from '../../module';
|
||||
import MessageLike from '../../message-like';
|
||||
import serifs from '../../serifs';
|
||||
|
||||
export default class TimerModule implements IModule {
|
||||
public name = 'timer';
|
||||
private ai: 藍;
|
||||
|
||||
public install = (ai: 藍) => {
|
||||
this.ai = ai;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (timeStr) {
|
||||
const num = parseInt(timeStr[1], 10);
|
||||
|
||||
if (num <= 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;
|
||||
|
||||
setTimeout(() => {
|
||||
this.ai.sendMessage(msg.userId, {
|
||||
text: serifs.timer.notify.replace('{time}', timeStr[0])
|
||||
});
|
||||
}, time);
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user