Ejemplo n.º 1
0
async def _(arg: Message = CommandArg()):
    msg = arg.extract_plain_text().strip()
    if not msg:
        await mc.finish()
    if msg.startswith("status"):
        addr = msg.replace("status", "", 1).strip()
        if addr:
            status = await get_mcstatus(addr)
            if status:
                await mc.finish(status)
            else:
                await mc.finish("出错了,请稍后再试")
    else:
        types = ["avatar", "head", "body", "skin", "cape", "model"]
        for t in types:
            if msg.startswith(t):
                username = msg.replace(t, "", 1).strip()
                if username:
                    uuid = await get_mc_uuid(username)
                    if not uuid:
                        await mc.finish("出错了,请稍后再试")
                    if uuid == "none":
                        await mc.finish("找不到该用户")
                    if t == "model":
                        await mc.send("生成中,请耐心等待。。。")
                        result = await get_mcmodel(uuid)
                    else:
                        result = await get_crafatar(t, uuid)
                    if result:
                        await mc.finish(MessageSegment.image(result))
                    else:
                        await mc.finish("出错了,请稍后再试")
    await mc.finish()
Ejemplo n.º 2
0
async def morning_handle(event: GroupMessageEvent,
                         arg: Message = CommandArg()):
    args = arg.extract_plain_text()

    group_id = event.group_id

    if args == "today":
        await morning_cmd.finish(await get_moring_message())

    if args == "update":
        await HOLIDAYS_DATA.update()
        await morning_cmd.finish("节假日数据更新成功")

    if args and group_id:
        if strtobool(args):
            plugin_config.morning_group_id += [group_id]
            await morning_cmd.finish("已在本群开启每日早安功能")
        else:
            plugin_config.morning_group_id = [
                n for n in plugin_config.morning_group_id if n != group_id
            ]
            await morning_cmd.finish("已在本群关闭每日早安功能")
    else:
        if group_id in plugin_config.morning_group_id:
            await morning_cmd.finish("每日早安功能开启中")
        else:
            await morning_cmd.finish("每日早安功能关闭中")
Ejemplo n.º 3
0
async def price_handle(event: MessageEvent, args: Message = CommandArg()):
    """查价"""
    argv = args.extract_plain_text().split()

    if len(argv) == 0:
        await price_cmd.finish(get_command_help("ff14.price"))

    if len(argv) == 1 and argv[0] == "默认值":
        world_or_dc = DATA.config.get(f"price-default-{event.user_id}", "猫小胖")
        await price_cmd.finish(f"当前设置的默认值为:{world_or_dc}")

    if len(argv) == 2 and argv[0] == "默认值":
        DATA.config.set(f"price-default-{event.user_id}", argv[1])
        await price_cmd.finish("查询区域默认值设置成功!")

    if len(argv) > 0:
        name = argv[0]
        if len(argv) >= 2:
            world_or_dc = argv[1]
        else:
            world_or_dc = DATA.config.get(f"price-default-{event.user_id}",
                                          "猫小胖")

        try:
            reply = await get_item_price(name, world_or_dc)
        except httpx.HTTPError:
            reply = "抱歉,网络出错,请稍后再试。"

        await price_cmd.finish(reply)
Ejemplo n.º 4
0
async def _(matcher: Matcher, event: MessageEvent,
            msg: Message = CommandArg()):
    if event.reply:
        reply = event.reply.message
        if parse_url(reply):
            matcher.set_arg("img_url", reply)
    else:
        matcher.set_arg("img_url", msg)
Ejemplo n.º 5
0
async def _(msg: Message = CommandArg()):
    text = msg.extract_plain_text().strip()
    if not text:
        await md2pic.finish()

    img = await m2p(text)
    if img:
        await md2pic.finish(MessageSegment.image(img))
Ejemplo n.º 6
0
async def roll_handle_first_receive(matcher: Matcher,
                                    arg: Message = CommandArg()):
    input = arg.extract_plain_text()

    # 如果有输入,则直接检查,出错就直接提示并结束对话
    if input and not check_roll_syntax(input):
        await roll_cmd.finish("请输入正确的参数 ~>_<~")
    if input:
        matcher.set_arg("input", arg)
Ejemplo n.º 7
0
async def add_data(matcher: Matcher, msg: Message = CommandArg()):
    chat_data = load_data(data_path)
    s_msg = str(msg).split(" ")
    # print(s_msg.split(" "))
    chat_data[s_msg[0]] = " ".join(s_msg[1:])

    await save_data(data_path, chat_data)
    matcher.stop_propagation()
    await matcher.finish("边人记住了" + Message(MessageSegment.face(16)))
