Esempio n. 1
0
    async def newHand(self):
        self.cardsToBeat = []
        self.numPasses = 0
        self.finished = []
        self.activePlayers = []
        for ID in self.players:
            self.playerHands.update({ID: []})

        playerIndex = 0
        from main import client, sortHand
        while len(self.DECK) > 0:
            dealToPlayer = client.get_user(int(self.players[playerIndex]))
            self.deal(dealToPlayer, 1)
            playerIndex += 1
            if playerIndex >= len(self.players):
                playerIndex = 0

        for ID in self.players:
            self.playerHands[ID] = sortHand(client.get_user(int(ID)),
                                            self.playerHands[ID])
            self.activePlayers.append(ID)

        embed = discord.Embed(title="President",
                              description="All cards have been dealt.",
                              color=0x0ff00)
        embed.set_thumbnail(url=President.imageUrl)
        embed.set_footer(text="Check your hand with c!hand.")
        await self.channel.send(embed=embed)
Esempio n. 2
0
    async def nextTurn(self):
        if len(self.activePlayers) == 1:
            return

        if self.turnIndex >= len(self.activePlayers):
            self.turnIndex = 0

        from main import client, showHand
        self.currentPlayer = client.get_user(
            int(self.activePlayers[self.turnIndex]))

        embed = discord.Embed(title=self.currentPlayer.name + "'s Hand",
                              description=None,
                              color=0x00ff00)
        embed.set_author(name=self.currentPlayer.display_name,
                         icon_url=self.currentPlayer.avatar_url)
        embed.set_thumbnail(url=client.get_user(716357127739801711).avatar_url)
        file = showHand(self.currentPlayer,
                        self.playerHands[str(self.currentPlayer.id)])
        embed.set_image(url="attachment://hand.png")
        embed.add_field(name="Number of Cards",
                        value=str(
                            len(self.playerHands[str(self.currentPlayer.id)])))
        await self.currentPlayer.send(file=file, embed=embed)

        embed = discord.Embed(title="President",
                              description="It is your turn.",
                              color=0x0ff00)
        embed.set_thumbnail(url=President.imageUrl)
        embed.set_author(name=self.currentPlayer.name,
                         icon_url=self.currentPlayer.avatar_url)

        if self.numPasses == len(self.activePlayers) - 1:
            embed.description = "Everyone passed on your cards. You have a free turn!"
            embed.set_thumbnail(url=President.imageUrl)
            self.numPasses = 0
            self.cardsToBeat = []

        playerList = ""

        for playerID in self.activePlayers:
            playerList += client.get_user(int(playerID)).name + ": " + str(
                len(self.playerHands[playerID])) + " card(s) left\n"

        embed.add_field(name="Players", value=playerList, inline=False)

        finishedList = ""

        for playerID in self.finished:
            finishedList += client.get_user(int(playerID)).name + "\n"

        if finishedList != "":
            embed.add_field(name="Finished", value=finishedList, inline=False)

        embed.add_field(name="Game ID", value=str(self.ID))

        await self.channel.send(embed=embed)
Esempio n. 3
0
 async def raise_error(self, ctx, error):
     if isinstance(error, commands.BadArgument):
         embed = discord.Embed(title="Command Error", description="Invalid arguments detected for command 'raise'. Check c!help raise for more details.", color=0x00ff00)
         embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
         from main import client
         embed.set_thumbnail(url=client.get_user(716357127739801711).avatar_url)
         await ctx.send(embed=embed)
Esempio n. 4
0
    async def __highest(self, ctx):
        embed = discord.Embed(title="Highest Bet", color=0x00ff00)
        embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
        from main import client
        embed.set_thumbnail(url=client.get_user(716357127739801711).avatar_url)

        if not checkInGame(ctx.author):
            embed.description = "You are not in a game."
            await ctx.send(embed=embed)
            return

        GAME = getGame(ctx.author)

        if not channelCheck(GAME, ctx.channel):
            embed.description = "You are not in the specified game's channel. Please go there."
            await ctx.send(embed=embed)
            return

        embed.add_field(name="Game ID", value=str(GAME.ID), inline=False)
        embed.set_thumbnail(url=GAME.imageUrl)

        if not GAME.gameUnderway:
            embed.description = "This game has not started."
            embed.set_footer(text="Use c!start to start this game.")
            await ctx.send(embed=embed)
            return

        embed.description = "The current highest bet is $" + str(GAME.maxBet) + "."
        await ctx.send(embed=embed)
