Beispiel #1
0
def command_yes(job, chan):
    number = 0
    data = open('lol.txt').read()
    if (data != ''):
        if 'yes' in data:
            sc.api_call('chat.postMessage',
                        as_user='******',
                        channel=chan,
                        text='Build is started')
            sc.api_call('chat.postMessage',
                        as_user='******',
                        channel=chan,
                        text=build.slack_build_job_jenkins(job))
            connect.clear_write_chat()
            number = 2
            return number
        elif 'no' in data:
            sc.api_call('chat.postMessage',
                        as_user='******',
                        channel=chan,
                        text='Okay, then i finish work')
            number = 2
            connect.clear_write_chat()
            return number
    else:
        return number
Beispiel #2
0
def change_request():
    message = open('write_chats.txt').read()
    num = 0
    oldpart = ''
    if "change my request" in message:
        message = request(message)
        chan = connect.get_channel()
        oldpart = all_strings(message)
        print(oldpart)
        if oldpart != '':
            sc.api_call('chat.postMessage', as_user='******', channel=connect.get_channel(), text='Write new request')
            num = 1
        else :
            sc.api_call('chat.postMessage', as_user='******', channel=connect.get_channel(), text='So request isn`t found')
            num = 3
        connect.clear_write_chat()
    while(num == 1):
        num = 2
    while(num == 2):
        new_message = open('write_chats.txt').read()
        if 'rechange to' in new_message:
            f = open('ask.txt','a')
            textwrite = '\n' + oldpart + new_request(new_message)
            f.write(textwrite)
            num = 3
            sc.api_call('chat.postMessage', as_user='******', channel=connect.get_channel(), text='I change it')
            connect.clear_write_chat()
Beispiel #3
0
def command_stop_watching():
    number = 0
    message = open('write_chats.txt').read()
    stopfile = open('stop.txt', 'w')
    if (message != ''):
        if 'stop watching' in message:
            text = 'stop it'
            file_stop = stopfile.write(text)
            connect.clear_write_chat()
Beispiel #4
0
def status_project():
    message = open('write_chats.txt').readlines()
    for i in range(0,len(message)):
        if 'what about' in message[i]:
            chan = connect.get_channel()
            text = message[i]
            connect.clear_write_chat()
            report = check_status_project(get_job(text))
            if report != 'Name of project is not right':
                report= 'status is ' + report
            sc.api_call('chat.postMessage', as_user='******', channel=chan, text=report)
Beispiel #5
0
def build_project():
    message = open('write_chats.txt').readlines()
    text = ''
    chan = ''
    for i in range(0,len(message)):
        if 'build please' in message[i]:
            chan = connect.get_channel()
            text = message[i]
            connect.clear_write_chat()
    if(text != ''):
        if status.check_status_project(status.get_job(text)) != 'In process, wait the end of build' :
            sc.api_call('chat.postMessage', as_user='******', channel=chan, text='Build started now!')
        else :
            sc.api_call('chat.postMessage', as_user='******', channel=chan, text='build already start, please wait!')
        sc.api_call('chat.postMessage', as_user='******', channel=chan, text=slack_build_job_jenkins(status.get_job(text)))
Beispiel #6
0
def delete_remind():
    text = ''
    number = 0
    send = 'Sorry, i don`t remind you at that time'
    job = ''
    chan = connect.get_channel()
    file1 = open('write_chats.txt').readlines()
    file2 = open('remindlist.txt').readlines()
    connect.clear_write_chat()
    for i in range(0, len(file1)):
        if 'stop_remind' in file1[i]:
            number = 5
            text = file1[i]
            job = status.get_job(text)
            if ('every' in job):
                if 'a.m.' in job:
                    job = job.replace('a.m.', '')
            else:
                number_start = job.find('at') + 3
                number_end = len(job)
                noformat_job = job[0:number_start]
                format_job = job[number_start:number_end]
                format_job = create_remind.format_date(format_job)
                job = noformat_job + format_job
            for i in range(0, len(file2)):
                if job in file2[i]:
                    file3 = open('remindlist.txt', 'w')
                    send = 'Okay, i stop to remind you about this'
                    text = file2[i]
                    text = text.replace(job, '')
                    file2[i] = text
                    file3 = file3.writelines(file2)
                    if 'every' in file2[i]:
                        remind_function.refresh_remind()
                        remind_function.shed_date_final()
        if (number == 5):
            sc.api_call('chat.postMessage',
                        as_user='******',
                        channel=chan,
                        text=send)