Ejemplo n.º 8
0
async def _(msg: Message = CommandArg()):
    keyword = msg.extract_plain_text().strip()
    if not keyword:
        await baike.finish()

    res = await get_content(keyword)
    if res:
        await baike.finish(res)
    else:
        await baike.finish("找不到相关的条目")
Ejemplo n.º 9
0
async def _(msg: Message = CommandArg()):
    text = msg.extract_plain_text().strip()
    if not text:
        await speak.finish()

    voice = await get_voice(text)
    if voice:
        await speak.finish(MessageSegment.record(voice))
    else:
        await speak.finish("出错了,请稍后再试")
Ejemplo n.º 10
0
async def _(msg: Message = CommandArg()):
    equation = msg.extract_plain_text().strip().strip("$")
    if not equation:
        await tex.finish()

    image = await tex2pic(equation)
    if image:
        await tex.finish(MessageSegment.image(image))
    else:
        await tex.finish("出错了,请检查公式或稍后再试")
Ejemplo n.º 11
0
async def add_data(matcher: Matcher, msg: Message = CommandArg()):
    chat_data = load_data(data_path)
    s_msg = str(msg).split(" ")
    # print(s_msg.split(" "))
    if (s_msg[0] in chat_data.keys()):
        chat_data.pop(s_msg[0])

    await save_data(data_path, chat_data)
    matcher.stop_propagation()
    await matcher.finish("边人忘记了" + Message(MessageSegment.face(39)))
Ejemplo n.º 12
0
async def ban_handle_first_receive(state: T_State,
                                   bot: Bot,
                                   arg: Message = CommandArg()):
    """获取需要的参数"""
    # 如果没有获取机器人在群中的职位,则获取
    if not _bot_role:
        await refresh_bot_role(bot)

    plaintext = arg.extract_plain_text()
    if plaintext and plaintext.isdigit():
        state["duration"] = int(plaintext)
Ejemplo n.º 13
0
async def _(msg: Message = CommandArg()):
    keyword = msg.extract_plain_text().strip()
    if not keyword:
        await nbnhhsh.finish()
    if not re.fullmatch(r"[a-zA-Z]+", keyword):
        await nbnhhsh.finish()

    res = await get_content(keyword, sources=["nbnhhsh"])
    if res:
        await nbnhhsh.finish(res)
    else:
        await nbnhhsh.finish("找不到相关的缩写")
Ejemplo n.º 14
0
async def history_handle_first_receive(state: T_State, arg: Message = CommandArg()):
    match = re.match(r"^(\d+)(?:\-(\d+)(?:\-(\d+))?)?$", arg.extract_plain_text())
    if match:
        year = match.group(1)
        month = match.group(2)
        day = match.group(3)
        if year:
            state["year"] = int(year)
        if month:
            state["month"] = int(month)
        if day:
            state["day"] = int(day)
Ejemplo n.º 15
0
async def _(msg: Message = CommandArg(), tome: bool = EventToMe()):
    keyword = msg.extract_plain_text().strip()
    if not keyword:
        await pixiv.finish()

    if not keyword.isdigit() and keyword not in ["日榜", "周榜", "月榜"]:
        if not tome:
            await pixiv.finish()

    res = await get_pixiv(keyword)
    if not res:
        await pixiv.finish("出错了,请稍后再试")
    await pixiv.finish(res)
Ejemplo n.º 16
0
async def calculate(matcher: Matcher, msg: Message = CommandArg()):
    s_msg = str(msg)

    res = ""
    if (not is_safe(str(s_msg))):
        res = Message.template("参数包含非法字符串{}").format(MessageSegment.face(96))
    else:
        try:
            res = str(eval(s_msg))
        except Exception as e:
            print(e)
            res = "看不懂" + Message(MessageSegment.face(178))
    matcher.stop_propagation()
    await matcher.finish(res)
Ejemplo n.º 17
0
async def help_handle(arg: Message = CommandArg()):
    args = arg.extract_plain_text()

    if args == "all":
        commands = get_commands()
        docs = "命令(别名)列表:\n"
        docs += "\n".join(sorted(map(format_name_aliases, commands)))
        await help_cmd.finish(docs)
    elif args:
        command_help = get_command_help(args)
        if command_help:
            await help_cmd.finish(command_help)
        await help_cmd.finish("请输入支持的命令")
    else:
        await help_cmd.finish(get_command_help("help"))
