コード例 #1
0
    async def _team_edit_name(self, ctx, *, name):
        """Edits your teams name"""

        player = Player(ctx.author)
        await player.get_stats()

        await player.team.edit_name(ctx, name)
コード例 #2
0
    async def _team_leave(self, ctx):
        """Removes yourself from the team."""

        player = Player(ctx.author)
        await player.get_stats()

        await player.team.remove_player(ctx.author)
コード例 #3
0
    async def _team_edit_abbrev(self, ctx, abbrev):
        """Edit your teams abbreviation"""

        player = Player(ctx.author)
        await player.get_stats()

        await player.team.edit_abbrev(ctx, abbrev)
コード例 #4
0
    async def _team_add(self, ctx, member: discord.Member):
        """Add a player to your team"""

        player = Player(ctx.author)
        await player.get_stats()

        await player.team.add_player(member)
コード例 #5
0
ファイル: admin.py プロジェクト: ByronJMackinnon/ElevateBot
    async def _search_player(self, ctx, member: discord.Member = None):
        if member is None:
            member = ctx.author
            return

        player = Player(member)
        await player.get_stats()

        embed = discord.Embed(color=0x00ffff)
        embed.set_author(name=player.name, icon_url=player.logo)
        if player.mmr is None:
            embed.add_field(name="MMR:", value="Not yet verified.")
        else:
            embed.add_field(name="MMR:", value=player.mmr)
        if player.team is None:
            embed.add_field(name="Team:", value="Free Agent")
            embed.set_footer(text=f"Player ID: {player.member.id}",
                             icon_url=config.elevate_logo)
        else:
            embed.add_field(
                name="Team:",
                value=f"""**[{player.team.abbrev}]** | {player.team.name}
            MMR: {player.team.mmr}
            Wins: {player.team.wins}
            Losses: {player.team.losses}
            Total Games: {player.team.wins + player.team.losses}
            Roster: {', '.join([f'<@{player_id}>' for player_id in player.team.players])}""",
                inline=False)
            embed.set_footer(
                text=
                f"Player ID: {player.member.id} | Team ID: {player.team.id}")
            embed.set_thumbnail(url=player.team.logo)

        await ctx.send(embed=embed)
コード例 #6
0
    async def _player_edit_logo(self, ctx, link = None):
        player = Player(ctx.author)
        await player.get_stats()

        if link is None:
            if len(ctx.message.attachments) == 0:
                await player.edit_logo(ctx.author.avatar_url)
            else:
                await player.edit_logo(ctx.message.attachments[0].url)
        else:
            await player.edit_logo(link)
コード例 #7
0
    async def _team_remove(self, ctx, member: discord.Member):
        """Removes player from team"""

        player = Player(ctx.author)
        await player.get_stats()

        if member == ctx.author:
            command = self.bot.get_command('team leave')
            await ctx.invoke(command)
            return

        await player.team.remove_player(member)
コード例 #8
0
    async def _player(self, ctx):
        if ctx.invoked_subcommand is None:
            player = Player(ctx.author)
            await player.get_stats()

            embed = discord.Embed(color=0x00ffff, description=f"MMR: {player.mmr}")
            embed.set_thumbnail(url=player.logo)
            embed.set_author(name=f'{ctx.author.name}#{ctx.author.discriminator}', icon_url=ctx.author.avatar_url)
            if player.team is None:
                await ctx.send(embed=embed)
            else:
                team_players = ', '.join([f'<@{mem_id}>' for mem_id in player.team.players])
                embed.add_field(name=f'[{player.team.abbrev}] | {player.team.name}', value=f"MMR: {player.team.mmr}\nWins: {player.team.wins}\nLosses: {player.team.losses}\n Total Games: {player.team.wins + player.team.losses}\nRoster: {team_players}")
                embed.set_image(url=player.team.logo)
                await ctx.send(embed=embed)
