dice.py (수정 필요함. 작동 안함)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import discord from discord.ext import commands from discord import Intents from discord import Status from discord import Object from smallFish import TOKEN, GUILD description = “”“낚시 중!”“” #bot = discord.Bot() class bot(commands.Bot): def __init__(self): intents = discord.Intents.default() intents.message_content = True super().__init__( intents=intents) async def on_ready(self): print(f“We have logged in as {bot.user}”) #@bot.event #async def on_ready(): # print(f”We have logged in as {bot.user}”) @bot.slash_command() async def rolldice(ctx:commands.context, location: str, type: str): “”“현재 위치를 입력해주세요 : Location에는 지역을, Type에는 수종를 입력하세요.”“” global ctx1 global str1 global str2 if location == “그린셰이드”: ctx1 = ctx str1 = location str2 = type await ctx.send(f“{str1}에서 {str2} 낚시 중…”) return str1, str2 await rolldice(ctx1, str1, str2) #@bot.event #async def on_message(message): # await rolldice() bot.run(TOKEN) | cs |
diceLoc.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import csv import pandas as pd #from dice import rolldice, str1, str2 from testDice import testDice, str1, str2 #str1 = str1 #str2 = str2 #ctx, str1, str2 = rolldice(ctx, str1, str2) str1, str2 = testDice(str1, str2) if str1 == “그린셰이드”: def fishAttr(): global fishList fishList = pd.read_csv(r‘Greenshade.csv’, dtype= {‘id’: str, ‘name’: str,‘type’: str, ‘grade’: str}, encoding=‘cp949’) print(“diceLoc: “, str2) return str2, fishList fishAttr() | cs |
diceFunc.py (dataFrame 형식에서 weights 인자 추가하기)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import csv import pandas as pd from diceLoc import fishAttr, str2, fishList #str2, fishList = fishAttr() str2 = str2 fishList = fishList if str2 == “호수”: def fishSet(): lFish = fishList.loc[fishList.type.isin([“호수”]),[‘type’, ‘name’, ‘grade’]] global fishRes fishRes = lFish.sample(1) print(“diceFunc: “, fishRes) return fishRes fishSet() elif str2 == “강”: def fishSet(): rFish = fishList.loc[fishList.type.isin([“강”]),[‘type’, ‘name’, ‘grade’]] global fishRes fishRes = rFish.sample(1) print(“diceFunc: “, fishRes) return fishRes fishSet() elif str2 == “웅덩이”: def fishSet(): fFish = fishList.loc[fishList.type.isin([“웅덩이”]),[‘type’, ‘name’, ‘grade’]] global fishRes fishRes = fFish.sample(1) print(“diceFunc: “, fishRes) return fishRes fishSet() elif str2 == “바다”: def fishSet(): sFish = fishList.loc[fishList.type.isin([“바다”]),[‘type’, ‘name’, ‘grade’]] global fishRes fishRes = sFish.sample(1) print(“diceFunc: “, fishRes) return fishRes fishSet() #fA_grade = fishAttr[‘grade’] #fA_g_val = set(fA_grade.values) #print(“물고기의 등급은 : “, fA_g_val) #class Fish: # def __init__(self, name, type, grade): # self.name = name # self.type = type # self.grade = grade # print(name, type, grade) # return | cs |
fishingResult.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import random from discord_webhook import DiscordWebhook from diceFunc import fishSet, fishRes url = “https://Your_address.com/WebHook_cord” #url = “https://Your_address.com/WebHook_cord” #fishRes = fishSet() flshRes = fishRes def fishResult(): result = random.choices([1, 2], weights = [0.3, 0.7]) fishSize = ‘ ‘.join(random.sample((‘생각보다 큽니다.’, ‘그럭저럭합니다.’, ‘기대보다 작습니다.’), 1)) resultList = fishRes.iloc[0].tolist() if result == [1]: message = f‘낚시 결과 : 낚시에 성공했습니다! {resultList[1]} 을/를 {resultList[0]} 에서 잡았습니다. 등급은 {resultList[2]} 입니다. 크기를 보아하니 {fishSize}’ print(“fishingResult: “, message) webhook = DiscordWebhook(url=url, content=message) webhook.execute() elif result == [2]: message = f‘낚시 결과 : 낚시에 실패했네요…’ webhook = DiscordWebhook(url=url, content=message) webhook.execute() fishResult() #def fishResult(): # result = random.choice([True, False]) # fishSize = random.sample((‘생각보다 큽니다.’, ‘그럭저럭합니다.’, ‘기대보다 작습니다.’), 1) # if result == “True”: # embed = discord.Embed(title=”낚시 결과”) # embed.add_field(name=”낚시에 성공했습니다!”, value=f”{fishRes[2]} 을/를 {fishRes[1]} 에서 잡았습니다. 등급은 {fishRes[3]} 입니다.”, inline=False) # embed.add_field(name=”크기를 보아하니,”, value=f”{fishSize}”) # # elif result == “False”: # embed = discord.Embed(title=”낚시 결과”) # embed.add_field(name=”낚시에 실패했네요…”, value=f”{fishRes[2]} 을/를 {fishRes[1]} 에서 잡았습니다. 등급은 {fishRes[3]} 입니다.”, inline=False) # embed.add_field(name=”크기를 짐작하자니,”, value=f”{fishSize}”) | cs |
이거저거 손대고 고치다가 재사용할 때 쓰기 좋으라고