async def goto(self, ctx, *,strProperty: funToLower):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)
        strTeamName = str(self.funTeamRole(ctx))

        # Check if property exists but try and guess #
        if strProperty not in self.lisProperties:
            for strValidProperty in self.lisProperties:
                intPartialRatio = fuzz.partial_ratio(strValidProperty, strProperty)
                intTokenSetRatio = fuzz.token_set_ratio(strValidProperty, strProperty)
                if intTokenSetRatio >= 80 or intTokenSetRatio >= 80:
                    await ctx.send(f':tophat: Could not find property however I have guessed you want: {strValidProperty}')
                    strProperty = strValidProperty
                    break
        
        # Check if property exists #
        if strProperty not in self.lisProperties:
            raise MonopolyRunError.InvalidPropertyName(strProperty)

        # Get money and visited from the database #
        dbcursor.execute(f"SELECT {strProperty}_visited FROM tbl_{strGuildID} WHERE id = ?", (strTeamName, ))
        lisVisted = dbcursor.fetchall()
        tupVisted = lisVisted[0]
        strVisted = tupVisted[0]

        # Check if the team has already visited that property #
        if strVisted == 'Y':
            raise MonopolyRunError.AlreadyVisted(strProperty)

        # Get which set of Questions the guild is using #
        dbcursor.execute("SELECT questions FROM tbl_guilds WHERE id = ?", (strGuildID, ))
        lisQuestions = dbcursor.fetchall()
        tupQuestions = lisQuestions[0]
        strQuestions = tupQuestions[0]

        # Get Location and Question from the Database #
        dbcursor.execute(f"SELECT location, question FROM tbl_{strQuestions} WHERE id = ?", (strProperty, ))
        lisLocationQuestion = dbcursor.fetchall()
        for item in lisLocationQuestion:
            strPropertyLocation = item[0]
            strQuestion = item[1]

        # Update Database to the Location the user is now at #
        dbcursor.execute(f"UPDATE tbl_{strGuildID} SET current_location = ? WHERE id = ?", (strProperty, strTeamName))

        # Send user a message telling the the Question, Location and Property #
        await ctx.send(f':question: The question for {strProperty} at {strPropertyLocation} is: {strQuestion}')
Exemplo n.º 2
0
    async def UpdateLeaderBoard(self, ctx):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)

        # Get teams and there money ordered highest to lowest #
        dbcursor.execute(
            f"SELECT id, money FROM tbl_{strGuildID} ORDER BY money DESC")
        lisLeaderBoard = dbcursor.fetchall()
        emLeaderBoard = embeds.Embed(title='Leaderboard!',
                                     color=Colour.orange())
        i = 1
        for item in lisLeaderBoard:

            # Add to embed #
            emLeaderBoard.add_field(name=f'{i}. {item[0]}',
                                    value=f'Money: {item[1]}',
                                    inline=False)
            i = i + 1

        # Get the properties channel #
        catMonopolyRun = utils.get(ctx.guild.categories, name='Monopoly Run')
        chaLeaderBoard = utils.get(ctx.guild.channels,
                                   name='leaderboard',
                                   category_id=catMonopolyRun.id)

        # Remove last message #
        await chaLeaderBoard.purge(limit=2)

        # Send the embed #
        await chaLeaderBoard.send(embed=emLeaderBoard)
        async def predicate(ctx):

            # Check if command is being used in a DM #
            if ctx.channel.type is ChannelType.private:
                raise commands.NoPrivateMessage

            # Check if guild is setup #
            strGuildID = str(ctx.guild.id)
            dbcursor.execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'monopolyrun' AND TABLE_NAME = ?", (f'tbl_{strGuildID}', ))
            lisGuildTable = dbcursor.fetchall()
            if not lisGuildTable:
                raise MonopolyRunError.DatabaseTableNotFound

            # Check if the user has a team role #
            lismyRoles = [r.name for r in ctx.author.roles]
            lismyRoles.reverse()
            r = re.compile("team.*")
            if not list(filter(r.match, lismyRoles)):
                raise commands.MissingRole("team?")

            # Check if user is using the command in their team channel #
            if re.search('team', ctx.channel.name) is None:
                raise commands.ChannelNotFound("team?")

            x = str(ctx.channel.name)
            y = str(next(filter(r.match, lismyRoles)))
            if x != y:
                raise MonopolyRunError.NotInTeamChannel(next(filter(r.match, lismyRoles)), ctx.channel.name)

            return True
    async def owner(self, ctx, *, strProperty: funToLower):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)

        # Check if property exists but try and guess #
        if strProperty not in self.lisProperties:
            for strValidProperty in self.lisProperties:
                intPartialRatio = fuzz.partial_ratio(strValidProperty, strProperty)
                intTokenSetRatio = fuzz.token_set_ratio(strValidProperty, strProperty)
                if intTokenSetRatio >= 80 or intTokenSetRatio >= 80:
                    await ctx.send(f':tophat: Could not find property however I have guessed you want: {strValidProperty}')
                    strProperty = strValidProperty
                    break
        
        # Check if property exists #
        if strProperty not in self.lisProperties:
            raise MonopolyRunError.InvalidPropertyName(strProperty)


        # Check if a team owns the property #
        dbcursor.execute(f"SELECT id FROM tbl_{strGuildID} WHERE {strProperty}_owner = 'Y'")
        lisOwner = dbcursor.fetchall()
        if not lisOwner:
            await ctx.send(f':house: {strProperty} is not owned by anyone!')
        else:
            tupOwner = lisOwner[0]
            strOwner = tupOwner[0]
            await ctx.send(f':house: {strProperty} is owned by {strOwner}!')
