Ejemplo n.º 1
0
async def end_event(event: Event) -> bool:
    try:
        await event.update(end_time=dt.beijing_now().timestamp(),
                           qq_group_number=None).apply()
        return True
    except Exception as e:
        logger.exception(e)
        return False
Ejemplo n.º 2
0
def init():
    # initial load
    global data_frame, last_collect_dt
    if data_frame is None:
        curr_dt = dt.beijing_now(bot.config.MESSAGE_COLLECTOR_DUMP_FREQ)
        data_frame = load(curr_dt)
        if data_frame is not None:
            last_collect_dt = curr_dt

    atexit.register(finalize)
Ejemplo n.º 3
0
async def append_message(data) -> None:
    global data_frame, last_collect_dt
    async with lock:
        curr_dt = dt.beijing_now(bot.config.MESSAGE_COLLECTOR_DUMP_FREQ)

        if data_frame is not None and \
                last_collect_dt and last_collect_dt != curr_dt:
            await aio.run_sync_func(dump, last_collect_dt)
            data_frame = None

        if data_frame is None:
            data_frame = DataFrame(data)
        else:
            data_frame = data_frame.append(DataFrame(data), ignore_index=True)
        last_collect_dt = curr_dt
Ejemplo n.º 4
0
async def start_event(ctx: Context_T,
                      title: str,
                      fields: List[Dict[str, Any]],
                      max_signups: int = 0) -> Optional[Event]:
    try:
        return await Event.create(
            context_id=ctx_id_by_user(ctx),
            title=title,
            code=random_string(8, string.ascii_uppercase + string.digits),
            fields=fields,
            start_time=dt.beijing_now().timestamp(),
            max_signups=max_signups,
        )
    except Exception as e:
        logger.exception(e)
        return None
Ejemplo n.º 5
0
async def index(session: CommandSession):
    now = dt.beijing_now()
    year = session.state.get('year', now.year)
    month = session.state.get('month', now.month)
    month = math.ceil(month / 3) * 3 - 3 + 1

    anime_list = await get_anime_list(year, month)
    if not anime_list:
        session.finish('没有查询到相关番剧……')

    reply = f'{year}年{month}月番剧\n按追番人数排序,前20部如下:\n\n'
    for anime in anime_list:
        title = anime.get('title')
        index_show = anime.get('index_show', '不详')
        if not title:
            continue
        reply += f'{title}  {index_show}\n'

    web_url = WEB_URL.format(year=year, month=month)
    reply += f'\n更多详细资料见哔哩哔哩官网 {web_url}'
    session.finish(reply)
Ejemplo n.º 6
0
def finalize():
    global data_frame
    if data_frame is not None:
        dump(last_collect_dt
             or dt.beijing_now(bot.config.MESSAGE_COLLECTOR_DUMP_FREQ))
        data_frame = None