遅延タスクや定期タスクを呼び出すための簡単なタイマー機能を提供します。
from datetime import datetime, timedelta
from dncore.plugin import Plugin
# depends(plugin.yml) に TimerLib を加える
from dncore.extensions.timerlib import Timer, TimerTask
class ExamplePlugin(Plugin):
def __init__(self):
# Timerの初期化
self.timer = Timer(self) # Pluginインスタンスを紐づける
async def on_enable(self):
# 1分後にスケジュール
self.timer.once(60, self.on_time)
# 毎朝7時にスケジュール
self.timer.daily(7, 0, self.on_morning)
async def on_time(self, task: TimerTask):
log.info("1分が経過しました!")
async def on_morning(self, task: TimerTask):
log.info("おはよう!")