async def stock_buy(self, ctx: commands.Context, name: str, shares: int = None): if shares and shares < 1: return await ctx.reply(embed=make_text_embed( ctx.author, "1주 이상부터 구매할수 있습니다.", colors.RED)) try: data = get_stock_info(self.bot.con, name) except NameError: return await ctx.reply(embed=make_text_embed( ctx.author, f"찾을 수 없는 주식 `{name}` 입니다.", colors.RED)) user = GameUser(self.bot.con, str(ctx.author.id)) if not shares: shares = user.money // data["price"] if not shares: return await ctx.reply(embed=make_text_embed( ctx.author, f"보유하고 있는 돈으로는 `{name}` 의 주식을 1주도 구매할 수 없습니다.", colors.RED, )) price = data["price"] * shares unit = self.bot.config["game"]["unit"] if user.money < price: more = format_money(price - user.money, unit) return await ctx.reply(embed=make_text_embed( ctx.author, f"`{name}` 의 주식을 {shares}주 구매하려면 {more}이(가) 더 필요합니다.", colors.RED, )) buy, message = await one_more_check( ctx, f"`{name}` 의 주식 {shares}주를 {format_money(price, unit)}으로 구매할까요?") if not buy: return await message.edit(embed=make_text_embed( ctx.author, "구매를 취소했습니다.", colors.ORANGE, )) user.money -= price for i in range(shares): user.stock[name].append(data["price"]) user.commit() return await message.edit(embed=make_text_embed( ctx.author, f"`{name}` 의 주식을 {format_money(price, unit)}으로 {shares}주 구매했습니다.\n" f"현재 보유 금액: {format_money(user.money, unit)}", ))
async def item_buy(self, ctx: commands.Context, *, name: str): item = Item.get(name) if not item: return await ctx.reply(embed=make_text_embed( ctx.author, f"{name}은(는) 찾을 수 없는 아이템입니다.", colors.RED)) user = GameUser(self.bot.con, str(ctx.author.id)) unit = self.bot.config["game"]["unit"] if item in user.items: return await ctx.reply(embed=make_text_embed( ctx.author, f"이미 {name}을(를) 보유중입니다.", colors.RED, )) if user.money < item.price: more = format_money(item.price - user.money, unit) return await ctx.reply(embed=make_text_embed( ctx.author, f"{name}을(를) 구매하려면 {more}이(가) 더 필요합니다.", colors.RED, )) buy, message = await one_more_check( ctx, f"{name}을(를) {format_money(item.price, unit)}(으)로 구매할까요?") if not buy: return await message.edit(embed=make_text_embed( ctx.author, "구매를 취소했습니다.", colors.ORANGE, )) user.money -= item.price user.items.append(item) user.commit() return await message.edit(embed=make_text_embed( ctx.author, f"{name}을(를) {format_money(item.price, unit)}(으)로 구매했습니다.\n" f"현재 보유 금액: {format_money(user.money, unit)}", ))
async def info_user(self, ctx: commands.Context, target: discord.User = None): if target: if not GameUser.exist_user(ctx.bot.con, str(target.id)): return await ctx.reply( embed=make_text_embed( ctx.author, f"유저 {target}는(은) 가입을 하지 않았습니다.", colors.RED ) ) else: if not GameUser.exist_user(ctx.bot.con, str(ctx.author.id)): return await ctx.reply( embed=make_text_embed(ctx.author, "가입이 필요한 커맨드입니다.", colors.RED) ) target = ctx.author user = GameUser(self.bot.con, str(target.id)) embed = make_text_embed( ctx.author, f"{seconds_to_timestr(int(time.time() - user.join_time))} 전 가입" if time.time() - user.join_time < 21600 else f"{timestamp_to_timestr(user.join_time)} 가입", colors.AQUA, ) itemsstr = "\n".join(map(lambda item: item.name, user.items)) embed.add_field( name="돈", value=format_money(user.money, self.bot.config["game"]["unit"]), inline=False, ) embed.add_field( name="주식", value="\n".join(map(lambda x: f"{x}: {len(user.stock[x])}주", user.stock)), inline=False, ) embed.add_field( name="아이템", value=itemsstr if itemsstr else "보유 중인 아이템이 없습니다.", inline=False, ) embed.set_author(name=target.name, icon_url=target.avatar_url) await ctx.reply(embed=embed)