Example #1
0
def send_match_message(message,
                       to_user,
                       against_user,
                       players_dictionary,
                       debug=True):
    if to_user is None:
        return

    if against_user is None:
        message = 'This week, you have a bye. Relax and get some practice in.'
    else:
        message = message.replace("@against_user", '<@' + against_user + '>')

    if debug and to_user == bot_config.get_commissioner_slack_id():
        slack_client.chat.post_message(bot_config.get_commissioner_slack_id(),
                                       message,
                                       as_user=True)

    debug_message = message.replace(against_user,
                                    players_dictionary[against_user])
    if debug:
        return "Debug sent to " + players_dictionary[
            to_user] + ": " + debug_message

    if not debug:
        slack_client.chat.post_message(to_user, message, as_user=True)
        return "For reals sent to " + players_dictionary[
            to_user] + ": " + debug_message
Example #2
0
    def parse_message(self, command, poster):
        isAdmin = poster == bot_config.get_commissioner_slack_id()

        if command.startswith('me over '):
            winner = poster
            loser = self.parse_first_slack_id(command)
        elif command.startswith('<@') and command.index('over me') > 0:
            winner = self.parse_first_slack_id(command)
            loser = poster
        elif isAdmin and command.startswith('<@'):
            winner = self.parse_first_slack_id(command)
            loser = self.parse_second_slack_id(command)
        else:
            self.logger.debug('Bad message format')
            return None

        if winner == loser:
            self.logger.debug('Cant play against yourself')
            return None

        try:
            score_1, score_2 = self.parse_score(command)
        except Exception as e:
            self.logger.debug('Malformed score', e)
            return None

        return {
            'winner_id': winner,
            'loser_id': loser,
            'score_total': (score_1 + score_2)
        }
Example #3
0
    def enter_score(self, winner_id, loser_id, score_total, channel,
                    timestamp):
        try:
            if not db.update_match_by_id(winner_id, loser_id, score_total):
                self.slack_client.api_call(
                    "chat.postMessage",
                    channel=channel,
                    text='Not a match I have (or I messed up).',
                    as_user=True)
                self.slack_client.api_call("reactions.add",
                                           name="x",
                                           channel=channel,
                                           timestamp=timestamp)
                return

            self.slack_client.api_call(
                "chat.postMessage",
                channel=bot_config.get_commissioner_slack_id(),
                text='Entered into db',
                as_user=True)
            self.slack_client.api_call("reactions.add",
                                       name="white_check_mark",
                                       channel=channel,
                                       timestamp=timestamp)

        except Exception as e:
            self.slack_client.api_call(
                "chat.postMessage",
                channel=bot_config.get_commissioner_slack_id(),
                text='Failed to enter into db',
                as_user=True)
            self.slack_client.api_call("reactions.add",
                                       name="x",
                                       channel=channel,
                                       timestamp=timestamp)

            self.logger.error(e)
Example #4
0
def send_custom_messages(message, debug=True):
    players = db.get_active_players()

    if debug:
        slack_client.chat.post_message(bot_config.get_commissioner_slack_id(),
                                       message,
                                       as_user=True)

    sent_messages = ""
    for player in players:
        if debug:
            sent_messages = sent_messages + "Debug sent to " + player.name + ": " + message + "\n"
        else:
            slack_client.chat.post_message(player.slack_id,
                                           message,
                                           as_user=True)
            sent_messages = sent_messages + "For reals sent to " + player.name + ": " + message + "\n"

        time.sleep(1.5)

    return sent_messages
Example #5
0
def send_custom_for_missed_games(message, num_missed, week, debug=True):
    season = db.get_current_season()
    season_matches = db.get_matches_for_season(season)
    players = {}
    for match in season_matches:
        if match.week <= week and match.winner_id is None:
            if match.player_1_id not in players:
                players[match.player_1_id] = set()
            if match.player_2_id not in players:
                players[match.player_2_id] = set()

            players[match.player_1_id].add(match.week)
            players[match.player_2_id].add(match.week)

    for player_id in players:
        test = len(players[player_id])
        if len(players[player_id]) >= num_missed:
            if debug and not player_id == bot_config.get_commissioner_slack_id(
            ):
                print('Sending to', player_id, ':', message)
            else:
                # slack_client.chat.post_message(player_id, message, as_user=True)
                print('For reals sent to', player_id, ':', message)
            time.sleep(1.5)