Example #1
0
def process_message(data):
    """
    @keyword `.*tr-*8r.*`
    @summary who is the team traitor?
    @see _find the *tr8r*_
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    if check_channel(data['channel']) and check_text(".*tr-*8r.*", text):
        import requests
        url = "https://slack.com/api/chat.postMessage"
        payload = dict(
            token=token,
            channel=data['channel'],
            as_user=True,
            attachments=json.dumps([{
                "color":
                "#36a64f",
                "title":
                "TR-8R",
                "image_url":
                "http://media0.giphy.com/gifsu/3orifdw1bewQErOomI/giphy-caption.gif"
            }]))
        r = requests.post(url, data=payload)
        if r.status_code != 200:
            print r.status_code, r.text
Example #2
0
def process_message(data):
    """
    @keyword *channel bomb:* `^kevin.*channel bomb.*`
    @summary send a channel bomb to really get peoples attention.
    @see *channel bomb:* _*kevin* send a giant *channel bomb* right now_
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    if check_channel(data['channel']) and check_text("^kevin.*channel bomb.*",
                                                     text):
        import requests
        url = "https://slack.com/api/reactions.add"
        payload = dict(token=token,
                       name='bomb',
                       channel=data['channel'],
                       timestamp=data['ts'])
        r = requests.post(url, data=payload)
        if r.status_code != 200:
            print r.status_code, r.text
        bomb_count = randint(2, 10)
        lie_count = randint(2, 100)
        outputs.append([data['channel'], "Armed {} bombs".format(lie_count)])
        guid = uuid.uuid4().hex[0:10]
        conn = sqlite3.connect('kevin.db')
        with conn:
            conn.execute(
                "INSERT INTO JOBS (channel, name, parms, status) VALUES (?, 'channel_bomb', ?, 0)",
                (data['channel'], "{},{}".format(guid, bomb_count)))
            conn.execute(
                "INSERT INTO BOMBS (bomb_id, disarm_id, status) VALUES (?, 0, 0)",
                (guid, ))
            conn.commit()
Example #3
0
def process_message(data):
    """
    @keyword *close ticket:* `^kevin.*close.*ticket.*PC-\d+`
    @summary tired of those pesky prod change tickets just sitting in pending, in progress or open? Then ask kevin to close them
    @see *close ticket:* _*kevin* can you please just *close* the silly *ticket* *PC-1234*_
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    if check_channel(data['channel']) and check_text(
            "^kevin.*close.*ticket.*PC-\d+", text):
        # EXTRACT TICKET FROM STATMENT
        comp = re.compile("(PC-\d+)")
        result = comp.findall(text)
        if len(result) != 1:
            print "DIDNT FIND MATCH"
            outputs.append([data['channel'], "DIDNT FIND MATNC"])
        else:
            conn = sqlite3.connect('kevin.db')
            with conn:
                conn.execute(
                    "INSERT INTO JOBS (channel, name, parms, status) VALUES (?, 'close_ticket', ?, 0)",
                    (data['channel'], '{}'.format(result[0])))
                conn.commit()
            outputs.append(
                [data['channel'], "SQUAAAAWWKKK {}".format(result[0])])
Example #4
0
def process_message(data):
    """
    @keyword *add channel:* `^kevin.*add.*channel`
    @summary this will add the channel to kevin's listed channels she's allowed to post in. Command only works from an admin
    @see *add channel:* _*kevin* I want you to *add* this *channel*_
    """
    if 'subtype' in data and data['subtype'] == 'message_changed':
        text = data['message']['text']
        if 'user' in data['message']:
            user = data['message']['user']
    elif 'text' in data:
        text = data['text']
        if 'user' in data:
            user = data['user']
    else:
        text = ''
        user = ''
    reg_ex = "^kevin.*add.*channel"

    if check_text(reg_ex, text) and user == 'U03ADBTJ9':
        # LOAD YAML CONFIG AND ADD CHANNEL
        config = yaml.load(file('rtmbot.conf', 'r'))
        config['CHANNELS'].add(data['channel'].encode('ascii'))
        yaml.dump(config, file('rtmbot.conf', 'w'))
        # DUMP IT IN THE DB AS WELL SO CHANGES TAKE IMMEDIATE EFFECT
        conn = sqlite3.connect('kevin.db')
        with conn:
            conn.execute("INSERT INTO CHANNELS (channel) VALUES (?) ",
                         (data['channel'].encode('ascii'), ))
            conn.commit()
        # PRINT TO THE CHANNEL SO THAT ONE KNOWS THE JOB WORKED
        outputs.append(
            [data['channel'], "SQUAAAAWWKKK!\n{}".format(config['CHANNELS'])])
Example #5
0
def process_message(data):
    """
    @keyword *send the bombs:* `^kevin.*squawk @ \a*`
    @summary send a channel bomb directly at someone, in case the group channel bombs where not enough
    @see *send the bombs:* _*kevin* I need you to *squawk @ matts* to find out if he's at lagoon with colinm_
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    if check_channel(data['channel']) and check_text("^kevin.*squawk @ \a*",
                                                     text):
        culprit_id = data['user']
        culprit = get_culprit_name(culprit_id)
        url = "https://slack.com/api/users.list"
        payload = dict(token=token)
        r = requests.post(url, data=payload)
        if r.status_code != 200:
            print r.status_code, r.text
        members = r.json()['members']

        pos = text.find("@") + 1
        user_name = text[pos:].strip()

        user_id = None

        for member in members:
            if member['name'] == user_name:
                user_id = member['id']

        if user_id is None:
            print 'User not found'
        else:
            open_message(user_id, culprit)
