def createPostGameThread(game): gameThread = getPostGameThreadText(game) gameTitle = "Default Stuff M'kay" if game['status']['forfeit']: badPerson = None if game['home']['playclockPenalties'] == 3: badPerson = 'home' else: badPerson = 'away' gameTitle = 'POSTGAME: {} wins after {} forfeits due to too many \ delay of games'.format(game[reverseHomeAway(badPerson)]['name'], game[badPerson]['name']) elif game['status']['endBoth']: gameTitle = 'POSTGAME: {} and {} both forfeit simultaneously'.format( game['home']['name'], game['away']['name']) elif game['score']['away'] > game['score']['home']: gameTitle = 'POSTGAME: {} defeats {} , {} to {}'.format( game['away']['name'], game['home']['name'], game['score']['away'], game['score']['home']) else: gameTitle = 'POSTGAME: {} defeats {} , {} to {}'.format( game['home']['name'], game['away']['name'], game['score']['home'], game['score']['away']) reddit.submitSelfPost(globals.SUBREDDIT, gameTitle, gameThread)
def startGame(homeTeam, awayTeam, startTime=None, location=None, station=None, homeRecord=None, awayRecord=None): log.debug("Creating new game between {} and {}".format(homeTeam, awayTeam)) result = verifyTeams([homeTeam, awayTeam]) if result is not None: log.debug("Coaches not verified, {}".format(result)) return "Something went wrong, someone is no longer an acceptable coach. Please try to start the game again" homeTeam = wiki.getTeamByTag(homeTeam.lower()) awayTeam = wiki.getTeamByTag(awayTeam.lower()) game = newGameObject(homeTeam, awayTeam) if startTime is not None: game.startTime = startTime if location is not None: game.location = location if station is not None: game.station = station if homeRecord is not None: homeTeam.record = homeRecord if awayRecord is not None: awayTeam.record = awayRecord gameThread = string_utils.renderGame(game) gameTitle = "[GAME THREAD] {}{} @ {}{}".format( "{} ".format(string_utils.unescapeMarkdown(awayRecord)) if awayRecord is not None else "", game.away.name, "{} ".format(string_utils.unescapeMarkdown(homeRecord)) if homeRecord is not None else "", game.home.name) threadID = str( reddit.submitSelfPost(globals.SUBREDDIT, gameTitle, gameThread)) game.thread = threadID log.debug("Game thread created: {}".format(threadID)) index.addNewGame(game) for user in game.home.coaches: log.debug("Coach added to home: {}".format(user)) for user in game.away.coaches: log.debug("Coach added to away: {}".format(user)) log.debug("Game started, posting coin toss comment") message = "{}\n\n" \ "The game has started! {}, you're home. {}, you're away, call **heads** or **tails** in the air." \ .format(wiki.intro, string_utils.getCoachString(game, True), string_utils.getCoachString(game, False)) sendGameComment(game, message, getActionTable(game, Action.COIN)) log.debug("Comment posted, now waiting on: {}".format( game.status.waitingId)) updateGameThread(game) log.debug("Returning game started message") return "Game started. Find it [here]({}).".format( string_utils.getLinkToThread(threadID))
def processMessageAcceptGame(dataTable, author): log.debug("Processing accept game message") if 'opponent' not in dataTable: log.warning("Couldn't find opponent in datatable") return False, "I couldn't figure out which opponent you were accepting. This shouldn't happen, please let /u/Watchful1 know" coachNum, result = utils.verifyCoaches([author, dataTable['opponent']]) if coachNum != -1: log.debug("Coaches not verified, {} : {}".format(coachNum, result)) return False, "Something went wrong, someone is no longer an acceptable coach. Please try to start the game again" homeTeam = wiki.getTeamByCoach(dataTable['opponent'].lower()) awayTeam = wiki.getTeamByCoach(author.lower()) for team in [homeTeam, awayTeam]: team['yardsPassing'] = 0 team['yardsRushing'] = 0 team['yardsTotal'] = 0 team['turnoverInterceptions'] = 0 team['turnoverFumble'] = 0 team['fieldGoalsScored'] = 0 team['fieldGoalsAttempted'] = 0 team['posTime'] = 0 game = utils.newGameObject(homeTeam, awayTeam) gameThread = utils.getGameThreadText(game) gameTitle = "[GAME THREAD] {} @ {}".format(game['away']['name'], game['home']['name']) threadID = str( reddit.submitSelfPost(globals.SUBREDDIT, gameTitle, gameThread)) game['thread'] = threadID log.debug("Game thread created: {}".format(threadID)) gameID = database.createNewGame(threadID) game['dataID'] = gameID log.debug("Game database record created: {}".format(gameID)) for user in game['home']['coaches']: database.addCoach(gameID, user, True) log.debug("Coach added to home: {}".format(user)) for user in game['away']['coaches']: database.addCoach(gameID, user, False) log.debug("Coach added to away: {}".format(user)) log.debug("Game started, posting coin toss comment") message = "The game has started! {}, you're away, call **heads** or **tails** in the air.".format( utils.getCoachString(game, 'away')) comment = utils.sendGameComment(game, message, {'action': 'coin'}) game['waitingId'] = comment.fullname log.debug("Comment posted, now waiting on: {}".format(game['waitingId'])) utils.updateGameThread(game) log.debug("Returning game started message") return True, "Game started. Find it [here]({}).".format( utils.getLinkToThread(threadID))
def endGame(game, winner, postThread=True): game.status.quarterType = QuarterType.END game.status.waitingAction = Action.END game.status.winner = winner if game.status.down > 4: game.status.down = 4 index.endGame(game) if postThread: postGameThread = renderPostGame(game) winnerHome = True if game.status.winner == game.home.name else False gameTitle = "[POST GAME THREAD] {} defeats {}, {}-{}".format( game.team(winnerHome).name, game.team(not winnerHome).name, game.status.state(winnerHome).points, game.status.state(not winnerHome).points) threadID = str( reddit.submitSelfPost(globals.SUBREDDIT, gameTitle, postGameThread)) return "[Post game thread]({}).".format(getLinkToThread(threadID)) else: return None
def startGame(homeCoach, awayCoach, startTime=None, location=None, station=None, homeRecord=None, awayRecord=None, neutral=False): log.debug("Creating new game between /u/{} and /u/{}".format( homeCoach, awayCoach)) coachNum, result = verifyCoaches([homeCoach, awayCoach]) if coachNum != -1: log.debug("Coaches not verified, {} : {}".format(coachNum, result)) return "Something went wrong, someone is no longer an \ acceptable coach. Please try to start the game again" homeTeam = wiki.getTeamByCoach(homeCoach.lower()) awayTeam = wiki.getTeamByCoach(awayCoach.lower()) for team in [homeTeam, awayTeam]: team['2PtAttempted'] = 0 team['2PtMade'] = 0 team['3PtAttempted'] = 0 team['3PtMade'] = 0 team['turnovers'] = 0 team['FTAttempted'] = 0 team['FTMade'] = 0 team['posTime'] = 0 team['record'] = None team['playclockPenalties'] = 0 team['bonus'] = 'N' team['offRebound'] = 0 team['defRebound'] = 0 team['fouls'] = [0, 0] team['steals'] = 0 team['blocks'] = 0 team['offDiffs'] = [] team['defDiffs'] = [] team['possessions'] = 0 game = newGameObject(homeTeam, awayTeam) if startTime is not None: game['startTime'] = startTime if location is not None: game['location'] = location if station is not None: game['station'] = station if homeRecord is not None: homeTeam['record'] = homeRecord if awayRecord is not None: awayTeam['record'] = awayRecord game['neutral'] = neutral gameThread = getGameThreadText(game) gameTitle = "[GAME THREAD] {}{} @ {}{}".format( game['away']['name'], " {}".format(awayRecord) if awayRecord is not None else "", game['home']['name'], " {}".format(homeRecord) if homeRecord is not None else "") threadID = str( reddit.submitSelfPost(globals.SUBREDDIT, gameTitle, gameThread)) game['thread'] = threadID log.debug("Game thread created: {}".format(threadID)) gameID = database.createNewGame(threadID) game['dataID'] = gameID log.debug("Game database record created: {}".format(gameID)) for user in game['home']['coaches']: database.addCoach(gameID, user, True) log.debug("Coach added to home: {}".format(user)) for user in game['away']['coaches']: database.addCoach(gameID, user, False) log.debug("Coach added to away: {}".format(user)) log.debug("Game started, posting tip ball comment") message = "The ball is thrown in the air! {}, {}, Respond to the DM message \ I sent you for a TIP number".format(getCoachString(game, 'home'), getCoachString(game, 'away')) sendGameComment(game, message, {'action': 'tip'}) log.debug("Comment posted, now waiting on both") updateGameThread(game) coaches = [game['home']['coaches'][0], game['away']['coaches'][0]] sendTipNumberMessages(game, coaches) log.debug("Returning game started message") return "Game started. Find it [here]({}).".format( getLinkToThread(threadID))