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 processMessageTip(game, message): number, error = utils.extractPlayNumber(message.body) if error is not None: return False, "Didn't send me a number. Reply to the original message and send me a number this time" author = str(message.author).lower() log.debug('author is {}'.format(author)) log.debug('number is {}'.format(number)) log.debug("Processing tip ball where game is dirty is {}".format(game['dirty'])) log.debug('is author in {} or {}'.format(game['away']['coaches'], game['home']['coaches'])) if author in game['away']['coaches']: resultMessage, worked = state.tipResults(game, 'away', number) elif author in game['home']['coaches']: resultMessage, worked = state.tipResults(game, 'home', number) else: return False, 'ooops' log.debug('Now checking if game is dirty and tip off is complete') log.debug('Dirty is {}'.format(game['dirty'])) if game['tip']['awayTip'] and game['tip']['homeTip']: awayTip = int(database.getTipById(game['dataID'],'awayTip')) homeTip = int(database.getTipById(game['dataID'],'homeTip')) botTip = utils.rngNumber() tipWinner = utils.getTipWinner(awayTip, homeTip, botTip) game['status']['wonTip'] = tipWinner game['waitingOn'] = utils.reverseHomeAway(tipWinner) game['status']['possession'] = tipWinner game['play']['defensiveNumber'] = True game['play']['offensiveNumber'] = False log.debug("sending initial defensive play comment to {}".format(game['waitingOn'])) resultMessage = "/u/{} has won the tippoff . /u/{} Will get a DM to start the action. \ \naway tip number: {}\ \nhome tip number: {}\ \nbot tip number: {}".format( game[tipWinner]['coaches'][0], game[game['waitingOn']]['coaches'][0], awayTip, homeTip, botTip ) defMessage = "You lost the tipoff . Please send me a number to start the game getween **1** and **{}**".format(globals.maxRange) log.debug('defensive message is {}'.format(defMessage)) game['dirty'] = True utils.sendDefensiveNumberMessage(game, defMessage) game['waitingAction'] = 'play' game['tip']['justTipped'] = True return True, resultMessage return worked, resultMessage
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)
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): log.debug("Processing offense number message") number, numberMessage = utils.extractPlayNumber(message) timeoutMessageOffense = None timeoutMessageDefense = None if message.find("timeout") > 0: if game['status']['timeouts'][game['status']['possession']] > 0: game['status']['requestedTimeout'][game['status'] ['possession']] = 'requested' else: timeoutMessageOffense = "The offense requested a timeout, but they don't have any left" playOptions = [ 'run', 'pass', 'punt', 'field goal', 'kneel', 'spike', 'two point', 'pat' ] playSelected = utils.findKeywordInMessage(playOptions, message) play = "default" if playSelected == "run": play = "run" elif playSelected == "pass": play = "pass" elif playSelected == "punt": play = "punt" elif playSelected == "field goal": play = "fieldGoal" elif playSelected == "kneel": play = "kneel" elif playSelected == "spike": play = "spike" elif playSelected == "two point": play = "twoPoint" elif playSelected == "pat": play = "pat" 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" success, resultMessage = state.executePlay(game, play, number, numberMessage) if game['status']['requestedTimeout'][game['status'] ['possession']] == 'used': timeoutMessageOffense = "The offense is charged a timeout" elif game['status']['requestedTimeout'][game['status'] ['possession']] == 'requested': timeoutMessageOffense = "The offense requested a timeout, but it was not used" game['status']['requestedTimeout'][game['status']['possession']] = 'none' if game['status']['requestedTimeout'][utils.reverseHomeAway( game['status']['possession'])] == 'used': timeoutMessageDefense = "The defense is charged a timeout" elif game['status']['requestedTimeout'][utils.reverseHomeAway( game['status']['possession'])] == 'requested': timeoutMessageDefense = "The defense requested a timeout, but it was not used" game['status']['requestedTimeout'][utils.reverseHomeAway( game['status']['possession'])] = 'none' result = [resultMessage] if timeoutMessageOffense is not None: result.append(timeoutMessageOffense) if timeoutMessageDefense is not None: result.append(timeoutMessageDefense) game['waitingOn'] = utils.reverseHomeAway(game['waitingOn']) game['dirty'] = True if game['waitingAction'] == 'play': utils.sendDefensiveNumberMessage(game) return success, utils.embedTableInMessage( '\n\n'.join(result), {'action': game['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']})