44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from faststream import Context
|
|
from faststream.nats import NatsBroker, NatsRouter
|
|
|
|
from consumers.enums.market import SubjectsEnum
|
|
from consumers.models import AccountAutoPriceInfo, ShopPublishResult
|
|
from consumers.utils.autoprice import calculate_valorant_account_price
|
|
from shopbot.bot.database.db import async_session
|
|
from shopbot.bot.database.models import Account
|
|
|
|
router = NatsRouter()
|
|
|
|
|
|
@router.subscriber(SubjectsEnum.ACCOUNT_SHOP_NOTIFY)
|
|
async def new_account_proceed(
|
|
data: AccountAutoPriceInfo,
|
|
broker: NatsBroker = Context(), # noqa: B008
|
|
):
|
|
new_price = calculate_valorant_account_price(data.account_info)
|
|
async with async_session() as session:
|
|
db_account = Account(
|
|
login=data.meta_info.account.username,
|
|
password=data.meta_info.account.password,
|
|
region=data.meta_info.account.region,
|
|
price=new_price,
|
|
agent_count=0,
|
|
inventory_value=0,
|
|
knife_count=0,
|
|
skin_count=0,
|
|
last_rank="0",
|
|
level=0,
|
|
current_rank="0",
|
|
valorant_points=0,
|
|
# last_game=0,
|
|
)
|
|
session.add(db_account)
|
|
await session.commit()
|
|
|
|
await broker.publish(
|
|
ShopPublishResult(
|
|
account_id=data.account_id, shop_id=db_account.id, new_price=new_price
|
|
),
|
|
SubjectsEnum.ACCOUNT_SHOP_PUBLISH_RESULT.format(result="success"),
|
|
)
|