Exemplo n.º 5
0
    async def remove(self, ctx, blnConfirm: bool):

        # Check if blnConfirm is false #
        if blnConfirm is False:
            raise commands.BadArgument()

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)

        # Check if there is anything to remove #
        dbcursor.execute("SELECT id FROM tbl_guilds WHERE id = ?",
                         (strGuildID, ))
        lisExists = dbcursor.fetchall()
        if not lisExists:
            raise MonopolyRunError.DatabaseRecordNotFound()

        # Delete all channels in the category Monopoly Run #
        for category in ctx.message.guild.categories:
            if 'Monopoly Run' in category.name:
                for channel in category.text_channels:
                    await channel.delete()
                await category.delete()

        dbcursor.execute("SELECT teams FROM tbl_guilds WHERE id = ?",
                         (strGuildID, ))
        lisNumberOfTeams = dbcursor.fetchall()
        tupNumberOfTeams = lisNumberOfTeams[0]
        intNumberOfTeams = tupNumberOfTeams[0]
        # Declare a list of roles to try and delete #
        lisRoles = ['Monopoly Run Administrator']
        for i in range(intNumberOfTeams):
            lisRoles.append(f'team{i+1}')

        # Delete roles #
        for role in ctx.guild.roles:
            if role.name in lisRoles:
                await role.delete()

        # Drop guilds table #
        dbcursor.execute(f"DROP TABLE tbl_{strGuildID}")

        # Remove record from tbl_guild #
        dbcursor.execute("DELETE FROM tbl_guilds WHERE id = ?", (strGuildID, ))
    async def money(self, ctx):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)
        strTeamName = str(self.funTeamRole(ctx))

        # Get money from database #
        dbcursor.execute(f"SELECT money FROM tbl_{strGuildID} WHERE id = ?", (strTeamName, ))
        lisMoney = dbcursor.fetchall()
        tupMoney = lisMoney[0]
        intMoney = tupMoney[0]

        # Notify the user #
        await ctx.send(f':dollar: You have £{intMoney}')
Exemplo n.º 7
0
    async def start(self, ctx):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)
        catMonopolyRun = utils.get(ctx.guild.categories, name='Monopoly Run')

        # Check if there is anything to add to #
        dbcursor.execute("SELECT teams from tbl_guilds WHERE id = ?",
                         (strGuildID, ))
        lisNumberOfTeams = dbcursor.fetchall()
        if not lisNumberOfTeams:
            raise MonopolyRunError.DatabaseRecordNotFound()

        # Start UpdatePropertiesChannel Loop and UpdateLeaderBoard Loop #
        self.UpdatePropertiesChannel.start(self, ctx)
        self.UpdateLeaderBoard.start(self, ctx)

        # Get the number of teams the guild currently has #
        tupNumberOfTeams = lisNumberOfTeams[0]
        intNumberOfTeams = tupNumberOfTeams[0]

        # Declare lisTeams based on number of teams #
        lisTeams = []
        for i in range(intNumberOfTeams):
            lisTeams.append(f'team{i+1}')

        # Update send permissions on team channels #
        for strTeam in lisTeams:
            rolTeam = utils.get(ctx.guild.roles, name=f'{strTeam}')
            chaTeam = utils.get(ctx.guild.channels, name=f'{strTeam}')
            await chaTeam.set_permissions(rolTeam,
                                          send_messages=True,
                                          view_channel=True)

        # Get Announcement Channel and send a message #
        chaAnnouncementChannel = utils.get(ctx.guild.channels,
                                           name='announcements',
                                           category_id=catMonopolyRun.id)
        await chaAnnouncementChannel.send('Game Start!')
