dev@locazia: fixes

This commit is contained in:
user 2024-04-05 08:24:03 +03:00
parent a03ec3d61d
commit 039abb5703
3 changed files with 20 additions and 9 deletions

View File

@ -67,7 +67,7 @@ class UserDataMiddleware(BaseMiddleware):
data['chat_wrap'] = Wrapped_CBotChat(data['bot'], chat_id=user_id, db_session=session, user=user) data['chat_wrap'] = Wrapped_CBotChat(data['bot'], chat_id=user_id, db_session=session, user=user)
data['memory'] = data['dispatcher']._s_memory data['memory'] = data['dispatcher']._s_memory
if isinstance(update_body, types.Message): if getattr(update_body, 'text', None):
message_type = 'common' message_type = 'common'
if update_body.text.startswith('/start'): if update_body.text.startswith('/start'):
message_type = 'start_command' message_type = 'start_command'

View File

@ -112,17 +112,26 @@ class Wrapped_CBotChat(T, PlayerTemplates):
async def delete_message(self, message_id): async def delete_message(self, message_id):
assert self._chat_id, "No chat_id" assert self._chat_id, "No chat_id"
message_id = int(message_id)
try: try:
make_log(self, f"Delete message {self._chat_id}/{message_id}", level='debug') make_log(self, f"Delete message {self._chat_id}/{message_id}", level='debug')
return await self._bot.delete_message( if (await self._bot.delete_message(
self._chat_id, self._chat_id,
message_id message_id
) )):
if self.db_session:
known_message = self.db_session.query(KnownTelegramMessage).filter(
KnownTelegramMessage.chat_id == self._chat_id,
KnownTelegramMessage.message_id == message_id
).first()
if known_message:
known_message.deleted = True
self.db_session.commit()
except Exception as e: except Exception as e:
make_log(self, f"Error deleting message {self._chat_id}/{message_id}. Error: {e}", level='warning') make_log(self, f"Error deleting message {self._chat_id}/{message_id}. Error: {e}", level='warning')
return None return None
async def send_photo(self, file_id, message_type='common', message_meta={}, **kwargs): async def send_photo(self, file_id, message_type='common', message_meta={}, content_id=None, **kwargs):
assert self._chat_id, "No chat_id" assert self._chat_id, "No chat_id"
try: try:
make_log(self, f"Send photo to {self._chat_id}. File: {file_id}", level='debug') make_log(self, f"Send photo to {self._chat_id}. File: {file_id}", level='debug')
@ -136,7 +145,7 @@ class Wrapped_CBotChat(T, PlayerTemplates):
make_log(self, f"Error sending photo to {self._chat_id}. Error: {e}", level='warning') make_log(self, f"Error sending photo to {self._chat_id}. Error: {e}", level='warning')
return None return None
async def send_document(self, file_id, message_type='common', message_meta={}, **kwargs): async def send_document(self, file_id, message_type='common', message_meta={}, content_id=None, **kwargs):
assert self._chat_id, "No chat_id" assert self._chat_id, "No chat_id"
try: try:
make_log(self, f"Send document to {self._chat_id}. File: {file_id}", level='debug') make_log(self, f"Send document to {self._chat_id}. File: {file_id}", level='debug')
@ -150,7 +159,7 @@ class Wrapped_CBotChat(T, PlayerTemplates):
make_log(self, f"Error sending document to {self._chat_id}. Error: {e}", level='warning') make_log(self, f"Error sending document to {self._chat_id}. Error: {e}", level='warning')
return None return None
async def send_video(self, file_id, message_type='common', message_meta={}, **kwargs): async def send_video(self, file_id, message_type='common', message_meta={}, content_id=None, **kwargs):
assert self._chat_id, "No chat_id" assert self._chat_id, "No chat_id"
try: try:
make_log(self, f"Send video to {self._chat_id}. File: {file_id}", level='debug') make_log(self, f"Send video to {self._chat_id}. File: {file_id}", level='debug')
@ -164,7 +173,7 @@ class Wrapped_CBotChat(T, PlayerTemplates):
make_log(self, f"Error sending video to {self._chat_id}. Error: {e}", level='warning') make_log(self, f"Error sending video to {self._chat_id}. Error: {e}", level='warning')
return None return None
async def send_audio(self, file_id, message_type='common', message_meta={}, **kwargs): async def send_audio(self, file_id, message_type='common', message_meta={}, content_id=None, **kwargs):
assert self._chat_id, "No chat_id" assert self._chat_id, "No chat_id"
try: try:
make_log(self, f"Send audio to {self._chat_id}. File: {file_id}", level='debug') make_log(self, f"Send audio to {self._chat_id}. File: {file_id}", level='debug')

View File

@ -1,6 +1,6 @@
from base58 import b58decode from base58 import b58decode
from sqlalchemy import Column, Integer, String, DateTime, JSON, BigInteger, Boolean from sqlalchemy import Column, Integer, String, DateTime, JSON, BigInteger, Boolean, ForeignKey
from sqlalchemy.orm import relationship
from .base import AlchemyBase from .base import AlchemyBase
@ -20,3 +20,5 @@ class KnownTelegramMessage(AlchemyBase):
created = Column(DateTime, nullable=False, default=0) created = Column(DateTime, nullable=False, default=0)
deleted = Column(Boolean, nullable=True, default=False) deleted = Column(Boolean, nullable=True, default=False)
meta = Column(JSON, nullable=False, default={}) meta = Column(JSON, nullable=False, default={})
content_id = Column(Integer, ForeignKey('node_storage.id'), nullable=True)