Esempio n. 5
0
    async def baltop(self, ctx):
        global userBal
        balance_load()
        userBal = {k: v for k, v in sorted(userBal.items(), key=lambda item: item[1], reverse=True)}
        output = "**TOP BALANCES**\n-----------------------------------------------\n"
        idx = 1;
        for user, balance in userBal.items():
            USER = client.get_user(int(user))
            output += str(idx) + ". " + USER.display_name + ": $" + str(balance) + "\n"
            idx += 1

        await ctx.send(output)
Esempio n. 6
0
    async def __pass(self, ctx):
        embed = discord.Embed(colour=0x00ff00)
        embed.set_author(name=ctx.author.display_name,
                         icon_url=ctx.author.avatar_url)
        embed.set_thumbnail(url=client.get_user(716357127739801711).avatar_url)

        if not checkInGame(ctx.author):
            embed.description = "You are not in any games."
            embed.set_footer(
                text="Use c!join <game ID> to join an existing game.")
            await ctx.send(embed=embed)
            return

        GAME = getGame(ctx.author)

        if not channelCheck(GAME, ctx.channel):
            embed.description = "You are not in the specified game's channel. Please go there."
            await ctx.send(embed=embed)
            return

        if not isinstance(GAME, President):
            embed.add_field(name="Game ID", value=str(GAME.ID))
            embed.description = "You are not in a President game."
            await ctx.send(embed=embed)
            return

        embed.set_thumbnail(url=President.imageUrl)
        embed.title = "President"

        if not GAME.gameUnderway:
            embed.add_field(name="Game ID", value=str(GAME.ID))
            embed.description = "This game has not started."
            embed.set_footer(text="Use c!start to start this game.")
            await ctx.send(embed=embed)
            return

        if ctx.author != GAME.currentPlayer:
            embed.description = "It is not your turn!"
            await ctx.send(embed=embed)
            return

        if len(GAME.cardsToBeat) == 0:
            embed.description = "You have a free turn, don't give it up!"
            await ctx.send(embed=embed)
            return

        embed.description = "You have passed."
        GAME.numPasses += 1
        GAME.turnIndex += 1
        await ctx.send(embed=embed)
        await GAME.nextTurn()
Esempio n. 7
0
    async def ctb(self, ctx):
        embed = discord.Embed(colour=0x00ff00)
        embed.set_author(name=ctx.author.display_name,
                         icon_url=ctx.author.avatar_url)
        embed.set_thumbnail(url=client.get_user(716357127739801711).avatar_url)

        if not checkInGame(ctx.author):
            embed.description = "You are not in any games."
            embed.set_footer(
                text="Use c!join <game ID> to join an existing game.")
            await ctx.send(embed=embed)
            return

        GAME = getGame(ctx.author)

        if not channelCheck(GAME, ctx.channel):
            embed.description = "You are not in the specified game's channel. Please go there."
            await ctx.send(embed=embed)
            return

        if not isinstance(GAME, President):
            embed.add_field(name="Game ID", value=str(GAME.ID))
            embed.description = "You are not in a President game."
            await ctx.send(embed=embed)
            return

        embed.set_thumbnail(url=President.imageUrl)
        embed.title = "President"

        if not GAME.gameUnderway:
            embed.add_field(name="Game ID", value=str(GAME.ID))
            embed.description = "This game has not started."
            embed.set_footer(text="Use c!start to start this game.")
            await ctx.send(embed=embed)
            return

        from main import showHand
        file = showHand(ctx.author, GAME.cardsToBeat)
        embed.set_image(url="attachment://hand.png")
        embed.description = "Here are the cards to beat."
        embed.add_field(name="Game ID", value=str(GAME.ID))
        await ctx.send(file=file, embed=embed)
