Пример #1
0
async def handle(bot: Bot, event: MessageEvent, state: T_State):
    raw_args = str(event.get_message()).strip()
    argc = 0
    if raw_args:
        arg_list = raw_args.split()
        argc = len(arg_list)
        for i in range(argc):
            state[f"arg{i+1}"] = arg_list[i]

    if argc > 0 and state["arg1"] == "日榜":
        is_timeout, is_error, status, data = await get_image_data_v1(
            url="https://rakuen.thec.me/PixivRss/daily-10")
    elif argc > 0 and state["arg1"] == "周榜":
        is_timeout, is_error, status, data = await get_image_data_v1(
            url="http://rakuen.thec.me/PixivRss/weekly-10")
    elif argc > 0 and state["arg1"] == "月榜":
        is_timeout, is_error, status, data = await get_image_data_v1(
            url="https://rakuen.thec.me/PixivRss/monthly-10")
    elif argc > 0:
        keyword = unescape(state["arg1"])
        await pixiv.send(f"正在搜索[{keyword}]……")
        is_timeout, is_error, status, data = await get_image_data_v2(
            tag=keyword)
    else:
        is_timeout, is_error, status, data = await get_image_data_v2()

    uid = event.user_id
    session_id = event.get_session_id().split("_")
    # 消息来自群聊
    if len(session_id) == 3:
        at = MessageSegment.at(uid) + "\n"
    else:
        at = ""

    if is_timeout:
        await pixiv.finish(at + "苦しい……请求超时了(´。_。`)")
    if status != 200 and status != 0:
        await pixiv.finish(at + f"苦しい……连接出错了({status}),可以马上重试一下呢!")
    if is_error:
        await pixiv.finish(at + "苦しい……连接出错了(´。_。`)")
    elif len(data) == 0:
        await pixiv.finish(at + "寂しい……什么都没找到呢。试试范围更大的关键词哦!")
    else:
        chosen = choice(data)
        try:
            await pixiv.send(at + f"{chosen[0]}\nPixiv 链接:{chosen[1]}\n" +
                             MessageSegment.image(chosen[2]) +
                             "可能会发不出图片呜呜,复制下面链接到浏览器查看吧")
        except ActionFailed as e:
            await pixiv.send(
                at +
                f"{chosen[0]}\nPixiv 链接:{chosen[1]}\n大概是太涩了差点发不出来,复制下面链接到浏览器查看吧"
            )
            print(f"[pixiv.py]: {e}")
        finally:
            await pixiv.finish(await async_shorten_url(chosen[2]))
Пример #2
0
async def handle_morning(bot: Bot, event: MessageEvent):
    session_id = event.get_session_id().split("_")
    gid = int(session_id[1])
    uid = int(event.get_user_id())
    time = datetime.now()
    date = time.date()

    # 起床时间储存到前一天的数据里
    date -= timedelta(days=1)

    # 0:00 ~ 3:00 及 14:00 ~ 24:00 拒绝命令
    if time.hour < 3 or time.hour >= 14:
        await good_morning.finish("早上好……诶!怎么想都不太对吧!")
        return

    # 存入起床时间
    if gid in data:
        if date in data[gid]:
            if uid in data[gid][date]:

                # 如果已有起床时间,不作理会
                if data[gid][date][uid][1] != -1:
                    await good_morning.finish(
                        "你已经跟小丛雨说过早上好啦!难道睡回笼觉了吗,要是这样小丛雨可要批评你了!")
                    return

                data[gid][date][uid][1] = time
            else:
                data[gid][date][uid] = [-1, time]
            data[gid][date][-1][1] += 1
        else:
            data[gid][date] = {-1: [0, 1], uid: [-1, time]}
    else:
        data[gid] = {date: {-1: [0, 1], uid: [-1, time]}}
    save_to_file(data)

    time_list = data[gid][date][uid]
    order = data[gid][date][-1][1]
    if time_list[0] != -1:
        delta = time_list[1] - time_list[0]
        hours, remains = divmod(delta.seconds, 3600)
        mins, secs = divmod(remains, 60)

        sleep_time_info = f"昨晚你睡了 {hours} 小时 {mins} 分,是本群起床第 {order} 人!"
    else:
        sleep_time_info = f"你是本群起床第 {order} 人!没有记录到你昨晚的入睡时间呢,今晚记得跟小丛雨说晚安哦!"

    await good_morning.finish(
        MessageSegment.at(uid) + "你醒啦!" + sleep_time_info)
Пример #3
0
async def handle(bot: Bot, event: MessageEvent):
    content = str(event.get_message()).strip()
    if not content:
        await contact.finish("啊叻?小丛雨不知道要发送什么啦...")

    else:
        now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        is_from_private = True
        session_id = event.get_session_id().split("_")
        if len(session_id) == 3:
            is_from_private = False
            group_id = session_id[1]

        if is_from_private:
            msg = f"[Contact Message]\nSender: {event.get_user_id()}\nFrom: Private\nTime: {now}\nContent: {content}"
        else:
            msg = f"[Contact Message]\nSender: {event.get_user_id()}\nFrom: Group({group_id})\nTime: {now}\nContent: {content}"
        await bot.send_private_msg(user_id=593457446, message=msg)

        await contact.finish("小丛雨已经向狗修金报告啦~")
Пример #4
0
async def handle_night(bot: Bot, event: MessageEvent):
    session_id = event.get_session_id().split("_")
    gid = int(session_id[1])
    uid = int(event.get_user_id())
    time = datetime.now()
    date = time.date()

    # 5:00 ~ 21:00 拒绝命令
    if 5 <= time.hour < 21:
        await good_night.finish("太早啦,还没到说晚安的时候呢!不要跟小丛雨开玩笑了啦……")
        return

    # 5:00 前收到的晚安命令算到前一天里
    if time.hour < 5:
        date -= timedelta(days=1)

    # 存入入睡时间
    if gid in data:
        if date in data[gid]:
            if uid in data[gid][date]:

                # 如果已有入睡时间,刷新为新时间
                if data[gid][date][uid][0] != -1:
                    data[gid][date][uid][0] = time
                    await good_night.finish("哼!不是已经说好了要睡觉了嘛!这次就原谅你了,赶快睡觉吧zzz")
                    return

                data[gid][date][uid][0] = time
            else:
                data[gid][date][uid] = [time, -1]
            data[gid][date][-1][0] += 1
        else:
            data[gid][date] = {-1: [1, 0], uid: [time, -1]}
    else:
        data[gid] = {date: {-1: [1, 0], uid: [time, -1]}}
    save_to_file(data)

    order = data[gid][date][-1][0]
    await good_night.finish(
        MessageSegment.at(uid) + f"晚安啦,你是本群第 {order} 个睡觉的人!记得睡觉要说到做到哦!")