Ejemplo n.º 1
0
def lookup(content, dst, srcName):
    log_info = ''
    content_new = content.replace('<br/>', '\n')
    buffer_content = content.split()
    info = ''

    date_time = datetime.datetime.now()
    name = ''
    if len(buffer_content) == 1:
        name = srcName.decode('UTF-8')
    elif len(buffer_content) == 2 and buffer_content[1].isalpha():
        name = buffer_content[1].decode('UTF-8')

    if name_dict.has_key(name):
        info = '[' + date_time.strftime(
            '%Y-%m-%d %H:%M') + ']: ' + name_dict[name] + ' login'
        check_info = {
            'name': name_dict[name],
            'time': date_time.strftime('%Y-%m-%d %H:%M')
        }
        log_info = ''
        msg = handleCheck(check_info, dst)
    else:
        msg = ''
    return msg, ''
Ejemplo n.º 2
0
def summary(content, dst, srcName):
    content_new = content.replace('<br/>', '\n')
    buffer_content = content.split()
    date_time = datetime.datetime.now()
    name = ''
    if len(buffer_content) == 1:
        name = srcName.decode('UTF-8')
    elif len(buffer_content) == 2 and buffer_content[1].isalpha():
        name = buffer_content[1].decode('UTF-8')

    if name_dict.has_key(name):
        check_info = {
            'name': name_dict[name],
            'time': date_time.strftime('%Y-%m-%d %H:%M')
        }
        msg = timeSum(check_info, dst)
    else:
        msg = ''

    return msg, ''
Ejemplo n.º 3
0
def logout(content, dst, srcName):
    date_time = datetime.datetime.now()
    name = srcName.decode('UTF-8')
    if name_dict.has_key(name):
        info = '[' + date_time.strftime(
            '%Y-%m-%d %H:%M') + ']: ' + name_dict[name] + ' logout'
        log_info = {
            'name': name_dict[name],
            'state': '0',
            'time': date_time.strftime('%Y-%m-%d %H:%M')
        }
        msg = info + '【自动回复】'
        extra_msg, flag = checkLogInfo(log_info)
        if not flag:
            msg = ''
    else:
        msg = ''
        extra_msg = ''

    return msg, extra_msg
Ejemplo n.º 4
0
def date_login(content, dst, srcName):
    try:
        if len(buffer_content) == 2 and buffer_content[0].isdigit(
        ) and buffer_content[1].isalpha():
            if len(buffer_content[0]) == 9:
                time = buffer_content[0][0:8]
                state = buffer_content[0][8]
                usr = buffer_content[1]

                date_time = datetime.datetime(datetime.date.today().year,
                                              int(buffer_content[0][0:2]),
                                              int(buffer_content[0][2:4]),
                                              int(buffer_content[0][4:6]),
                                              int(buffer_content[0][6:8]))

                if state is '1':
                    if name_dict.has_key(usr):
                        if usr == 'gjq':
                            date_time = date_time + datetime.timedelta(
                                0, 46800)
                            info = '[' + date_time.strftime(
                                '%Y-%m-%d %H:%M'
                            ) + ']: ' + name_dict[usr] + ' login'
                            log_info = {
                                'name': name_dict[usr],
                                'state': '1',
                                'time': date_time.strftime('%Y-%m-%d %H:%M')
                            }
                        else:
                            info = '[' + date_time.strftime(
                                '%Y-%m-%d %H:%M'
                            ) + ']: ' + name_dict[usr] + ' login'
                            log_info = {
                                'name': name_dict[usr],
                                'state': '1',
                                'time': date_time.strftime('%Y-%m-%d %H:%M')
                            }
                    else:
                        info = '用户未注册'
                        log_info = ''
                elif state is '0':
                    if name_dict.has_key(usr):
                        if usr == 'gjq':
                            date_time = date_time + datetime.timedelta(
                                0, 46800)
                            info = '[' + date_time.strftime(
                                '%Y-%m-%d %H:%M'
                            ) + ']: ' + name_dict[usr] + ' logout'
                            log_info = {
                                'name': name_dict[usr],
                                'state': '0',
                                'time': date_time.strftime('%Y-%m-%d %H:%M')
                            }
                        else:
                            info = '[' + date_time.strftime(
                                '%Y-%m-%d %H:%M'
                            ) + ']: ' + name_dict[usr] + ' logout'
                            log_info = {
                                'name': name_dict[usr],
                                'state': '0',
                                'time': date_time.strftime('%Y-%m-%d %H:%M')
                            }
                    else:
                        info = '用户未注册'
                        log_info = ''
                else:
                    info = 'error'
                    log_info = ''
            else:
                msg = '时间格式错误【自动回复】'
                log_info = ''
    except Exception, e:
        msg = ''
        log_info = ''
        pass
