예제 #1
0
파일: prack.py 프로젝트: martinb3/helpbot
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'])
        prs.ack(ack_pr)
        text = ":angel: %s has acknowledged PR review for %s!" % (username,
                                                                  ack_pr)
        outputs.append([channel, text, message_attrs])
예제 #2
0
파일: help.py 프로젝트: ryandub/helpbot
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])
예제 #3
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])
예제 #4
0
파일: prack.py 프로젝트: ryandub/helpbot
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])
예제 #5
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])
예제 #6
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])
예제 #7
0
파일: prtimer.py 프로젝트: ryandub/helpbot
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])
예제 #8
0
파일: prtimer.py 프로젝트: ryandub/helpbot
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])
예제 #9
0
파일: ack.py 프로젝트: ryandub/helpbot
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])
예제 #10
0
파일: ack.py 프로젝트: Gifflen/helpbot
def process_message(data):
    if data.get('text', '').startswith('!ack'):
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}
        channel = data.get('channel')

        # Only allow !invite 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'])
        halps.ack(ack_channel)
        text = ":angel: %s has acknowledged help for %s!" % (username,
                                                             ack_channel)
        outputs.append([channel, text, message_attrs])
예제 #11
0
파일: ack.py 프로젝트: martinb3/helpbot
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"])
        halps.ack(ack_channel)
        text = ":angel: %s has acknowledged help for %s!" % (username, ack_channel)
        outputs.append([channel, text, message_attrs])
예제 #12
0
def process_message(data):
    if data.get('text', '').split()[0] == '!invite':
        text = data.get('text').split()
        channel = data.get('channel')

        # Setup plugin
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}

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

        user = data.get('user')
        username = utils.get_user_name(user, slack_client)
        if len(text) > 1:
            invite_channel = text[1].strip('#')
        else:
            text = ("%s - to join a channel or private group type "
                    "`!invite <channel/group>`" % username)
            outputs.append([channel, text, message_attrs])
            return
        invite_channel_id = utils.get_channel_id_by_name(
            invite_channel, slack_client)
        invite = utils.invite_user(user, invite_channel_id, slack_client)
        if invite['ok']:
            text = "Invited %s to %s channel." % (username, invite_channel)
        else:
            text = ("Failed to invite %s to %s"
                    " channel - %s" % (username, invite_channel,
                                       invite.get('error', 'Unknown error!')))
        logging.info(text)
        print(text)
        outputs.append([channel, text, message_attrs])
예제 #13
0
파일: invite.py 프로젝트: martinb3/helpbot
def process_message(data):
    if data.get('text', '').split(' ')[0] == '!invite':
        text = data.get('text').split(' ')
        channel = data.get('channel')

        # Setup plugin
        admin_channel, botname, icon_emoji = utils.setup_bot(config)
        message_attrs = {'icon_emoji': icon_emoji, 'username': botname}

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

        user = data.get('user')
        username = utils.get_user_name(user, slack_client)
        if len(text) > 1:
            invite_channel = text[1].strip('#')
        else:
            text = ("%s - to join a channel or private group type "
                    "`!invite <channel/group>`" % username)
            outputs.append([channel, text, message_attrs])
            return
        invite_channel_id = utils.get_channel_id_by_name(invite_channel,
                                                         slack_client)
        invite = utils.invite_user(user, invite_channel_id, slack_client)
        if invite['ok']:
            text = "Invited %s to %s channel." % (username, invite_channel)
        else:
            text = ("Failed to invite %s to %s"
                    " channel - %s" % (username, invite_channel,
                                       invite.get('error', 'Unknown error!')))
        logging.info(text)
        print(text)
        outputs.append([channel, text, message_attrs])