Beispiel #7
0
def eye_on_server():
    message = open('write_chats.txt').readlines()
    for i in range(0, len(message)):
        if 'watching to' in message[i]:
            text = message[i]
            chan = connect.get_channel()
            job = status.get_job(text)
            connect.clear_write_chat()
            if (status.check_status_project(get_server_and_job(job)[1]) ==
                    'Name of project is not right'):
                sc.api_call('chat.postMessage',
                            as_user='******',
                            channel=chan,
                            text='Name of project is not right')
            else:
                sc.api_call('chat.postMessage',
                            as_user='******',
                            channel=chan,
                            text='Ok, i will keep an eye on it')
                while (ping_the_server(get_server_and_job(job)[0]) !=
                       'server is down!'):
                    for i in range(0, 600):
                        stopfile = open('stop.txt').read()
                        if (stopfile != ''):
                            if 'stop it' in stopfile:
                                sc.api_call(
                                    'chat.postMessage',
                                    as_user='******',
                                    channel=chan,
                                    text='Ok, i end watching on server')
                                return True
                        else:
                            time.sleep(0.1)
                else:
                    job_Name = get_server_and_job(job)[1]
                    build_or_nothing(job_Name,
                                     get_server_and_job(job)[0], chan)
                    connect.clear_write_chat()
Beispiel #8
0
def command_hello():
    message = open('write_chats.txt').read()
    if 'hi jean' in message:
        sc.api_call('chat.postMessage', as_user='******', channel=connect.get_channel(),text="hello, if you need help, use command help")
        connect.clear_write_chat()
Beispiel #9
0
def write_remindlist():
    text = ''
    send = ''
    job = ''
    chan = connect.get_channel()
    file3 = open('remindlist.txt').read()
    file1 = open('write_chats.txt').readlines()
    file2 = open('remindlist.txt', 'a')
    for i in range(0, len(file1)):
        try:
            if ' remind' in file1[i]:
                text = file1[i]
                job = status.get_job(text)
                number_start = job.find('at') + 3
                number_end = len(job)
                noformat_job = job[0:number_start]
                format_job = job[number_start:number_end]
                if not ':' in job:
                    time = re.findall('(\d+)', format_job)
                    time_replace = time[0] + ':' + '00'
                    format_job = format_job.replace(time[0], time_replace)
                    job = noformat_job + format_job
                if ('every' in job):
                    if 'p.m.' in job:
                        time = re.findall('(\d+)', format_job)
                        time_replace = time[0] + ':'
                        time_null = str(int(time[0]) + 12) + ':'
                        format_job = format_job.replace(
                            time_replace, time_null)
                        format_job = format_job.replace('p.m.', '')
                        job = noformat_job + format_job
                    if 'a.m.' in job:
                        job = job.replace('a.m.', '')
                        job = '@' + job
                else:
                    format_job = format_date(format_job)
                    job = '@' + noformat_job + format_job
                if job in file3:
                    send = 'So remind already has in remindlist'
                    sc.api_call('chat.postMessage',
                                as_user='******',
                                channel=chan,
                                text=send)
                else:
                    if(verify.verify_username(i) == 'Void') or \
                        (verify.verify_eventname(i) == 'Void') or (verify.verify_time_and_date(i) == 'Void'):
                        sc.api_call('chat.postMessage',
                                    as_user='******',
                                    channel=chan,
                                    text='Incorrect data')
                    else:
                        if 'channel' in verify.verify_username(i):
                            send = 'Okay, i will remind ' + '<!channel>'
                        elif '@' in verify.verify_username(i):
                            send = 'Okay, i will remind ' + '<' + verify.verify_username(
                                i) + '>'
                        else:
                            send = 'Okay, i will remind ' + verify.verify_username(
                                i)
                        file2 = file2.write(chan + ' ' + job + '\n')
                        sc.api_call('chat.postMessage',
                                    as_user='******',
                                    channel=chan,
                                    text=send)
                connect.clear_write_chat()
        except IndexError:
            sc.api_call('chat.postMessage',
                        as_user='******',
                        channel=chan,
                        text='Incorrect time')
            connect.clear_write_chat()