Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加定时任务 #49

Open
wants to merge 1 commit into
base: broken
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lagrange/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(
device_info_path="./device.json",
signinfo_path="./sig.bin",
):
self.scheduled_tasks = [] # 添加这行来存储计划任务
self.im = InfoManager(uin, device_info_path, signinfo_path)
self.uin = uin
self.info = app_list[protocol]
Expand All @@ -40,6 +41,9 @@ async def login(self, client: Client):
return True
else:
return await client.login()
def schedule_task(self, task):
"""添加计划任务"""
self.scheduled_tasks.append(task)

async def run(self):
with self.im as im:
Expand All @@ -57,6 +61,9 @@ async def run(self):
if not status:
log.login.error("Login failed")
return
# 登录成功后执行计划任务
for task in self.scheduled_tasks:
asyncio.create_task(task(self.client))
await self.client.wait_closed()

def launch(self):
Expand Down