added pokemon xp gain on message, and added level calc

This commit is contained in:
phixxy 2024-01-09 12:10:21 -08:00
parent 1e6f1019f1
commit 906e58bdb5

View file

@ -1721,6 +1721,10 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
json_data = await get_json(url)
return json_data
async def calc_pkmn_buddy_level(pkmn_json): #this uses the 'fast' xp rate
buddy_xp = pkmn_json['buddy_xp']
return math.floor(((5*buddy_xp)/4)**(1/3))
async def make_pmkn_embed(pkmn_dict):
if pkmn_dict['nickname']:
title = pkmn_dict['nickname'] + ' (' + pkmn_dict['name'].capitalize() + ')'
@ -1732,7 +1736,7 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
else:
embed.set_image(url=pkmn_dict['sprites']['front_default'])
nature = pkmn_dict['nature']
buddy_level = pkmn_dict['buddy_level']
buddy_level = await calc_pkmn_buddy_level(pkmn_dict)
buddy_xp = pkmn_dict['buddy_xp']
types = []
for key in pkmn_dict['types']:
@ -1744,6 +1748,8 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
embed.add_field(name="Types", value=type_str, inline=False)
return embed
async def add_pkmn_reacts(message):
await message.add_reaction('🥰')
await message.add_reaction('🍙')
@ -1773,9 +1779,6 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
await ctx.channel.send("You already have a pokemon!")
return
if arg1 == 'nick' or arg1 == 'nickname':
nickname = arg2
json_data = await load_pokemon(ctx.author.id)
@ -1796,9 +1799,6 @@ async def pokemon(ctx, arg1=None, arg2=None, arg3=None, arg4=None):
await add_pkmn_reacts(message)
return
@bot.command(
description="Pokedex",
help="Get information on pokemon",
@ -1890,6 +1890,17 @@ async def on_reaction_add(reaction, user):
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
async def on_message(ctx):
@ -1898,6 +1909,9 @@ async def on_message(ctx):
channel_vars = await get_channel_config(ctx.channel.id)
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)
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