import nonebot
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
from nonebot.log import logger

from .config import global_config
from .schedule import anti_cpdaily_check_routine


cpdaily = on_command('cpdaily')
scheduler = nonebot.require("nonebot_plugin_apscheduler").scheduler


async def one_shot_routine():
    scheduler.remove_job('anti_cpdaily_oneshot')
    await anti_cpdaily_check_routine()


@cpdaily.handle()
async def handle_command(bot: Bot, event: Event, state: T_State):
    """ Manually activate the routine in 1 min
    """
    if event.get_user_id() in bot.config.superusers:
        logger.debug('manually activate the cpdaily routine')
        # await anti_cpdaily_check_routine()
        scheduler.add_job(one_shot_routine, trigger='interval', minutes=1, id='anti_cpdaily_oneshot', replace_existing=True)
        logger.debug('manual process end')
        await cpdaily.finish('启动今日校园打卡程序ing')

[((12, 10, 12, 31), 'nonebot.on_command', 'on_command', ({(12, 21, 12, 30): '"""cpdaily"""'}, {}), "('cpdaily')", False, 'from nonebot import on_command\n'), ((13, 12, 13, 57), 'nonebot.require', 'nonebot.require', ({(13, 28, 13, 56): '"""nonebot_plugin_apscheduler"""'}, {}), "('nonebot_plugin_apscheduler')", False, 'import nonebot\n'), ((26, 8, 26, 61), 'nonebot.log.logger.debug', 'logger.debug', ({(26, 21, 26, 60): '"""manually activate the cpdaily routine"""'}, {}), "('manually activate the cpdaily routine')", False, 'from nonebot.log import logger\n'), ((29, 8, 29, 42), 'nonebot.log.logger.debug', 'logger.debug', ({(29, 21, 29, 41): '"""manual process end"""'}, {}), "('manual process end')", False, 'from nonebot.log import logger\n')]