def processMessageDefenseNumber(game, message, author): numberMessage = None resultMessage = None log.debug("Processing defense number message") if message.find(globals.intFoul) > -1: log.debug('defense will commit an intentional foul') game['status']['ifoul'] = True else: number, resultMessage = utils.extractPlayNumber(message) if resultMessage is not None and not game['status']['ifoul']: return False, resultMessage elif resultMessage is None and not game['status']['ifoul']: log.debug("Saving defense number: {}".format(number)) database.saveDefensiveNumber(game['dataID'], number) else: log.debug('saving defesive number as 0 due to an intentional foul') database.saveDefensiveNumber(game['dataID'],0) log.debug("offense is currently {}".format(game['play']['offensiveNumber'])) log.debug("we were waiting on {}".format(game['waitingOn'])) if game['status']['techFoul']: game['waitingOn'] = game['status']['possession'] game['play']['defensiveNumber'] = False game['play']['offensiveNumber'] = True game['play']['playResult'] = '' log.debug('we are currently awiting on {}'.format(game['waitingOn'])) else: state.setWaitingOn(game) log.debug("we are now waiting on {}".format(game['waitingOn'])) log.debug("offene is is {}".format(game['play']['offensiveNumber'])) game['dirty'] = True log.debug("Sending offense play comment") if not game['status']['free']: resultMessage = "{} has submitted their number. {} you're up\ .\n\n{}\n\n{} reply with {} and your number. [Play list]({})".format( game[utils.reverseHomeAway(game['waitingOn'])]['name'], game[game['waitingOn']]['name'], utils.getCurrentPlayString(game), utils.getCoachString(game, game['waitingOn']), utils.listSuggestedPlays(game), "https://www.reddit.com/r/TestFakeCBB/wiki/refbot" ) else: resultMessage = "{} has submitted their number for your free throw. {} you're up\ .\n\n{}\n\n{} reply with a free throw number between **1** and **{}**".format( game[utils.reverseHomeAway(game['waitingOn'])]['name'], game[game['waitingOn']]['name'], utils.getCurrentPlayString(game), utils.getCoachString(game, game['waitingOn']), globals.maxRange ) utils.sendGameComment(game, resultMessage, {'action': 'play'}) if not game['status']['ifoul']: result = ["I've got {} as your number.".format(number)] else: result = ["You called an intentional foul"] return True, '\n\n'.join(result)
def technicalFouls(game): log.debug('Going to keep setup Technical Free throw stuff') ##set waiting on and possession badPerson = game['waitingOn'] offendPerson = utils.reverseHomeAway(game['waitingOn']) ## if badPerson is the in possesion then possession flips if badPerson == game['status']['possession']: game['status']['possession'] = offendPerson game['play']['defensiveNumber'] = True game['play']['offensisiveNumber'] = False game[badPerson]['fouls'] += 1 ##set free stats game['status']['frees'] = 2 game['status']['free'] = True game['status']['freeType'] = 'TF' game['waitingAction'] = 'play' game['status']['freeStatus'] = 2 game['status']['techFoul'] = True ##Set foul types if SB and DB change if globals.singleBonus <= game[badPerson]['fouls'] < globals.doubleBonus: game[offendPerson]['bonus'] = 'SB' elif globals.doubleBonus <= game[badPerson]['fouls']: game[offendPerson]['bonus'] = 'DB' currentDel = game[badPerson]['playclockPenalties'] leftDel = 3 - currentDel delayMessage = '{0} has commited a delay of game. They have commited {3} so far. {4} more and they will forfeit their game. {1} will now be shooting \ two free throws and they will get the ball after. /u/{2} reply to the DM that \ I send you.'.format(game[badPerson]['name'],game[offendPerson]['name'], game[badPerson]['coaches'][0], currentDel, leftDel) utils.sendGameComment(game, delayMessage, {'action': 'play'}) utils.sendDelayDefensiveNumberMessage(game)
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 processMessageDefenseNumber(game, message, author): log.debug("Processing defense number message") number, resultMessage = utils.extractPlayNumber(message) if resultMessage is not None: return False, resultMessage log.debug("Saving defense number: {}".format(number)) game.status.defensiveNumber = number timeoutMessage = None if "timeout" in message: if game.status.state(game.status.possession.negate()).timeouts > 0: game.status.state(game.status.possession.negate() ).requestedTimeout = TimeoutOption.REQUESTED timeoutMessage = "Timeout requested successfully" else: timeoutMessage = "You requested a timeout, but you don't have any left" game.status.waitingOn.reverse() game.dirty = True utils.setGamePlayed(game) log.debug("Sending offense play comment") resultMessage = "{} has submitted their number. {} you're up. You have until {}.\n\n{}\n\n{} reply with {} and your number. [Play list]({}){}".format( game.team(game.status.waitingOn.negate()).name, game.team(game.status.waitingOn).name, utils.renderDatetime(game.playclock), utils.getCurrentPlayString(game), utils.getCoachString(game, game.status.waitingOn), utils.listSuggestedPlays(game), "https://www.reddit.com/r/FakeCollegeFootball/wiki/refbot", "\n\nThe clock has stopped" if not game.status.timeRunoff else "") utils.sendGameComment( game, resultMessage, utils.getActionTable(game, game.status.waitingAction)) result = ["I've got {} as your number.".format(number)] if timeoutMessage is not None: result.append(timeoutMessage) return True, '\n\n'.join(result)
def processMessageDefenseNumber(game, message, author): log.debug("Processing defense number message") number, resultMessage = utils.extractPlayNumber(message) if resultMessage is not None: return False, resultMessage log.debug("Saving defense number: {}".format(number)) database.saveDefensiveNumber(game['dataID'], number) timeoutMessage = None if message.find("timeout") > 0: if game['status']['timeouts'][utils.reverseHomeAway( game['status']['possession'])] > 0: game['status']['requestedTimeout'][utils.reverseHomeAway( game['status']['possession'])] = 'requested' timeoutMessage = "Timeout requested successfully" else: timeoutMessage = "You requested a timeout, but you don't have any left" game['waitingOn'] = utils.reverseHomeAway(game['waitingOn']) game['dirty'] = True log.debug("Sending offense play comment") resultMessage = "{} has submitted their number. {} you're up.\n\n{}\n\n{} reply with {} and your number. [Play list]({})".format( game[utils.reverseHomeAway(game['waitingOn'])]['name'], game[game['waitingOn']]['name'], utils.getCurrentPlayString(game), utils.getCoachString(game, game['waitingOn']), utils.listSuggestedPlays(game), "https://www.reddit.com/r/FakeCollegeFootball/wiki/refbot") utils.sendGameComment(game, resultMessage, {'action': 'play'}) result = ["I've got {} as your number.".format(number)] if timeoutMessage is not None: result.append(timeoutMessage) return True, '\n\n'.join(result)
else: log.debug("Waiting on defense, touchdown") if utils.isGameOvertime(game): state.forceTouchdown(game, game.status.possession) resultMessage = state.overtimeTurnover(game) if game.status.waitingAction != Action.END: utils.sendDefensiveNumberMessage(game) else: state.forceTouchdown(game, game.status.possession) state.setStateTouchback(game, game.status.possession.negate()) game.status.waitingOn.reverse() utils.sendDefensiveNumberMessage(game) resultMessage = "Automatic 7 point touchdown, {} has the ball.".format(string_utils.flair(game.team(game.status.waitingOn))) utils.sendGameComment(game, "{}\n\n{}".format(penaltyMessage, resultMessage), None, False) utils.setGamePlayed(game) utils.updateGameThread(game) utils.clearLogGameID() for game in index.getGamesPastPlayclockWarning(): warningText = "This is a warning that your [game]({}) is waiting on a reply from you to " \ "this {}. You have 12 hours until a delay of game penalty."\ .format(string_utils.getLinkToThread(game.thread), string_utils.getLinkFromGameThing(game.thread, utils.getPrimaryWaitingId(game.status.waitingId))) results = reddit.sendMessage(recipients=game.team(game.status.waitingOn).coaches, subject="{} vs {} 12 hour warning".format(game.away.name, game.home.name), message=warningText) log.debug("12 hour warning sent to {} for game {}: {}" .format(
utils.getCoachString(game, game['waitingOn']),globals.delayHours, utils.getNthWord(game[game['waitingOn']]['playclockPenalties'])) if game['home']['playclockPenalties'] == 3 and game['away']['playclockPenalties'] == 3: ## This needs to be where we do something if both players hit 3 utils.endGameBothDelay(game,threadId) elif game[game['waitingOn']]['playclockPenalties'] >= 3: log.debug("3 penalties, game over") game['status']['halfType'] = 'end' game['waitingAction'] = 'end' resultMessage = "They forfeit the game. {} has won!".format(utils.flair(game[utils.reverseHomeAway(game['waitingOn'])])) utils.endGameDelayOfGame(game, threadId) elif techFoul: state.technicalFouls(game) else: utils.sendGameComment(game, penaltyMessage, {'action': 'death'}) pass database.setGamePlayed(game['dataID']) utils.updateGameThread(game) log.debug("Message processed after: %d", int(time.perf_counter() - startTime)) utils.clearLogGameID() if once: database.close() break except Exception as err: log.warning("Hit an error in main loop") log.warning(traceback.format_exc())
def processMessageOffensePlay(game, message, author): log.debug("Processing offense number message") timeoutMessageOffense = None timeoutMessageDefense = None if "timeout" in message: if game.status.state(game.status.possession).timeouts > 0: game.status.state(game.status.possession).requestedTimeout = TimeoutOption.REQUESTED else: timeoutMessageOffense = "The offense requested a timeout, but they don't have any left" if game.forceChew: timeOption = TimeOption.CHEW else: timeOption = TimeOption.NORMAL if any(x in message for x in ['chew the clock', 'milk the clock', 'chew clock']): timeOption = TimeOption.CHEW elif any(x in message for x in ['hurry up', 'no huddle', 'no-huddle']): timeOption = TimeOption.HURRY elif any(x in message for x in ['normal']): timeOption = TimeOption.NORMAL normalOptions = ["run", "pass", "punt", "field goal", "kneel", "spike"] conversionOptions = ["two point", "pat"] kickoffOptions = ["normal", "squib", "onside"] if game.status.waitingAction == Action.PLAY: playSelected = utils.findKeywordInMessage(normalOptions, message) elif game.status.waitingAction == Action.CONVERSION: playSelected = utils.findKeywordInMessage(conversionOptions, message) elif game.status.waitingAction == Action.KICKOFF: playSelected = utils.findKeywordInMessage(kickoffOptions, message) else: return False, "Something went wrong, invalid waiting action: {}".format(game.status.waitingAction) if playSelected == "run": play = Play.RUN elif playSelected == "pass": play = Play.PASS elif playSelected == "punt": play = Play.PUNT elif playSelected == "field goal": play = Play.FIELD_GOAL elif playSelected == "kneel": play = Play.KNEEL elif playSelected == "spike": play = Play.SPIKE elif playSelected == "two point": play = Play.TWO_POINT elif playSelected == "pat": play = Play.PAT elif playSelected == "normal": play = Play.KICKOFF_NORMAL elif playSelected == "squib": play = Play.KICKOFF_SQUIB elif playSelected == "onside": play = Play.KICKOFF_ONSIDE elif playSelected == "mult": log.debug("Found multiple plays") return False, "I found multiple plays in your message. Please repost it with just the play and number." else: log.debug("Didn't find any plays") return False, "I couldn't find a play in your message" number, numberMessage = utils.extractPlayNumber(message) if play not in classes.timePlays and number == -1: log.debug("Trying to execute a {} play, but didn't have a number".format(play)) return False, numberMessage success, resultMessage = state.executePlay(game, play, number, timeOption) if game.status.state(game.status.possession).requestedTimeout == TimeoutOption.USED: timeoutMessageOffense = "The offense is charged a timeout" elif game.status.state(game.status.possession).requestedTimeout == TimeoutOption.REQUESTED: timeoutMessageOffense = "The offense requested a timeout, but it was not used" game.status.state(game.status.possession).requestedTimeout = TimeoutOption.NONE if game.status.state(game.status.possession.negate()).requestedTimeout == TimeoutOption.USED: timeoutMessageDefense = "The defense is charged a timeout" elif game.status.state(game.status.possession.negate()).requestedTimeout == TimeoutOption.REQUESTED: timeoutMessageDefense = "The defense requested a timeout, but it was not used" game.status.state(game.status.possession.negate()).requestedTimeout = TimeoutOption.NONE result = [resultMessage] if timeoutMessageOffense is not None: result.append(timeoutMessageOffense) if timeoutMessageDefense is not None: result.append(timeoutMessageDefense) if not game.status.timeRunoff: result.append("The clock is stopped.") game.status.waitingOn.reverse() game.dirty = True utils.setGamePlayed(game) if game.status.waitingAction in classes.playActions: utils.sendDefensiveNumberMessage(game) elif game.status.waitingAction == Action.OVERTIME: log.debug("Starting overtime, posting coin toss comment") message = "Overtime has started! {}, you're away, call **heads** or **tails** in the air.".format( string_utils.getCoachString(game, False)) comment = utils.sendGameComment(game, message, utils.getActionTable(game, Action.COIN)) utils.setWaitingId(game, comment.fullname) game.status.waitingAction = Action.COIN game.status.waitingOn = classes.HomeAway(False) return success, string_utils.embedTableInMessage('\n\n'.join(result), utils.getActionTable(game, game.status.waitingAction))
def processMessageOffensePlay(game, message, author): ##set some information for later. current = game['status']['possession'] other = utils.reverseHomeAway(current) game['play']['ocoach'] = game[current]['coaches'][0] game['play']['dcoach'] = game[other]['coaches'][0] game['play']['playMessage'] = message log.debug("Processing offense number message") if game['status']['ifoul']: numberMessage = '' number = 0 else: number, numberMessage = utils.extractPlayNumber(message) playOptions = ['chew', 'average', 'push', 'regular'] if not game['status']['ifoul']: playSelected = utils.findKeywordInMessage(playOptions, message) play = "default" if game['status']['free']: play = 'free' elif playSelected == "chew": play = "chew" elif playSelected == "average": play = "average" elif playSelected == "push": play = "push" elif playSelected == "mult": log.debug("Found multiple plays") return False, "I found multiple plays in your message. Please repost it with just the play and number." else: log.debug("Didn't find any plays") return False, "I couldn't find a play in your message. Please reply to this one with a play and a number." else: play = 'foul' numberMessage = 'intentional foul' playSelected = 'foul' game['play']['playType'] = play success, resultMessage = state.executePlay(game, play, number, numberMessage) result = [resultMessage] if playSelected != 'default' and success: state.setWaitingOn(game) game['dirty'] = True if game['waitingAction'] == 'play' and playSelected != 'default' and success: log.debug('going to set the play data up, save it, then remove it') utils.insertPlayData(game) game['status']['sendDef'] = True elif game['waitingAction'] == 'overtime': log.debug("Starting overtime, posting coin toss comment") message = "Overtime has started! {}, you're away, call **heads** or **tails** in the air.".format( utils.getCoachString(game, 'away')) comment = utils.sendGameComment(game, message, {'action': 'tip'}) game['waitingId'] = comment.fullname game['waitingAction'] = 'tip' return success, utils.embedTableInMessage('\n\n'.join(result), {'action': game['waitingAction']})