Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ build-backend = "hatchling.build"
packages = ["src/ttt"]

[project.scripts]
ttt = "ttt.main.aiogram_slim.__main__:main"
ttt = "ttt.main.aiogram_prod.__main__:main"
ttt-dev = "ttt.main.aiogram_dev.__main__:main"

[tool.uv]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@


@dataclass(frozen=True)
class WaitingLocationsPush:
class GameStartingQueuePush:
was_location_dedublicated: bool


class WaitingLocations(ABC):
class GameStartingQueue(ABC):
@abstractmethod
async def push(
self,
location: UserLocation,
/,
) -> WaitingLocationsPush: ...
) -> GameStartingQueuePush: ...

@abstractmethod
async def push_many(
Expand Down
2 changes: 1 addition & 1 deletion src/ttt/application/game/game/make_move_in_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def __call__(

try:
tracking = Tracking()
user_move = game.make_move(
user_move = game.make_user_move(
location.user_id,
cell_number_int,
game_result_id,
Expand Down
4 changes: 2 additions & 2 deletions src/ttt/application/game/game/ports/game_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ async def already_completed_game_to_cancel(
) -> None: ...

@abstractmethod
async def users_already_in_game_to_start_game_via_matchmaking_queue(
async def users_already_in_game_to_start_game_via_game_starting_queue(
self,
locations_of_users_in_game: Sequence[UserLocation],
/,
) -> None: ...

@abstractmethod
async def bad_attempt_to_start_game_via_matchmaking_queue(
async def bad_attempt_to_start_game_via_game_starting_queue(
self,
locations_of_users_not_in_game: Sequence[UserLocation],
/,
Expand Down
16 changes: 9 additions & 7 deletions src/ttt/application/game/game/start_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from ttt.application.common.ports.map import Map
from ttt.application.common.ports.transaction import Transaction
from ttt.application.common.ports.uuids import UUIDs
from ttt.application.game.common.ports.game_starting_queue import (
GameStartingQueue,
)
from ttt.application.game.common.ports.game_views import GameViews
from ttt.application.game.common.ports.games import Games
from ttt.application.game.common.ports.waiting_locations import WaitingLocations
from ttt.application.game.game.ports.game_log import GameLog
from ttt.application.user.common.ports.user_views import CommonUserViews
from ttt.application.user.common.ports.users import Users
Expand All @@ -25,12 +27,12 @@ class StartGame:
user_views: CommonUserViews
games: Games
game_views: GameViews
waiting_locations: WaitingLocations
game_starting_queue: GameStartingQueue
transaction: Transaction
log: GameLog

async def __call__(self) -> None:
async for user1_location, user2_location in self.waiting_locations:
async for user1_location, user2_location in self.game_starting_queue:
async with self.transaction, self.emojis:
user1, user2 = await self.users.users_with_ids(
(user1_location.user_id, user2_location.user_id),
Expand Down Expand Up @@ -63,7 +65,7 @@ async def __call__(self) -> None:
user2_location,
)
if user1 is None or user2 is None:
await self.waiting_locations.push_many(
await self.game_starting_queue.push_many(
tuple(
location
for user, location in users_and_locations
Expand Down Expand Up @@ -98,18 +100,18 @@ async def __call__(self) -> None:

await (
self.log
.users_already_in_game_to_start_game_via_matchmaking_queue(
.users_already_in_game_to_start_game_via_game_starting_queue(
locations_of_users_in_game,
)
)
await (
self.log
.bad_attempt_to_start_game_via_matchmaking_queue(
.bad_attempt_to_start_game_via_game_starting_queue(
locations_of_users_not_in_game,
)
)

await self.waiting_locations.push_many(
await self.game_starting_queue.push_many(
locations_of_users_not_in_game,
)
await self.game_views.user_already_in_game_views(
Expand Down
8 changes: 5 additions & 3 deletions src/ttt/application/game/game/wait_game.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from dataclasses import dataclass

from ttt.application.common.ports.transaction import Transaction
from ttt.application.game.common.ports.game_starting_queue import (
GameStartingQueue,
)
from ttt.application.game.common.ports.game_views import GameViews
from ttt.application.game.common.ports.waiting_locations import WaitingLocations
from ttt.application.game.game.ports.game_log import GameLog
from ttt.application.user.common.ports.user_views import CommonUserViews
from ttt.application.user.common.ports.users import Users
Expand All @@ -12,7 +14,7 @@
@dataclass(frozen=True, unsafe_hash=False)
class WaitGame:
users: Users
waiting_locations: WaitingLocations
game_starting_queue: GameStartingQueue
user_views: CommonUserViews
game_views: GameViews
transaction: Transaction
Expand All @@ -28,7 +30,7 @@ async def __call__(self, location: UserLocation) -> None:
)
return

push = await self.waiting_locations.push(location)
push = await self.game_starting_queue.push(location)

if push.was_location_dedublicated:
await self.log.double_waiting_for_game_start(location)
Expand Down
6 changes: 4 additions & 2 deletions src/ttt/application/game/game_with_ai/start_game_with_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from ttt.application.common.ports.transaction import Transaction
from ttt.application.common.ports.uuids import UUIDs
from ttt.application.game.common.ports.game_ai_gateway import GameAiGateway
from ttt.application.game.common.ports.game_starting_queue import (
GameStartingQueue,
)
from ttt.application.game.common.ports.game_views import GameViews
from ttt.application.game.common.ports.games import Games
from ttt.application.game.common.ports.waiting_locations import WaitingLocations
from ttt.application.game.game.ports.game_log import GameLog
from ttt.application.user.common.ports.user_views import CommonUserViews
from ttt.application.user.common.ports.users import Users
Expand All @@ -29,7 +31,7 @@ class StartGameWithAi:
user_views: CommonUserViews
games: Games
game_views: GameViews
waiting_locations: WaitingLocations
game_starting_queue: GameStartingQueue
transaction: Transaction
ai_gateway: GameAiGateway
log: GameLog
Expand Down
2 changes: 1 addition & 1 deletion src/ttt/application/user/common/dto/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@dataclass(frozen=True)
class PaidStarsPurchasePayment:
purshase_id: UUID
purchase_id: UUID
location: UserLocation
success: PaymentSuccess
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class StarsPurchasePaymentGateway(ABC):
@abstractmethod
async def send_invoice(
self,
purshase: StarsPurchase,
purchase: StarsPurchase,
location: UserLocation,
) -> None: ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@


@dataclass(frozen=True, unsafe_hash=False)
class CompleteStarsPurshasePayment:
class CompleteStarsPurchasePayment:
clock: Clock
inbox: PaidStarsPurchasePaymentInbox
users: Users
transaction: Transaction
map_: Map
common_views: CommonUserViews
stars_purshase_views: StarsPurchaseUserViews
stars_purchase_views: StarsPurchaseUserViews
log: StarsPurchaseUserLog

async def __call__(self) -> None:
Expand All @@ -47,7 +47,7 @@ async def __call__(self) -> None:
tracking = Tracking()
try:
user.complete_stars_purchase_payment(
paid_payment.purshase_id,
paid_payment.purchase_id,
paid_payment.success,
current_datetime,
tracking,
Expand All @@ -58,16 +58,16 @@ async def __call__(self) -> None:
paid_payment,
)
else:
await self.log.stars_purshase_payment_completed(
await self.log.stars_purchase_payment_completed(
user,
paid_payment,
)

await self.map_(tracking)
await (
self.stars_purshase_views.completed_stars_purshase_view(
self.stars_purchase_views.completed_stars_purchase_view(
user,
paid_payment.purshase_id,
paid_payment.purchase_id,
paid_payment.location,
)
)
4 changes: 2 additions & 2 deletions src/ttt/application/user/stars_purchase/ports/user_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ async def user_started_stars_puchase_payment(
) -> None: ...

@abstractmethod
async def stars_purshase_payment_completion_started(
async def stars_purchase_payment_completion_started(
self,
payment: PaidStarsPurchasePayment,
/,
) -> None: ...

@abstractmethod
async def stars_purshase_payment_completed(
async def stars_purchase_payment_completed(
self,
user: User,
payment: PaidStarsPurchasePayment,
Expand Down
6 changes: 3 additions & 3 deletions src/ttt/application/user/stars_purchase/ports/user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class StarsPurchaseUserViews(ABC):
@abstractmethod
async def wait_stars_to_start_stars_purshase_view(
async def wait_stars_to_start_stars_purchase_view(
self,
location: UserLocation,
/,
Expand All @@ -28,10 +28,10 @@ async def stars_purchase_will_be_completed_view(
) -> None: ...

@abstractmethod
async def completed_stars_purshase_view(
async def completed_stars_purchase_view(
self,
user: User,
purshase_id: UUID,
purchase_id: UUID,
location: UserLocation,
/,
) -> None: ...
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StartStarsPurchase:
uuids: UUIDs
clock: Clock
common_views: CommonUserViews
stars_purshase_views: StarsPurchaseUserViews
stars_purchase_views: StarsPurchaseUserViews
payment_gateway: StarsPurchasePaymentGateway
map_: Map
log: StarsPurchaseUserLog
Expand Down Expand Up @@ -69,7 +69,7 @@ async def __call__(self, location: UserLocation, stars: Stars) -> None:
)
await self.fsm.set(None)
await (
self.stars_purshase_views
self.stars_purchase_views
.invalid_stars_for_stars_purchase_view(location)
)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@dataclass(frozen=True, unsafe_hash=False)
class StartStarsPurshasePaymentCompletion:
class StartStarsPurchasePaymentCompletion:
inbox: PaidStarsPurchasePaymentInbox
payment_gateway: StarsPurchasePaymentGateway
views: StarsPurchaseUserViews
Expand All @@ -27,6 +27,6 @@ async def __call__(self) -> None:
await self.views.stars_purchase_will_be_completed_view(
paid_payment.location,
)
await self.log.stars_purshase_payment_completion_started(
await self.log.stars_purchase_payment_completion_started(
paid_payment,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@


@dataclass(frozen=True, unsafe_hash=False)
class WaitStarsToStartStarsPurshase:
class WaitStarsToStartStarsPurchase:
fsm: UserFsm
views: StarsPurchaseUserViews
log: StarsPurchaseUserLog

async def __call__(self, location: UserLocation) -> None:
await self.log.user_intends_to_buy_stars(location)
await self.views.wait_stars_to_start_stars_purshase_view(
await self.views.wait_stars_to_start_stars_purchase_view(
location,
)
2 changes: 1 addition & 1 deletion src/ttt/entities/core/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def cancel(
self.state = GameState.completed
tracking.register_mutated(self)

def make_move(
def make_user_move(
self,
user_id: int,
cell_number_int: int,
Expand Down
8 changes: 4 additions & 4 deletions src/ttt/infrastructure/adapters/game_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,31 @@ async def already_completed_game_to_cancel(
game_id=game.id.hex,
)

async def users_already_in_game_to_start_game_via_matchmaking_queue(
async def users_already_in_game_to_start_game_via_game_starting_queue(
self,
locations_of_users_in_game: Sequence[UserLocation],
/,
) -> None:
await gather(
*(
self._logger.awarning(
"user_already_in_game_to_start_game_via_matchmaking_queue",
"user_already_in_game_to_start_game_via_game_starting_queue",
chat_id=location.chat_id,
user_id=location.user_id,
)
for location in locations_of_users_in_game
),
)

async def bad_attempt_to_start_game_via_matchmaking_queue(
async def bad_attempt_to_start_game_via_game_starting_queue(
self,
locations_of_users_not_in_game: Sequence[UserLocation],
/,
) -> None:
await gather(
*(
self._logger.awarning(
"bad_attempt_to_start_game_via_matchmaking_queue",
"bad_attempt_to_start_game_via_game_starting_queue",
chat_id=location.chat_id,
user_id=location.user_id,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

from pydantic import TypeAdapter

from ttt.application.game.common.ports.waiting_locations import (
WaitingLocations,
WaitingLocationsPush,
from ttt.application.game.common.ports.game_starting_queue import (
GameStartingQueue,
GameStartingQueuePush,
)
from ttt.entities.core.user.location import UserLocation
from ttt.infrastructure.redis.batches import InRedisFixedBatches


@dataclass(frozen=True, unsafe_hash=False)
class InRedisFixedBatchesWaitingLocations(WaitingLocations):
class InRedisFixedBatchesWaitingLocations(GameStartingQueue):
_batches: InRedisFixedBatches

_adapter: ClassVar = TypeAdapter(UserLocation)
Expand All @@ -22,11 +22,11 @@ async def push_many(self, locations: Sequence[UserLocation], /) -> None:
if locations:
await self._batches.add(map(self._bytes, locations))

async def push(self, location: UserLocation, /) -> WaitingLocationsPush:
async def push(self, location: UserLocation, /) -> GameStartingQueuePush:
push_code = await self._batches.add([self._bytes(location)])
was_location_added_in_set = bool(push_code)

return WaitingLocationsPush(
return GameStartingQueuePush(
was_location_dedublicated=not was_location_added_in_set,
)

Expand Down
Loading