Exemple #1
0
    def modify_keywords_msg_reply(cls, content, reply_type):
        # 添加关键字消息回复策略 关键字 消息编号(多个用英文,分割)
        reply_type_name = MsgReply.get_reply_type_name(reply_type)

        content_arr = content.split(' ')
        if len(content_arr) != 3:
            cls.send_text_msg('格式不正确\n添加{0}消息回复策略 {1} 消息编号(多个用英文,分割)'.format(
                reply_type_name, reply_type_name))
            return
        keyword, msg_number = content_arr[1], content_arr[2]

        reply_model = MsgReply.get_model_filter(
            MsgReply.TopicId == cls.robot_model.TopicId,
            MsgReply.Condition == keyword, MsgReply.Type == reply_type)
        if reply_model is None:
            cls.send_text_msg('{0} [{1}] 不存在'.format(reply_type_name, keyword))
            return

        msg_numbers = msg_number.split(',')
        if len(msg_numbers) == 0:
            cls.send_text_msg('请输入消息编号')
            return

        msg_lib_models = Msg.get_models_filter(
            Msg.TopicId == cls.robot_model.TopicId, Msg.Id.in_(msg_numbers))
        if msg_lib_models is None or len(msg_numbers) != len(msg_lib_models):
            cls.send_text_msg('消息编号错误')
            return

        reply_model.MsgIds = msg_numbers
        MsgReply.save([reply_model], True)
        cls.send_text_msg('修改{0}消息回复策略成功'.format(reply_type_name))
Exemple #2
0
    def refresh_settings(cls):
        now = time.time()
        if now - cls.last_update_time < cls.UPDATE_SETTING_INTERVAL:
            return

        reply_models = MsgReply.get_models_filter(MsgReply.TopicId == cls.robot_model.TopicId)
        if reply_models is None:
            logger.warn('{0} not setting replay config'.format(cls.robot_model.TopicId))
            return

        logger.debug('refresh reply settings')
        cls.keywords_reply = {}
        cls.member_count_reply = {}
        cls.kick_member_keywords_replay = {}
        cls.kick_out_reply = {}

        for reply_model in reply_models:
            if reply_model.Type == MsgReply.TYPE_KEYWORDS_REPLY:
                cls.keywords_reply[reply_model.Condition] = reply_model.MsgIds
            elif reply_model.Type == MsgReply.TYPE_CHAT_ROOM_COUNT_REPLY:
                cls.member_count_reply[reply_model.Condition] = reply_model.MsgIds
            elif reply_model.Type == MsgReply.TYPE_KICK_KEYWORDS_REPLY:
                cls.kick_member_keywords_replay[reply_model.Condition] = reply_model.MsgIds
            elif reply_model.Type == MsgReply.TYPE_KICKOUT_REPLY:
                cls.kick_out_reply[reply_model.Condition] = reply_model.MsgIds

        cls.last_update_time = time.time()
Exemple #3
0
    def add_kick_out_keywords(cls, content):
        content_arr = content.split(' ')
        if len(content_arr) != 3:
            cls.send_text_msg('格式错误\n{0}'.format(cls.ADD_KICK_OUT_KEYWORDS))
            return
        _, keywords, msg_lib_ids = content_arr

        msg_lib_models = Msg.get_models_filter(
            Msg.TopicId == cls.robot_model.TopicId, Msg.Id.in_(msg_lib_ids))
        if msg_lib_models is None or len(msg_lib_ids) != len(msg_lib_models):
            cls.send_text_msg('消息编号错误')
            return

        MsgReply.add_reply(cls.robot_model.TopicId,
                           MsgReply.TYPE_KICK_KEYWORDS_REPLY,
                           keywords,
                           msg_lib_ids,
                           auto_commit=True)
        cls.send_text_msg('添加成功')