Example #6
0
def process_message(data):
    """
    @keyword *aks kevin a question:* `^kevin.*\?`
    @summary Ask kevin anything you like, and she will try and find an answer for you, or a link for it
    @see *ask kevin a question:* _*kevin what is the average air speed velocity of an unladen swallow?*_
    """
    if 'subtype' in data and data['subtype'] == 'message_changed':
        text = data['message']['text']
    elif 'text' in data:
        text = data['text']
    else:
        text = ''

    reg_ex = "^kevin.*\?"
    bad_ex = [
        "^kevin.*version.*service", "^kevin.*service.*version",
        "^kevin.*result.*/[\w\d ]+/[\w\d /.]+/[\w\d/. ]+",
        "^kevin.*add.*channel", "^kevin.*witness me.*"
    ]
    # CHECK ALL THE KNOWN REGEX, CANNOT MATCH ANY OF THESE SO WE DON'T WOLFRAMFOR NO REASON
    match = False
    for reg in bad_ex:
        if check_text(reg, text):
            match = True
            break

    if check_channel(data['channel']):
        if check_text(reg_ex, text) and not match:
            # SEND JOB TO DB
            conn = sqlite3.connect('kevin.db')
            with conn:
                conn.execute(
                    "INSERT INTO JOBS (channel, name, parms, status) VALUES (?, 'wolfram', ?, 0)",
                    (data['channel'], text))
                conn.commit()
            outputs.append([data['channel'], "SQUAAAAWWKKK?"])
        elif (text.startswith('kevin')
              or text.startswith('kevin')) and not match:
            time.sleep(0.5)
            outputs.append([data['channel'], "*SQUAAAAWWKKK!*"])
