purchase notify, fix preview

This commit is contained in:
user 2025-02-05 13:06:30 +03:00
parent 21a83cf5b8
commit 4d15211344
3 changed files with 26 additions and 2 deletions

View File

@ -169,7 +169,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
content_list.append( content_list.append(
types.InlineQueryResultCachedAudio( types.InlineQueryResultCachedAudio(
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}", id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
audio_file_id=decrypted_content.meta.get('telegram_file_cache_preview', decrypted_content.meta['telegram_file_cache']), audio_file_id=decrypted_content.meta['telegram_file_cache_preview'],
title=title, title=title,
performer=performer, performer=performer,
caption=hashtags_str + user.translated('p_playerContext_preview'), caption=hashtags_str + user.translated('p_playerContext_preview'),
@ -194,7 +194,7 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use
content_list.append( content_list.append(
types.InlineQueryResultCachedVideo( types.InlineQueryResultCachedVideo(
id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}", id=f"NC_{content.id}_{int(datetime.now().timestamp() // 60)}",
video_file_id=decrypted_content.meta.get('telegram_file_cache_preview', decrypted_content.meta['telegram_file_cache']), video_file_id=decrypted_content.meta['telegram_file_cache_preview'],
title=title, title=title,
caption=hashtags_str + user.translated('p_playerContext_preview'), caption=hashtags_str + user.translated('p_playerContext_preview'),
parse_mode='html', parse_mode='html',

View File

@ -47,12 +47,28 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
if not licensed_content: if not licensed_content:
make_log("Indexer", f"Licensed content not found: {new_license.content_id}", level="error") make_log("Indexer", f"Licensed content not found: {new_license.content_id}", level="error")
content_metadata = licensed_content.metadata_json(session)
assert content_metadata, "No content metadata found"
try: try:
user = new_license.user user = new_license.user
if user.telegram_id and licensed_content: if user.telegram_id and licensed_content:
await (Wrapped_CBotChat(memory._client_telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)).send_content( await (Wrapped_CBotChat(memory._client_telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)).send_content(
session, licensed_content session, licensed_content
) )
for wallet_owner_connection in session.query(WalletConnection).filter_by(wallet_address=licensed_content.owner_address).all():
wallet_owner_user = wallet_owner_connection.user
if wallet_owner_user.telegram_id:
wallet_owner_bot = Wrapped_CBotChat(memory._client_telegram_bot, chat_id=wallet_owner_user.telegram_id, user=wallet_owner_user, db_session=session)
await wallet_owner_bot.send_message(
user.translated('p_licenseWasBought').format(
username=user.front_format(),
nft_address=f'"{new_license.onchain_address}"',
content_title=content_metadata.get('name', 'Unknown'),
),
message_type='notification',
)
except BaseException as e: except BaseException as e:
make_log("IndexerSendNewLicense", f"Error: {e}" + '\n' + traceback.format_exc(), level="error") make_log("IndexerSendNewLicense", f"Error: {e}" + '\n' + traceback.format_exc(), level="error")

View File

@ -1,3 +1,4 @@
import json
from base58 import b58decode from base58 import b58decode
from sqlalchemy import Column, BigInteger, Integer, String, ForeignKey, DateTime, JSON, Boolean from sqlalchemy import Column, BigInteger, Integer, String, ForeignKey, DateTime, JSON, Boolean
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
@ -140,6 +141,13 @@ class StoredContent(AlchemyBase, AudioContentMixin):
"updated": spec_field_updated, "updated": spec_field_updated,
} }
def metadata_json(self, db_session):
metadata_cid = self.meta.get('metadata_cid')
if metadata_cid:
metadata_content = StoredContent.from_cid(db_session, metadata_cid)
with open(metadata_content.filepath, 'r') as f:
return json.loads(f.read())
@classmethod @classmethod
def from_cid(cls, db_session, content_id): def from_cid(cls, db_session, content_id):
if isinstance(content_id, str): if isinstance(content_id, str):