Esempio n. 1
0
def getClockRunoff(message, offensivePlaybook, clockRunoffType):
    """
    Get the clock runoff based on the offensive playbook and return it
    
    """

    clockRunoff = 0
    gameInfo = getGameInfo(message.channel)
    clockStopped = gameInfo["clock stopped"]
    # Add clock runoff
    if clockStopped == "NO":
        if clockRunoffType == "normal":
            if offensivePlaybook == "flexbone":
                clockRunoff = 20
            if offensivePlaybook == "west coast":
                clockRunoff = 17
            if offensivePlaybook == "pro":
                clockRunoff = 15
            if offensivePlaybook == "spread":
                clockRunoff = 13
            if offensivePlaybook == "air raid":
                clockRunoff = 10
        elif clockRunoffType == "chew":
            clockRunoff = 30
        elif clockRunoffType == "hurry":
            clockRunoff = 7
        return clockRunoff
    else:
        return 0
Esempio n. 2
0
async def handleDeleteCommand(client, message):
    """
    Handle deleting the games
    
    """

    if message.content.startswith('&delete'):
        command = message.content.split('&delete')[1].strip()
        try:
            # Get all the information necessary to delete a game
            homeTeam = command.split("vs")[0].strip()
            awayTeam = command.split("vs")[1].strip()

            gameChannel = None
            name = homeTeam.lower() + " vs " + awayTeam.lower()
            channelName = name.replace(" ", "-")
            if "&" in channelName:
                channelName = channelName.replace("&", "")
            for channel in message.guild.channels:
                if channel.name == channelName:
                    gameChannel = channel
                    break

            # Ensure you can only delete in the game channel
            if gameChannel.name == message.channel.name:
                gameInfo = getGameInfo(message.channel)

                guild = client.get_guild(guildID)
                gameLogChannel = None
                for channel in guild.channels:
                    if channel.name == "game-logs":
                        gameLogChannel = channel
                        break
                if gameInfo["embedded message"] is not None and gameInfo[
                        "embedded message"] != "":
                    embedMessage = await gameLogChannel.fetch_message(
                        gameInfo["embedded message"])
                    await embedMessage.delete()

                deleteGameData(message.channel)
                deleteLogFile(gameInfo["gist link"])
                await gameChannel.delete()
                print(gameChannel.name + " was successfully deleted")
                return
            else:
                await message.channel.send(
                    "You cannot delete a game here, you must be in the specific game channel"
                )
                return
        except:
            await message.channel.send(
                "There was an issue deleting the game, please ensure you used the right command by using '&help' and then contact Dick"
            )
            print("There was an issue deleting " + message.channel.name +
                  "due to " + str(Exception))
            raise Exception
    else:
        return
Esempio n. 3
0
async def handleHalftime(client, message, gameInfo):
    """
    Handle halftime updates for the DB and set up the kickoff

    """

    updatePlayType(message.channel, "KICKOFF")
    updateClockStopped(message.channel, "YES")

    # Home team kickoff scenarios
    if gameInfo["coin toss winner"] == gameInfo["home user"] and gameInfo[
            "coin toss decision"] == "receive":
        updatePossession(message.channel,
                         gameInfo["home name"])  # home team is kicking off
        await message.channel.send("It is halftime, " + gameInfo["home name"] +
                                   " is kicking off")
    elif gameInfo["coin toss winner"] == gameInfo["home user"] and gameInfo[
            "coin toss decision"] == "defer":
        updatePossession(message.channel,
                         gameInfo["away name"])  # home team is receiving
        await message.channel.send("It is halftime, " + gameInfo["away name"] +
                                   " is kicking off")
    # Away team kickoff scenarios
    elif gameInfo["coin toss winner"] == gameInfo["away user"] and gameInfo[
            "coin toss decision"] == "receive":
        updatePossession(message.channel,
                         gameInfo["away name"])  # away team is kicking off
        await message.channel.send("It is halftime, " + gameInfo["away name"] +
                                   " is kicking off")
    elif gameInfo["coin toss winner"] == gameInfo["away user"] and gameInfo[
            "coin toss decision"] == "defer":
        updatePossession(message.channel,
                         gameInfo["home name"])  # away team is receiving
        await message.channel.send("It is halftime, " + gameInfo["home name"] +
                                   " is kicking off")

    gameInfo = getGameInfo(message.channel)
    if str(gameInfo["possession"]) == str(gameInfo["home name"]):
        waitingOnUser = getDiscordUser(client, str(gameInfo["away user"]))
    else:
        waitingOnUser = getDiscordUser(client, str(gameInfo["home user"]))
    await message.channel.send(
        "\nPlease ignore all DMs sent immediately before halftime\n" +
        "**Waiting on " + waitingOnUser.mention + " for a message**\n")
    await messageUser(waitingOnUser, gameInfo)

    updateHomeTimeouts(message.channel, 3)
    updateAwayTimeouts(message.channel, 3)
    updateDown(message.channel, 1)
    updateDistance(message.channel, 10)
    updateHalftime(message.channel, "NO")