コード例 #9
0
    async def _team_edit_logo(self, ctx, link = None):
        """Edits your team logo
        
        You can give a link, upload a file"""

        if link is None:
            if len(ctx.message.attachments) == 0:
                await ctx.author.send("I'm sorry, please send a photo with the command or paste a link to the photo.")
                return
            link = ctx.message.attachments[0].url

        player = Player(ctx.author)
        await player.get_stats()

        await player.team.edit_logo(ctx, link)
コード例 #10
0
    async def _updatemylogo(self, ctx, link = None):
        """Edits your own logo
        
        You can give a link, upload a file, or if you give nothing, it will update to your current discord profile picture.
        """

        if link is None:
            try:
                link = ctx.message.attachments[0].url
            except IndexError:
                link = ctx.author.avatar_url

        player = Player(ctx.author)
        await player.get_stats()

        await player.edit_logo(link)

        await send_confirm(ctx, "Your logo has been updated!")
コード例 #11
0
    async def _team(self, ctx):
        """Shows your current teams information."""

        if ctx.invoked_subcommand is None:
            player = Player(ctx.author)
            await player.get_stats()
            if player.team is None:
                embed = discord.Embed(title="Free Agent", color=0x00ffff)
                embed.add_field(name="MMR:", value=player.mmr)
                embed.set_thumbnail(url=player.logo)
            else:
                roster = list(filter(None, player.team.players))
                roster = [f'<@{member}>' for member in roster]

                embed = discord.Embed(title=f'[{player.team.abbrev}] | {player.team.name}', color=0x00ffff, description=', '.join(roster))
                embed.add_field(name="MMR:", value=player.team.mmr)
                embed.add_field(name="Stats:", value=f'Wins: {player.team.wins}\nLosses: {player.team.losses}\nTotal Games: {player.team.wins + player.team.losses}', inline=False)
                embed.set_thumbnail(url=player.team.logo)
            embed.set_author(name=player.name, icon_url=ctx.author.avatar_url)
            await ctx.send(embed=embed)
コード例 #12
0
    async def _team_edit_owner(self, ctx, member: discord.Member):
        """Transfer Ownership of Team to a new player"""

        player = Player(ctx.author)
        await player.get_stats()

        if member.id not in player.team.players:
            await ctx.author.send("You are only able to transfer ownership to someone on your team.")
            return

        players = player.team.players
        players.remove(member.id)

        new_captain = [member.id]

        players = new_captain + players

        await dbupdate('data.db', "UPDATE teams SET Player1, Player2, Player3, Player4, Player5 WHERE ID=?", (player.team.id,))

        captain_role = get(ctx.guild.roles, id=config.team_captain_role_id)

        await ctx.author.remove_roles(captain_role)
        await member.add_roles(captain_role)
コード例 #13
0
    async def _challenge(self, ctx, *, id: typing.Union[discord.Member, int,
                                                        str]):
        """
        This command is used to challenge another team
        
        It takes 3 different arguments. Member, Team ID, or Team Name.
        """

        if type(id) is discord.Member:  # Player/Member passed
            member = id

        elif type(id) is int:  # Team ID Passed
            id = await dbselect('data.db',
                                "SELECT Player1 FROM teams WHERE ID=?", (id, ))
            member = get(ctx.guild.members, id=id)
            print("Member Object:", member)

        elif type(id) is str:  # Team Name Passed
            id = await dbselect('data.db',
                                "SELECT Player1 FROM teams WHERE Name=?",
                                (id.title(), ))
            member = get(ctx.guild.members, id=id)

        challenger = Player(ctx.author)
        await challenger.get_stats()

        challenged = Player(member)
        await challenged.get_stats()

        challenger_players = [
            f'<@{player_id}>' for player_id in challenger.team.players
        ]

        challenged_players = [
            f'<@{player_id}>' for player_id in challenged.team.players
        ]

        if len(challenger_players) < 3:
            return await ctx.author.send(
                "Your team has less than 3 players. Therefore you cannot challenge another team."
            )
        if len(challenged_players) < 3:
            return await ctx.author.send(
                "The team you challenged does not currently have enough players to complete a match."
            )

        embed = discord.Embed(
            color=0x00ffff,
            description=
            f"{challenged.team.name} has been challenged by {challenger.team.name}. Are you interested?"
        )
        embed.add_field(name="Roster:", value=', '.join(challenger_players))
        embed.add_field(
            name="Team Stats:",
            value=
            f'Wins: {challenger.team.wins}\nLosses: {challenger.team.losses}\nTotal Games: {challenger.team.wins + challenger.team.losses}',
            inline=False)
        embed.set_thumbnail(url=challenger.team.logo)
        embed.set_footer(
            text=
            "You will have 4 days (96 hours) to report a match if accepted.",
            icon_url=config.elevate_logo)

        msg = await ctx.send(embed=embed)
        channel = msg.channel.id

        await msg.add_reaction(config.checkmark_emoji)
        await msg.add_reaction(config.cross_emoji)

        await dbupdate(
            'data.db',
            "INSERT INTO invites (Channel, MessageID, Challenger, Challenged, Inviter) VALUES (?, ?, ?, ?, ?)",
            (
                channel,
                msg.id,
                challenger.team.id,
                challenged.team.id,
                ctx.author.id,
            ))

        reaction, user = await self.bot.wait_for('reaction_add')

        player = Player(user)
        await player.get_stats()

        if player.team.id == challenged.team.id:
            if str(reaction) == config.checkmark_emoji:
                await ctx.send("Okay, match is a go!")
                return await DBInsert.match(player.team.id, challenged.team)

            elif str(reaction) == config.cross_emoji:
                return await ctx.send("Okay, no match.")

        else:
            pass