Esempio n. 8
0
async def get_levelling_top(guild: discord.Guild) -> str:
    from main import client

    path = os.path.join("data", "configs", f"{guild.id}.json")
    with open(path, "r") as f:
        data = json.load(f)
    levelling_dict = data["levelling"]["user"]
    top_list = []
    passes = 1
    top_string = ""
    for user in levelling_dict:
        user_dict = {
            "id": str(user),
            "xp": data["levelling"]["user"][str(user)]["xp"],
            "level": data["levelling"]["user"][str(user)]["level"],
        }
        top_list.append(user_dict)
    sorted_list_cache = sorted(top_list, key=lambda i: i["xp"], reverse=True)
    sorted_list = sorted(sorted_list_cache,
                         key=lambda i: i["level"],
                         reverse=True)[:10]

    for user in sorted_list:
        discord_user = client.get_user(int(user["id"]))
        if not discord_user:
            user_data = await get_user_levelling_data(userid=int(user["id"]),
                                                      guild=guild)
        else:
            user_data = await get_user_levelling_data(user=discord_user,
                                                      guild=guild)
        top_string = (
            top_string +
            f"\n{passes}. {discord_user.mention if discord_user else '@<' + user['id'] + '>'} - Level: {user_data['level']} | XP: {user_data['xp']}"
        )
        passes += 1
    return top_string
Esempio n. 9
0
    async def gameLoop(self):
        if not self.gameUnderway:
            self.expireTimer += 1

        if self.expireTimer >= 60:
            embed = discord.Embed(
                title="President",
                description=
                "This game did not start in time and will be deleted.",
                colour=0x00ff00)
            embed.add_field(name="Game ID", value=str(self.ID))
            embed.set_thumbnail(url=TexasHoldEm.imageUrl)
            await self.channel.send(embed=embed)

            import main
            main.gameList.remove(self)
            del self
            return

        if len(self.players) == 0 and self.gameUnderway:
            embed = discord.Embed(
                title="President",
                description=
                "No players left in game. This game will now terminate.",
                colour=0x00ff00)
            embed.add_field(name="Game ID", value=str(self.ID))
            embed.set_thumbnail(url=President.imageUrl)
            await self.channel.send(embed=embed)
            import main
            main.gameList.remove(self)
            del self
            return

        if not self.gameUnderway:
            return

        if self.turnIndex >= len(self.activePlayers):
            self.turnIndex = 0

        from main import client
        self.currentPlayer = client.get_user(
            int(self.activePlayers[self.turnIndex]))

        if len(self.finished) == len(self.players) - 1:
            self.endGame()

        if self.gameEnded:
            embed = discord.Embed(
                title="President",
                description="Game finished, showing positions.",
                color=0x0ff00)
            embed.set_thumbnail(url=President.imageUrl)

            for i in range(0, len(self.finished)):
                if i == 0:
                    embed.add_field(name="1st Place",
                                    value=client.get_user(int(
                                        self.finished[i])).name,
                                    inline=False)
                elif i == 1:
                    embed.add_field(name="2nd Place",
                                    value=client.get_user(int(
                                        self.finished[i])).name,
                                    inline=False)
                elif i == 2:
                    embed.add_field(name="3rd Place",
                                    value=client.get_user(int(
                                        self.finished[i])).name,
                                    inline=False)
                else:
                    embed.add_field(name=str(i + 1) + "th Place",
                                    value=client.get_user(int(
                                        self.finished[i])),
                                    inline=False)

            embed.add_field(name="Last Place",
                            value=client.get_user(int(
                                self.activePlayers[0])).name,
                            inline=False)
            embed.add_field(name="Game ID", value=str(self.ID), inline=False)
            await self.channel.send(embed=embed)
            import main
            main.gameList.remove(self)
            del self
            return
Esempio n. 10
0
    async def gameLoop(self):
        if not self.gameUnderway:
            self.expireTimer += 1

        if self.expireTimer >= 60:
            embed = discord.Embed(
                title="Texas Hold 'Em",
                description=
                "This game did not start in time and will be deleted.",
                colour=0x00ff00)
            embed.add_field(name="Game ID", value=str(self.ID))
            embed.set_thumbnail(url=TexasHoldEm.imageUrl)
            await self.channel.send(embed=embed)

            import main
            main.gameList.remove(self)
            del self
            return

        self.updateStatus()
        if len(self.players) == 0 and self.gameUnderway:
            embed = discord.Embed(
                title="Texas Hold 'Em",
                description=
                "No players left in game. This game will now terminate.",
                colour=0x00ff00)
            embed.add_field(name="Game ID", value=str(self.ID))
            embed.set_thumbnail(url=TexasHoldEm.imageUrl)
            await self.channel.send(embed=embed)

            import main
            main.gameList.remove(self)
            del self
            return

        if len(self.communityCards) == 5:
            self.endGame()

        if self.gameEnded:
            embed = discord.Embed(title="Texas Hold 'Em", colour=0x00ff00)
            embed.add_field(name="Game ID", value=str(self.ID))
            embed.set_thumbnail(url=TexasHoldEm.imageUrl)

            import main
            from main import client, showHand

            score = {}
            overallMax = 0
            embed.add_field(name="Combo", value="value")
            for ID in self.players:
                user = client.get_user(int(ID))
                embed.title = user.name + "'s Hand"

                if self.playerStatus[ID] == "Fold":
                    embed.description = "Folded"
                    embed.set_field_at(1, name="Combo", value="None")
                    await self.channel.send(embed=embed)
                    continue

                maxScore = 0
                cardChoices = [
                    self.communityCards[0], self.communityCards[1],
                    self.communityCards[2], self.communityCards[3],
                    self.communityCards[4], self.playerHands[str(user.id)][0],
                    self.playerHands[str(user.id)][1]
                ]
                combos = list(itertools.combinations(cardChoices, 5))
                for combo in combos:
                    maxScore = max(maxScore, evaluateHand(combo))

                score.update({maxScore: ID})
                overallMax = max(maxScore, overallMax)
                file = showHand(user, self.playerHands[ID])
                embed.set_image(url="attachment://hand.png")
                embed.set_field_at(1, name="Combo", value=handType(maxScore))
                await self.channel.send(file=file, embed=embed)

            winners = []
            for userScore, userID in score.items():
                if userScore == overallMax:
                    print(client.get_user(int(userID)).name)
                    winners.append(userID)

            if len(winners) == 1:
                winner = client.get_user(int(score[overallMax]))

                embed.title = "Texas Hold 'Em"
                embed.description = "The winner is " + winner.name + ", winning the pot of $" + str(
                    self.pot
                ) + ".\n\nStart next hand? Thumps up for yes, thumbs down for no."
                embed.set_thumbnail(url=winner.avatar_url)
                embed.set_footer(text="Use c!leave to leave this game.")

                userMoney = DBConnection.fetchUserData("userBalance",
                                                       score[overallMax])
                userMoney += self.pot
                DBConnection.updateUserBalance(score[overallMax], userMoney)
            else:
                payout = self.pot / len(winners)
                embed.title = "Texas Hold 'Em"
                desc = "The winners are "
                for winnerID in winners:
                    winner = client.get_user(int(winnerID))
                    desc += winner.name + ", "
                    userMoney = DBConnection.fetchUserData(
                        "userBalance", winnerID)
                    userMoney += payout
                    DBConnection.updateUserBalance(winnerID, userMoney)

                desc += ", splitting the pot of $" + str(
                    self.pot
                ) + ".\n\nStart next hand? Thumbs up for yes, thumbs down for no."
                embed.description = desc
                embed.set_thumbnail(url=TexasHoldEm.imageUrl)
                embed.set_footer(text="Use c!leave to leave this game.")

            confirmEmoji = '👍'
            quitEmoji = '👎'

            embed.remove_field(0)
            embed.remove_field(0)
            msg = await self.channel.send(embed=embed)
            embed.set_thumbnail(url=TexasHoldEm.imageUrl)

            rxn = None
            await msg.add_reaction(confirmEmoji)
            await msg.add_reaction(quitEmoji)

            def check(reaction, user):
                global rxn
                rxn = reaction
                return self.players.count(str(user.id)) > 0 and not user.bot

            try:
                rxn = await client.wait_for('reaction_add',
                                            timeout=30.0,
                                            check=check)
            except asyncio.TimeoutError:
                embed.description = "Nobody chose in time. Game terminated."
                embed.add_field(name="Game ID", value=str(self.ID))
                await self.channel.send(embed=embed)

                import main
                main.gameList.remove(self)
                del self
                return
            else:
                if str(rxn[0].emoji) == confirmEmoji:
                    await self.newHand()
                elif str(rxn[0].emoji) == quitEmoji:
                    embed.description = "Game terminated."
                    embed.add_field(name="Game ID", value=str(self.ID))
                    await self.channel.send(embed=embed)

                    import main
                    main.gameList.remove(self)
                    del self
                    return
