Пример #1
0
def main():
    try:
        count = 0
        while True:
            count += 1
            if count % SAVE_INTERVAL == 0:
                _save_cache()

            time.sleep(1)

            message = parse_next_msg()
            if not message:
                continue

            karma_changes = KARMA_ACTION.findall(message.text)
            if not karma_changes:
                continue

            logging.debug('karma changes: {}'.format(str(karma_changes)))
            process_karma_changes(message, karma_changes)
    finally:
        logging.info('Script ended, saving karma cache to file')
        # making sure we store karma cache before exiting the script, see
        # https://stackoverflow.com/questions/3850261/doing-something-before-program-exit
        _save_cache()
Пример #2
0
 def test_parse_next_msg(self):
     self.mock_rtm_read.return_value = None
     assert parse_next_msg() == None
     self.mock_rtm_read.return_value = [
         {'user': '******'}  # karmabot self
     ]
     assert parse_next_msg() == None
     channel, text = None, 'some text'
     assert parse_next_msg() == None
     channel, text = 'codechallenges', None
     assert parse_next_msg() == None
     channel, text, giverid = 'codechallenges', 'some new message', 'U5Z6ABCDE'
     self.mock_rtm_read.return_value = [
         {'user': giverid,
         'channel': channel,
         'text': text,}
     ]
     assert parse_next_msg() == Message(giverid=giverid, channel=channel, text=text)
Пример #3
0
def test_slack_team_join(mock_slack_rtm_read_team_join, mock_slack_api_call):
    user_id = SLACK_CLIENT.rtm_read()[0].get("user")["id"]
    welcome_text = welcome_user(user_id)

    actual = parse_next_msg()

    assert actual.user_id == KARMABOT_ID
    assert actual.channel_id == GENERAL_CHANNEL
    assert user_id in actual.text
    assert "Introduce yourself in #general if you like" in actual.text
Пример #4
0
def main():
    db_session.global_init()
    check_connection()

    while True:
        time.sleep(1)

        # Processes all interaction but karma changes
        message = parse_next_msg()
        if not message:
            continue

        # Finds and processes karma changes
        karma_changes = KARMA_ACTION.findall(message.text)
        if not karma_changes:
            continue

        logging.info(f"Karma changes: {str(karma_changes)}")
        process_karma_changes(message, karma_changes)
Пример #5
0
def main():
    try:
        count = 0
        while True:
            count += 1

            message = parse_next_msg()
            if not message:
                continue

            karma_changes = KARMA_ACTION.findall(message.text)
            if not karma_changes:
                continue

            logging.debug('karma changes: {}'.format(str(karma_changes)))
            """add exclusion list for channels to do karma in"""
            """give feedback if channel does not accept karma?"""
            process_karma_changes(message, karma_changes)
    finally:
        logging.info('Script ended, saving karma cache to file')