async def 포기(ctx): global nickname global processing global turn global channel if ctx.author.id in processing: if channel != ctx.channel: return if ctx.author.id == processing[turn]: #내 카드가 상대카드보다 숫자가 더 큰지 확인 if turn == CardCheck(): if turn == 1: print(nickname[0]) financial.givemoney(ctx, nickname[0], sum(stack)) else: print(nickname[1]) financial.givemoney(ctx, nickname[1], sum(stack)) else: financial.givemoney(ctx, nickname[turn], int(stack[turn] / 2)) stack[turn] -= int(stack[turn] / 2) if turn == 1: print(nickname[0]) financial.givemoney(ctx, nickname[0], sum(stack)) else: print(nickname[1]) financial.givemoney(ctx, nickname[1], sum(stack)) await channel.delete() else: await ctx.author.send("상대방의 턴입니다.") else: await ctx.author.send("사용할 수 없는 명령어입니다.") return
async def 기부(ctx, userid=None, moa=None): try: if userid == None or not userid.isdigit(): raise Exception("기부할 유저의 id를 입력해주세요.") if moa == None: raise Exception("모아를 입력해주세요.") if int(moa) <= 0: raise Exception("0원이하로 기부할수 없습니다.") # 파일 읽어서 기부하는 사람의 닉네임, 기부받는 사람의 닉네임 받아들이기 giveuserInfo = json.load(f"data/{ctx.guild.id}/{ctx.author.id}.json") receiveuserInfo = json.load(f"data/{ctx.guild.id}/{userid}.json") if giveuserInfo["money"] < int(moa): raise Exception("자신 보유 자산보다 많이 기부할수 없습니다.") # 기부 하는 사람이랑 기부 받는 사람이랑 닉네임 같으면 기부불가 if ctx.author.id == int(userid): raise Exception("자신에게 기부할수 없습니다.") givemoney(ctx, giveuserInfo["nickname"], -int(moa)) givemoney(ctx, receiveuserInfo["nickname"], int(moa)) # 기부 완료 메세지 보내기 await ctx.send( f"{giveuserInfo['nickname']}, {receiveuserInfo['nickname']}에게 {moa}모아 기부완료" ) except Exception as e: await ctx.send(f"{e}\n$기부 (닉네임) (기부할 돈)") return
async def 구걸(ctx): filename = f"{datapath}{ctx.guild.id}/{ctx.author.id}.json" if not os.path.isfile(filename): await ctx.send("가입을 해주세요.") return userData = {} with open(filename, "r") as f: userData = json.load(f) nickname = userData["nickname"] money = userData["money"] if money > 0: await ctx.send("0모아를 가지고 있어야 구걸할수 있습니다.") 구걸.reset_cooldown(ctx) return getmoa = financial.GetBeggingMoa() if ispreseason: getmoa *= 3 givemoney(ctx, nickname, getmoa) await ctx.send(f"'{nickname}', {getmoa}모아 획득!")
async def BuyLotto(ctx, amount, FromBox=False): global Lottomax global lottoRange lottoPrice = 10000 * amount if ispreseason: lottoRange = 8 else: lottoRange = 10 showtext = "```" nickname = "" filename = f"{datapath}{ctx.guild.id}/{ctx.author.id}.json" userData = None if int(amount) > Lottomax and not FromBox: await ctx.send(f"한번에 {Lottomax}개까지 구매 가능합니다.") return if not os.path.isfile(filename): await ctx.send("가입을 해주세요.") return with open(filename) as f: userData = json.load(f) nickname = userData["nickname"] money = userData["money"] if not FromBox: if money < lottoPrice: await ctx.send(f"복권을 살 돈이 부족합니다.({lottoPrice}모아)") return else: givemoney(ctx, nickname, -lottoPrice) writetext = "" for num in range(amount): i = 0 number = [0, 0, 0, 0] num = 0 while i < 4: num = random.randint(1, lottoRange) if not num in number: number[i] = num i += 1 number.sort() number.append(random.choice(number)) showtext += nickname + " " + str(number) + "\n" for num in number: writetext += str(num) + "," writetext += str(ctx.author.id) + ",\n" f = open(f"lotto_{ctx.guild.id}", "a") f.write(writetext) f.close() showtext += "```" await ctx.send(showtext) await CheckLotto(f"lotto_{ctx.guild.id}", ctx)
async def 베팅(ctx, mode=None, moa=10000): global maxlucky try: bonusback = 0 success = True userinfo = datamanage.GetUserData(ctx) money = userinfo["money"] nickname = userinfo["nickname"] if money <= 0: raise Exception("베팅할 돈이 없습니다.") if mode == None: raise Exception("모드를 입력해주세요.") if int(mode) == 6 or int(mode) == 7: if moa == 10000: moa = math.floor(money * 0.5 * (int(mode) - 5)) else: await ctx.send("베팅 6,7은 금액 입력을 할 수 없습니다. 6-절반 7-올인") return if money < int(moa) or int(moa) < 0: raise Exception("보유량보다 많거나 0원 미만으로 베팅하실 수 없습니다.") if int(mode) > 7 or int(mode) < 1: raise Exception("모드를 잘못 입력했습니다.") except Exception as e: await ctx.send( f"{e}\n$베팅 (모드) (모아)\n(모드 종류 : 1 80% 1.2배, 2 64% 1.6배, 3 48% 2.2배, 4 32% 3배, 5 16% 4배, 6 60% 2배(올인만 가능)" ) return chance, multiple = get_chance_multiple(int(mode)) result = random.randrange(0, 100) lose = int(moa) profit = 0 if result < chance: profit = math.floor(multiple * int(moa)) await ctx.send(f"{nickname} 베팅 성공!") success = True else: await ctx.send(f"{nickname} 베팅 실패!") save2 = random.randrange(0, 100) success = False if save2 < 10: bonusback = math.floor(lose * 0.3) await ctx.send("건 돈의 30% 지급") givemoney(ctx, nickname, profit - lose + bonusback) if not success: await setluckypang(math.floor(int(moa) * 0.1), ctx, maxlucky, datapath)
async def 자산이전(ctx, nickname1, nickname2, moa): if ctx.author.id != 382938103435886592: await ctx.send("제작자 전용 명령어입니다.") return check = [] moa = int(moa) check.append(givemoney(ctx, nickname1, moa)) check.append(givemoney(ctx, nickname2, moa)) if 0 in check: await ctx.send("존재하지 않는 유저입니다.") return await ctx.send(f"{nickname1}의 {moa}모아를 {nickname2}에게 이전 완료")
async def 베팅(ctx, price): global process global processing global stack global turn global nickname global channel if ctx.author.id in processing: if channel != ctx.channel: return if ctx.author.id == processing[turn]: canbet = financial.givemoney(ctx, nickname[turn], price, 3) if canbet == -1: await ctx.author.send("자신 보유액보다 많이 베팅할수 없습니다.") return else: if int(price) > 5000: await ctx.author.send("5000모아를 넘길수 없습니다.") return stack[turn] += int(price) if turn == 0: turn = 1 else: turn = 0 await channel.send(f"{nickname[turn]}의 차례입니다.({sum(stack)})") else: await ctx.author.send("상대방의 턴입니다.") else: await ctx.author.send("사용할 수 없는 명령어입니다.") return
async def 운영자지급(ctx, nickname, moa): if ctx.author.id != 382938103435886592: await ctx.send("권한이 없습니다.") return check = givemoney(ctx, nickname, moa) if check == 0: await ctx.send("존재하지 않는 유저입니다.") return await ctx.send(f"{nickname}에게 {moa}모아 지급 완료")
async def buyforce(ctx, level, isadvance=False): try: filename = datamanage.GetFileName(ctx) if not os.path.isfile(filename): await ctx.send("가입을 해주세요.") return name = "" forceSale = {} userforce = {} if isadvance: name = "고오급 " with open(f"data/{ctx.guild.id}/advforcestore.json", "r") as forceFile: forceSale = json.load(forceFile) else: with open(f"data/{ctx.guild.id}/forcestore.json", "r") as forceFile: forceSale = json.load(forceFile) sale = False chour = datetime.datetime.now().time().hour if chour == 13 or chour == 21 or chour == 17: sale = True nickname = "" showtext = "```" if level == None: head = "" if isadvance: head = "고오급 " if sale: showtext += "의문의 물건 +15이상 20% 할인중!\n" for key, value in list(sorted(forceSale.items())): price = get_price(key, isadvance)[0] if int(key) >= 15 and sale: showtext += ( f"{head}의문의 물건 +{key}, {value}개 남음, {math.floor(price*0.8)}모아\n" ) else: showtext += f"{head}의문의 물건 +{key}, {value}개 남음, {price}모아\n" showtext += "```" await ctx.send(showtext) return userfile = open(filename, "r") userInfo = json.load(userfile) nickname = userInfo["nickname"] money = userInfo["money"] mylevel = userInfo["unknownLevel"] if isadvance: with open(f"data/{ctx.guild.id}/advforceuser.json", "r") as forceFile: userforce = json.load(forceFile) if str(ctx.author.id) in userforce.keys(): mylevel = userforce[str(ctx.author.id)] else: mylevel = 0 if mylevel > 0: await ctx.send("의문의 물건은 1개만 보유할수 있습니다.") return if not str(level) in forceSale.keys(): await ctx.send(f"의문의 물건 +{level}의 매물이 없습니다.") return price = 0 if int(level) >= 15 and sale and (not isadvance): price = math.floor(get_price(level)[0] * 0.8) else: price = get_price(level, isadvance)[0] print(price) if money >= price: if not isadvance: givemoney(ctx, nickname, price, 2, level) else: givemoney(ctx, nickname, -price) else: await ctx.send(f"{price-money}모아가 부족합니다.") return forceSale[level] -= 1 if forceSale[level] <= 0: forceSale.pop(level) userforce[str(ctx.author.id)] = int(level) if not isadvance: with open(f"data/{ctx.guild.id}/forcestore.json", "w") as forceFile: json.dump(forceSale, forceFile) else: with open(f"data/{ctx.guild.id}/advforcestore.json", "w") as forceFile: json.dump(forceSale, forceFile) with open(f"data/{ctx.guild.id}/advforceuser.json", "w") as forceFile: json.dump(userforce, forceFile) await ctx.send(f"{nickname}, {name}의문의 물건 +{level} 구매 성공") except Exception as e: await ctx.send(f"{e}\n$강화구매 (레벨)") traceback.print_exc()
async def sellforce(message, reuser, isAdvance=False): head = "" filename = "" userhave = {} if isAdvance: head = "고오급 " filename = "data/advforcestore.json" with open("data/advforceuser.json", "r") as file: userhave = json.load(file) else: head = "" filename = "data/forcestore.json" ctx = message.channel level = 0 maxlevel = GetMaxLevel(isAdvance) file = open(f"data/user_info{message.guild.id}", "r") file.seek(0) lines = file.readlines() file.close() nickname = "" for user in lines: user_info = user.split(",") if user_info[2] == str(reuser.id): nickname = user_info[1] level = int(user_info[4]) if isAdvance: if str(reuser.id) in userhave.keys(): level = userhave[str(reuser.id)] else: return if level <= 1: await reuser.send(f"{head}의문의 물건이 +1이거나 가지고 있지 않습니다.") return pricesell = get_price(level, isAdvance)[1] if not isAdvance: givemoney(ctx, nickname, pricesell, 1) else: givemoney(ctx, nickname, pricesell) if level >= maxlevel: await ctx.send( f"{head}의문의 물건 {maxlevel}강을 판매되어서 시즌이 종료되었습니다. 관련 공지가 있을때까지 프리시즌이 유지됩니다." ) datamanage.datareset(message.guild) return True forceSale = {} with open(filename, "r") as forceFile: forceSale = json.load(forceFile) print(userhave) if isAdvance: userhave.pop(str(reuser.id)) if f"{level}" in forceSale.keys(): forceSale[f"{level}"] += 1 else: forceSale[f"{level}"] = 1 with open(filename, "w") as forceFile: json.dump(forceSale, forceFile) if isAdvance: with open("data/advforceuser.json", "w") as file: json.dump(userhave, file) await ctx.send(f"의문의 물건 +{level}이 판매되었습니다.")
async def CheckLotto(filename, ctx): global canLotto global Lottocool if ispreseason: lottoRange = 8 else: lottoRange = 10 file = open(filename, "r") lines = file.readlines() await ctx.send(f"{len(lines)}/{Lottocool}") showtext = "```" if len(lines) >= Lottocool: canLotto = False result = [0, 0, 0, 0] special = 0 totalSell = float(len(lines) * 1000) i = 0 # region 로또 추첨 while i < 4: num = random.randint(1, lottoRange) if not num in result: result[i] = num i += 1 result.sort() special = random.choice(result) # endregion showtext += ( f"당첨 번호 : {result[0]},{result[1]},{result[2]},{result[3]},{special}\n" ) for line in lines: nickname = "" submit = line.split(",") i = 0 correct = 0 place = 0 getprice = 0 while i < 4: if int(submit[i]) in result: correct += 1 i += 1 if correct > 0: if correct == 4: if special == int(submit[4]): place = 1 getprice = 5000000 else: place = 2 getprice = 1000000 elif correct == 3: place = 3 getprice = 100000 elif correct == 2: place = 4 getprice = 20000 userfile = open(f"{datapath}user_info{ctx.guild.id}", "r") userdata = userfile.readlines() file.close() for sub in userdata: cuser = sub.split(",") if submit[5] == cuser[2]: nickname = cuser[1] givemoney(ctx, nickname, getprice) if place != 0: showtext += f"{nickname} {place}등 당첨! {getprice}모아 지급! [{submit[0]},{submit[1]},{submit[2]},{submit[3]},{submit[4]}]\n" showtext += "```" await ctx.send(showtext) os.remove(filename) canLotto = True Lottocool = random.randint(10, 30)
async def job(): iswriting = False isgiving = False if testmode: datapath = "testdata/" channel = bot.get_channel(709647685417697372) else: datapath = "data/" channel = bot.get_channel(771203131836989443) while True: currentTime = datetime.datetime.now() hour = currentTime.hour minute = currentTime.minute second = currentTime.second if hour == 1 and second >= 0 and second < 10 and minute == 0: forceSale = {} with open(f"{datapath}forcestore.json", "r") as forceFile: forceSale = json.load(forceFile) if forceSale["1"] < 100: forceSale["1"] = 100 with open(f"{datapath}forcestore.json", "w") as forceFile: json.dump(forceSale, forceFile) await channel.send("의문의 물건 +1의 남은 개수가 100개가 되었습니다.") with open(f"{datapath}advforcestore.json", "r") as forceFile: forceSale = json.load(forceFile) if forceSale["1"] < 20: forceSale["1"] = 20 with open(f"{datapath}advforcestore.json", "w") as forceFile: json.dump(forceSale, forceFile) await channel.send("고오급 의문의 물건 +1의 남은 개수가 20개가 되었습니다.") elif ((hour % 12 == 5 or hour % 12 == 11) and minute == 0 and second >= 0 and second < 10): if not isgiving: userlist = financial.GetInfo(channel) minlist = [] maxlist = [] minimum = 0 maximum = 0 index = 0 for key, value in userlist.items(): if index == 0: minimum = int(value) maximum = int(value) minlist.append([key, value]) maxlist.append([key, value]) else: if int(value) > maximum: maximum = int(value) maxlist.clear() maxlist.append([key, value]) elif int(value) == maximum: maxlist.append([key, value]) elif int(value) < minimum: minimum = int(value) minlist.clear() minlist.append([key, value]) elif int(value) == minimum: minlist.append([key, value]) index += 1 maxstack = 0 for user in maxlist: tempstack = -math.floor(user[1] * 0.1) givemoney(channel, user[0], tempstack) maxstack -= tempstack remain = len(minlist) for user in minlist: print(maxstack) if remain != 1: willgive = math.floor(maxstack / remain) maxstack = willgive givemoney(channel, user[0], willgive) else: givemoney(channel, user[0], maxstack) remain -= 1 print(maxstack) if remain == 0: break await channel.send("자산 분배가 완료되었습니다.") else: return await asyncio.sleep(10)