Esempio n. 4
0
def getFGResult(message, difference):
    """
    Get the field goal result from the ranges sheet and return it
    
    """

    distanceColumn = []
    madeColumn = []
    missColumn = []
    blockedColumn = []
    kickSixColumn = []

    gameInfo = getGameInfo(message.channel)
    yardLine = convertYardLine(gameInfo)

    for i in range(fieldgoalRanges.nrows):
        distanceColumn.append(ranges.cell_value(i, 0))
        madeColumn.append(ranges.cell_value(i, 1))
        missColumn.append(ranges.cell_value(i, 2))
        blockedColumn.append(ranges.cell_value(i, 3))
        kickSixColumn.append(ranges.cell_value(i, 4))

    fieldGoalDistance = int(yardLine) + 17

    # Iterate through each row in the column and find what bucket the distance falls into
    for i in range(4, len(distanceColumn)):
        if fieldGoalDistance == distanceColumn[i]:
            minNum = int(madeColumn[i].split("-")[0])
            maxNum = int(madeColumn[i].split("-")[1])
            if minNum <= difference <= maxNum:
                return "Made"
            if "-" in str(missColumn[i]):
                minNum = int(madeColumn[i].split("-")[0])
                maxNum = int(madeColumn[i].split("-")[1])
                if minNum <= difference <= maxNum:
                    return "Miss"
            if "-" in str(blockedColumn[i]):
                minNum = int(blockedColumn[i].split("-")[0])
                maxNum = int(blockedColumn[i].split("-")[1])
                if minNum <= difference <= maxNum:
                    return "Blocked"
            if "-" in str(kickSixColumn[i]):
                minNum = int(kickSixColumn[i].split("-")[0])
                maxNum = int(kickSixColumn[i].split("-")[1])
                if minNum <= difference <= maxNum:
                    return "Kick 6"
        else:
            return "Miss"
