fixed bug in pkmn, moved pkmn msg counter to cog
This commit is contained in:
parent
d90c8a4418
commit
6aede9296b
2 changed files with 92 additions and 91 deletions
|
|
@ -139,90 +139,105 @@ class PokemonGame(commands.Cog):
|
||||||
embed.add_field(name="Buddy XP", value=buddy_xp, inline=True)
|
embed.add_field(name="Buddy XP", value=buddy_xp, inline=True)
|
||||||
embed.add_field(name="Types", value=type_str, inline=False)
|
embed.add_field(name="Types", value=type_str, inline=False)
|
||||||
return embed
|
return embed
|
||||||
|
try:
|
||||||
|
if args[0]=='start':
|
||||||
|
if not os.path.isdir("databases/pokemon/"):
|
||||||
|
os.makedirs("databases/pokemon/")
|
||||||
|
if not os.path.isfile("databases/pokemon/"+str(ctx.author.id)+'.json'):
|
||||||
|
uniq_id = time.time()
|
||||||
|
starter_id = await generate_starter(ctx.author.id)
|
||||||
|
json_data = await get_pkmn_from_id(starter_id)
|
||||||
|
is_shiny = await shiny_roll()
|
||||||
|
nature = random.randint(0,19)
|
||||||
|
nature_data = await self.get_json('https://pokeapi.co/api/v2/nature/')
|
||||||
|
nature = nature_data['results'][nature]['name']
|
||||||
|
json_data['shiny'] = is_shiny
|
||||||
|
json_data['nickname'] = None
|
||||||
|
json_data['unique_id'] = uniq_id
|
||||||
|
json_data['nature'] = nature
|
||||||
|
json_data['buddy_level'] = 1
|
||||||
|
json_data['buddy_xp'] = 0
|
||||||
|
json_data['last_food'] = 0
|
||||||
|
json_data['last_hug'] = 0
|
||||||
|
await save_pokemon(ctx.author.id, json_data)
|
||||||
|
embed = await make_pmkn_embed(json_data)
|
||||||
|
await ctx.channel.send(embed=embed)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
await ctx.channel.send("You already have a pokemon!")
|
||||||
|
return
|
||||||
|
|
||||||
if args[0]=='start':
|
elif args[0] == 'nick' or args[0] == 'nickname':
|
||||||
if not os.path.isdir("databases/pokemon/"):
|
nickname = args[1]
|
||||||
os.makedirs("databases/pokemon/")
|
json_data = await load_pokemon(ctx.author.id)
|
||||||
if not os.path.isfile("databases/pokemon/"+str(ctx.author.id)+'.json'):
|
json_data['nickname'] = nickname
|
||||||
uniq_id = time.time()
|
|
||||||
starter_id = await generate_starter(ctx.author.id)
|
|
||||||
json_data = await get_pkmn_from_id(starter_id)
|
|
||||||
is_shiny = await shiny_roll()
|
|
||||||
nature = random.randint(0,19)
|
|
||||||
nature_data = await self.get_json('https://pokeapi.co/api/v2/nature/')
|
|
||||||
nature = nature_data['results'][nature]['name']
|
|
||||||
json_data['shiny'] = is_shiny
|
|
||||||
json_data['nickname'] = None
|
|
||||||
json_data['unique_id'] = uniq_id
|
|
||||||
json_data['nature'] = nature
|
|
||||||
json_data['buddy_level'] = 1
|
|
||||||
json_data['buddy_xp'] = 0
|
|
||||||
json_data['last_food'] = 0
|
|
||||||
json_data['last_hug'] = 0
|
|
||||||
await save_pokemon(ctx.author.id, json_data)
|
await save_pokemon(ctx.author.id, json_data)
|
||||||
embed = await make_pmkn_embed(json_data)
|
message = "You gave " + nickname + ' a new name!'
|
||||||
await ctx.channel.send(embed=embed)
|
await ctx.channel.send(message)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
elif args[0] == 'feed':
|
||||||
|
json_data = await load_pokemon(ctx.author.id)
|
||||||
|
json_data, fed = await give_buddy_food(json_data)
|
||||||
|
if fed:
|
||||||
|
await save_pokemon(ctx.author.id, json_data)
|
||||||
|
if json_data['nickname']:
|
||||||
|
message = "You " + args[0] + ' ' + json_data['nickname']
|
||||||
|
else:
|
||||||
|
message = "You " + args[0] + ' ' + json_data['name']
|
||||||
|
await ctx.channel.send(message)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
if json_data['nickname']:
|
||||||
|
message = "Your " + json_data['nickname'] + " isn't hungry!"
|
||||||
|
else:
|
||||||
|
message = "Your " + json_data['name'] + " isn't hungry!"
|
||||||
|
await ctx.channel.send(message)
|
||||||
|
return
|
||||||
|
|
||||||
|
elif args[0] == 'hug':
|
||||||
|
json_data = await load_pokemon(ctx.author.id)
|
||||||
|
json_data, hugged = await give_buddy_affection(json_data)
|
||||||
|
if hugged:
|
||||||
|
await save_pokemon(ctx.author.id, json_data)
|
||||||
|
if json_data['nickname']:
|
||||||
|
message = "You " + args[0] + ' ' + json_data['nickname']
|
||||||
|
else:
|
||||||
|
message = "You " + args[0] + ' ' + json_data['name']
|
||||||
|
await ctx.channel.send(message)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
if json_data['nickname']:
|
||||||
|
message = "You hugged " + json_data['nickname'] + " but " + json_data['nickname'] + " has been hugged recently."
|
||||||
|
else:
|
||||||
|
message = "You hugged " + json_data['name'] + " but " + json_data['name'] + " has been hugged recently."
|
||||||
|
await ctx.channel.send(message)
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
#Default !pokemon behavior (Load and show pokemon embed)
|
||||||
|
discord_id = ctx.author.id
|
||||||
|
buddy_json = await load_pokemon(discord_id)
|
||||||
|
if not buddy_json:
|
||||||
|
await ctx.channel.send("You don't have a buddy yet. Type ```!pokemon start``` to start your Pokemon journey!")
|
||||||
else:
|
else:
|
||||||
await ctx.channel.send("You already have a pokemon!")
|
embed = await make_pmkn_embed(buddy_json)
|
||||||
|
message = await ctx.channel.send(embed=embed)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif args[0] == 'nick' or args[0] == 'nickname':
|
async def pkmn_msg(self, discord_id):
|
||||||
nickname = args[1]
|
path = "databases/pokemon/"+str(discord_id)+'.json'
|
||||||
json_data = await load_pokemon(ctx.author.id)
|
if os.path.isfile(path):
|
||||||
json_data['nickname'] = nickname
|
with open(path, 'r') as f:
|
||||||
await save_pokemon(ctx.author.id, json_data)
|
json_data = json.loads(f.readline())
|
||||||
message = "You gave " + nickname + ' a new name!'
|
json_data['buddy_xp'] += random.randint(1,5)
|
||||||
await ctx.channel.send(message)
|
json_data = json.dumps(json_data)
|
||||||
return
|
with open(path, 'w') as f:
|
||||||
|
f.writelines(json_data)
|
||||||
|
|
||||||
elif args[0] == 'feed':
|
@commands.Cog.listener()
|
||||||
json_data = await load_pokemon(ctx.author.id)
|
async def on_message(self, message: discord.Message):
|
||||||
json_data, fed = await give_buddy_food(json_data)
|
await self.pkmn_msg(message.author.id)
|
||||||
if fed:
|
|
||||||
await save_pokemon(ctx.author.id, json_data)
|
|
||||||
if json_data['nickname']:
|
|
||||||
message = "You " + args[0] + ' ' + json_data['nickname']
|
|
||||||
else:
|
|
||||||
message = "You " + args[0] + ' ' + json_data['name']
|
|
||||||
await ctx.channel.send(message)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
if json_data['nickname']:
|
|
||||||
message = "Your " + json_data['nickname'] + " isn't hungry!"
|
|
||||||
else:
|
|
||||||
message = "Your " + json_data['name'] + " isn't hungry!"
|
|
||||||
await ctx.channel.send(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
elif args[0] == 'hug':
|
|
||||||
json_data = await load_pokemon(ctx.author.id)
|
|
||||||
json_data, hugged = await give_buddy_affection(json_data)
|
|
||||||
if hugged:
|
|
||||||
await save_pokemon(ctx.author.id, json_data)
|
|
||||||
if json_data['nickname']:
|
|
||||||
message = "You " + args[0] + ' ' + json_data['nickname']
|
|
||||||
else:
|
|
||||||
message = "You " + args[0] + ' ' + json_data['name']
|
|
||||||
await ctx.channel.send(message)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
if json_data['nickname']:
|
|
||||||
message = "You hugged " + json_data['nickname'] + " but " + json_data['nickname'] + " has been hugged recently."
|
|
||||||
else:
|
|
||||||
message = "You hugged " + json_data['name'] + " but " + json_data['name'] + " has been hugged recently."
|
|
||||||
await ctx.channel.send(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
#Default !pokemon behavior (Load and show pokemon embed)
|
|
||||||
discord_id = ctx.author.id
|
|
||||||
buddy_json = await load_pokemon(discord_id)
|
|
||||||
if not buddy_json:
|
|
||||||
await ctx.channel.send("You don't have a buddy yet. Type ```!pokemon start``` to start your Pokemon journey!")
|
|
||||||
else:
|
|
||||||
embed = await make_pmkn_embed(buddy_json)
|
|
||||||
message = await ctx.channel.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
description="Pokedex",
|
description="Pokedex",
|
||||||
|
|
|
||||||
|
|
@ -214,17 +214,6 @@ async def on_reaction_add(reaction, user):
|
||||||
await message.add_reaction(emoji)
|
await message.add_reaction(emoji)
|
||||||
|
|
||||||
|
|
||||||
async def pkmn_msg(discord_id):
|
|
||||||
path = "databases/pokemon/"+str(discord_id)+'.json'
|
|
||||||
if os.path.isfile(path):
|
|
||||||
with open(path, 'r') as f:
|
|
||||||
json_data = json.loads(f.readline())
|
|
||||||
json_data['buddy_xp'] += random.randint(1,5)
|
|
||||||
json_data = json.dumps(json_data)
|
|
||||||
with open(path, 'w') as f:
|
|
||||||
f.writelines(json_data)
|
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_message(ctx):
|
async def on_message(ctx):
|
||||||
#log stuff
|
#log stuff
|
||||||
|
|
@ -232,9 +221,6 @@ async def on_message(ctx):
|
||||||
channel_vars = await get_channel_config(ctx.channel.id)
|
channel_vars = await get_channel_config(ctx.channel.id)
|
||||||
chat_history_string = await log_chat_and_get_history(ctx, logfile, channel_vars)
|
chat_history_string = await log_chat_and_get_history(ctx, logfile, channel_vars)
|
||||||
|
|
||||||
#add pokemon xp
|
|
||||||
await pkmn_msg(ctx.author.id)
|
|
||||||
|
|
||||||
#handle non-text channels (dms, etc)
|
#handle non-text channels (dms, etc)
|
||||||
if ctx.channel.type.value != 0 and ctx.author.id != 242018983241318410:
|
if ctx.channel.type.value != 0 and ctx.author.id != 242018983241318410:
|
||||||
#This used to notify the user it cannot respond in this channel, but that spammed threads
|
#This used to notify the user it cannot respond in this channel, but that spammed threads
|
||||||
|
|
@ -242,7 +228,7 @@ async def on_message(ctx):
|
||||||
|
|
||||||
await react_to_msg(ctx, channel_vars["react_to_msgs"]) #emoji reactions
|
await react_to_msg(ctx, channel_vars["react_to_msgs"]) #emoji reactions
|
||||||
|
|
||||||
if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "!"):
|
if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "?"):
|
||||||
await bot.process_commands(ctx)
|
await bot.process_commands(ctx)
|
||||||
if not channel_vars["commands_enabled"]:
|
if not channel_vars["commands_enabled"]:
|
||||||
await ctx.channel.send("This command only ran because you set it to allow to run even when commands are disabled")
|
await ctx.channel.send("This command only ran because you set it to allow to run even when commands are disabled")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue