Skip to content

Commit

Permalink
Исправление ошибок
Browse files Browse the repository at this point in the history
  • Loading branch information
thereareyou123 committed Feb 1, 2025
1 parent c2d920b commit d40aa76
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/app/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ async def update(
await session.refresh(db_obj)
return db_obj

async def delete(self, db_obj: ModelType, session: AsyncSession,) -> ModelType:
async def delete(self, db_obj: ModelType, session: AsyncSession,
) -> ModelType:
"""Delete object in database."""
await session.delete(db_obj)
await session.commit()
Expand Down
8 changes: 5 additions & 3 deletions src/app/crud/message.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import TypeVar

from app.crud.base import CRUDBase
from app.models.models import (Group, Message, MessageGroupAssociation,
MessageStatus)
from app.schemas.message import MessageCreate

from sqlalchemy import not_, select
from sqlalchemy.ext.asyncio import AsyncSession

from app.crud.base import CRUDBase
from app.models.models import Group, Message, MessageGroupAssociation, MessageStatus
from app.schemas.message import MessageCreate

ModelType = TypeVar('ModelType')

Expand Down
16 changes: 4 additions & 12 deletions src/app/models/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import pathlib
from datetime import datetime

from sqlalchemy import (
BigInteger,
Boolean,
CheckConstraint,
Column,
DateTime,
ForeignKey,
String,
Enum,
)
from sqlalchemy.orm import relationship

from app.core.db import Base
from app.models.constants import LENGTH_32, LENGTH_64, LENGTH_1000

from sqlalchemy import (BigInteger, Boolean, CheckConstraint, Column, DateTime,
Enum, ForeignKey, String)
from sqlalchemy.orm import relationship


class MessageGroupAssociation(Base):
"""Model for many-to-many relation between messages and groups."""
Expand Down
22 changes: 14 additions & 8 deletions src/bot/ratelimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from datetime import datetime, timedelta
from typing import Any

from telegram import InputMediaPhoto
from telegram.constants import ParseMode
from telegram.ext import Application, ContextTypes
from telegram.error import BadRequest, Forbidden

from app.core.db import get_async_session_context
from app.crud.message import crud_message
from app.crud.user_tg import crud_user
from app.schemas.message import MessageUpdate
from app.models.models import MessageStatus
from app.schemas.message import MessageUpdate

from telegram import InputMediaPhoto
from telegram.constants import ParseMode
from telegram.error import BadRequest, Forbidden
from telegram.ext import Application, ContextTypes


async def load_unsent_messages(context: ContextTypes.DEFAULT_TYPE) -> None:
Expand Down Expand Up @@ -127,7 +127,11 @@ async def send_message(context: ContextTypes.DEFAULT_TYPE) -> None: # noqa: C90
if user.is_active and not user.is_block
}
new_statuses = [
MessageStatus(message_id=message.id, user_id=user_id, status='pending')
MessageStatus(
message_id=message.id,
user_id=user_id,
status='pending'
)
for user_id in users_to_notify - existing_statuses.keys()
]
session.add_all(new_statuses)
Expand Down Expand Up @@ -157,7 +161,9 @@ async def send_message(context: ContextTypes.DEFAULT_TYPE) -> None: # noqa: C90
#Если указан неверный tg_id, или пользователь удалил аккаунт,
#или пользователь удалил бота
error_msg = str(e)
logging.error(f'Отправка сообщения отменена из-за ошибки {error_msg}')
logging.error(
f'Отправка сообщения отменена из-за ошибки {error_msg}'
)
session.delete(status)
except Exception as e:
error_msg = str(e)
Expand Down

0 comments on commit d40aa76

Please sign in to comment.