Exemplo n.º 8
0
    async def UpdatePropertiesChannel(self, ctx):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)

        # Get which set of Questions the guild is using #
        dbcursor.execute("SELECT questions FROM tbl_guilds WHERE id = ?",
                         (strGuildID, ))
        lisQuestions = dbcursor.fetchall()
        tupQuestions = lisQuestions[0]
        strQuestions = tupQuestions[0]

        # Create Embeds #
        emBrownProperties = embeds.Embed(title='Brown Properties',
                                         color=Colour.from_rgb(139, 69, 19))
        emLightBlueProperties = embeds.Embed(title='Light Blue Properties',
                                             color=Colour.from_rgb(
                                                 135, 206, 235))
        emPinkProperties = embeds.Embed(title='Pink Properties',
                                        color=Colour.from_rgb(218, 112, 214))
        emOrangeProperties = embeds.Embed(title='Orange Properties',
                                          color=Colour.from_rgb(255, 165, 0))
        emRedProperties = embeds.Embed(title='Red Properties',
                                       color=Colour.from_rgb(255, 0, 0))
        emYellowProperties = embeds.Embed(title='Yellow Properties',
                                          color=Colour.from_rgb(255, 255, 0))
        emGreenProperties = embeds.Embed(title='Green Properties',
                                         color=Colour.from_rgb(0, 179, 0))
        emDarkBlueProperties = embeds.Embed(title='Dark Blue Properties',
                                            color=Colour.from_rgb(0, 0, 255))
        emBlackProperties = embeds.Embed(title='Train Stations',
                                         color=Colour.from_rgb(255, 255, 255))

        # Get id, value and location from database and add to the relevant embeds #
        dbcursor.execute(f"SELECT id, value, location FROM tbl_{strQuestions}")
        lisProperties = dbcursor.fetchall()
        for item in lisProperties:

            # Get owner if any #
            dbcursor.execute(
                f"SELECT id FROM tbl_{strGuildID} WHERE {item[0]}_owner = 'Y'")
            lisOwner = dbcursor.fetchall()
            if not lisOwner:
                strOwner = None
            else:
                tupOwner = lisOwner[0]
                strOwner = tupOwner[0]

            # Add fields to Embed #
            if re.sub('[0-9]+', '', item[0]) == 'brown':
                emBrownProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'lightblue':
                emLightBlueProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]}  \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'pink':
                emPinkProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'orange':
                emOrangeProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'red':
                emRedProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'yellow':
                emYellowProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'green':
                emGreenProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'darkblue':
                emDarkBlueProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')
            elif re.sub('[0-9]+', '', item[0]) == 'black':
                emBlackProperties.add_field(
                    name=item[2],
                    value=
                    f'ID: {item[0]} \n Value: {item[1]} \n Owner: {strOwner}')

        # Get the properties channel #
        catMonopolyRun = utils.get(ctx.guild.categories, name='Monopoly Run')
        chaProperties = utils.get(ctx.guild.channels,
                                  name='properties',
                                  category_id=catMonopolyRun.id)

        # Remove last message #
        await chaProperties.purge(limit=10)

        # Send the embeds #
        await chaProperties.send(embed=emBrownProperties)
        await chaProperties.send(embed=emLightBlueProperties)
        await chaProperties.send(embed=emPinkProperties)
        await chaProperties.send(embed=emOrangeProperties)
        await chaProperties.send(embed=emBlackProperties)
        await chaProperties.send(embed=emRedProperties)
        await chaProperties.send(embed=emYellowProperties)
        await chaProperties.send(embed=emGreenProperties)
        await chaProperties.send(embed=emDarkBlueProperties)
