fixes to locking / unlocking pillage lock
@@ -364,6 +364,7 @@ class Econ(commands.Cog):
res = await self.ipc.request({"type": PacketType.ACQUIRE_PILLAGE_LOCK, "user_ids": [ctx.author.id]})
+ try:
if res.locked:
await self.bot.reply_embed(ctx, ctx.l.misc.errors.nrn_buddy)
return
@@ -412,6 +413,9 @@ class Econ(commands.Cog):
await self.bot.reply_embed(
ctx, ctx.l.econ.dep.deposited.format(amount, self.d.emojis.emerald_block, amount * 9, self.d.emojis.emerald)
)
+ finally:
+ if not res.locked:
+ await self.ipc.send({"type": PacketType.RELEASE_PILLAGE_LOCK, "user_ids": [ctx.author.id]})
@commands.command(name="withdraw", aliases=["with"])
@commands.cooldown(1, 2, commands.BucketType.user)
@@ -873,6 +877,7 @@ class Econ(commands.Cog):
res = await self.ipc.request({"type": PacketType.ACQUIRE_PILLAGE_LOCK, "user_ids": [ctx.author.id, user.id]})
+ try:
if res.locked:
await self.bot.reply_embed(ctx, ctx.l.misc.errors.nrn_buddy)
return
@@ -927,6 +932,9 @@ class Econ(commands.Cog):
if (await self.db.fetch_user(user.id))["give_alert"]:
await self.bot.send_embed(user, ctx.l.econ.give.gaveyou.format(ctx.author.mention, amount, db_item["name"]))
+ finally:
+ if not res.locked:
+ await self.ipc.send({"type": PacketType.RELEASE_PILLAGE_LOCK, "user_ids": [ctx.author.id, user.id]})
@commands.command(name="gamble", aliases=["bet", "stonk", "stonks"])
# @commands.cooldown(1, 30, commands.BucketType.user)
@@ -1222,11 +1230,11 @@ class Econ(commands.Cog):
res = await self.ipc.request({"type": PacketType.ACQUIRE_PILLAGE_LOCK, "user_ids": [ctx.author.id, victim.id]})
+ try:
if res.locked:
await self.bot.reply_embed(ctx, ctx.l.misc.errors.nrn_buddy)
return
- try:
pillager_pillages, victim_pillages = await asyncio.gather(
self.ipc.exec(f"pillages[{ctx.author.id}] += 1; return pillages[{ctx.author.id}] - 1"),
self.ipc.eval(f"pillages[{victim.id}] - 1"),
@@ -1295,7 +1303,8 @@ class Econ(commands.Cog):
)
await self.bot.send_embed(victim, random.choice(ctx.l.econ.pillage.u_lose.victim).format(ctx.author.mention))
finally:
- await self.ipc.send({"type": PacketType.RELEASE_PILLAGE_LOCK, "user_ids": [ctx.author.id, victim.id]})
+ if not res.locked:
+ await self.ipc.send({"type": PacketType.RELEASE_PILLAGE_LOCK, "user_ids": [ctx.author.id]})
@commands.command(name="use", aliases=["eat", "chug", "smoke"])
# @commands.cooldown(1, 2, commands.BucketType.user)
