Esempio n. 1
0
async def _(bot: Bot, event: MessageEvent):
    msg = str(event.get_message())
    if 'type=flash,' in msg:
        msg = msg.replace('type=flash,', '')
        await flashimg.finish(message=Message("不要发闪照,好东西就要分享。" + msg),
                              at_sender=True)
    else:  #复读
        if not randint(0, 99):
            await flashimg.send(event.get_message())
Esempio n. 2
0
async def _keyrepo(bot: Bot, event: MessageEvent) -> None:
    msg = str(event.get_message())
    data = load_key_data()

    for key in data.keys():
        if key in msg:
            await keyrepo.finish(choice(data[key]))
async def say_unescape(bot: Bot, event: MessageEvent):
    def _unescape(message: Message, segment: MessageSegment):
        if segment.is_text():
            return message.append(unescape(str(segment)))
        return message.append(segment)

    message = reduce(_unescape, event.get_message(), Message())  # type: ignore
    await bot.send(message=message, event=event)
Esempio n. 4
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]))
Esempio n. 5
0
async def _eat_what(bot: Bot, event: MessageEvent):
    user_id = event.get_user_id()
    if not _eat_flmt.check(user_id):
        return

    msg = str(event.get_message())
    user_name = event.sender.nickname or "裙友"
    eat = await Funny().eat_what(user_name, msg)
    _eat_flmt.start_cd(user_id)
    await eat_what.finish(Message(eat))
Esempio n. 6
0
async def say_unescape(bot: Bot, event: MessageEvent):

    # def _unescape(msg: Message, segment: MessageSegment):
    #    if segment.is_text():
    #        return msg.append(unescape(str(segment)))
    #    return msg.append(segment)

    # message = reduce(_unescape, event.get_message(), Message())  # type: ignore
    # await bot.send(message=message, event=event)
    await bot.send(message=Message(unescape(str(event.get_message()))), event=event)
Esempio n. 7
0
async def handle(bot: Bot, event: MessageEvent):
    msg = str(event.get_message()).strip()

    groups_data = await bot.get_group_list() # list<dict>
    cnt = 0
    for group in groups_data:
        gid = group["group_id"]
        await bot.send_group_msg(group_id=gid, message=msg)
        cnt += 1

    await broadcast.finish(f"已经发送给共 {cnt} 个群组。")
Esempio n. 8
0
async def handle_echo(bot: Bot, event: MessageEvent, state: dict):
    message = str(event.get_message())

    # print('user id', event.user_id)
    # print('message id', event.message_id)
    # print('bot config', bot.config)

    for echo_map in echo_maps:
        for rule in echo_map['rules']:
            if type(rule) is re.Pattern and rule.search(message):
                await send_message(echo_map['reply'], message)
                raise StopPropagation()
            elif type(rule) is str and rule in message:
                await send_message(echo_map['reply'], message)
                raise StopPropagation()
Esempio n. 9
0
async def handle(bot: Bot, event: MessageEvent, state: T_State):
    argc = 0
    raw_args = str(event.get_message()).strip()
    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 <= 1:
        is_valid = True
        if "arg1" in state:
            try:
                max_num = int(state["arg1"])
            except ValueError:
                max_num = -1
            if max_num <= 0:
                is_valid = False
        else:
            max_num = 100

        if is_valid:
            r = randint(0, max_num)
            ending = "好耶!"
            if r <= round(max_num / 3):
                ending = "不会吧不会吧?"
            await roll.finish(
                MessageSegment.at(event.get_user_id()) + f"摇了 {r}!" + ending)
        else:
            await roll.finish("小丛雨只会摇正整数哦!")

    # 摇选项
    else:
        # 消去重复选项
        arg_list = list(set(arg_list))

        if len(arg_list) > 1:
            start = ["当然是", "必然", "这不得"]
            end = ["啦!", "。", "?"]
            r = randint(0, len(start) - 1)
            await roll.finish(f"{start[r]}{choice(arg_list)}{end[r]}")
        else:
            await roll.finish(f"只能是{arg_list[0]}了!你根本就没想让小丛雨帮你决定,哼!")
Esempio n. 10
0
async def _code_runner(bot: Bot, event: MessageEvent):
    user_id = event.get_user_id()
    if not _flmt.check(user_id):
        await code_runner.finish(_flmt_notice)

    msg = str(event.get_message())
    args = msg.split("\n")

    if not args:
        content = f"> {MessageSegment.at(user_id)}\n" + "请键入 /code help 以获取帮助~!"
    elif args[0] == "help":
        content = f"> {MessageSegment.at(user_id)}\n" + CodeRunner().help()
    elif args[0] == "list":
        content = f"> {MessageSegment.at(user_id)}\n" + CodeRunner(
        ).list_supp_lang()
    else:
        content = MessageSegment.at(user_id) + await CodeRunner().runner(msg)

    _flmt.start_cd(user_id)
    await code_runner.finish(Message(content))
Esempio n. 11
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("小丛雨已经向狗修金报告啦~")
Esempio n. 12
0
async def _(bot: Bot, event: MessageEvent):
    msg: Message = event.get_message()

    for i in msg:
        if i.type == "image":
            return

    sentence = event.raw_message.strip()

    if sentence.split()[0] in [
            'add', 'list', 'del', 'help', 'info', 'jita', '签到', '兑换', '积分',
            '抽奖', '柏青哥', '积分池'
    ]:
        return
    keywords = await redis_client.keys()
    for index, i in enumerate(keywords):
        sub = sentence.find(i)
        if sub != -1:
            word = await redis_client.srandmember(keywords[index])
            await group.finish(word)
            return
Esempio n. 13
0
async def _(bot: Bot, event: MessageEvent):
    msg = str(event.get_message())
    if 'type=flash,' in msg:
        msg = msg.replace('type=flash,', '')
        await flash_img.finish(message=Message("不要发闪照,好东西就要分享。" + msg),
                               at_sender=True)
Esempio n. 14
0
async def handle(bot: Bot, event: MessageEvent):
    msg = str(event.get_message()).strip()
    await say.finish(msg)
Esempio n. 15
0
async def handle_print(bot: Bot, event: MessageEvent, state: dict):
    message = str(event.get_message())
    logger.info(f'receive message: {message}')
Esempio n. 16
0
async def echo_escape(bot: Bot, event: MessageEvent):
    await bot.send(message=event.get_message(), event=event)
Esempio n. 17
0
async def _me_re_you(bot: Bot, event: MessageEvent):
    if randint(0, 15) == 5:
        msg = str(event.get_message())
        content, is_ok = Funny().me_re_you(msg)
        if is_ok:
            await me_re_you.finish(content)