コード例 #1
0
def receive_group_msg(ctx: GroupMsg):
    # check
    plugin = PluginControl()
    if not plugin.check("reply", ctx.FromUserId, ctx.FromGroupId):
        return

    # param
    param = plugin.find_one("reply", ctx.FromGroupId)["param"]
    p = float(param["p"])
    q = float(param["q"])
    delay_time = float(param["delay_time"])

    if random.random() < p and ctx.FromUserId != configuration.qq:
        time.sleep(random.random() * delay_time)
        action = Action(configuration.qq)
        if ctx.MsgType == 'TextMsg' and not plugin.is_command(
                ctx.Content.split(' ', 1)[0], ctx.FromGroupId):
            action.send_group_text_msg(ctx.FromGroupId,
                                       replace_text_msg(ctx.Content, q))
        elif ctx.MsgType == 'PicMsg':
            pic_msg = json.loads(ctx.Content)
            for pic_content in pic_msg['GroupPic']:
                action.send_group_pic_msg(
                    ctx.FromGroupId,
                    fileMd5=pic_content['FileMd5'],
                    picBase64Buf=pic_content['ForwordBuf'])
コード例 #2
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

        action = Action(configuration.qq)
        if ctx.MsgType == 'TextMsg':
            command = ctx.Content
            if command == "绝对音感测试":

                # check
                plugin = PluginControl()
                if not plugin.check("绝对音感测试", ctx.FromUserId, ctx.FromGroupId):
                    return

                param = plugin.find_one("绝对音感测试", ctx.FromGroupId)["param"]

                sleep_time = int(param["time"])
                low = int(param["low"])
                high = int(param["high"])

                num = random.randint(low, high)
                key = random_pitch(num)

                url = "http://jinfans.top/others/perfect_pitch/" + str(
                    num) + ".mp3"
                print(url)

                action.send_group_voice_msg(ctx.FromGroupId, url)

                action.send_group_text_msg(
                    ctx.FromGroupId, "绝对音感测试开始!" + str(sleep_time) + "s后公布答案")

                time.sleep(sleep_time)
                action.send_group_text_msg(ctx.FromGroupId, "正确答案是:" + key)
コード例 #3
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

        # check
        plugin = PluginControl()
        if not plugin.check("setu", ctx.FromUserId, ctx.FromGroupId):
            return

        action = Action(configuration.qq)
        if ctx.MsgType == 'TextMsg':
            command = ctx.Content.split(' ')
            if command[0] == "setu":

                if len(command) == 2:
                    execute = command[1]
                else:

                    # param
                    param = plugin.find_one("setu", ctx.FromGroupId)["param"]
                    execute = param["default"]

                id_url = "http://jinfans.top/setu/latest/view/random?type=" + execute
                id_image = get_html_text(id_url)
                id_json = json.loads(id_image)
                url = "http://jinfans.top/setu/latest/view/direct/" + id_json["_id"]
                action.send_group_pic_msg(ctx.FromGroupId, content=execute, picUrl=url)
コード例 #4
0
ファイル: bot_latex.py プロジェクト: Centauria/GrandBot
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

        # check
        plugin = PluginControl()
        if not plugin.check("latex", ctx.FromUserId, ctx.FromGroupId):
            return

        action = Action(configuration.qq)
        if ctx.MsgType == 'TextMsg':

            command = ctx.Content.split(' ', 1)
            if command[0] == "latex" and len(command) > 1:
                latex_content = command[1]
                url = 'https://quicklatex.com/latex3.f'

                # param
                param = plugin.find_one("latex", ctx.FromGroupId)["param"]
                fsize = str(param["fsize"])

                data = {"formula": transfer_spacing(latex_content), "fcolor": "000000", "fsize": fsize, "mode": "0", "out": "1", "remhost": "quicklatex.com"}
                response = post(url, data)
                content = response.text.split("\r\n")
                if content[0] == "0":
                    pic_url = content[1].split(' ')[0]
                    print(pic_url)
                    action.send_group_pic_msg(ctx.FromGroupId, picUrl=pic_url, timeout=20)
                else:
                    action.send_group_text_msg(ctx.FromGroupId, "无法识别公式!")
コード例 #5
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

        action = Action(configuration.qq)
        if ctx.MsgType == 'TextMsg':
            command = ctx.Content.split(' ')
            if command[0] == "说话" and len(command) >= 2:

                # check
                plugin = PluginControl()
                if not plugin.check("说话", ctx.FromUserId, ctx.FromGroupId):
                    return

                text = command[1]

                # param
                param = plugin.find_one("说话", ctx.FromGroupId)["param"]
                voiceId = str(param["voiceId"])
                speed = str(param["speed"])
                volume = str(param["volume"])
                audioType = str(param["audioType"])
                for i in range(len(command) - 2):
                    if command[i + 2][:8] == 'voiceId=':
                        voiceId = command[i + 2].lstrip('voice=Id')
                    elif command[i + 2][:6] == 'speed=':
                        speed = command[i + 2].lstrip('speed=')
                    elif command[i + 2][:7] == 'volume=':
                        volume = command[i + 2].lstrip('volume=')
                    elif command[i + 2][:10] == 'audioType=':
                        audioType = command[i + 2].lstrip('audioType=')

                url = "https://dds.dui.ai/runtime/v1/synthesize?voiceId=" + voiceId + "&speed=" + speed + \
                   "&volume=" + volume + "&audioType=" + audioType + "&text=" + text

                action.send_group_voice_msg(ctx.FromGroupId, url)

            elif command[0] == "对话" and len(command) >= 2:

                # check
                plugin = PluginControl()
                if not plugin.check("对话", ctx.FromUserId, ctx.FromGroupId):
                    return

                ask = command[1]

                # param
                param = plugin.find_one("对话", ctx.FromGroupId)["param"]
                voiceId = str(param["voiceId"])
                speed = str(param["speed"])
                volume = str(param["volume"])
                audioType = str(param["audioType"])
                for i in range(len(command) - 2):
                    if command[i + 2][:8] == 'voiceId=':
                        voiceId = command[i + 2].lstrip('voice=Id')
                    elif command[i + 2][:6] == 'speed=':
                        speed = command[i + 2].lstrip('speed=')
                    elif command[i + 2][:7] == 'volume=':
                        volume = command[i + 2].lstrip('volume=')
                    elif command[i + 2][:10] == 'audioType=':
                        audioType = command[i + 2].lstrip('audioType=')

                res_url = "https://api.ownthink.com/bot?appid=xiaosi&spoken=" + ask

                res = json.loads(get_html_text(res_url))

                print(res)
                if res["message"] == "error":
                    action.send_group_text_msg(ctx.FromGroupId, "对话请求错误!")
                    return
                elif not res["data"]["type"] == 5000:
                    action.send_group_text_msg(ctx.FromGroupId, "对话返回错误!")
                    return
                else:
                    text = res["data"]["info"]["text"]

                url = "https://dds.dui.ai/runtime/v1/synthesize?voiceId=" + voiceId + "&speed=" + speed + \
                   "&volume=" + volume + "&audioType=" + audioType + "&text=" + text

                action.send_group_voice_msg(ctx.FromGroupId, url)