Ejemplo n.º 5
0
    def handleGroupMsg(self, content, srcName):
        log_info = ''
        content_new = content.replace('<br/>', '\n')
        buffer_content = content.split()
        info = ''
        # query keywords: query or q (for short).
        if buffer_content[0] == "状态" or buffer_content[0].lower(
        ) == "state" or buffer_content[0].lower() == "s":
            date_time = datetime.datetime.now()
            name = ''
            if len(buffer_content) == 1:
                name = srcName.decode('UTF-8')
            elif len(buffer_content) == 2 and buffer_conternt[1].isalpha():
                name = buffer_content[1].decode('UTF-8')

            if name_dict.has_key(name):
                check_info = {'name': name_dict[name]}
                log_info = ''
                return self.checkStatus(check_info)
        elif buffer_content[0] == "查询" or buffer_content[0].lower(
        ) == "query" or buffer_content[0].lower() == "q":
            date_time = datetime.datetime.now()
            name = ''
            if len(buffer_content) == 1:
                name = srcName.decode('UTF-8')
            elif len(buffer_content) == 2 and buffer_content[1].isalpha():
                name = buffer_content[1].decode('UTF-8')

            if name_dict.has_key(name):
                info = '[' + date_time.strftime(
                    '%Y-%m-%d %H:%M') + ']: ' + name_dict[name] + ' login'
                check_info = {
                    'name': name_dict[name],
                    'time': date_time.strftime('%Y-%m-%d %H:%M')
                }
                log_info = ''
                return self.handleCheck(check_info)
            else:
                info = '查无此人'
                log_info = ''
        # Response to "签入/签到" "签出"
        # login keywords: login or in (for short).
        elif content == "签入" or content == "签到" or content.lower(
        ) == "login" or content.lower() == "in":
            date_time = datetime.datetime.now()
            print repr(srcName)
            print srcName
            name = srcName.decode('UTF-8')
            if name_dict.has_key(name):
                info = '[' + date_time.strftime(
                    '%Y-%m-%d %H:%M') + ']: ' + name_dict[name] + ' login'
                log_info = {
                    'name': name_dict[name],
                    'state': '1',
                    'time': date_time.strftime('%Y-%m-%d %H:%M')
                }
            else:
                info = '用户未注册'
                log_info = ''
        # logout keywords: logout or out (for short).
        elif content == "签出" or content.lower() == "logout" or content.lower(
        ) == "out":
            date_time = datetime.datetime.now()
            name = srcName.decode('UTF-8')
            if name_dict.has_key(name):
                info = '[' + date_time.strftime(
                    '%Y-%m-%d %H:%M') + ']: ' + name_dict[name] + ' logout'
                log_info = {
                    'name': name_dict[name],
                    'state': '0',
                    'time': date_time.strftime('%Y-%m-%d %H:%M')
                }
            else:
                info = "用户未注册"
                log_info = ''
        # sum keywords: sum.
        elif content == "统计" or content.lower() == "sum":
            date_time = datetime.datetime.now()
            name = ''
            if len(buffer_content) == 1:
                name = srcName.decode('UTF-8')
            elif len(buffer_content) == 2 and buffer_content[1].isalpha():
                name = buffer_content[1].decode('UTF-8')

            if name_dict.has_key(name):
                check_info = {
                    'name': name_dict[name],
                    'time': date_time.strftime('%Y-%m-%d %H:%M')
                }
                return self.timeSum(check_info)
        # thisrank keywords: thisrank.
        elif content == "今日排名" or content == "今日排行" or content.lower(
        ) == "thisrank":
            date_time = datetime.datetime.now()
            name = srcName.decode('UTF-8')
            check_info = {
                'name': name_dict[name],
                'time': date_time.strftime('%Y-%m-%d %H:%M')
            }
            return self.thisRank(check_info)
        # rank keywords: rank.
        elif content == "排名" or content == "排行" or content.lower() == "rank":
            date_time = datetime.datetime.now()
            name = srcName.decode('UTF-8')
            check_info = {
                'name': name_dict[name],
                'time': date_time.strftime('%Y-%m-%d %H:%M')
            }
            return self.timeRank(check_info)
        elif content == "读取状态":
            return self.readStatus()
        elif content == "sudo清空重置":
            date_time = datetime.datetime.now()
            fn = 'data/data_' + date_time.strftime('%Y-%m-%d') + '.json'
            fd = open(fn, 'w+')
            for i in range(self.memberNum):
                line = (str)(self.state_in[i]) + '\t' + (str)(
                    self.last_login[i])
                for j in range(7):
                    line = line + '\t' + (str)(
                        self.online_time[j][i].total_seconds())
                line = line + '\t' + 'end' + '\n'
                fd.write(line)
            fd.close()
            for i in range(self.memberNum):
                self.state_in[i] = 0
                self.last_login[i] = self.time_init
                for j in range(7):
                    self.online_time[j][i] = datetime.timedelta(0)
            fd = open('cache', 'w+')
            for i in range(self.memberNum):
                line = (str)(self.state_in[i]) + '\t' + (str)(
                    self.last_login[i])
                for j in range(7):
                    line = line + '\t' + (str)(
                        self.online_time[j][i].total_seconds())
                line = line + '\t' + 'end' + '\n'
                fd.write(line)
            fd.close()
            return '重置成功'

        else:
            try:
                if len(buffer_content) == 2 and buffer_content[0].isdigit(
                ) and buffer_content[1].isalpha():
                    if len(buffer_content[0]) == 9:
                        time = buffer_content[0][0:8]
                        state = buffer_content[0][8]
                        usr = buffer_content[1]

                        date_time = datetime.datetime(
                            datetime.date.today().year,
                            int(buffer_content[0][0:2]),
                            int(buffer_content[0][2:4]),
                            int(buffer_content[0][4:6]),
                            int(buffer_content[0][6:8]))

                        if state is '1':
                            if name_dict.has_key(usr):
                                if usr == 'gjq':
                                    date_time = date_time + datetime.timedelta(
                                        0, 43200)
                                    info = '[' + date_time.strftime(
                                        '%Y-%m-%d %H:%M'
                                    ) + ']: ' + name_dict[usr] + ' login'
                                    log_info = {
                                        'name':
                                        name_dict[usr],
                                        'state':
                                        '1',
                                        'time':
                                        date_time.strftime('%Y-%m-%d %H:%M')
                                    }
                                else:
                                    info = '[' + date_time.strftime(
                                        '%Y-%m-%d %H:%M'
                                    ) + ']: ' + name_dict[usr] + ' login'
                                    log_info = {
                                        'name':
                                        name_dict[usr],
                                        'state':
                                        '1',
                                        'time':
                                        date_time.strftime('%Y-%m-%d %H:%M')
                                    }
                            else:
                                info = '用户未注册'
                                log_info = ''
                        elif state is '0':
                            if name_dict.has_key(usr):
                                if usr == 'gjq':
                                    date_time = date_time + datetime.timedelta(
                                        0, 43200)
                                    info = '[' + date_time.strftime(
                                        '%Y-%m-%d %H:%M'
                                    ) + ']: ' + name_dict[usr] + ' logout'
                                    log_info = {
                                        'name':
                                        name_dict[usr],
                                        'state':
                                        '0',
                                        'time':
                                        date_time.strftime('%Y-%m-%d %H:%M')
                                    }
                                else:
                                    info = '[' + date_time.strftime(
                                        '%Y-%m-%d %H:%M'
                                    ) + ']: ' + name_dict[usr] + ' logout'
                                    log_info = {
                                        'name':
                                        name_dict[usr],
                                        'state':
                                        '0',
                                        'time':
                                        date_time.strftime('%Y-%m-%d %H:%M')
                                    }
                            else:
                                info = '用户未注册'
                                log_info = ''
                        else:
                            info = 'error'
                            log_info = ''
                    else:
                        return '时间格式错误【自动回复】'
                        log_info = ''

            except Exception, e:
                return (str(e) + '【自动回复】')
                log_info = ''
                pass