Esempio n. 1
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

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

            if ctx.Content[:3] == "计时 ":

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

                command_time = ctx.Content.lstrip("计时 ")
                if time_shift(command_time):
                    sleep_time = time_shift(command_time)
                    if sleep_time > 4294967:
                        action.send_group_text_msg(ctx.FromGroupId,
                                                   "爷发现你输入了非法参数:\n设置时间过长!")
                    elif sleep_time < 0:
                        action.send_group_text_msg(ctx.FromGroupId,
                                                   "爷发现你输入了非法参数:\n设置时间为负!")
                    else:
                        action.send_group_text_msg(ctx.FromGroupId, "爷开始计时啦!")
                        time.sleep(sleep_time)
                        msg = " 计时 " + command_time + " 结束!"
                        action.send_group_text_msg(ctx.FromGroupId,
                                                   atUser=ctx.FromUserId,
                                                   content=msg)
                else:
                    action.send_group_text_msg(ctx.FromGroupId, "非法时间格式!")

            if ctx.Content[:3] == "闹钟 ":

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

                command = ctx.Content.lstrip("闹钟 ").split(' ', 1)
                time_array = alarm_shift(command[1])
                if time_array:
                    time_stamp = int(time.mktime(time_array))
                    sleep_time = time_stamp - int(time.time())
                    print(sleep_time)
                    if sleep_time <= 0:
                        action.send_group_text_msg(ctx.FromGroupId,
                                                   "爷发现你输入了非法参数:\n设定时间已过!")
                    else:
                        action.send_group_text_msg(ctx.FromGroupId, "爷设好闹钟啦!")
                        time.sleep(sleep_time)
                        msg = " 闹钟 " + f"""{command[0]}""" + " 到时间啦!"
                        action.send_group_text_msg(ctx.FromGroupId,
                                                   atUser=ctx.FromUserId,
                                                   content=msg)
                else:
                    action.send_group_text_msg(ctx.FromGroupId,
                                               "爷发现你输入了非法参数:\n非法时间格式!")
Esempio n. 2
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

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

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

            command = ctx.Content.split(' ')
            if command[0] == "百度" and len(command) > 1:
                baidu_content = get_text(command[1])
                url_new = "https:" + get_html_url("https://baike.baidu.com/search/word?word=" + command[1])
                print("内容", baidu_content, baidu_content == "")

                if baidu_content == "":
                    action.send_group_text_msg(ctx.FromGroupId, "爷没有搜索到结果!")
                else:
                    if len(command) == 2:
                        action.send_group_text_msg(ctx.FromGroupId, baidu_content[:] + url_new)
                    elif len(command) == 3:
                        try:
                            i = int(command[2])
                        except:
                            action.send_group_text_msg(ctx.FromGroupId, "爷发现你输入了非法参数!")
                        if i > 0:
                            action.send_group_text_msg(ctx.FromGroupId, baidu_content[:i] + "......\n\n" + url_new)
                        else:
                            action.send_group_text_msg(ctx.FromGroupId, "爷发现你输入了非法参数!")
                    else:
                        action.send_group_text_msg(ctx.FromGroupId, "爷发现你输入了非法参数!")
Esempio n. 3
0
def receive_events(ctx: dict):
	if ctx['CurrentPacket']['Data']['EventName'] == 'ON_EVENT_GROUP_REVOKE' and \
			ctx['CurrentPacket']['Data']['EventData']['UserID'] != configuration.qq:

		# check
		plugin = PluginControl()
		if not plugin.check("防撤回", ctx['CurrentPacket']['Data']['EventData']['UserID'],
							ctx['CurrentPacket']['Data']['EventData']['GroupID']):
			return

		action = Action(configuration.qq)
		msg_set = ctx['CurrentPacket']['Data']['EventData']
		msg_seq = msg_set['MsgSeq']
		msg_group_id = msg_set['GroupID']
		msg_revoke = find_group_msg_by_msg_seq(msg_seq, msg_group_id)
		if msg_revoke is None:
			logger.error('db.find returns null result')
			return
		if msg_revoke["msg_type"] == 'TextMsg':
			msg = "爷发现 " + msg_revoke["from_nickname"] + " 撤回了消息:\n\n"
			action.send_group_text_msg(msg_revoke["from_group_id"], msg + msg_revoke["content"])
		if msg_revoke["msg_type"] == 'PicMsg':
			msg = "爷发现 " + msg_revoke["from_nickname"] + " 撤回了图片:\n\n"
			msg_content = msg_revoke["content"] if msg_revoke["content"] is not None else ""
			action.send_group_text_msg(msg_revoke["from_group_id"], msg + msg_content)
			pics = msg_revoke["pics"]
			for pic_id in pics:
				pic_content = find_img_by_id(pic_id)
				action.send_group_pic_msg(
					msg_revoke["from_group_id"],
					fileMd5=pic_content['FileMd5'],
					picBase64Buf=pic_content['ForwordBuf']
				)
Esempio n. 4
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'])
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
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, "无法识别公式!")
Esempio n. 8
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

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

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

            command = ctx.Content.split(' ')
            if command[0] == "runpython" and len(command) == 2:

                if not judge_name(command[1]):
                    action.send_group_text_msg(ctx.FromGroupId,
                                               content="文件名非法")
                    return

                res = runpy(command[1])
                action.send_group_text_msg(ctx.FromGroupId, content=res)

            # 判断用\r还是\n
            char_r = ctx.Content.find('\r')
            char_n = ctx.Content.find('\n')
            if (char_r < char_n and char_r != -1) or char_n == -1:
                char = '\r'
            else:
                char = '\n'

            all_content = ctx.Content.split(char, 1)

            if len(all_content) == 2:
                command = all_content[0].split(' ')
                pycontent = all_content[1]

            if len(command) == 2 and command[0] == "newpython" and command[1][
                    -3:] == ".py":

                if not judge_name(command[1]):
                    action.send_group_text_msg(ctx.FromGroupId,
                                               content="文件名非法")
                    return

                if not judge_py(pycontent):
                    action.send_group_text_msg(ctx.FromGroupId, " 文件包含不允许的字符串")
                    return

                res = newpy(command[1], pycontent)

                if res:
                    action.send_group_text_msg(ctx.FromGroupId,
                                               content=command[1] + " 创建成功")
                else:
                    action.send_group_text_msg(ctx.FromGroupId,
                                               content="文件创建失败")
Esempio n. 9
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

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

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

            if ctx.Content[:5] == "echo ":
                command_test = ctx.Content[5:]
                action.send_group_text_msg(ctx.FromGroupId,
                                           content=command_test)
Esempio n. 10
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 == 'PicMsg':
            labels = ["drawings", "hentai", "neutral", "p**n", "sexy"]
            for key in labels:
                if ctx.Content.find(key) != -1:
                    time.sleep(15)
                    action.revoke_msg(ctx.FromGroupId, ctx.MsgSeq, ctx.MsgRandom)
Esempio n. 11
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] == "help":

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

				with open("res/json/help_group.json", 'r') as load_file:
					help_content = json.load(load_file)

				if len(command) == 1:

					content = "帮助:\n"
					for key, value in help_content.items():
						if key in plugin.keywords:
							content += '\n' + value + '\n'

					action.send_group_text_msg(ctx.FromGroupId, content)

				elif len(command) == 2 and command[1] == "admin":

					content = "管理员帮助:\n"

					with open("res/json/help_admin.json", 'r') as load_file:
						help_content = json.load(load_file)

					for key, value in help_content.items():
						content += '\n' + value + '\n'

					action.send_group_text_msg(ctx.FromGroupId, content)

				elif len(command) == 2:

					content = "帮助:"
					for key, value in help_content.items():
						if command[1] == key and key in plugin.keywords:
							content += value

					if not content == "帮助:":
						action.send_group_text_msg(ctx.FromGroupId, content)
Esempio n. 12
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] == "点歌":

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

                if len(command) == 2:
                    content = xml_get_qq(command[1])
                    print(content)
                    action.send_group_xml_msg(ctx.FromGroupId, content)
                if len(command) == 3:
                    content = xml_get_qq(command[1], int(command[2]))
                    print(content)
                    action.send_group_xml_msg(ctx.FromGroupId, content)
Esempio n. 13
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:

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

        action = Action(configuration.qq)
        if ctx.MsgType == 'AtMsg':
            all_content = json.loads(ctx.Content)
            content = all_content["Content"].split(" ", 1)[1]

            # 判断@的人
            if not all_content["UserID"][0] == configuration.qq:
                return

            if content == "爬" or content == "爪巴":
                plugin.blacklist.add(ctx.FromUserId,
                                     ctx.FromGroupId,
                                     10 * 60,
                                     srartTime=int(time.time()))
                action.send_group_text_msg(ctx.FromGroupId,
                                           content="爬什么爬,午夜凶铃啊!十分钟后再和我说话!",
                                           atUser=ctx.FromUserId)
            else:
                res_url = "https://api.ownthink.com/bot?appid=xiaosi&spoken=" + content

                res = json.loads(get_html_text(res_url))

                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"]

                action.send_group_text_msg(ctx.FromGroupId, text)
Esempio n. 14
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)