async def _sell_stock(self, ctx, name, count='모두'): stock_names = { '삼송': '삼송증권', '알지': '알지전자', '현내': '현내보험', '동영': '동영화학', '한와': '한와금융', '로데': '로데관광', '동안': '동안출판', '하태': '하태식품', '소울': '소울우유', '남영': '남영유업', '대환': '대환통운' } if not (name in list(stock_names.keys()) or name in list(stock_names.values())): return await warn(ctx=ctx, content='주식을 찾을 수 없습니다.') if name in list(stock_names.keys()): name = stock_names[name] if isfile(f'stocks/users/{ctx.author.id}.bin'): with open(f'stocks/users/{ctx.author.id}.bin', 'rb') as f: data = load(f) else: return await warn(ctx=ctx, content=f'{ctx.author.mention}님은 주식을 갖고 있지 않습니다.') if not name in data: return await warn(ctx=ctx, content=f'{ctx.author.mention}님은 주식을 갖고 있지 않습니다.') with open('stocks/stocks.bin', 'rb') as f: stocks = load(f) if count in ['모두', 'ㅇㅇ', '올인', '최대']: count = 0 for i in data[name]: count += i['count'] else: count = int(count) if count < 1: return await warn(ctx=ctx, content='팔 주식의 개수를 1개 이상으로 입력해 주세요') user_stocks = 0 for i in data[name]: user_stocks += i['count'] if user_stocks < count: return await warn(ctx=ctx, content='팔 주식이 부족합니다.') addmoney = 0 counts = 0 while count != 0: if count >= data[name][0]['count']: addmoney += data[name][0]['count'] * stocks[name]['price'] count -= data[name][0]['count'] counts += data[name][0]['count'] del data[name][0] else: data[name][0]['count'] -= count counts += count addmoney += count * stocks[name]['price'] count = 0 deliting = [] for i in data: if len(data[i]) == 0: deliting.append(i) for i in deliting: del data[i] with open(f'stocks/users/{ctx.author.id}.bin', 'wb') as f: dump(data, f) writedata(id=ctx.author.id, item='point', value=str(int(getdata(id=ctx.author.id, item='point')) + addmoney)) await sendEmbed(ctx=ctx, title='매도', content=f'{name}의 주식을 `{counts}`주 매도했습니다.')
async def _sendmoney(self, ctx, user:discord.Member, amount:int): if amount < 50: return await warn(ctx=ctx, content='50λ” μ�΄μƒ�부터 송κΈ�ν• μ�� μ��μ�µλ‹�다') if user.bot or user.id == ctx.author.id: return await warn(ctx=ctx, content='송κΈ�ν• μ�� μ—†λ�” μ� μ €μ�…λ‹�다') if amount > int(getdata(id=ctx.author.id, item='point')): return await warn(ctx=ctx, content='λ��μ�΄ 부족합λ‹�다') writedata(id=ctx.author.id, item='point', value=str(int(getdata(id=ctx.author.id, item='point'))-amount)) writedata(id=user.id, item='point', value=str(int(getdata(id=user.id, item='point'))+round(amount*0.95))) await sendEmbed(ctx=ctx, title='π�’µ 송κΈ� π�’µ', content=f'`{user}`λ‹�κ»� π�’µ `{round(amount*0.95)}`λ§�ν�Ό 송κΈ�λ��μ—�μ�µλ‹�다.\nμ��μ��λ£�: π�’µ `{amount-round(amount*0.95)}`')
async def give_stock_profit(self): for i in listdir('stocks/users'): user_id = int(i.replace('.bin', '')) with open(i, 'rb') as f: data = load(f) with open('stocks/stocks.bin', 'rb') as f: stock_price = load(f) for i in data: count = 0 for j in data[i]: count += j['count'] writedata(id=user_id, item='point', value=str(int(getdata(id=user_id, item='point')) + round(stock_price[i]['price'] * 0.01 * count))) await log(embed=discord.Embed(title='정상적으로 배당금 부여', description=str(datetime.now()), color=embedcolor), bot=self.bot)
async def _addpoint(self, ctx, user: discord.user, addpoint: int): point = int(getdata(id=user.id, item='point')) point += addpoint writedata(id=user.id, item='point', value=str(point)) await sendEmbed(ctx=ctx, title='관리자송금', content=f'{addpoint}원이 {user.mention}님께 보내졌습니다.') await log(embed=discord.Embed( title='관리자송금', description= f'{user.mention}님의 돈에 `{addpoint}`가 추가되었습니다.\n처리자: {ctx.author.mention}\n{(str(ctx.message.created_at))[:-7]}', color=embedcolor), bot=self.bot)
async def _buy_stock(self, ctx, name, count='모두'): stock_names = { '삼송': '삼송증권', '알지': '알지전자', '현내': '현내보험', '동영': '동영화학', '한와': '한와금융', '로데': '로데관광', '동안': '동안출판', '하태': '하태식품', '소울': '소울우유', '남영': '남영유업', '대환': '대환통운' } if not (name in list(stock_names.keys()) or name in list(stock_names.values())): return await warn(ctx=ctx, content='주식을 찾을 수 없습니다.') if name in list(stock_names.keys()): name = stock_names[name] if isfile(f'stocks/users/{ctx.author.id}.bin'): with open(f'stocks/users/{ctx.author.id}.bin', 'rb') as f: data = load(f) else: data = {} with open('stocks/stocks.bin', 'rb') as f: stocks = load(f) if count in ['모두', 'ㅇㅇ', '올인', '최대']: count = int(getdata(id=ctx.author.id, item='point')) // stocks[name]['price'] if count == 0: return await warn(ctx=ctx, content='돈이 부족합니다') else: count = int(count) if count < 1: return await warn(ctx=ctx, content='살 주식의 개수를 1개 이상으로 입력해 주세요') if count * stocks[name]['price'] > int(getdata(id=ctx.author.id, item='point')): return await warn(ctx=ctx, content='돈이 부족합니다') if name in data: data[name].append({'count': count, 'price': stocks[name]['price']}) else: data[name] = [{'count': count, 'price': stocks[name]['price']}] deliting = [] for i in data: if len(data[i]) == 0: deliting.append(i) for i in deliting: del data[i] with open(f'stocks/users/{ctx.author.id}.bin', 'wb') as f: dump(data, f) writedata(id=ctx.author.id, item='point', value=str(int(getdata(id=ctx.author.id, item='point')) - count * stocks[name]['price'])) await sendEmbed(ctx=ctx, title='매수', content=f'{name}의 주식을 `{count}`주 매수했습니다.')
async def _betting(self, ctx, amount): point = int(getdata(id=ctx.author.id, item='point')) if amount in ['μ�¬μ�Έ', 'λ�¨λ‘�']: amount = point try: amount = int(amount) except ValueError: await warn(ctx=ctx, content='κ±Έ λ��μ�„ μ �λ�€λ΅� λ„£μ–΄ μ£Όμ„Έμ�”.') return if int(point) < amount: return await warn(ctx=ctx, content='λ��μ�΄ 부족합λ‹�다.') result = randint(-1, 1) writedata( id=ctx.author.id, item='countRandom', value=str(int(getdata(id=ctx.author.id, item='countRandom')) + 1)) if result == 1: writedata(id=ctx.author.id, item='point', value=str(point + amount)) await sendEmbed( ctx=ctx, title='와아아', content=f'μ�΄κ²Όμ�µλ‹�다!\nν�„μ�¬ ν�¬μ�Έν�Έ: `{point+amount}`' ) writedata( id=ctx.author.id, item='winningRandom', value=str( int(getdata(id=ctx.author.id, item='winningRandom')) + 1)) elif result == 0: await sendEmbed( ctx=ctx, title='ν�΄...', content= 'μ�΄κΈ°μ§„ λ�»ν–�지λ§� 다행ν�� μ�ƒμ§€λ�” μ•�μ•�μ–΄μ�”!') else: writedata(id=ctx.author.id, item='point', value=str(point - amount)) await sendEmbed( ctx=ctx, title='μ�΄λ�°!', content= f'아쉽κ²�λ�„ μ Έμ„� π�’µ {amount}λ§�ν�Ό μ�ƒμ—�μ–΄μ�”...\nν�„μ�¬ ν�¬μ�Έν�Έ: `{point-amount}`' )
async def _check(self, ctx): date = getnow('%Y%m%d') if getdata(id=ctx.author.id, item='lastCheck') == date: await warn(ctx=ctx, content='μ�¤λ��μ�€ μ�΄λ―Έ μ¶�μ„�ν–�μ�µλ‹�다. λ‚΄μ�Ό μ¶�μ„�ν•΄ μ£Όμ‹μ‹�μ�¤.') return point = str(int(getdata(id=ctx.author.id, item='point')) + 500 * randint(2, 4)) writedata(id=ctx.author.id, item='point', value=point) writedata(id=ctx.author.id, item='coundCheck', value=str(1+int(getdata(id=ctx.author.id, item='countCheck')))) writedata(id=ctx.author.id, item='lastCheck', value=date) await sendEmbed(ctx=ctx, title='μ¶�μ„�', content=f'μ¶�μ„� μ™„λ£�λ��μ—�μ�µλ‹�다.\nν�„μ�¬ ν�¬μ�Έν�Έ: `{point}`') writingDate = getnow('**%H:%M:%S.%f**') if not isdir('rank'): makedirs('rank') if not isfile('rank/check.json'): with open('rank/check.json', 'w') as f: json.dump({ 'date': date, '1': {'id': 'none', 'time': 'none'}, '2': {'id': 'none', 'time': 'none'}, '3': {'id': 'none', 'time': 'none'}, '4': {'id': 'none', 'time': 'none'}, '5': {'id': 'none', 'time': 'none'}, 'len': '0' }, f) with open('rank/check.json', 'r') as f: data = json.load(f) if data['date'] != date: data = { 'date': date, '1': {'id': 'none', 'time': 'none'}, '2': {'id': 'none', 'time': 'none'}, '3': {'id': 'none', 'time': 'none'}, '4': {'id': 'none', 'time': 'none'}, '5': {'id': 'none', 'time': 'none'}, 'len': '0' } if data['len'] == '5': return data['len'] = str(int(data['len']) + 1) data[data['len']]['id'] = str(ctx.author.id) data[data['len']]['time'] = writingDate data['date'] = date with open('rank/check.json', 'w') as f: json.dump(data, f) content = [] for i in range(int(data['len'])): content.append('**' + str(i+1) + '**. `' + str(await self.bot.fetch_user(int(data[str(i+1)]['id']))) + '` : ' + data[str(i+1)]['time']) await sendEmbed(ctx=ctx, title='μ¶�μ„� λ�ν‚Ή', content='\n'.join(content))
async def _sendmoney(self, ctx, user: discord.User, amount: int): if amount < 100: await warn( ctx=ctx, content='100μ›� μ�΄μƒ�부터 송κΈ�ν• μ�� μ��μ�µλ‹�다') return if user.bot: return await warn( ctx=ctx, content='봇μ—�κ²�λ�” 송κΈ�ν• μ�� μ—†μ�µλ‹�다') writedata( id=ctx.author.id, item='point', value=str(int(getdata(id=ctx.author.id, item='point')) - amount)) writedata(id=user.id, item='point', value=str( int(getdata(id=user.id, item='point')) + round(amount * 0.95))) await sendEmbed( ctx=ctx, title='π�’µ 송κΈ� π�’µ', content= f'`{user}`λ‹�κ»� π�’µ `{round(amount*0.95)}`λ§�ν�Ό 송κΈ�λ��μ—�μ�µλ‹�다.\nμ��μ��λ£�: π�’µ `{amount-round(amount*0.95)}`' )
async def _introduce(self, ctx, *, content=''): writedata(id=ctx.author.id, item='introduce', value=content) await sendEmbed( ctx=ctx, title='소개말설정', content=f'{ctx.author.name}님의 소개말이 `{content}`로 변경되었습니다.')
async def on_command_completion(self, ctx): if ctx.author.bot: return writedata( id=ctx.author.id, item='commandCount', value=str(1 + int(getdata(id=ctx.author.id, item='commandCount'))))