Esempio n. 5
0
def getScoreboardString(message, difference, down, possessingTeam,
                        waitingOnUser):
    """
    Get the scoreboard string for the message on Discord

    """

    gameInfo = getGameInfo(message.channel)
    if gameInfo["clock stopped"] == "YES":
        scoreBoard = (
            "**Offensive Number: **" + str(gameInfo["offensive number"]) +
            "\n" + "**Defensive Number:** " +
            str(gameInfo["defensive number"]) + "\n" + "**Difference:** " +
            str(difference) + "\n\n" + "==========================\n" + "**Q" +
            str(gameInfo["quarter"]) + " | " + str(gameInfo["time"]) + " | " +
            str(gameInfo["home name"]) + " " + str(gameInfo["home score"]) +
            " " + str(gameInfo["away name"]) + " " +
            str(gameInfo["away score"]) + "**\n" + str(down) + " & " +
            str(gameInfo["distance"]) + " | " + str(gameInfo["yard line"]) +
            " | :football: " + possessingTeam + "\n" +
            "The clock is stopped\n" + str(gameInfo["home name"]) + " has " +
            str(gameInfo["home timeouts"]) + " timeouts\n" +
            str(gameInfo["away name"]) + " has " +
            str(gameInfo["away timeouts"]) + " timeouts\n" +
            "==========================\n" + "\n\n**Waiting on " +
            waitingOnUser.mention + " for a number.**\n\n")
    else:
        scoreBoard = (
            "**Offensive Number: **" + str(gameInfo["offensive number"]) +
            "\n" + "**Defensive Number:** " +
            str(gameInfo["defensive number"]) + "\n" + "**Difference:** " +
            str(difference) + "\n\n" + "==========================\n" + "**Q" +
            str(gameInfo["quarter"]) + " | " + str(gameInfo["time"]) + " | " +
            str(gameInfo["home name"]) + " " + str(gameInfo["home score"]) +
            " " + str(gameInfo["away name"]) + " " +
            str(gameInfo["away score"]) + "**\n" + str(down) + " & " +
            str(gameInfo["distance"]) + " | " + str(gameInfo["yard line"]) +
            " | :football: " + possessingTeam + "\n" +
            "The clock is moving\n" + str(gameInfo["home name"]) + " has " +
            str(gameInfo["home timeouts"]) + " timeouts\n" +
            str(gameInfo["away name"]) + " has " +
            str(gameInfo["away timeouts"]) + " timeouts\n" +
            "==========================\n" + "\n\n**Waiting on " +
            waitingOnUser.mention + " for a number.**\n\n")
    return scoreBoard
Esempio n. 6
0
def getPuntResultRow(message, difference):
    """
    Get the row that the punt result is on in the ranges sheet
    
    """

    gameInfo = getGameInfo(message.channel)
    yardLine = convertYardLine(gameInfo)

    fieldPositionColumnNum = getFieldPositionColumnNum(yardLine)

    fieldPositionColumn = []
    resultsColumn = []
    resultRow = 0

    for i in range(puntRanges.nrows):
        fieldPositionColumn.append(
            puntRanges.cell_value(i, fieldPositionColumnNum))
        resultsColumn.append(puntRanges.cell_value(i, 0))

    # Iterate through each row in the column and find what bucket the difference falls into
    for i in range(3, len(fieldPositionColumn)):
        if "-" in str(fieldPositionColumn[i]):
            minNum = int(fieldPositionColumn[i].split("-")[0])
            maxNum = int(fieldPositionColumn[i].split("-")[1])
            if minNum <= difference <= maxNum:
                resultRow = i
                break
        elif "-" not in str(fieldPositionColumn[i]) and "N/A" not in str(
                fieldPositionColumn[i]):
            if fieldPositionColumn[i] == difference:
                resultRow = i
                break
    if resultRow == 0:
        print("Could not find the row in the range sheet that the result was")
    return resultRow