Ejemplo n.º 18
0
async def PushAnswer(matcher: Matcher, msg: Message = CommandArg()):
    matcher.stop_propagation()
    l = await GetJson("https://lab.magiconch.com/api/nbnhhsh/guess",
                      "post",
                      data={"text": f"{msg}"})
    res = ""
    for d in l:
        res += Message(f"====={d['name']}=====\n")
        if ('trans' in d.keys()):
            res += Message(
                "\n".join([f"{i+1}. {s}"
                           for i, s in enumerate(d['trans'])]) + "\n")
        else:
            res += Message("啥意思啊?我不道啊!")

    await matcher.finish(res)
Ejemplo n.º 19
0
 async def __call__(
         self,
         state: T_State,
         cmd: Optional[Tuple[str, ...]] = Command(),
         msg: Optional[Message] = CommandArg(),
 ) -> bool:
     if cmd in self.cmds and msg is not None:
         message = str(msg)
         state[SHELL_ARGV] = shlex.split(message)
         if self.parser:
             try:
                 args = self.parser.parse_args(state[SHELL_ARGV])
                 state[SHELL_ARGS] = args
             except ParserExit as e:
                 state[SHELL_ARGS] = e
         return True
     else:
         return False
Ejemplo n.º 20
0
async def hello_handle(event: GroupMessageEvent, arg: Message = CommandArg()):
    args = arg.extract_plain_text()

    group_id = event.group_id

    if args and group_id:
        if strtobool(args):
            plugin_config.hello_group_id += [group_id]
            await hello_cmd.finish("已在本群开启启动问候功能")
        else:
            plugin_config.hello_group_id = [
                n for n in plugin_config.hello_group_id if n != group_id
            ]
            await hello_cmd.finish("已在本群关闭启动问候功能")
    else:
        if group_id in plugin_config.hello_group_id:
            await hello_cmd.finish("启动问候功能开启中")
        else:
            await hello_cmd.finish("启动问候功能关闭中")
Ejemplo n.º 21
0
async def repeat_handle(event: GroupMessageEvent, arg: Message = CommandArg()):
    args = arg.extract_plain_text()

    group_id = event.group_id

    if args and group_id:
        if strtobool(args):
            plugin_config.group_id += [group_id]
            recorder_obj.add_new_group()
            await repeat_cmd.finish("已在本群开启复读功能")
        else:
            plugin_config.group_id = [
                n for n in plugin_config.group_id if n != group_id
            ]
            await repeat_cmd.finish("已在本群关闭复读功能")
    else:
        if group_id in plugin_config.group_id:
            await repeat_cmd.finish("复读功能开启中")
        else:
            await repeat_cmd.finish("复读功能关闭中")
Ejemplo n.º 22
0
async def _(msg: Message = CommandArg()):
    text = msg.extract_plain_text().strip()

    plaintext = False
    pattern = [r"-p +.*?", r".*? +-p", r"--plaintext +.*?", r".*? +--plaintext"]
    for p in pattern:
        if re.fullmatch(p, text):
            plaintext = True
            break
    text = text.replace("-p", "").replace("--plaintext", "").strip()
    if not text:
        await wolfram.finish()

    if plaintext:
        res = await get_wolframalpha_text(text)
    else:
        res = await get_wolframalpha_simple(text)
    if not res:
        await wolfram.finish("出错了,请稍后再试")

    await wolfram.finish(res)
Ejemplo n.º 23
0
async def rank_handle_first_receive(state: T_State, arg: Message = CommandArg()):
    match = re.match(r"^(?:(\d+))?(?:n(\d+))?$", arg.extract_plain_text())
    if match:
        display_number = match.group(1)
        minimal_msg_number = match.group(2)
        display_total_number = False

        if display_number:
            display_number = int(display_number)
        else:
            display_number = 3

        if minimal_msg_number:
            minimal_msg_number = int(minimal_msg_number)
            display_total_number = True
        else:
            minimal_msg_number = 30

        state["display_number"] = display_number
        state["minimal_msg_number"] = minimal_msg_number
        state["display_total_number"] = display_total_number
