Exemple #1
0
def init():
	global games
	games = {}
	for gameFile in os.listdir(globals.SAVE_FOLDER_NAME):
		game = reloadAndReturn(gameFile)
		if game is not None:
			changed = False
			for team in [game.home, game.away]:
				wikiTeam = wiki.getTeamByTag(team.tag)
				if ((team.coaches > wikiTeam.coaches) - (team.coaches < wikiTeam.coaches)) != 0:
					log.debug("Coaches for game {}, team {} changed from {} to {}".format(
						game.thread,
						team.tag,
						team.coaches,
						wikiTeam.coaches
					))
					changed = True
					team.coaches = wikiTeam.coaches

			if changed:
				try:
					log.debug("Reverting status and reprocessing {}".format(game.previousStatus[0].messageId))
					utils.revertStatus(game, 0)
					utils.saveGameObject(game)
					message = reddit.getThingFromFullname(game.status.messageId)
					if message is None:
						return "Something went wrong. Not valid fullname: {}".format(game.status.messageId)
					messages.processMessage(message, True)
				except Exception as err:
					log.warning(traceback.format_exc())
					log.warning("Unable to revert game when changing coaches")

			games[game.thread] = game
Exemple #2
0
def processMessageDefaultChew(body):
    log.debug("Processing default chew message")
    threadIds = re.findall('(?: )([\da-z]{6})', body)
    if len(threadIds) < 1:
        log.debug("Couldn't find a thread id in message")
        return "Couldn't find a thread id in message"
    log.debug("Found thread id: {}".format(threadIds[0]))

    game = utils.loadGameObject(threadIds[0])
    if game is None:
        return "Game not found: {}".format(threadIds[0])

    if "normal" in body:
        game.forceChew = False
        result = "Game changed to normal plays by default: {}".format(
            threadIds[0])
    else:
        game.forceChew = True
        result = "Game changed to chew the clock plays by default: {}".format(
            threadIds[0])

    utils.updateGameThread(game)
    utils.saveGameObject(game)

    return result
Exemple #3
0
def addWinnerFieldToGames():
    folder = "games"
    for fileName in os.listdir(folder):
        if not os.path.isfile(os.path.join(folder, fileName)):
            continue
        game = utils.loadGameObject(fileName)
        game.status.winner = None
        for status in game.previousStatus:
            status.winner = None
        utils.saveGameObject(game)
Exemple #4
0
def processMessageAbandonGame(body):
    log.debug("Processing abandon game message")
    threadIds = re.findall('(?: )([\da-z]{6})', body)
    if len(threadIds) < 1:
        log.debug("Couldn't find a thread id in message")
        return "Couldn't find a thread id in message"
    log.debug("Found thread id: {}".format(threadIds[0]))

    game = utils.loadGameObject(threadIds[0])
    if game is None:
        return "Game not found: {}".format(threadIds[0])

    utils.endGame(game, "Abandoned", False)
    utils.updateGameThread(game)
    utils.saveGameObject(game)

    return "Game {} abandoned".format(threadIds[0])
Exemple #5
0
def processMessagePauseGame(body):
    log.debug("Processing pause game message")
    threadIds = re.findall('([\da-z]{6})', body)
    if len(threadIds) < 1:
        log.debug("Couldn't find a thread id in message")
        return "Couldn't find a thread id in message"
    log.debug("Found thread id: {}".format(threadIds[0]))

    hours = re.findall('(\d{1,3})', body)
    if len(hours) < 1:
        log.debug("Couldn't find a number of hours in message")
        return "Couldn't find a number of hours in message"
    log.debug("Found hours: {}".format(hours[0]))

    game = index.reloadAndReturn(threadIds[0])
    utils.pauseGame(game, hours[0])
    utils.saveGameObject(game)

    return "Game {} paused for {} hours".format(threadIds[0], hours[0])
Exemple #6
0
def processMessageKickGame(body):
    log.debug("Processing kick game message")
    threadIds = re.findall('([\da-z]{6})', body)
    if len(threadIds) < 1:
        log.debug("Couldn't find a thread id in message")
        return "Couldn't find a thread id in message"
    log.debug("Found thread id: {}".format(threadIds[0]))

    game = utils.loadGameObject(threadIds[0])
    if game is None:
        return "Game not found: {}".format(threadIds[0])

    game = index.reloadAndReturn(threadIds[0])
    index.clearGameErrored(game)
    utils.saveGameObject(game)
    result = ["Kicked game: {}".format(threadIds[0])]

    statusIndex = re.findall('(?:revert:)(\d+)', body)
    if len(statusIndex) > 0:
        log.debug("Reverting to status: {}".format(statusIndex[0]))
        utils.revertStatus(game, int(statusIndex[0]))
        utils.saveGameObject(game)
        result.append("Reverted to status: {}".format(statusIndex[0]))

    messageFullname = re.findall('(?:message:)(t\d_[\da-z]{6,})', body)
    if len(messageFullname) > 0:
        log.debug("Reprocessing message/comment: {}".format(
            messageFullname[0]))
        message = reddit.getThingFromFullname(messageFullname[0])
        if message is None:
            return "Something went wrong. Not valid fullname: {}".format(
                messageFullname[0])
        processMessage(message, True)
        result.append("Reprocessed message: {}".format(messageFullname[0]))

    log.debug("Finished kicking game")
    return '\n\n'.join(result)