Пример #1
0
def process_message(data):
    if data.get('text', '').split()[0] == '!help':
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}

        # Translate channel id to channel name
        channel = data.get('channel')
        channel_name = utils.get_channel_name(channel, slack_client)

        # Translate user id to username
        user = data.get('user')
        username = utils.get_user_name(user, slack_client)

        # Store help request in Redis
        halps = helps.Helps(config['redis'])
        stored = halps.store(channel_name, username, data.get('ts'))

        if stored:
            text = "%s needs help in %s!" % (username, channel_name)
            outputs.append([admin_channel, text, message_attrs])

        text = ("Thanks %s, your help request has been received."
                " A DevOps Support Racker will be with you shortly." %
                username)
        outputs.append([channel, text, message_attrs])
Пример #2
0
def process_message(data):
    if data.get('text', '').split()[0] == ('!pr'):
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}

        # Translate channel id to channel name
        channel = data.get('channel')

        # Only allow !pr from admin_channel
        admin_channel_id = utils.get_channel_id_by_name(admin_channel,
                                                        slack_client)
        if admin_channel_id not in channel:
            return

        # Translate user id to username
        user = data.get('user')
        username = utils.get_user_name(user, slack_client)

        text = data.get('text').split()
        if len(text) > 1:
            link = text[1]
        else:
            text = ("%s - to request PR help, type "
                    "`!pr <link-to-pr>`" % username)
            outputs.append([channel, text, message_attrs])
            return

        # Store pr request in Redis
        prs = helps.Helps(config['redis'])
        stored = prs.store(link, username, data.get('ts'))

        if stored:
            text = "%s needs this PR reviewed: %s" % (username, link)
            outputs.append([admin_channel, text, message_attrs])
Пример #3
0
def process_message(data):
    if data.get('text', '').split()[0] == '!ack-pr':
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}
        channel = data.get('channel')

        # Only allow !ack-pr from admin_channel
        admin_channel_id = utils.get_channel_id_by_name(
            admin_channel, slack_client)
        if admin_channel_id not in channel:
            return

        acktext = data['text'].split()
        user = data.get('user')
        username = utils.get_user_name(user, slack_client)
        if len(acktext) > 1:
            ack_pr = acktext[1]
        else:
            text = ("%s - to acknowledge PR requests, type "
                    "`!ack-pr <link_to_pr>`" % username)
            outputs.append([channel, text, message_attrs])
            return

        prs = helps.Helps(config['redis'])
        count = prs.ack_pr(ack_pr, username)
        text = ":angel: %s has acknowledged PR review for %s!" % (username,
                                                                  ack_pr)
        if count is not None and count > 0.0:
            text = text + " %s has acknowledged %d PRs since tracking began." % (
                username, count)

        outputs.append([channel, text, message_attrs])
Пример #4
0
def helptimer():
    admin_channel, botname, icon_emoji = utils.setup_bot(config)
    message_attrs = {'icon_emoji': icon_emoji, 'username': botname}
    admin_channel_id = utils.get_channel_id_by_name(admin_channel,
                                                    slack_client)
    halps = helps.Helps(config['redis'])
    all_halps = halps.get_all()
    text = utils.format_helps(all_halps)
    if text:
        text.insert(0, "These customers need help!")
        text = '\n'.join(text)
        outputs.append([admin_channel_id, text, message_attrs])
Пример #5
0
def prtimer():
    prs = helps.Helps(config['redis'])
    all_prs = prs.get_all()
    text = utils.format_prs(all_prs)
    if text:
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}
        admin_channel_id = utils.get_channel_id_by_name(
            admin_channel, slack_client)
        text.insert(0, "These Pull Requests need review!")
        text.append("To acknowledge PR requests, type `!ack-pr <link_to_pr>`")
        text = '\n'.join(text)
        outputs.append([admin_channel_id, text, message_attrs])
Пример #6
0
def process_message(data):
    if data.get('text', '').split()[0] == '!ack':
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}
        channel = data.get('channel')

        # Only allow !ack from admin_channel
        admin_channel_id = utils.get_channel_id_by_name(
            admin_channel, slack_client)
        if admin_channel_id not in channel:
            return

        acktext = data['text'].split()
        user = data.get('user')
        username = utils.get_user_name(user, slack_client)
        if len(acktext) > 1:
            ack_channel = acktext[1].strip('#')
        else:
            text = ("%s - to acknowledge help requests, type "
                    "`!ack <channel>`" % username)
            outputs.append([channel, text, message_attrs])
            return
        ack_channel_id = utils.get_channel_id_by_name(ack_channel,
                                                      slack_client)
        invite = utils.invite_user(user, ack_channel_id, slack_client)
        if invite['ok']:
            logging.info("Invited %s to %s channel." % (username, ack_channel))
        else:
            text = (
                "Failed to invite %s to %s"
                " channel - %s" %
                (username, ack_channel, invite.get('error', 'Unknown error!')))
            logging.info(text)
            outputs.append([channel, text, message_attrs])
            return
        halps = helps.Helps(config['redis'])
        count = halps.ack_help(ack_channel, username)
        text = ":angel: %s has acknowledged help for %s!" % (username,
                                                             ack_channel)

        if count is not None and count > 0.0:
            text = text + " %s has acknowledged %d requests for help since tracking began." % (
                username, count)

        outputs.append([channel, text, message_attrs])