Ejemplo n.º 1
0
    async def buy(self, ctx, corn_type="None", amount=0):
        "Usage: >buy corn-tag amount (leave amount blank to buy max)"
        game = load_game()
        transaction_result = game.do_buy_transaction(ctx.author.id, corn_type,
                                                     amount)

        # no swtich statements in python
        if transaction_result == "invalid type":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "Please input a valid corn tag (type >cp in chat to view a list)"
            )
            await ctx.send(embed=error_message)
        elif transaction_result == "no supply":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "There is no more corn of that type avaliable, wait a bit for it to re-stock"
            )
            await ctx.send(embed=error_message)
        elif transaction_result == "not number":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "Please input a valid number for the amount you want to buy")
            await ctx.send(embed=error_message)
        elif transaction_result == "below 0":
            error_message = Embed(
                title="Transaction Failed",
                description="Please input a valid number above 0")
            await ctx.send(embed=error_message)
        elif transaction_result == "cant buy 1":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "You cant afford even a single cob of that type of corn!")
            await ctx.send(embed=error_message)
        elif transaction_result == "buy amount high":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "The amount you asked for is more than the amount of corn on the market!"
            )
            await ctx.send(embed=error_message)
        elif transaction_result == "cant buy amount":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "You cant afford that much corn, enter a lower amount")
            await ctx.send(embed=error_message)
        else:
            message = Embed(title="Transaction Success",
                            description=transaction_result,
                            color=0x00ff00)
            message.set_author(name=ctx.message.author.name,
                               icon_url=ctx.message.author.avatar_url)
            await ctx.send(embed=message)

        save_game(game)
Ejemplo n.º 2
0
    async def sell(self, ctx, corn_type="None", amount=0):
        "Usage: >sell corn-tag amount (leave amount blank to sell max)"
        game = load_game()
        transaction_result = game.do_sell_transaction(ctx.author.id, corn_type,
                                                      amount)

        # no swtich statements in python
        if transaction_result == "invalid type":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "Please input a valid corn tag (type >cp in chat to view a list)\n You also may not own any of that type of corn!"
            )
            await ctx.send(embed=error_message)
        elif transaction_result == "not number":
            error_message = Embed(
                title="Transaction Failed",
                description=
                "Please input a valid number for the amount you want to sell")
            await ctx.send(embed=error_message)
        elif transaction_result == "below 0":
            error_message = Embed(
                title="Transaction Failed",
                description="Please input a valid number above 0")
            await ctx.send(embed=error_message)
        else:
            message = Embed(title="Transaction Success",
                            description=transaction_result,
                            color=0x00ff00)
            message.set_author(name=ctx.message.author.name,
                               icon_url=ctx.message.author.avatar_url)
            await ctx.send(embed=message)

        save_game(game)
Ejemplo n.º 3
0
async def manage_market(bot):
    
    await bot.wait_until_ready()

    print("Starting loop")

    reverse = [(60-(i/2))*-1 for i in range(120)]

    while not bot.is_closed():
        game = load_game()

        plt.clf()
        #plt.style.use('seaborn-darkgrid')
        plt.style.use('dark_background')
        plt.xlabel("Minutes ago")
        plt.ylabel("Demand")

        for corn_tag in game.corn_markets.keys():
            market = game.corn_markets[corn_tag]
            market.update_supply()
            market.update_history() 
            plt.plot(reverse, market.history_data, color=market.display_color, label=market.name)
            
        plt.legend(loc=3)
        save_game(game)
        save_plot(plt)
        await asyncio.sleep(30)
Ejemplo n.º 4
0
    async def pay(self, ctx, Mention="", amount=""):
        game = load_game()
        try:
            reciever = game.get_player(ctx.message.mentions[0].id)
            sender = game.get_player(ctx.message.author.id)
        except IndexError:
            message = Embed(
                title=f"Transaction Failed",
                description=
                f"No mention was included, or the user is not in this server",
                color=0xff0000)
            await ctx.send(embed=message)
            return

        try:
            dollars = float(amount)
        except ValueError:
            message = Embed(
                title=f"Transaction Failed",
                description=f"You must enter an amount greater than 0",
                color=0xff0000)
            await ctx.send(embed=message)
            return

        if dollars <= 0:
            message = Embed(
                title=f"Transaction Failed",
                description=f"You must enter an amount greater than 0",
                color=0xff0000)
            await ctx.send(embed=message)
            return

        if dollars > sender.money:
            message = Embed(title=f"Transaction Failed",
                            description=f"You do not have that much money!",
                            color=0xff0000)
            await ctx.send(embed=message)
            return

        sender.money -= dollars
        reciever.money += dollars

        save_game(game)

        message = Embed(
            title=f"Transaction Completed",
            description=
            f"{ctx.message.author.name} sent {ctx.message.mentions[0].name} ${'{:,.2f}'.format(dollars)}",
            color=0x00ff00)
        await ctx.send(embed=message)
    async def update_markets(self, ctx):
        "Used to add new types of corn, only for bot admins"
        if ctx.author.id not in self.__admins:
            return

        message = Embed(title="Preparing to Update",
                        description="Please wait one moment . . .",
                        color=0x000088)
        await ctx.send(embed=message)
        game = load_game()
        game.__init__(game.players)
        save_game(game)
        message = Embed(title="Updated Market",
                        description="Wallets are saved, Corn Market Updated",
                        color=0x0000ff)
        await ctx.send(embed=message)
    async def cycle(self, ctx):
        if ctx.author.id not in self.__admins:
            return

        game = load_game()
        message = Embed(title="Running Cycle",
                        description="Please wait one moment . . .",
                        color=0x000088)
        await ctx.send(embed=message)

        for i in range(120):
            for corn_tag in game.corn_markets.keys():
                market = game.corn_markets[corn_tag]
                market.update_supply()
                market.update_history()

        message = Embed(title="Completed Cycle",
                        description="Corn Market Updated",
                        color=0x0000ff)
        await ctx.send(embed=message)
        save_game(game)