Ejemplo n.º 24
0
async def pixiv_look(bot: Bot,
                     event: Union[GroupMessageEvent, PrivateMessageEvent],
                     args: Message = CommandArg()):
    args = args.__str__().split()
    if len(args) == 2:
        if args[0] in ["p", "pid", "id", "i", "P", "Pid", "PID"]:
            if pixiv_config.on_temp:
                info = pixivlist.search(Q["pid"] == int(args[1]))
                if info:
                    resp = info[0]["data"]
                    logger.info(info)
                    msg = info[0]["msg"]
                    if pixiv_config.pic_msg:
                        await bot.send(
                            event=event,
                            message=Message(
                                [MessageSegment.image(i) for i in resp] +
                                MessageSegment.text(msg + "\n") +
                                MessageSegment.at(event.get_user_id())))
                    else:
                        mid = await bot.send(
                            event=event,
                            message=Message(
                                MessageSegment.reply(event.message_id) +
                                [MessageSegment.image(i) for i in resp]))
                        pixivhistory.insert({
                            "mid": mid['message_id'],
                            "msg": msg,
                            "data": resp
                        })
                    return
            pid = int(args[1])
            await pixiv_api.send_illust_detail(pid=pid, bot=bot, event=event)
        elif args[0] in ["u", "uid", "Uid", "UID", "U"]:
            uid = int(args[1])
            await pixiv_api.send_usr_detail(uid=uid, bot=bot, event=event)
    else:
        await bot.send(
            event=event,
            message=f"{cmd}pixiv pid p站id 查看图片\n{cmd}pixiv uid p站用户id 查看用户")
Ejemplo n.º 25
0
async def PushAnswer(matcher: Matcher, msg: Message = CommandArg()):
    matcher.stop_propagation()
    if (str(msg) == ""):
        await matcher.finish(Message("? 翻译啥呢"))

    page_text = await spider.GetPage(
        "https://www.youdao.com/w/" + str(msg) + r"/", "get")
    answers = []

    l1 = await spider.ParsePage(
        page_text,
        "/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div/p/text()")
    l2 = await spider.ParsePage(
        page_text,
        "/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div[2]/ul/li/text()"
    )
    l3 = await spider.ParsePage(
        page_text,
        "/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div[@id='ydTrans']/div/div/p[2]/text()"
    )
    l4 = await spider.ParsePage(
        page_text,
        "/html/body/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div[2]/ul/p/span/a/text()"
    )
    answers.extend(l1 + l2 + l3 + l4)

    if (not answers):
        await matcher.finish(Message("说的是人话吗" + MessageSegment.face(14)))
    res = ""
    res += Message(f"原词(句):{msg}\n\n结果=========\n")

    for i in answers:
        i = i.strip()
        if (i == '' or (i[0] == "[" and i[len(i) - 1] == "]")):
            continue
        res += Message(i + "\n")

    await matcher.finish(str(res))
Ejemplo n.º 26
0
async def _(event: MessageEvent, msg: Message = CommandArg()):
    keyword = msg.extract_plain_text().strip()
    if not keyword:
        return

    plugins = get_plugins(event)
    plugin = None
    for p in plugins[::-1]:
        if keyword.lower() in (p.name.lower(), p.short_name.lower()):
            plugin = p
            break
    if not plugin:
        await unblock.finish(f"插件 {keyword} 不存在!")

    plugin_manager = PluginManager()
    conv: Conv = get_conv(event)
    if conv["group"]:
        conv["user"] = []
    result = plugin_manager.unblock_plugin([plugin.name], conv)
    if result.get(plugin.name, False):
        res = f"插件 {plugin.short_name} 启用成功"
    else:
        res = f"插件 {plugin.short_name} 不存在或已关闭编辑权限!"
    await unblock.finish(res)
async def handle_first_receive(event: Event,
                               state: T_State,
                               args: Message = CommandArg()):
    # 通过是否为group判读信息结构
    global group
    group = True if event.get_event_name().find(
        "group") != -1 else plugin_config.same_message_structure
    args: list = args.extract_plain_text().strip().split()
    state["help"] = False
    state["redraw"] = False
    state["test"] = ""
    if args:
        if "help" in args:
            state["help"] = True
        elif ("r" in args) or ("重抽" in args) or ("redraw" in args):
            state["redraw"] = True
        elif "test" in args:
            state["test"] = args[1]

    else:
        await luck.send(await luck_daily(user_id=int(event.get_user_id()),
                                         redraw=False,
                                         group_message=group),
                        at_sender=group)
Ejemplo n.º 28
0
 async def handler(msg: Message = CommandArg()):
     text = msg.extract_plain_text().strip()
     await handle(matcher, type, text)
Ejemplo n.º 29
0
async def uixiv_look(bot: Bot,
                     event: Union[GroupMessageEvent, PrivateMessageEvent],
                     args: Message = CommandArg()):
    args = args.__str__().split()
    uid = int(args[0])
    await pixiv_api.send_usr_detail(uid=uid, bot=bot, event=event)
Ejemplo n.º 30
0
async def _(msg: Message = CommandArg()):
    await handle(setu_, msg, r18=True)