コード例 #14
0
    async def _report(self, ctx, matchID, winorloss):
        """
        This command is used to report scores for matches played.

        This command takes 2 arguments. The ID for the match, and whether you won or loss.
        """

        check = await dbselect('data.db',
                               "SELECT Complete FROM matches WHERE ID=?",
                               (matchID, ))

        if winorloss.lower() in ['w', 'win', 'won']:
            wl_mine = 'W'
            wl_other = 'L'

        elif winorloss.lower() in ['l', 'loss', 'lost']:
            wl_mine = 'L'
            wl_other = 'W'

        if check is None:
            await ctx.send(
                "There is not match in the database with this ID. Please check the ID again."
            )
            return

        elif check is True:
            await ctx.send(
                "This match has already been reported. Please reach out to a staff member if there is an issue."
            )
            return

        match = Match(matchID)
        await match.get_stats()

        if ctx.author.id in match.team1.players:
            my_team = match.team1
            other_team = match.team2
            pass
        elif ctx.author.id in match.team2.players:
            my_team = match.team2
            other_team = match.team1
        else:
            await ctx.send(
                "You aren't able to report a match you weren't a part of.")
            return

        if winorloss.lower() in ['w', 'win', 'won']:  # Reporter Won
            if my_team.mmr > other_team.mmr:
                for player in my_team.players:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.loss)

                for player in other_team.players:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.loss * -1)

            elif my_team.mmr < other_team.mmr:
                for player in my_team.players:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.gain)

                for player in other_team.players:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.gain * -1)

        elif winorloss.lower() in ['l', 'loss', 'lost']:  # Reporter Lost
            if my_team.mmr > other_team.mmr:
                for player in my_team.players:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.gain * -1)

                for player in other_team.mmr:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.gain)

            elif my_team.mmr < other_team.mmr:
                for player in my_team.players:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.loss * -1)

                for player in other_team.players:
                    player = get(ctx.guild.members, id=player)
                    player = Player(player)
                    await player.mmr_change(match.loss)

        reporter = Player(ctx.author)
        await reporter.get_stats()

        if reporter.team.id == match.team1.id:
            await dbupdate(
                'data.db',
                "UPDATE matches SET WL1=?, WL2=?, Complete=? WHERE ID=?", (
                    wl_mine,
                    wl_other,
                    True,
                    matchID,
                ))

        elif reporter.team.id == match.team2.id:
            await dbupdate(
                'data.db',
                "UPDATE matches SET WL1=?, WL2=?, Complete=? WHERE ID=?", (
                    wl_other,
                    wl_mine,
                    True,
                    matchID,
                ))