1
0
forked from sass/tipibot

Fix shop interation

This commit is contained in:
Rene Arumetsa
2026-05-19 18:37:42 +03:00
parent 8d7ac504ca
commit b83b347d6a
2 changed files with 27 additions and 21 deletions

View File

@@ -822,8 +822,9 @@ def register_economy_extra_commands(
async def callback(interaction: discord.Interaction): async def callback(interaction: discord.Interaction):
self._tier = tier self._tier = tier
self._update_buttons() self._update_buttons()
await interaction.response.defer(edit_message=True)
self._user_data = await economy.get_user(interaction.user.id) self._user_data = await economy.get_user(interaction.user.id)
await interaction.response.edit_message( await interaction.edit_original_response(
embed=_shop_embed(self._tier, self._user_data), embed=_shop_embed(self._tier, self._user_data),
view=self, view=self,
) )

View File

@@ -22,12 +22,13 @@ def register_economy_income_commands(
) -> None: ) -> None:
@tree.command(name="daily", description=S.CMD["daily"]) @tree.command(name="daily", description=S.CMD["daily"])
async def cmd_daily(interaction: discord.Interaction): async def cmd_daily(interaction: discord.Interaction):
await interaction.response.defer()
res = await economy.do_daily(interaction.user.id) res = await economy.do_daily(interaction.user.id)
if not res["ok"]: if not res["ok"]:
if res["reason"] == "banned": if res["reason"] == "banned":
await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) await interaction.followup.send(S.MSG_BANNED, ephemeral=True)
elif res["reason"] == "cooldown": elif res["reason"] == "cooldown":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["daily"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["daily"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
@@ -51,7 +52,7 @@ def register_economy_income_commands(
lines.append(S.DAILY_UI["footer"].format(streak_str=streak_str, balance=coin(res["balance"]))) lines.append(S.DAILY_UI["footer"].format(streak_str=streak_str, balance=coin(res["balance"])))
embed = discord.Embed(title=S.TITLE["daily"], description="\n".join(lines), color=0xF4C430) embed = discord.Embed(title=S.TITLE["daily"], description="\n".join(lines), color=0xF4C430)
await interaction.response.send_message(embed=embed) await interaction.followup.send(embed=embed)
asyncio.create_task(maybe_remind(interaction.user.id, "daily")) asyncio.create_task(maybe_remind(interaction.user.id, "daily"))
asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["daily"])) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["daily"]))
@@ -59,17 +60,18 @@ def register_economy_income_commands(
async def cmd_work(interaction: discord.Interaction): async def cmd_work(interaction: discord.Interaction):
if await check_cmd_rate(interaction): if await check_cmd_rate(interaction):
return return
await interaction.response.defer()
res = await economy.do_work(interaction.user.id) res = await economy.do_work(interaction.user.id)
if not res["ok"]: if not res["ok"]:
if res["reason"] == "banned": if res["reason"] == "banned":
await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) await interaction.followup.send(S.MSG_BANNED, ephemeral=True)
elif res["reason"] == "cooldown": elif res["reason"] == "cooldown":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["work"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["work"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
elif res["reason"] == "jailed": elif res["reason"] == "jailed":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
@@ -84,7 +86,7 @@ def register_economy_income_commands(
desc += S.WORK_UI["laud"] desc += S.WORK_UI["laud"]
desc += S.WORK_UI["balance"].format(balance=coin(res["balance"])) desc += S.WORK_UI["balance"].format(balance=coin(res["balance"]))
embed = discord.Embed(title=S.TITLE["work"], description=desc, color=0x57F287) embed = discord.Embed(title=S.TITLE["work"], description=desc, color=0x57F287)
await interaction.response.send_message(embed=embed) await interaction.followup.send(embed=embed)
asyncio.create_task(maybe_remind(interaction.user.id, "work")) asyncio.create_task(maybe_remind(interaction.user.id, "work"))
asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["work"])) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["work"]))
@@ -92,12 +94,13 @@ def register_economy_income_commands(
async def cmd_beg(interaction: discord.Interaction): async def cmd_beg(interaction: discord.Interaction):
if await check_cmd_rate(interaction): if await check_cmd_rate(interaction):
return return
await interaction.response.defer()
res = await economy.do_beg(interaction.user.id) res = await economy.do_beg(interaction.user.id)
if not res["ok"]: if not res["ok"]:
if res["reason"] == "banned": if res["reason"] == "banned":
await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) await interaction.followup.send(S.MSG_BANNED, ephemeral=True)
elif res["reason"] == "cooldown": elif res["reason"] == "cooldown":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["beg"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["beg"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
@@ -114,7 +117,7 @@ def register_economy_income_commands(
beg_lines.append(S.BEG_UI["klaviatuur"]) beg_lines.append(S.BEG_UI["klaviatuur"])
beg_lines.append(S.BEG_UI["balance"].format(balance=coin(res["balance"]))) beg_lines.append(S.BEG_UI["balance"].format(balance=coin(res["balance"])))
embed = discord.Embed(title=title, description="\n".join(beg_lines), color=color) embed = discord.Embed(title=title, description="\n".join(beg_lines), color=color)
await interaction.response.send_message(embed=embed) await interaction.followup.send(embed=embed)
asyncio.create_task(maybe_remind(interaction.user.id, "beg")) asyncio.create_task(maybe_remind(interaction.user.id, "beg"))
asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["beg"])) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["beg"]))
@@ -122,17 +125,18 @@ def register_economy_income_commands(
async def cmd_crime(interaction: discord.Interaction): async def cmd_crime(interaction: discord.Interaction):
if await check_cmd_rate(interaction): if await check_cmd_rate(interaction):
return return
await interaction.response.defer()
res = await economy.do_crime(interaction.user.id) res = await economy.do_crime(interaction.user.id)
if not res["ok"]: if not res["ok"]:
if res["reason"] == "banned": if res["reason"] == "banned":
await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) await interaction.followup.send(S.MSG_BANNED, ephemeral=True)
elif res["reason"] == "cooldown": elif res["reason"] == "cooldown":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["crime"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["crime"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
elif res["reason"] == "jailed": elif res["reason"] == "jailed":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
@@ -161,7 +165,7 @@ def register_economy_income_commands(
+ S.CRIME_UI["balance"].format(balance=coin(res["balance"])), + S.CRIME_UI["balance"].format(balance=coin(res["balance"])),
color=0xED4245, color=0xED4245,
) )
await interaction.response.send_message(embed=embed) await interaction.followup.send(embed=embed)
asyncio.create_task(maybe_remind(interaction.user.id, "crime")) asyncio.create_task(maybe_remind(interaction.user.id, "crime"))
if res["success"]: if res["success"]:
asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["crime_win"])) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["crime_win"]))
@@ -180,27 +184,28 @@ def register_economy_income_commands(
await interaction.response.send_message(S.ERR["rob_house_blocked"], ephemeral=True) await interaction.response.send_message(S.ERR["rob_house_blocked"], ephemeral=True)
return return
await interaction.response.defer()
res = await economy.do_rob(interaction.user.id, sihtmärk.id) res = await economy.do_rob(interaction.user.id, sihtmärk.id)
if not res["ok"]: if not res["ok"]:
if res["reason"] == "banned": if res["reason"] == "banned":
await interaction.response.send_message(S.MSG_BANNED, ephemeral=True) await interaction.followup.send(S.MSG_BANNED, ephemeral=True)
elif res["reason"] == "cooldown": elif res["reason"] == "cooldown":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["rob"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["rob"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
elif res["reason"] == "jailed": elif res["reason"] == "jailed":
await interaction.response.send_message( await interaction.followup.send(
S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])), S.CD_MSG["jailed"].format(ts=cd_ts(res["remaining"])),
ephemeral=True, ephemeral=True,
) )
elif res["reason"] == "broke": elif res["reason"] == "broke":
await interaction.response.send_message( await interaction.followup.send(
S.ERR["rob_too_poor"].format(name=sihtmärk.display_name), S.ERR["rob_too_poor"].format(name=sihtmärk.display_name),
ephemeral=True, ephemeral=True,
) )
elif res["reason"] == "target_jailed": elif res["reason"] == "target_jailed":
await interaction.response.send_message( await interaction.followup.send(
S.ERR["rob_target_jailed"].format(name=sihtmärk.display_name), S.ERR["rob_target_jailed"].format(name=sihtmärk.display_name),
ephemeral=True, ephemeral=True,
) )
@@ -242,7 +247,7 @@ def register_economy_income_commands(
), ),
color=0xED4245, color=0xED4245,
) )
await interaction.response.send_message(embed=embed) await interaction.followup.send(embed=embed)
asyncio.create_task(maybe_remind(interaction.user.id, "rob")) asyncio.create_task(maybe_remind(interaction.user.id, "rob"))
if res["success"]: if res["success"]:
asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["rob_win"])) asyncio.create_task(award_exp(interaction, economy.EXP_REWARDS["rob_win"]))