Exemplo n.º 9
0
    async def setup(self, ctx, intNumberOfTeams: int, strQuestionSet):

        # Declare some variables for later #
        strGuildID = str(ctx.guild.id)
        strGuildName = str(ctx.guild.name)
        intGuildID = int(ctx.guild.id)
        lisRoles = []

        # Check if guild is already setup #
        dbcursor.execute("SELECT id FROM tbl_guilds WHERE id = ?",
                         (strGuildID, ))
        lisExists = dbcursor.fetchall()
        for item in lisExists:
            if intGuildID == item[0]:
                await ctx.send(':no_entry: You have already run setup!')
                return None

        # Check Question set exists #
        dbcursor.execute(
            "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE ?",
            (f'tbl_{strQuestionSet}', ))
        lisQuestionSet = dbcursor.fetchall()
        if not lisQuestionSet:
            await ctx.send(':no_entry: That question set was not found!')
            return None

        # Check number of teams is greater than 2 and less than 46 #
        if intNumberOfTeams < 2:
            raise MonopolyRunError.NotEnoughTeams()
        elif intNumberOfTeams >= 47:
            raise MonopolyRunError.TooManyTeams()

        # Declare lisTeams based on user input #
        lisTeams = []
        for i in range(intNumberOfTeams):
            lisTeams.append(f'team{i+1}')

        # Create Monopoly Run category and role #
        roleMonopolyRunAdministrator = await ctx.guild.create_role(
            name='Monopoly Run Administrator')
        catMonopolyRun = await ctx.guild.create_category('Monopoly Run')

        # Create team roles #
        for strTeam in lisTeams:
            diRole = await ctx.guild.create_role(name=f'{strTeam}')
            lisRoles.append(
                diRole
            )  # Append role to lisRoles for setting channel permissions

        # Create announcements channel and set permissions #
        chaAnnouncements = await ctx.guild.create_text_channel(
            'announcements', category=catMonopolyRun)
        await chaAnnouncements.set_permissions(ctx.guild.default_role,
                                               send_messages=False,
                                               read_messages=False)

        # Create leaderboard channel and set permissions #
        chaLeaderBoard = await ctx.guild.create_text_channel(
            'leaderboard', category=catMonopolyRun)
        await chaLeaderBoard.set_permissions(ctx.guild.default_role,
                                             send_messages=False,
                                             read_messages=False)

        # Create properties channel and set permissions #
        chaProperties = await ctx.guild.create_text_channel(
            'properties', category=catMonopolyRun)
        await chaProperties.set_permissions(ctx.guild.default_role,
                                            send_messages=False,
                                            read_messages=False)

        # Create help channel and set permissions #
        chaHelp = await ctx.guild.create_text_channel('help',
                                                      category=catMonopolyRun)
        await chaHelp.set_permissions(ctx.guild.default_role,
                                      send_messages=False,
                                      read_messages=False)
        msg = await chaHelp.send('If you need help click the 👍 button below...'
                                 )
        await msg.add_reaction('👍')

        # Allow teams to view the announcements, leaderboard, properties and help channels #
        for roleTeam in lisRoles:
            for category in ctx.message.guild.categories:
                if 'Monopoly Run' in category.name:
                    for channel in category.text_channels:
                        await channel.set_permissions(roleTeam,
                                                      send_messages=False,
                                                      read_messages=True,
                                                      view_channel=True)

        # Create team channels and set permissions #
        for strTeam, roleTeam in zip(
                lisTeams,
                lisRoles):  # Loop through both lists at the same time
            chaChannel = await ctx.guild.create_text_channel(
                f'{strTeam}', category=catMonopolyRun)
            await chaChannel.set_permissions(ctx.guild.default_role,
                                             send_messages=False,
                                             read_messages=False)
            await chaChannel.set_permissions(roleTeam,
                                             send_messages=False,
                                             read_messages=True,
                                             view_channel=True)

        # Allow monopoly run administrators to view and send messages in all channels #
        for chaChannel in catMonopolyRun.channels:
            await chaChannel.set_permissions(roleMonopolyRunAdministrator,
                                             send_messages=True,
                                             read_messages=True,
                                             view_channel=True)

        # Create guilds table in the database #
        dbcursor.execute(f"""CREATE OR REPLACE TABLE tbl_{strGuildID} (
        id varchar(6) NOT NULL PRIMARY KEY,
        money smallint(5) NOT NULL,
        current_location TEXT,
        brown1_owner set('Y','N') NOT NULL DEFAULT 'N',
        brown1_visited set('Y','N') NOT NULL DEFAULT 'N',
        brown2_owner set('Y','N') NOT NULL DEFAULT 'N',
        brown2_visited set('Y','N') NOT NULL DEFAULT 'N',
        lightblue1_owner set('Y','N') NOT NULL DEFAULT 'N',
        lightblue1_visited set('Y','N') NOT NULL DEFAULT 'N',
        lightblue2_owner set('Y','N') NOT NULL DEFAULT 'N',
        lightblue2_visited set('Y','N') NOT NULL DEFAULT 'N',
        lightblue3_owner set('Y','N') NOT NULL DEFAULT 'N',
        lightblue3_visited set('Y','N') NOT NULL DEFAULT 'N',
        pink1_owner set('Y','N') NOT NULL DEFAULT 'N',
        pink1_visited set('Y','N') NOT NULL DEFAULT 'N',
        pink2_owner set('Y','N') NOT NULL DEFAULT 'N',
        pink2_visited set('Y','N') NOT NULL DEFAULT 'N',
        pink3_owner set('Y','N') NOT NULL DEFAULT 'N',
        pink3_visited set('Y','N') NOT NULL DEFAULT 'N',
        orange1_owner set('Y','N') NOT NULL DEFAULT 'N',
        orange1_visited set('Y','N') NOT NULL DEFAULT 'N',
        orange2_owner set('Y','N') NOT NULL DEFAULT 'N',
        orange2_visited set('Y','N') NOT NULL DEFAULT 'N',
        orange3_owner set('Y','N') NOT NULL DEFAULT 'N',
        orange3_visited set('Y','N') NOT NULL DEFAULT 'N',
        black1_owner set('Y','N') NOT NULL DEFAULT 'N',
        black1_visited set('Y','N') NOT NULL DEFAULT 'N',
        black2_owner set('Y','N') NOT NULL DEFAULT 'N',
        black2_visited set('Y','N') NOT NULL DEFAULT 'N',
        black3_owner set('Y','N') NOT NULL DEFAULT 'N',
        black3_visited set('Y','N') NOT NULL DEFAULT 'N',
        black4_owner set('Y','N') NOT NULL DEFAULT 'N',
        black4_visited set('Y','N') NOT NULL DEFAULT 'N',
        red1_owner set('Y','N') NOT NULL DEFAULT 'N',
        red1_visited set('Y','N') NOT NULL DEFAULT 'N',
        red2_owner set('Y','N') NOT NULL DEFAULT 'N',
        red2_visited set('Y','N') NOT NULL DEFAULT 'N',
        red3_owner set('Y','N') NOT NULL DEFAULT 'N',
        red3_visited set('Y','N') NOT NULL DEFAULT 'N',
        yellow1_owner set('Y','N') NOT NULL DEFAULT 'N',
        yellow1_visited set('Y','N') NOT NULL DEFAULT 'N',
        yellow2_owner set('Y','N') NOT NULL DEFAULT 'N',
        yellow2_visited set('Y','N') NOT NULL DEFAULT 'N',
        yellow3_owner set('Y','N') NOT NULL DEFAULT 'N',
        yellow3_visited set('Y','N') NOT NULL DEFAULT 'N',
        green1_owner set('Y','N') NOT NULL DEFAULT 'N',
        green1_visited set('Y','N') NOT NULL DEFAULT 'N',
        green2_owner set('Y','N') NOT NULL DEFAULT 'N',
        green2_visited set('Y','N') NOT NULL DEFAULT 'N',
        green3_owner set('Y','N') NOT NULL DEFAULT 'N',
        green3_visited set('Y','N') NOT NULL DEFAULT 'N',
        darkblue1_owner set('Y','N') NOT NULL DEFAULT 'N',
        darkblue1_visited set('Y','N') NOT NULL DEFAULT 'N',
        darkblue2_owner set('Y','N') NOT NULL DEFAULT 'N',
        darkblue2_visited set('Y','N') NOT NULL DEFAULT 'N'
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;""")

        # Create records in guilds table  #
        for strTeam in lisTeams:
            dbcursor.execute(
                f"INSERT INTO tbl_{strGuildID} (id, money, current_location) VALUES (?, ?, ?)",
                (strTeam, 0, ''))

        # Create a record in tbl_guild #
        dbcursor.execute(
            "INSERT INTO tbl_guilds (id, name, questions, teams) VALUES (?, ?, ?, ?)",
            (intGuildID, strGuildName, strQuestionSet, intNumberOfTeams))

        # Tell the user setup is complete #
        await ctx.send('Setup is done!')