Example #7
0
def process_message(data):
    """
    @keyword *disarm bomb:* `^kevin for great justice`
    @summary to disarm a channel bomb, you must do so for great justice.
    @see *disarm bomb:* _*kevin for great justice*_
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    print data
    if check_channel(data['channel']) and check_text(
            "^kevin for great justice", text):
        print "DISARMING BOMB"
        conn = sqlite3.connect('kevin.db')
        with conn:
            conn.execute(
                "INSERT INTO JOBS (channel, name, parms, status) VALUES (?, 'disarm_bomb', '', 0)",
                (data['channel'], ))
            conn.commit()
Example #8
0
def process_message(data):
    """
     *kevin* _[]_ *quotes* _[]_ *star_wars:{x}* _[]_
     This will set the quote type and quote rate in the config, accepts (star_wars, mad_max)
     _*kevin* I want you to set the *quotes* to *star_wars:2*
    """
    if 'subtype' in data and data['subtype'] == 'message_changed':
        text = data['message']['text']
        if 'user' in data['message']['user']:
            user = data['message']['user']
    elif 'text' in data:
        text = data['text']
        if 'user' in data:
            user = data['user']
    else:
        text = ''
        user = ''
    reg_ex = "^kevin.*quotes.*(star_wars|mad_max):\d"

    if check_text(reg_ex, text):
        # LOAD YAML CONFIG
        config = yaml.load(file('rtmbot.conf', 'r'))
        # GET QUOTE TYPE AND LEVEL
        ret = re.findall("^kevin.*quotes.*(star_wars|mad_max):(\d)", text,
                         re.IGNORECASE)
        if len(ret) > 0:
            quote_type = ret[0][0]
            quote_rate = ret[0][1]
        config['QUOTES'] = quote_type
        config['QUOTE_RATE'] = quote_rate
        yaml.dump(config, file('rtmbot.conf', 'w'))
        # DUMP IT IN THE DB AS WELL SO CHANGES TAKE IMMEDIATE EFFECT
        conn = sqlite3.connect('kevin.db')
        with conn:
            conn.execute("INSERT INTO CHANNELS (channel) VALUES (?) ",
                         (data['channel'].encode('ascii'), ))
            conn.commit()
        # PRINT TO THE CHANNEL SO THAT ONE KNOWS THE JOB WORKED
        outputs.append(
            [data['channel'], "SQUAAAAWWKKK!\n{}".format(config['CHANNELS'])])
Example #9
0
def process_message(data):
    """
    @keyword *giphy post:* `^kevin.*post.*[picture|gif|image] of (.*)`
    @summary ever want kevin to post a funny gif, now you can tell him to.
    @see_*kevin* could you *post* a *picture* *of* *Nicholas Cage*_
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    if check_channel(data['channel']) and check_text(
            "^kevin.*post.*[picture|gif|image] of .*", text):
        pos = text.find("of") + 2
        image_name = text[pos:].strip()
        image_tag = image_name.replace(" ", "+")
        import requests

        giphy_url = "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&rating=pg&tag={}".format(
            image_tag)
        r = requests.get(giphy_url)
        if r.status_code == 200:
            image_data = r.json()['data']
            if not image_data:
                outputs.append([data['channel'], "*SQUAAAAWWKKK! NOT FOUND!*"])
            else:
                image_url = image_data['image_url']
                url = "https://slack.com/api/chat.postMessage"
                payload = dict(token=token,
                               channel=data['channel'],
                               as_user=True,
                               attachments=json.dumps([{
                                   "color": "#36a64f",
                                   "title": image_name,
                                   "image_url": image_url
                               }]))
                r = requests.post(url, data=payload)
                if r.status_code != 200:
                    print r.status_code, r.text