Esempio n. 7
0
    async def on_message(message):

        # Message is from the server
        if message.guild is not None:
            if message.channel.category.name != "Scrimmages" or message.channel.name == "bot-game-chat":
                if message.content == '&help':
                    await message.channel.send(commandMessage)

                elif message.content.startswith('&start'):
                    category = getCategory(client, "Scrimmages")
                    if category == "COULD NOT FIND":
                        await message.channel.send(helpMessage)
                    else:
                        await handleStartCommand(client, message, category)

                elif message.content.startswith('&end'):
                    await message.channel.send(
                        "You cannot end a game here, you must be in the specific game channel"
                    )

                elif message.content.startswith('&delete'):
                    await message.channel.send(
                        "You cannot delete a game here, you must be in the specific game channel"
                    )

                elif message.content.startswith('&create'):
                    await handleCreateCommand(message)

                elif message.content.startswith('&remove'):
                    await handleRemoveCommand(message)

                elif message.content.startswith('&view'):
                    await handleViewCommand(message)

                elif message.content.startswith('&database'):
                    await handleDatabaseCommand(client, message)

                elif message.content.startswith('&'):
                    await message.channel.send(helpMessage)

            else:
                gameInfo = getGameInfo(message.channel)

                if message.content == '&help':
                    await message.channel.send(commandMessage)

                elif message.content.startswith('&end'):
                    category = getCategory(client, "Scrimmages")
                    if category == "COULD NOT FIND":
                        await message.channel.send(helpMessage)
                    else:
                        await handleEndCommand(message)

                elif message.content.startswith('&database'):
                    await handleDatabaseCommand(client, message)

                elif message.content.startswith('&delete'):
                    category = getCategory(client, "Scrimmages")
                    if category == "COULD NOT FIND":
                        await message.channel.send(helpMessage)
                    else:
                        await handleDeleteCommand(client, message)

                # Game is invalid
                elif gameInfo["home user"] is None or gameInfo[
                        "away user"] is None or gameInfo[
                            "home user"] == "" or gameInfo["away user"] == "":
                    if str(
                            message.author
                    ) != "FCFB Ref Bot#3976" and message.channel.name != "bot-game-chat":
                        await message.channel.send(
                            "No game appears to be found, but a channel for the game exists, please contact Dick."
                        )
                elif gameInfo["number submitted"] == "YES":
                    await game(client, message)
                    gameInfo = getGameInfo(message.channel)
                    if gameInfo["gist link"] is not None and gameInfo[
                            "gist link"] != "":
                        gistLink = getLogFileURL(gameInfo["gist link"])
                        await editEmbed(client, gameInfo, gistLink)

        # Message is from the DM for a game
        else:
            await gameDM(client, message)
Esempio n. 8
0
async def handleDatabaseCommand(client, message):
    """
    Handle the database command, which displays the information for the game

    """

    if message.content.startswith('&database'):
        try:
            post = ''
            if "vs" in message.content:
                command = message.content.split('&database')[1].strip()
                # Get all the information necessary to start a game
                homeTeam = command.split("vs")[0].strip()
                awayTeam = command.split("vs")[1].strip()
                gameInfo = getGameInfoTeam(homeTeam)
            else:
                gameInfo = getGameInfo(message.channel)
                if gameInfo is None:
                    await message.channel.send(
                        "There was an issue getting game information. " +
                        "Are you in the game channel? If you are not in a " +
                        "game channel you must use [HOME TEAM] vs [AWAY TEAM] in your command"
                    )
                    return

            post = (
                "**" + gameInfo["home name"] + " vs " + gameInfo["away name"] +
                "**\n\n" + "Home User: "******"home user"] + "\n" +
                "Away User: "******"away user"] + "\n" +
                "Home Offensive Playbook: " +
                gameInfo["home offensive playbook"] + "\n" +
                "Away Offensive Playbook: " +
                gameInfo["away offensive playbook"] + "\n" +
                "Home Defensive Playbook: " +
                gameInfo["home defensive playbook"] + "\n" +
                "Away Offensive Playbook: " +
                gameInfo["away defensive playbook"] + "\n" +
                "Home Offensive Playbook: " +
                gameInfo["home offensive playbook"] + "\n" +
                "Coin Toss Winner: " + gameInfo["coin toss winner"] + "\n" +
                "Coin Toss Decision: " + gameInfo["coin toss decision"] +
                "\n" + "Quarter: " + str(gameInfo["quarter"]) + "\n" +
                "Time: " + gameInfo["time"] + "\n" + "Yard Line: " +
                gameInfo["yard line"] + "\n" + "Possession: " +
                gameInfo["possession"] + "\n" + "Waiting On: " +
                gameInfo["waiting on"] + "\n" + "Next Play Type: " +
                gameInfo["play type"] + "\n" + "Game Status: " +
                gameInfo["game status"] + "\n" + "Clock Stopped: " +
                gameInfo["clock stopped"] + "\n" + "Coin Toss Decision: " +
                gameInfo["coin toss decision"] + "\n" + "Number Submitted: " +
                gameInfo["number submitted"] + "\n" + "Halftime: " +
                gameInfo["halftime"] + "\n")
            await message.channel.send(post)
        except:
            await message.channel.send(
                "There was an issue getting the game information, please ensure you used the right command by using '&help' and then contact Dick"
            )
            print("There was an issue getting information for " +
                  message.content.split('&database')[1].strip() + " due to " +
                  str(Exception))
            raise Exception