Exemplo n.º 10
0
    async def add(self, ctx):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)

        # Check if there is anything to add to #
        dbcursor.execute("SELECT teams from tbl_guilds WHERE id = ?",
                         (strGuildID, ))
        lisNumberOfTeams = dbcursor.fetchall()
        if not lisNumberOfTeams:
            raise MonopolyRunError.DatabaseRecordNotFound()

        # Get the number of teams the guild currently has #
        tupNumberOfTeams = lisNumberOfTeams[0]
        intNumberOfTeams = tupNumberOfTeams[0]

        # Handle max number of teams #
        if intNumberOfTeams == 46:
            raise MonopolyRunError.TooManyTeams()

        # Get the Monopoly Run Category #
        catMonopolyRun = utils.get(ctx.guild.categories, name='Monopoly Run')

        # Define a variable with the new team to add #
        strNewTeamName = f'team{intNumberOfTeams + 1}'

        # Create team Role #
        roleNewTeam = await ctx.guild.create_role(name=strNewTeamName)

        # Get Monopoly Run Administrator Role #
        roleMonopolyRunAdministrator = utils.get(
            ctx.guild.roles, name='Monopoly Run Administrator')

        # Create team channel and set permissions  #
        chaChannel = await ctx.guild.create_text_channel(
            strNewTeamName, category=catMonopolyRun)
        await chaChannel.set_permissions(ctx.guild.default_role,
                                         send_messages=False,
                                         read_messages=False)
        await chaChannel.set_permissions(roleNewTeam,
                                         send_messages=False,
                                         read_messages=True,
                                         view_channel=True)
        await chaChannel.set_permissions(roleMonopolyRunAdministrator,
                                         send_messages=True,
                                         read_messages=True,
                                         view_channel=True)

        # Set permissions on announcements, leaderboard, properties and help channel #
        chaAnnouncements = utils.get(ctx.guild.channels,
                                     name='announcements',
                                     category=catMonopolyRun)
        chaLeaderBoard = utils.get(ctx.guild.channels,
                                   name='leaderboard',
                                   category=catMonopolyRun)
        chaProperties = utils.get(ctx.guild.channels,
                                  name='properties',
                                  category=catMonopolyRun)
        chaHelp = utils.get(ctx.guild.channels,
                            name='help',
                            category=catMonopolyRun)

        await chaAnnouncements.set_permissions(roleNewTeam,
                                               send_messages=False,
                                               read_messages=True,
                                               view_channel=True)
        await chaLeaderBoard.set_permissions(roleNewTeam,
                                             send_messages=False,
                                             read_messages=True,
                                             view_channel=True)
        await chaProperties.set_permissions(roleNewTeam,
                                            send_messages=False,
                                            read_messages=True,
                                            view_channel=True)
        await chaHelp.set_permissions(roleNewTeam,
                                      send_messages=False,
                                      read_messages=True,
                                      view_channel=True)

        # Add team record to guilds table #
        dbcursor.execute(
            f"INSERT INTO tbl_{strGuildID} (id, money, current_location) VALUES (?, ?, ?)",
            (strNewTeamName, 0, ''))

        # Update number of teams in guild table #
        dbcursor.execute("UPDATE tbl_guilds SET teams = ? WHERE id = ?",
                         (intNumberOfTeams + 1, strGuildID))
