예제 #1
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)
예제 #2
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)