Esempio n. 11
0
    async def newHand(self):
        from main import client, showHand
        self.gameEnded = False
        self.playerHands.clear()
        self.DECK = [
            "deck/AD.png", "deck/AC.png", "deck/AH.png", "deck/AS.png",
            "deck/2D.png", "deck/2C.png", "deck/2H.png", "deck/2S.png",
            "deck/3D.png", "deck/3C.png", "deck/3H.png", "deck/3S.png",
            "deck/4D.png", "deck/4C.png", "deck/4H.png", "deck/4S.png",
            "deck/5D.png", "deck/5C.png", "deck/5H.png", "deck/5S.png",
            "deck/6D.png", "deck/6C.png", "deck/6H.png", "deck/6S.png",
            "deck/7D.png", "deck/7C.png", "deck/7H.png", "deck/7S.png",
            "deck/8D.png", "deck/8C.png", "deck/8H.png", "deck/8S.png",
            "deck/9D.png", "deck/9C.png", "deck/9H.png", "deck/9S.png",
            "deck/10D.png", "deck/10C.png", "deck/10H.png", "deck/10S.png",
            "deck/JD.png", "deck/JC.png", "deck/JH.png", "deck/JS.png",
            "deck/QD.png", "deck/QC.png", "deck/QH.png", "deck/QS.png",
            "deck/KD.png", "deck/KC.png", "deck/KH.png", "deck/KS.png"
        ]
        self.pot = 0
        self.communityCards.clear()
        self.deal(client.get_user(716357127739801711), 3)

        embed = discord.Embed(title="Texas Hold 'Em",
                              description="Starting new hand. Ante is $50",
                              colour=0x00ff00)
        embed.set_thumbnail(url=TexasHoldEm.imageUrl)
        embed.set_footer(text="Use c!leave to leave this game.")
        file = showHand(client.get_user(716357127739801711),
                        self.communityCards)
        embed.set_image(url="attachment://hand.png")

        playerList = ""
        for ID in self.players:
            self.playerHands.update({ID: []})
            self.playerStatus[ID] = "Active"
            userMoney = DBConnection.fetchUserData("userBalance", ID)
            if ID not in self.bets:
                self.bets.update({ID: 50})
            else:
                self.bets[ID] = 50
            if userMoney < 50:
                await self.channel.send(
                    client.get_user(int(ID)).mention +
                    " you cannot afford to play a new hand.")
                self.players.remove(ID)
                continue

            user = client.get_user(int(ID))
            playerList += user.name + "\n"
            self.maxBet = 50
            self.pot += 50
            self.deal(client.get_user(int(ID)), 2)

            userMoney -= 50
            DBConnection.updateUserBalance(ID, userMoney)

        embed.add_field(name="Players", value=playerList)
        embed.add_field(name="Pot", value="$" + str(self.pot))
        embed.add_field(name="Game ID", value=str(self.ID))
        embed.add_field(name="Community Cards",
                        value="Cards Dealt: " + str(len(self.communityCards)),
                        inline=False)

        await self.channel.send(file=file, embed=embed)