Esempio n. 9
0
async def handleStartCommand(client, message, category):
    """
    Handle starting the games
    
    """

    if message.content.startswith('&start'):
        command = message.content.split('&start')[1].strip()
        try:
            # Get all the information necessary to start a game
            homeTeam = command.split("vs")[0].strip()
            awayTeam = command.split("vs")[1].strip()

            homeUser = getUser(homeTeam)
            awayUser = getUser(awayTeam)

            homeDiscordUser = getDiscordUser(client, homeUser)
            awayDiscordUser = getDiscordUser(client, awayUser)

            # Verify the users aren't already in a game
            homeUserFree = checkUserFree(homeUser)
            awayUserFree = checkUserFree(awayUser)

            # Home user is already playing
            if not homeUserFree:
                await message.channel.send(
                    homeDiscordUser.mention +
                    " is already playing in a game! I cannot schedule them for a second game at this time"
                )
                return
            elif not awayUserFree:
                await message.channel.send(
                    awayDiscordUser.mention +
                    " is already playing in a game! I cannot schedule them for a second game at this time"
                )
                return

            homeNickname = getNickname(homeTeam)
            awayNickname = getNickname(awayTeam)

            homeOffensivePlaybook = getOffensivePlaybook(homeTeam)
            homeDefensivePlaybook = getDefensivePlaybook(homeTeam)

            awayOffensivePlaybook = getOffensivePlaybook(awayTeam)
            awayDefensivePlaybook = getDefensivePlaybook(awayTeam)

            homeTeamInfo = {
                "name": homeTeam,
                "nickname": homeNickname,
                "user": homeUser,
                "offensive playbook": homeOffensivePlaybook,
                "defensive playbook": homeDefensivePlaybook
            }
            awayTeamInfo = {
                "name": awayTeam,
                "nickname": awayNickname,
                "user": awayUser,
                "offensive playbook": awayOffensivePlaybook,
                "defensive playbook": awayDefensivePlaybook
            }

            valid = await checkValidInfo(homeTeamInfo, awayTeamInfo, message)
            if valid is False:
                await message.channel.send(
                    "There was an issue starting your game due to invalid team info"
                )
                return

            # Create the game channel
            channel = await message.guild.create_text_channel(
                homeTeam + " vs " + awayTeam, category=category)

            # Add game to the database
            addGameToDatabase(channel, homeTeamInfo, awayTeamInfo)

            homeDiscordUser = getDiscordUser(client, homeUser)
            awayDiscordUser = getDiscordUser(client, awayUser)

            if homeDiscordUser == "COULD NOT FIND":
                await message.channel.send("Could not find the discord user " +
                                           homeUser +
                                           ". Please verify it is correct.")
            elif awayDiscordUser == "COULD NOT FIND":
                await message.channel.send("Could not find the discord user " +
                                           awayUser +
                                           ". Please verify it is correct.")

            await createLogFile(channel, homeTeam, awayTeam)

            gameInfo = getGameInfo(channel)
            gistLink = getLogFileURL(gameInfo["gist link"])

            await createEmbed(client, channel, homeTeam, awayTeam, gistLink)

            await channel.send(
                "Welcome to this week's FCFB matchup between " + homeTeam +
                " and " + awayTeam +
                "! If you ever see any typos or errors with the bot, please ping Dick\n\n"
                + homeDiscordUser.mention + ", you're home, " +
                awayDiscordUser.mention + ", you're away. " +
                awayDiscordUser.mention +
                " please call **heads** or **tails** in the air")
            await message.channel.send(homeTeam + " vs " + awayTeam +
                                       " was successfully started")
            print(channel.name + " was successfully started")
        except:
            await message.channel.send(
                "There was an issue starting the game, please ensure you used the right command by using '&help' and then contact Dick"
            )
            print("There was an issue starting " +
                  message.content.split('&start')[1].strip() + " due to " +
                  str(Exception))
            raise Exception
    else:
        return