Exemple #4
0
    def del_kick_out_keywords(cls, content):
        content_arr = content.split(' ')
        if len(content_arr) != 2:
            cls.send_text_msg('格式错误\n{0}'.format(cls.DEL_KICK_OUT_KEYWORDS))
            return

        _, keywords = content_arr
        reply_model = MsgReply.get_model_filter(
            MsgReply.TopicId == cls.robot_model.TopicId,
            MsgReply.Condition == keywords,
            MsgReply.Type == MsgReply.TYPE_KICK_KEYWORDS_REPLY)

        if reply_model is None:
            cls.send_text_msg('{0} [{1}] 不存在'.format(
                MsgReply.get_reply_type_name(
                    MsgReply.TYPE_KICK_KEYWORDS_REPLY), keywords))
            return

        MsgReply.delete(reply_model, True)
        cls.send_text_msg('删除成功')
Exemple #5
0
    def show_all_msg_reply(cls, reply_type):

        reply_models = MsgReply.get_models_filter_by(
            TopicId=cls.robot_model.TopicId, Type=reply_type)
        if reply_models is None or len(reply_models) == 0:
            cls.send_text_msg('你还没有{0}回复'.format(
                MsgReply.get_reply_type_name(reply_type)))
            return None

        msg = ''
        n = 0
        for reply_model in reply_models:
            msg += '{0} 回复消息编号: {1}\n'.format(reply_model.Condition,
                                              reply_model._MsgIds)
            n += 1
            if n % 15 == 0:
                cls.send_text_msg(msg)
                msg = ''

        if len(msg) > 0:
            cls.send_text_msg(msg)
Exemple #6
0
    def add_keyword_msg_reply(cls, content, reply_type):
        # 添加关键字消息回复策略 关键字 消息编号(多个用英文,分割)
        reply_type_name = MsgReply.get_reply_type_name(reply_type)

        content_arr = content.split(' ')
        if len(content_arr) != 3:
            cls.send_text_msg('格式不正确\n添加{0}消息回复策略 {1} 消息编号(多个用英文,分割)'.format(
                reply_type_name, reply_type_name))
            return
        keyword, msg_number = content_arr[1], content_arr[2]

        reply_model = MsgReply.get_model_filter(
            MsgReply.TopicId == cls.robot_model.TopicId,
            MsgReply.Condition == keyword, MsgReply.Type == reply_type)
        if reply_model:
            cls.send_text_msg('{0} [{1}] 已存在'.format(reply_type_name, keyword))
            return

        msg_numbers = msg_number.split(',')
        if len(msg_numbers) == 0:
            cls.send_text_msg('请输入消息编号')
            return

        msg_lib_models = Msg.get_models_filter(
            Msg.TopicId == cls.robot_model.TopicId, Msg.Id.in_(msg_numbers))
        if msg_lib_models is None or len(msg_numbers) != len(msg_lib_models):
            cls.send_text_msg('消息编号错误')
            return

        tips = '失败'
        if MsgReply.add_reply(cls.robot_model.TopicId,
                              reply_type,
                              keyword,
                              msg_numbers,
                              auto_commit=True):
            tips = '成功'
        cls.send_text_msg('添加{0}消息回复策略-{1}'.format(reply_type_name, tips))
Exemple #7
0
    def del_keyword_msg_reply(cls, content, reply_type):
        """删除关键字消息回复策略 关键字"""
        content_arr = content.split(' ')
        if len(content_arr) != 2:
            cls.send_text_msg('格式不正确\n删除{0}消息回复策略 {1}'.format(
                MsgReply.get_reply_type_name(reply_type),
                MsgReply.get_reply_type_name(reply_type)))
            return

        keywords = content_arr[1]
        reply_model = MsgReply.get_model_filter(
            MsgReply.TopicId == cls.robot_model.TopicId,
            MsgReply.Condition == keywords, MsgReply.Type == reply_type)
        if reply_model is None:
            cls.send_text_msg('{0} [{1}] 消息回复不存在'.format(
                MsgReply.get_reply_type_name(reply_type), keywords))
            return

        MsgReply.delete(reply_model, True)
        cls.send_text_msg('删除成功')