Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e09fa13d0f |
@ -148,6 +148,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
# target_time = get_target_time(notify_time)
|
||||
try:
|
||||
target_time = ptimeparse.parse(notify_time)
|
||||
logger.info(f"从 {notify_time} 解析出了时间:{target_time}")
|
||||
except Exception:
|
||||
logger.info(f"无法从 {notify_time} 中解析出时间")
|
||||
return
|
||||
@ -159,7 +160,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
|
||||
await DATA_FILE_LOCK.acquire()
|
||||
cfg = load_notify_config()
|
||||
|
||||
|
||||
if isinstance(mEvt, ConsoleMessageEvent):
|
||||
platform = "console"
|
||||
target = mEvt.get_user_id()
|
||||
@ -186,7 +187,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
notify_time=target_time,
|
||||
notify_msg=notify_text,
|
||||
)
|
||||
await create_notify_task(notify)
|
||||
task = create_notify_task(notify)
|
||||
|
||||
cfg.notifies.append(notify)
|
||||
save_notify_config(cfg)
|
||||
@ -194,6 +195,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
|
||||
await evt.send(await UniMessage().at(mEvt.get_user_id()).text(
|
||||
f" 了解啦!将会在 {notify.notify_time} 提醒你哦~").export())
|
||||
logger.info(f"创建了一条于 {notify.notify_time} 的代办提醒")
|
||||
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
@ -209,20 +211,27 @@ async def _():
|
||||
return
|
||||
|
||||
NOTIFIED_FLAG["task_added"] = True
|
||||
logger.info("第一次探测到 Bot 连接,等待 10 秒后开始通知")
|
||||
|
||||
await asyncio.sleep(10)
|
||||
DELTA = 2
|
||||
logger.info(f"第一次探测到 Bot 连接,等待 {DELTA} 秒后开始通知")
|
||||
await asyncio.sleep(DELTA)
|
||||
|
||||
await DATA_FILE_LOCK.acquire()
|
||||
|
||||
tasks: set[asyncio.Task[Any]] = set()
|
||||
cfg = load_notify_config()
|
||||
if cfg.version == 1:
|
||||
logger.info("将配置文件的版本升级为 2")
|
||||
cfg.version = 2
|
||||
else:
|
||||
for notify in cfg.notifies:
|
||||
counter = 0
|
||||
for notify in [*cfg.notifies]:
|
||||
task = create_notify_task(notify, fail2remove=False)
|
||||
tasks.add(task)
|
||||
task.add_done_callback(lambda self: tasks.remove(self))
|
||||
counter += 1
|
||||
logger.info(f"成功创建了 {counter} 条代办事项")
|
||||
save_notify_config(cfg)
|
||||
DATA_FILE_LOCK.release()
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
Reference in New Issue
Block a user