async def show_progress(session: CommandSession): """progress: 查询本周刷题进度(周日18点为界线) 用法: progress """ group_id = session.ctx['group_id'] qq_id = session.ctx['user_id'] dm = DataManager(group_id) accounts = dm.query_binded_accounts(qq_id) starttime = last_sunday() endtime = dm.get_latest_csttime_by_qq(qq_id) vs, ve = dm.report_by_qq(qq_id, starttime, endtime) tf = "%Y/%m/%d %H:%M" msg = f"""Progress this week: [{starttime.strftime(tf)}] Accepted: {vs} [{endtime.strftime(tf)}] Accepted: {ve} (+{ve-vs})""" await session.send(msg)
async def update_database(session: CommandSession): """update: 立刻更新账号数据(冷却时间10分钟) 除此之外,爬虫会在每日18点左右自动更新账号数据(如有bug请 @Nuullll) 用法: update """ group_id = session.ctx['group_id'] qq_id = session.ctx['user_id'] debug = session.ctx.get('debug', False) if not debug: dm = DataManager(group_id) accounts = dm.query_binded_accounts(qq_id) await session.send("正在更新数据", at_sender=True) if not accounts: await session.finish("请先绑定账号!命令:register") latest = dm.get_latest_csttime_by_qq(qq_id) now = cstnow() delta = int((now - latest).total_seconds()) print(latest, now, delta) await session.send(f"最近更新: {latest}") if delta < USER_UPDATE_COOLDOWN: await session.finish(f"技能冷却中:剩余{USER_UPDATE_COOLDOWN-delta}秒") for user_id, platform in accounts: ok, snapshot = await dm.get_and_save_user_summary( qq_id, user_id, platform) if not ok: await session.send("ID错误或网络错误!请检查后重试。") for msg in multiline_msg_generator(snapshot.lines): await session.bot.send_msg_rate_limited(group_id=group_id, message=msg) else: dm = DataManager(group_id) accounts = dm.query_binded_accounts(qq_id) for user_id, platform in accounts: ok, snapshot = await dm.get_and_save_user_summary( qq_id, user_id, platform) for msg in multiline_msg_generator(snapshot.lines): await session.bot.send_msg_rate_limited(user_id=724463877, message=msg)