Example #10
0
def process_message(data):
    """
    @keyword *prod change:* `^kevin.*prod change*(\\n|\|){2}`
    *kevin* _[]_ *prod change* _[]_ * _|[user]|[summary title]|[|more details]_
    @summary instead of switching context to jira just to make a silly change to ST2, have kevin make the prod change
    @see *prod change:* _*kevin* create *prod change* ticket *|steve|Rolling Latest PHP Core to ST2
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text'].encode('ascii', 'ignore')
    else:
        text = ''
    if check_channel(data['channel']) and check_text("^kevin.*prod change.*",
                                                     text):
        # EXTRACT TICKET DATA FROM STATEMENT
        print "Prod CHange"
        n_text = text.split("\n")
        p_text = text.split("|")
        if len(n_text) >= 3 or len(p_text) >= 3:
            # ASSIGN THE TEXT
            split_text = p_text if len(p_text) >= 3 else n_text
            # user_id = data['user']
            # user_name = get_culprit_name(user_id)
            user_name = split_text[1]
            summary = "{} - {}".format(user_name, split_text[2])
            # desc = "\n".join(split_text[3:])
            conn = sqlite3.connect('kevin.db')
            with conn:
                conn.execute(
                    "INSERT INTO JOBS (channel, name, parms, status) VALUES (?, 'prod_change', ?, 0)",
                    (data['channel'], '{}|{}'.format(user_name, summary)))
                conn.commit()
            outputs.append([data['channel'], 'Summary: {}'.format(summary)])
        else:
            print "NOT ENOUGH FIELDS: {}".format(text)
            outputs.append([
                data['channel'], "SQUAAAWWKK Not enough Fields for Prod change"
            ])
Example #11
0
def process_message(data):
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    if check_channel(data['channel']) and check_text("^kevin help", text):
        commands = ''
        examples = ''
        count = 0
        results = ''
        help_commands = "{}) *kevin help*\n\n" \
                   "{}) *kevin help examples*\n\n" \
                   "{}) *kevin help verbose*\n\n".format(count+1, count+2, count+3)
        count += 3
        directory = os.getcwd()
        for plugin in glob.glob(directory + '/plugins/*'):
            sys.path.insert(0, plugin)
            sys.path.insert(0, directory + "/plugins/")
        for plugin in glob.glob(directory + '/plugins/*.py') + glob.glob(directory + "/plugins/*/*.py"):
            name = plugin.split('/')[-1][:-3]
            module = __import__(name)
            # print module.__name__
            if hasattr(module, 'process_message'):
                # print module.process_message.__doc__
                doc_string = module.process_message.__doc__
                doc_dict = help_builder(doc_string)
                if len(doc_dict) > 0:
                    count += 1
                    results += "{count}) {keyword}\n{summary}\n{see}\n\n".format(count=count, **doc_dict)
                    commands += "{count}) {keyword}\n\n".format(count=count, keyword=doc_dict['keyword'])
                    examples += "{count} {see}\n\n".format(count=count, see=doc_dict['see'])
        if 'example' in text:
            outputs.append([data['channel'], help_commands + examples])
        elif 'verbose' in text:
            outputs.append([data['channel'], help_commands + results])
        else:
            outputs.append([data['channel'], help_commands + commands])
Example #12
0
def process_message(data):
    """
    @keyword *cage bomb:* `^(?i)kevin .*teach ([a-zA-Z]+) .*cage.*`
    @summary ever want to make sure your buddy knows more about Nicolas Cage? Kevin can teach them!
    @see *cage bomb:* _*kevin* please *teach* *colinm* about the great Nicolas *Cage*_
    """
    # IF ALL CHECKS PASS SEND JOB TO DB
    if 'text' in data:
        text = data['text']
    else:
        text = ''
    if check_channel(data['channel']) and check_text(
            "^(?i)kevin .*teach ([a-zA-Z]+) .*cage.*", text):
        import requests
        culprit_id = data['user']
        culprit = get_culprit_name(culprit_id)
        url = "https://slack.com/api/users.list"
        payload = dict(token=token)
        r = requests.post(url, data=payload, verify=False)
        if r.status_code != 200:
            print r.status_code, r.text
        members = r.json()['members']

        user_name = re.findall("^(?i)kevin.*teach ([a-zA-Z]+) .*cage.*",
                               text)[0]

        user_id = None

        for member in members:
            if member['name'] == user_name:
                user_id = member['id']

        if user_id is None:
            print 'User not found'
        else:
            open_message(user_id, culprit)