Exemplo n.º 11
0
    async def answer(self, ctx, *, strAnswer):

        # Declare some key variables #
        strGuildID = str(ctx.guild.id)
        strTeamName = str(self.funTeamRole(ctx))

        # Get teams current location #
        dbcursor.execute(f"SELECT current_location FROM tbl_{strGuildID} WHERE id = ?", (strTeamName, ))
        lisCurrentLocation = dbcursor.fetchall()
        tupCurrentLocation = lisCurrentLocation[0]
        strCurrentLocation = tupCurrentLocation[0]

        # Check if team has said they are going to visit the property #
        if strCurrentLocation not in self.lisProperties:
            if strCurrentLocation == '':
                await ctx.send(':tophat: You need to use goto first to tell the game where your going! ```mr goto brown1```')
                return None

        # Set property to location #
        strProperty = strCurrentLocation

        # Get teams money and if they have visited this property from the database #
        dbcursor.execute(f"SELECT money, {strProperty}_visited FROM tbl_{strGuildID} WHERE id = ?", (strTeamName, ))
        lisMoneyVisted = dbcursor.fetchall()
        for item in lisMoneyVisted:
            intTeamsMoney = item[0]
            strVisted = item[1]

        # Check if the team has already visited that property #
        if strVisted == 'Y':
            raise MonopolyRunError.AlreadyVisted(strProperty)

        # Check if a team owns the property #
        dbcursor.execute(f"SELECT id FROM tbl_{strGuildID} WHERE {strProperty}_owner = 'Y'")
        lisOwner = dbcursor.fetchall()
        if not lisOwner:
            strOwner = None
        else:
            tupOwner = lisOwner[0]
            strOwner = tupOwner[0]

            # Get how much money the owner has #
            dbcursor.execute(f"SELECT money FROM tbl_{strGuildID} WHERE id = ?", (strOwner, ))
            lisOwnersMoney = dbcursor.fetchall()
            tupOwnersMoney = lisOwnersMoney[0]
            intOwnersMoney = tupOwnersMoney[0]

        # Get which set of Questions the guild is using #
        dbcursor.execute("SELECT questions FROM tbl_guilds WHERE id = ?", (strGuildID, ))
        lisQuestions = dbcursor.fetchall()
        tupQuestions = lisQuestions[0]
        strQuestions = tupQuestions[0]

        # Get answer and value from database #
        dbcursor.execute(f"SELECT answer, value FROM tbl_{strQuestions} WHERE id = ?", (strProperty, ))
        lisOwnerAnswer = dbcursor.fetchall()
        for item in lisOwnerAnswer:
            strCorrectAnswers = item[0]
            intValue = item[1]

        # Check if a set of properties is owned by one team #
        lisPropertiesToSelect = [i for i in self.lisProperties if i.startswith(re.sub('[0-9]+', '', strProperty))]
        intNumberofPropertiesToSelect = len(lisPropertiesToSelect)
        if intNumberofPropertiesToSelect == 2:
            dbcursor.execute(f"SELECT id FROM tbl_{strGuildID} WHERE {lisPropertiesToSelect[0]}_owner = 'Y' and {lisPropertiesToSelect[1]}_owner = 'Y'")
            lisPropertiesInSet = dbcursor.fetchall()
            if not lisPropertiesInSet:
                blnDoubleRent = False
            else:
                blnDoubleRent = True

        elif intNumberofPropertiesToSelect == 3:
            dbcursor.execute(f"SELECT id FROM tbl_{strGuildID} WHERE {lisPropertiesToSelect[0]}_owner = 'Y' and {lisPropertiesToSelect[1]}_owner = 'Y' and {lisPropertiesToSelect[2]}_owner = 'Y'")
            lisPropertiesInSet = dbcursor.fetchall()
            if not lisPropertiesInSet:
                blnDoubleRent = False
            else:
                blnDoubleRent = True

        elif intNumberofPropertiesToSelect == 4:
            dbcursor.execute(f"SELECT id FROM tbl_{strGuildID} WHERE {lisPropertiesToSelect[0]}_owner = 'Y' and {lisPropertiesToSelect[1]}_owner = 'Y' and {lisPropertiesToSelect[2]}_owner = 'Y' and {lisPropertiesToSelect[3]}_owner = 'Y'", ())
            lisPropertiesInSet = dbcursor.fetchall()
            if not lisPropertiesInSet:
                blnDoubleRent = False
            else:
                blnDoubleRent = True
  
        else:
            blnDoubleRent = False

        # Check if answer is correct #
        lisCorrectAnswers = strCorrectAnswers.split('-')
        for item in lisCorrectAnswers:

            # Convert to lowercase and remove spaces #
            strCorrectAnswer = item.lower()
            strCorrectAnswer = re.sub("\s+", '', strCorrectAnswer)

            strAnswer = strAnswer.lower()
            strAnswer = re.sub("\s+", '', strAnswer)
            # Use fuzzy-wuzzy to compare the users answer with the correct answer #
            intPartialRatio = fuzz.partial_ratio(strCorrectAnswer, strAnswer)
            intTokenSetRatio = fuzz.token_set_ratio(strCorrectAnswer, strAnswer)

            if intPartialRatio >= 80 or intTokenSetRatio >= 80:
                blnAnswerCorrect = True
                break
            else:
                blnAnswerCorrect = False

        # Checks #
        # Answer is correct AND the property is NOT owned #
        if blnAnswerCorrect is True and strOwner is None and blnDoubleRent is False:

            # Update property visited in database #
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET {strProperty}_visited = 'Y' WHERE id = ?", (strTeamName, ))

            # Update teams money and set owner #
            intUpdatedMoney = intTeamsMoney + intValue
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET money = '{intUpdatedMoney}', {strProperty}_owner = 'Y' WHERE id = '{strTeamName}'")

            # Notify announcements of the Owner #
            catMonopolyRun = utils.get(ctx.guild.categories, name="Monopoly Run")
            chaAnnouncementChannel = utils.get(ctx.guild.channels, name="announcements", category_id=catMonopolyRun.id)
            await chaAnnouncementChannel.send(f':house: {strTeamName} now owns {strProperty}!')

            await ctx.send(f':white_check_mark: You now own {strProperty}!')

            # Set current_location to empty #
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET current_location = ? WHERE id = ?", ("", strTeamName))

        # Answer is correct AND the property is owned #
        elif blnAnswerCorrect is True and strOwner is not None and blnDoubleRent is False:

            # Update property visited in database #
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET {strProperty}_visited = 'Y' WHERE id = ?", (strTeamName, ))

            # Update teams money #
            intUpdatedMoney = intTeamsMoney + intValue
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET money = ? WHERE id = ?", (intUpdatedMoney, strTeamName))

            # Update owners money #
            chaOwner = utils.get(ctx.guild.channels, name=strOwner)
            await chaOwner.send(f':dollar: {strTeamName} just paid £{intValue} on {strProperty}!')
            intUpdatedMoney = intOwnersMoney + intValue
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET money = ? WHERE id = ?", (intUpdatedMoney, strOwner))
            await ctx.send(f':white_check_mark: However since: {strOwner} already owns that property you paid: £{intValue} in rent!')

            # Set current_location to empty #
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET current_location = ? WHERE id = ?", ("", strTeamName))

        # Answer is correct AND the property is owned  AND double rent #
        elif blnAnswerCorrect is True and strOwner is not None and blnDoubleRent is True:

            # Update property visited in database #
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET {strProperty}_visited = 'Y' WHERE id = ?", (strTeamName, ))

            # Update teams money #
            intUpdatedMoney = intTeamsMoney + intValue
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET money = ? WHERE id = ?", (intUpdatedMoney, strTeamName))

            # Update owners money #
            chaOwner = utils.get(ctx.guild.channels, name=strOwner)
            await chaOwner.send(f':dollar: {strTeamName} just paid £{intValue * 2} on {strProperty}!')
            intUpdatedMoney = intOwnersMoney + (intValue * 2)
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET money = ? WHERE id = ?", (intUpdatedMoney, strOwner))
            await ctx.send(f':white_check_mark: However since: {strOwner} already owns that property and the other properties in the same group you paid: £{intValue*2} in rent!')

            # Set current_location to empty #
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET current_location = ? WHERE id = ?", ("", strTeamName))

        # Answer is incorrect AND the property is NOT owned #
        elif blnAnswerCorrect is False and strOwner is None and blnDoubleRent is False:
            await ctx.send(':negative_squared_cross_mark: Try again!')

        # Answer is incorrect AND the property is owned  #
        elif blnAnswerCorrect is False and strOwner is not None and blnDoubleRent is False:

            await ctx.send(f':negative_squared_cross_mark: Try again! However since: {strOwner} already owns that property you paid: £{intValue} in rent!')

            # Update owners money #
            chaOwner = utils.get(ctx.guild.channels, name=strOwner)
            await chaOwner.send(f':dollar: {strTeamName} just paid £{intValue} on {strProperty}, even though they got the answer incorrect!')
            intUpdatedMoney = intOwnersMoney + intValue
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET money = ? WHERE id = ?", (intUpdatedMoney, strOwner))

        # Answer is incorrect AND the property is owned AND double rent  #
        elif blnAnswerCorrect is False and strOwner is not None and blnDoubleRent is True:

            await ctx.send(f':negative_squared_cross_mark: Try again! However since: {strOwner} already owns that property and the other properties in the same group you paid: £{intValue*2} in rent!')

            # Update owners money #
            chaOwner = utils.get(ctx.guild.channels, name=strOwner)
            await chaOwner.send(f':dollar: {strTeamName} just paid £{intValue * 2} on {strProperty}, even though they got the answer incorrect!')
            intUpdatedMoney = intOwnersMoney + (intValue * 2)
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET money = ? WHERE id = ?", (intUpdatedMoney, strOwner))

        # Error #
        else:

            # Set current_location to empty #
            dbcursor.execute(f"UPDATE tbl_{strGuildID} SET current_location = ? WHERE id = ?", ("", strTeamName))
            logging.error(f'Unexpected error: Answer, Correct Answer, Answer Correct, Owner, Double Rent, Afford is not valid! {strAnswer, strCorrectAnswer, blnAnswerCorrect, strOwner, blnDoubleRent, }')
            await ctx.send(f':satellite: An unexpected error occurred! ```The error is: Answer, Correct Answer, Answer Correct, Owner, Double Rent, Afford is not valid! {strAnswer, strCorrectAnswer, blnAnswerCorrect, strOwner, blnDoubleRent, }``` ')