Esempio n. 12
0
    async def __call(self, ctx):
        ID = str(ctx.author.id)
        authorMoney = DBConnection.fetchUserData("userBalance", ID)
        embed = discord.Embed(title="Bet Call", color=0x00ff00)
        embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
        from main import client
        embed.set_thumbnail(url=client.get_user(716357127739801711).avatar_url)

        if not checkInGame(ctx.author):
            embed.description = "You are not in a game."
            await ctx.send(embed=embed)
            return

        GAME = getGame(ctx.author)

        if not channelCheck(GAME, ctx.channel):
            embed.description = "You are not in the specified game's channel. Please go there."
            await ctx.send(embed=embed)
            return

        embed.add_field(name="Game ID", value=str(GAME.ID), inline=False)
        embed.set_thumbnail(url=GAME.imageUrl)

        if not GAME.gameUnderway:
            embed.description = "This game has not started."
            embed.set_footer(text="Use c!start to start this game.")
            await ctx.send(embed=embed)
            return

        embed.set_footer(text="Format is c!raise <amount to raise by>.")
        embed.add_field(name="Your Balance", value="$" + str(authorMoney), inline=False)

        if GAME.playerStatus[ID] == "Fold":
            embed.description = "You are not participating in the current hand. Wait for the next one to start."
            await ctx.send(embed=embed)
            return

        embed.add_field(name="Current Highest Bet", value="$" + str(GAME.maxBet), inline=False)
        if str(ID) in GAME.bets:
            if GAME.bets[ID] == GAME.maxBet:
                embed.description = "Your bet already matches the highest bet."
                await ctx.send(embed=embed)
                return

        if authorMoney < GAME.maxBet - GAME.bets[ID]:
            embed.description = "You do not have the funds to match the highest bet."
            await ctx.send(embed=embed)
            return

        if ID in GAME.bets:
            difference = GAME.maxBet - GAME.bets[ID]
            GAME.pot += difference
            GAME.bets[ID] = GAME.maxBet
            authorMoney -= difference
        else:
            GAME.pot += GAME.maxBet
            GAME.bets[ID] = GAME.maxBet
            authorMoney -= GAME.maxBet

        DBConnection.updateUserBalance(ID, authorMoney)

        embed.set_field_at(1, name="Your New Balance", value ="$" + str(authorMoney), inline=False)
        embed.add_field(name="Pot", value="$" + str(GAME.pot))
        embed.description = "You matched the highest bet of $" + str(GAME.maxBet) + "."
        await ctx.send(embed=embed)
Esempio n. 13
0
    async def __raise(self, ctx, raiseBy: float = None):
        ID = str(ctx.author.id)
        embed = discord.Embed(title="Bet Raise", color=0x00ff00)
        embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
        from main import client
        embed.set_thumbnail(url=client.get_user(716357127739801711).avatar_url)

        authorMoney = DBConnection.fetchUserData("userBalance", ID)

        if not checkInGame(ctx.author):
            embed.description = "You are not in a game."
            await ctx.send(embed=embed)
            return

        GAME = getGame(ctx.author)

        if not channelCheck(GAME, ctx.channel):
            embed.description = "You are not in the specified game's channel. Please go there."
            await ctx.send(embed=embed)
            return

        embed.add_field(name="Game ID", value=str(GAME.ID), inline=False)
        embed.set_thumbnail(url=GAME.imageUrl)

        if not GAME.gameUnderway:
            embed.description = "This game has not started."
            embed.set_footer(text="Use c!start to start this game.")
            await ctx.send(embed=embed)
            return

        embed.set_footer(text="Format is c!raise <amount to raise by>.")
        embed.add_field(name="Your Balance", value="$" + str(authorMoney), inline=False)

        if GAME.playerStatus[ID] == "Fold":
            embed.description = "You are not participating in the current hand. Wait for the next one to start."
            await ctx.send(embed=embed)
            return

        if authorMoney < raiseBy:
            embed.description = "You do not have the funds to raise by $" + str(raiseBy) + "."
            await ctx.send(embed=embed)
            return

        if raiseBy + GAME.bets[ID] <= GAME.maxBet:
            embed.add_field(name="Current Highest Bet", value="$" + str(GAME.maxBet), inline=False)
            embed.description = "Does not beat the current highest bet."
            await ctx.send(embed=embed)
            return

        GAME.bets[ID] += raiseBy
        authorMoney -= raiseBy
        GAME.maxBet = GAME.bets[ID]
        GAME.pot += raiseBy
        DBConnection.updateUserBalance(ID, authorMoney)

        embed.remove_field(1)
        embed.add_field(name="Your New Balance", value="$" + str(authorMoney), inline=False)
        embed.add_field(name="Current Highest Bet", value="$" + str(GAME.maxBet), inline=False)
        embed.add_field(name="Pot", value="$" + str(GAME.pot))
        embed.description = "You raised your bet to $" + str(GAME.bets[ID])

        await ctx.send(embed=embed)