stars
This commit is contained in:
1 parent
8647352d0f
commit
758defee99
7 files changed
+183
-52
No files matched your search
@@ -11,7 +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 import UserContent, KnownTelegramMessage
|
||||
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
|
||||
@@ -212,6 +212,16 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
|
||||
}]
|
||||
])
|
||||
)
|
||||
|
||||
user_uploader_wrapper = Wrapped_CBotChat(memory._telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)
|
||||
for hint_message in session.query(KnownTelegramMessage).filter(
|
||||
and_(
|
||||
KnownTelegramMessage.user_id == user.id,
|
||||
KnownTelegramMessage.message_type == 'hint',
|
||||
KnownTelegramMessage.meta.contains({'encrypted_content_hash': encrypted_stored_content.hash})
|
||||
)
|
||||
):
|
||||
await user_uploader_wrapper.delete_message(hint_message.message_id)
|
||||
elif encrypted_stored_content.type.startswith('onchain') and encrypted_stored_content.onchain_index == item_index:
|
||||
encrypted_stored_content.type = "onchain/content" + ("_unknown" if (encrypted_stored_content.key_id is None) else "")
|
||||
encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1)
|
||||
|
||||
@@ -20,6 +20,7 @@ from app.core.models._telegram import Wrapped_CBotChat
|
||||
from app.core.storage import db_session
|
||||
from app.core._config import CLIENT_TELEGRAM_API_KEY
|
||||
from app.core.models.user import User
|
||||
from app.core.models import StarsInvoice
|
||||
import os
|
||||
import traceback
|
||||
|
||||
@@ -27,6 +28,51 @@ import traceback
|
||||
async def license_index_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
|
||||
make_log("LicenseIndex", "Service running", level="debug")
|
||||
with db_session() as session:
|
||||
async def check_telegram_stars_transactions():
|
||||
# Проверка звездных telegram транзакций, обновление paid
|
||||
offset = {'desc': 'Статичное число заранее известного количества транзакций, которое даже не знает наш бот', 'value': 1}['value'] + \
|
||||
session.query(StarsInvoice).count()
|
||||
limit = 100
|
||||
while True:
|
||||
make_log("StarsProcessing", f"Star payments: offset={offset}, limit={limit}", level="DEBUG")
|
||||
star_payments = (await memory._client_telegram_bot.get_star_transactions(offset, limit)).transactions
|
||||
if not star_payments:
|
||||
make_log("StarsProcessing", "No more star payments", level="DEBUG")
|
||||
return
|
||||
|
||||
for star_payment in star_payments:
|
||||
if star_payment.receiver:
|
||||
continue
|
||||
|
||||
try:
|
||||
existing_invoice = session.query(StarsInvoice).filter(
|
||||
StarsInvoice.external_id == star_payment.source.invoice_payload
|
||||
).first()
|
||||
if not existing_invoice:
|
||||
continue
|
||||
|
||||
if star_payment.amount == existing_invoice.amount:
|
||||
if not existing_invoice.paid:
|
||||
existing_invoice.paid = True
|
||||
session.commit()
|
||||
|
||||
licensed_content = session.query(StoredContent).filter(StoredContent.hash == existing_invoice.content_hash).first()
|
||||
user = session.query(User).filter(User.id == existing_invoice.user_id).first()
|
||||
|
||||
await (Wrapped_CBotChat(memory._client_telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)).send_content(
|
||||
session, licensed_content
|
||||
)
|
||||
except BaseException as e:
|
||||
make_log("StarsProcessing", f"Local error: {e}" + '\n' + traceback.format_exc(), level="error")
|
||||
|
||||
offset += limit
|
||||
|
||||
try:
|
||||
await check_telegram_stars_transactions()
|
||||
except BaseException as e:
|
||||
make_log("StarsProcessing", f"Error: {e}" + '\n' + traceback.format_exc(), level="error")
|
||||
|
||||
# Проверка кошельков пользователей на появление новых NFT, добавление их в базу как неопознанные
|
||||
for user in session.query(User).filter(
|
||||
User.last_use > datetime.now() - timedelta(minutes=10)
|
||||
).all():
|
||||
@@ -47,6 +93,7 @@ async def license_index_loop(memory, platform_found: bool, seqno: int) -> [bool,
|
||||
except BaseException as e:
|
||||
make_log("LicenseIndex", f"Error: {e}" + '\n' + traceback.format_exc(), level="error")
|
||||
|
||||
# Проверка NFT на актуальность данных, в том числе уже проверенные
|
||||
process_content = session.query(UserContent).filter(
|
||||
and_(
|
||||
UserContent.type.startswith('nft/'),
|
||||
|
||||
Reference in new issue
Block a user