fixed bug in pkmn, moved pkmn msg counter to cog

This commit is contained in:
phixxy 2024-01-20 22:28:36 -08:00
parent d90c8a4418
commit 6aede9296b
2 changed files with 92 additions and 91 deletions

View file

@ -139,7 +139,7 @@ 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 args[0]=='start':
if not os.path.isdir("databases/pokemon/"): if not os.path.isdir("databases/pokemon/"):
os.makedirs("databases/pokemon/") os.makedirs("databases/pokemon/")
@ -213,7 +213,7 @@ class PokemonGame(commands.Cog):
message = "You hugged " + json_data['name'] + " but " + json_data['name'] + " has been hugged recently." message = "You hugged " + json_data['name'] + " but " + json_data['name'] + " has been hugged recently."
await ctx.channel.send(message) await ctx.channel.send(message)
return return
except:
#Default !pokemon behavior (Load and show pokemon embed) #Default !pokemon behavior (Load and show pokemon embed)
discord_id = ctx.author.id discord_id = ctx.author.id
buddy_json = await load_pokemon(discord_id) buddy_json = await load_pokemon(discord_id)
@ -224,6 +224,21 @@ class PokemonGame(commands.Cog):
message = await ctx.channel.send(embed=embed) message = await ctx.channel.send(embed=embed)
return return
async def pkmn_msg(self, 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)
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
await self.pkmn_msg(message.author.id)
@commands.command( @commands.command(
description="Pokedex", description="Pokedex",
help="Get information on pokemon", help="Get information on pokemon",

View file

@ -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")