Beispiel #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'])
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)
def receive_events(ctx: dict):
	if ctx['CurrentPacket']['Data']['EventName'] == "ON_EVENT_GROUP_JOIN" and\
			ctx['CurrentPacket']['Data']['EventData']['UserID'] == configuration.qq:
		action = Action(configuration.qq)
		plugins = PluginControl()
		msg_group_id = ctx['CurrentPacket']['Data']['EventMsg']['FromUin']

		msg = "爷来啦!\n\n默认开启插件:\n"
		for plugin_default in configuration.keywords_default:
			print(plugin_default)
			msg += plugins.add(plugin_default, msg_group_id)["content"] + '\n'
		msg.rstrip('\n')

		results = plugins.find_all(msg_group_id)

		content = "插件列表:\n"
		for key in plugins.keywords:
			flag = 0
			for result in results:
				if key == result["plugin"]:
					flag = 1
			is_opened = '(√) ' if flag else '(×) '
			content += is_opened + key + "\n"

		msg += "\n" + content

		action.send_group_text_msg(msg_group_id, msg)
Beispiel #4
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, "无法识别公式!")
Beispiel #5
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']
				)
Beispiel #6
0
def receive_group_msg(ctx: GroupMsg):
    if ctx.FromUserId != configuration.qq:
        if ctx.MsgType == 'TextMsg':
            commands = ctx.Content.split(' ')

            if len(commands) == 2 and commands[0] == "plugins":
                plugins = PluginControl()
                action = Action(configuration.qq)

                # list命令
                if commands[1] == "list":

                    results = plugins.find_all(ctx.FromGroupId)

                    content = "插件列表:\n"
                    for key in plugins.keywords:
                        flag = 0
                        for result in results:
                            if key == result["plugin"]:
                                flag = 1
                        is_opened = '(√) ' if flag else '(×) '
                        content += is_opened + key + "\n"

                    action.send_group_text_msg(ctx.FromGroupId,
                                               content=content)
Beispiel #7
0
def action_in_type(fromId, content, flag, result):
	if flag == 1:
		action = Action(configuration.qq)
		res = action.send_group_text_msg(fromId, content)
		if res["Ret"] == 241:
			time.sleep(1)
			return action.send_group_text_msg(fromId, content)
		else:
			return res
	else:
		return {"result": result, "content": content}
Beispiel #8
0
def admin_else(flag, content, fromId):
    content = content.lstrip('.').split(" ", 1)[0]

    if content not in admin_command_set:

        if flag == 1:
            action = Action(configuration.qq)
            action.send_group_text_msg(fromId, "不要乱发指令啊喂")
        elif flag == 2:
            action = Action(configuration.qq)
            action.send_friend_text_msg(fromId, "不要乱发指令啊喂")
        else:
            return {"result": True, "content": "不要乱发指令啊喂"}
Beispiel #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)
Beispiel #10
0
def admin_refresh(bot, flag, content, fromId):
	content = content.lstrip('.')

	if content == 'refresh':

		if flag == 1:
			bot.refresh_plugins()
			plugins = PluginControl()
			plugins.refresh()
			action = Action(configuration.qq)
			action.send_group_text_msg(fromId, '插件已刷新')
		elif flag == 2:
			bot.refresh_plugins()
			action = Action(configuration.qq)
			action.send_friend_text_msg(fromId, '插件已刷新')
		else:
			bot.refresh_plugins()
			return {"result": True, "content": '插件已刷新'}
Beispiel #11
0
def receive_events(ctx: EventMsg):
    # 这样写是因为第一次整这个插件时事件上下文还是字典,
    # 这里我因为懒得改了,所以这样写
    # 用对象的字段会方便和简洁一点,自己修改吧
    ctx = ctx.message  #
    ######################
    action = Action(ctx['CurrentQQ'])
    data = ctx['CurrentPacket']['Data']

    # 欢迎新群员
    if data['EventName'] == "ON_EVENT_GROUP_JOIN":
        uid = data['EventData']['UserID']
        uname = data['EventData']['UserName']
        gid = data['EventMsg']['FromUin']
        action.send_group_text_msg(gid, '欢迎<%s>入群![表情175]' % uname, uid)
        return

    # 群友退群
    if data['EventName'] == "ON_EVENT_GROUP_EXIT":
        uid = data['EventData']['UserID']
        gid = data['EventMsg']['FromUin']
        action.send_group_text_msg(
            gid, f'群友【{uid}】\n[表情107]离开了本群!\n[表情66]请珍惜在一起的每一分钟!')
        return
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
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="文件创建失败")
Beispiel #15
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非法时间格式!")
Beispiel #16
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)
Beispiel #17
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, "爷发现你输入了非法参数!")