|
21 | 21 | from ballsdex.core.discord import UNKNOWN_INTERACTION, Container, LayoutView, Modal |
22 | 22 | from ballsdex.core.utils.buttons import ConfirmChoiceView |
23 | 23 | from ballsdex.core.utils.menus import CountryballFormatter, Menu, ModelSource, TextFormatter, TextSource |
| 24 | +from bd_models.enums import TradeCooldownPolicy |
24 | 25 | from bd_models.models import BallInstance, Player, Trade, TradeObject |
25 | 26 | from settings.models import settings |
26 | 27 | from settings.utils import format_currency |
|
49 | 50 | log = logging.getLogger(__name__) |
50 | 51 |
|
51 | 52 | TRADE_TIMEOUT = 60 * 30 |
| 53 | +COOLDOWN_BYPASS_TIMEOUT = 10 |
52 | 54 |
|
53 | 55 |
|
54 | 56 | class SetMoneyModal(Modal, title="Set money offering"): |
@@ -423,6 +425,7 @@ def __init__(self, cog: "TradeCog"): |
423 | 425 | self.confirmation_lock = asyncio.Lock() |
424 | 426 | self.edit_lock = asyncio.Lock() |
425 | 427 | self.next_edit_interaction: Interaction | None = None |
| 428 | + self.confirmation_phase_start: datetime | None = None |
426 | 429 |
|
427 | 430 | self.timeout_task = asyncio.create_task(self._timeout(), name=f"trade-timeout-{id(self)}") |
428 | 431 |
|
@@ -465,6 +468,8 @@ async def lock_button(self, interaction: Interaction, button: Button): |
465 | 468 | except TradeError as e: |
466 | 469 | await interaction.followup.send(e.error_message, ephemeral=True) |
467 | 470 | else: |
| 471 | + if self.confirmation_phase and self.confirmation_phase_start is None: |
| 472 | + self.confirmation_phase_start = datetime.now() |
468 | 473 | await self.edit_message(interaction) |
469 | 474 |
|
470 | 475 | @buttons.button(label="Reset", emoji="\N{DASH SYMBOL}", style=discord.ButtonStyle.secondary) |
@@ -517,6 +522,18 @@ async def cancel_button(self, interaction: Interaction, button: Button): |
517 | 522 | ) |
518 | 523 | async def confirm_button(self, interaction: Interaction, button: Button): |
519 | 524 | trader = {self.trader1.user.id: self.trader1, self.trader2.user.id: self.trader2}[interaction.user.id] |
| 525 | + both_bypass = ( |
| 526 | + self.trader1.player.trade_cooldown_policy == TradeCooldownPolicy.BYPASS |
| 527 | + and self.trader2.player.trade_cooldown_policy == TradeCooldownPolicy.BYPASS |
| 528 | + ) |
| 529 | + if not both_bypass and self.confirmation_phase_start is not None: |
| 530 | + elapsed = (datetime.now() - self.confirmation_phase_start).total_seconds() |
| 531 | + remaining = COOLDOWN_BYPASS_TIMEOUT - elapsed |
| 532 | + if remaining > 0: |
| 533 | + await interaction.response.send_message( |
| 534 | + f"Please wait {remaining:.0f} more second(s) before confirming.", ephemeral=True |
| 535 | + ) |
| 536 | + return |
520 | 537 | await interaction.response.defer() |
521 | 538 | try: |
522 | 539 | await trader.confirm() |
|
0 commit comments