purchase notifications

This commit is contained in:
user committed 2024-10-28 17:43:53 +03:00
1 parent 2609495b91
commit 0f13479cb6
4 files changed
+34 -23

No files matched your search

+26
View File
@@ -3,6 +3,7 @@ from base64 import b64decode
from datetime import datetime
from base58 import b58encode
from sqlalchemy import and_
from tonsdk.boc import Cell
from tonsdk.utils import Address
@@ -10,6 +11,7 @@ from app.core._blockchain.ton.platform import platform
from app.core._blockchain.ton.toncenter import toncenter
from app.core._utils.send_status import send_status
from app.core.logger import make_log
from app.core.models import UserContent
from app.core.models.node_storage import StoredContent
from app.core._utils.resolve_content import resolve_content
from app.core.models.wallet_connection import WalletConnection
@@ -32,6 +34,28 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
make_log("Indexer", "Service running", level="debug")
with db_session() as session:
new_licenses = session.query(UserContent).filter(
and_(
~UserContent.meta.contains({'notification_sent': True}),
UserContent.type == 'nft/listen'
)
).all()
for new_license in new_licenses:
licensed_content = session.query(StoredContent).filter(
StoredContent.id == new_license.content_id
).first()
if not licensed_content:
make_log("Indexer", f"Licensed content not found: {new_license.content_id}", level="error")
user = new_license.user
if user.telegram_id and licensed_content:
await (Wrapped_CBotChat(memory._telegram_bot, chat_id=user.telegram_id)).send_content(
session, licensed_content
)
new_license.meta = {**new_license.meta, 'notification_sent': True}
session.commit()
content_without_cid = session.query(StoredContent).filter(
StoredContent.content_id == None
)
@@ -224,6 +248,8 @@ async def main_fn(memory, ):
await asyncio.sleep(5)
seqno += 1
# if __name__ == '__main__':
# loop = asyncio.get_event_loop()
# loop.run_until_complete(main())