change way user data is updated + user is unpaused after mob fight
@@ -134,11 +134,6 @@ class MobSpawner(commands.Cog):
break
- await self.ipc.exec(f"econ_paused_users[{ctx.author.id}] = {time.time()}")
-
- async def free(new_user_health: int) -> None:
- await self.db.update_user(user.id, health=new_user_health)
- await self.ipc.eval(f"econ_paused_users.pop({ctx.author.id}, None)") # unpause user
# fetch user's sword, slime trophy, and suppress the engage message
user_sword, slime_trophy, _ = await asyncio.gather(
@@ -147,6 +142,9 @@ class MobSpawner(commands.Cog):
engage_msg.edit(suppress=True),
)
+ await self.ipc.exec(f"econ_paused_users[{ctx.author.id}] = {time.time()}")
+
+ try:
for iteration in itertools.count(start=1):
# create embed with mob image
embed = discord.Embed(color=self.d.cc, title=ctx.l.mobs_mech.attack_or_flee)
@@ -187,7 +185,6 @@ class MobSpawner(commands.Cog):
# check if user is a fucking baby
if timed_out or user_action in self.d.mobs_mech.valid_flees:
await fight_msg.edit(suppress=True)
- await free(user_health)
await self.bot.send_embed(ctx, random.choice(ctx.l.mons_mech.flee_insults))
return
@@ -207,7 +204,6 @@ class MobSpawner(commands.Cog):
if mob.health < 1: # user wins
await fight_msg.edit(suppress=True)
- await free(user_health)
await self.bot.send_embed(
ctx, random.choice(ctx.l.mobs_mech.user_finishers).format(mob.nice.lower(), user_sword.lower())
)
@@ -232,7 +228,6 @@ class MobSpawner(commands.Cog):
user_health = 0
await fight_msg.edit(suppress=True)
- await free(user_health)
await self.bot.send_embed(ctx, random.choice(mob.finishers))
break
@@ -243,7 +238,6 @@ class MobSpawner(commands.Cog):
user_health = max(user_health, 0)
if user_health < 1: # you == noob
- await free(user_health)
await self.bot.send_embed(ctx, random.choice(mob.finishers))
else:
await self.bot.send_embed(ctx, random.choice(mob.attacks))
@@ -354,6 +348,9 @@ class MobSpawner(commands.Cog):
ctx,
random.choice(ctx.l.mobs_mech.lost.normal).format(mob.nice.lower(), ems_lost, self.d.emojis.emerald),
)
+ finally:
+ await self.db.update_user(user.id, health=user_health)
+ await self.ipc.eval(f"econ_paused_users.pop({ctx.author.id}, None)") # unpause user
def setup(bot):
