async def buy_item(self, ctx: commands.Command, count: int, item_name: str): result = InventoryUtil.buyShopitem(ctx.guild.id, ctx.author.id, item_name, count) if result == ErrorCode.CannotFindProduct: await ctx.send("沒有該項商品,請確認!") elif result == ErrorCode.LevelDoesNotReach: await ctx.send("等級不夠,無法購買!") elif result == ErrorCode.TokenDoesNotEnough: await ctx.send("雞腿不夠,無法購買!") elif result == ErrorCode.SupplyDoesNotEnough: await ctx.send("商品數量不足,無法購買!") else: await ctx.send(f"{count}個{result.item.name} 購買成功!") InventoryUtil.checkZeroAmount(ctx.guild.id)
def test_buyShopitem_success_shopItemchangeHidden(self): MemberUtil.add_member(member_id=123) MemberUtil.add_token(member_id=123, amount=500) ItemUtil.createItem(guild_id=1, item_name="hello", item_type=ItemType.ATTACK, buff_type=BuffType.ATTACK, buff_value=-1, buff_round=2, level_required=0, price=1) InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10) InventoryUtil.buyShopitem(guild_id=1, user_id=123, item_name="hello", count=10) InventoryUtil.checkZeroAmount(guild_id=1) result = InventoryUtil.ShopMenu(guild_id=1) assert len(result) == 0 and result == []