Skip to content

Commit

Permalink
final fix of get user
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoom-Developer committed Nov 4, 2024
1 parent 28ff598 commit 24c3a91
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backend/src/domain/likes/repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlmodel import select, delete, insert
from sqlmodel import desc, select, delete, insert

from infrastructure.db import BaseRepository, Like, User

Expand All @@ -19,7 +19,7 @@ async def get_byuser(self, user: User, second_user: User) -> Like | None:
return res.first()

async def get_mutually(self, user: User) -> list[User]:
query = select(User).join_from(Like, Like.target_user).filter((Like.user_id == user.id) & (Like.is_mutually == True))
query = select(User).join_from(Like, Like.target_user).filter((Like.user_id == user.id) & (Like.is_mutually == True)).order_by(desc(Like.created_at))
res = await self.session.exec(query)
return res.all()

Expand Down
4 changes: 2 additions & 2 deletions backend/src/interface/rabbit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ async def ban_user(data: VerifyUser) -> TelegramRequestResponse:

@router.subscriber("user")
@router.publisher("user-res")
async def ban_user(data: GetUser) -> TelegramRequestResponse:
async def ban_user(data: GetUser) -> GetUserResponse:
user = await UserRepository().get(data.user_id)
if not user:
return TelegramRequestResponse(msg_id = data.msg_id, success = False)
return GetUserResponse(msg_id = data.msg_id, success = False, text = "", attachments = [])
return GetUserResponse(
text =
f"\n<b>Имя:</b> {user.mention} <b>(<code>{user.id}</code>)</b>"
Expand Down
2 changes: 1 addition & 1 deletion bot/src/models/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class TelegramRequestResponse(TelegramRequest):

class GetUserResponse(TelegramRequestResponse):
text: str
attachments: str
attachments: list[str]
9 changes: 4 additions & 5 deletions bot/src/rabbit/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
router = RabbitRouter("adm_")

@router.subscriber("banned")
async def msg(res: TelegramRequestResponse) -> None:
async def banned(res: TelegramRequestResponse) -> None:
await bot.send_message(
chat_id = TG_ADMIN_CHAT,
reply_to_message_id = res.msg_id,
text = "🚫 Пользователь заблокирован" if res.success else "❕ Неверный пользователь"
)

@router.subscriber("unbanned")
async def msg(res: TelegramRequestResponse) -> None:
async def unbanned(res: TelegramRequestResponse) -> None:
await bot.send_message(
chat_id = TG_ADMIN_CHAT,
reply_to_message_id = res.msg_id,
text = "⛓️‍💥 Пользователь разблокирован" if res.success else "❕ Неверный пользователь"
)

@router.subscriber("verified")
async def msg(res: TelegramRequestResponse) -> None:
async def verified(res: TelegramRequestResponse) -> None:
await bot.send_message(
chat_id = TG_ADMIN_CHAT,
reply_to_message_id = res.msg_id,
text = "✅ Статус верификации пользователя обновлён" if res.success else "❕ Неверный пользователь"
)

@router.subscriber("user-res")
async def msg(res: TelegramRequestResponse | GetUserResponse) -> None:
async def get_user(res: GetUserResponse) -> None:
if not res.success:
return await bot.send_message(
chat_id = TG_ADMIN_CHAT,
Expand All @@ -44,6 +44,5 @@ async def msg(res: TelegramRequestResponse | GetUserResponse) -> None:
await send_media(
chat_id = TG_ADMIN_CHAT,
text = res.text,
parse_mode = "markdown",
files = res.attachments
)
16 changes: 9 additions & 7 deletions bot/src/rabbit/routers/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
router = RabbitRouter("tg_")

@router.subscriber("msg")
async def msg(msg: SendMessage | SendAdminMessage) -> None:
await bot.send_message(
chat_id = msg.chat_id if msg.chat_id != -1 else TG_ADMIN_CHAT,
text = msg.text,
parse_mode = msg.parse_mode
)
async def sendmsg(msg: SendMessage | SendAdminMessage) -> None:
try:
await bot.send_message(
chat_id = msg.chat_id if msg.chat_id != -1 else TG_ADMIN_CHAT,
text = msg.text,
parse_mode = msg.parse_mode
)
except: pass

@router.subscriber("media")
async def msg(msg: SendMediaMessage | SendAdminMediaMessage) -> None:
async def sendmedia(msg: SendMediaMessage | SendAdminMediaMessage) -> None:
await send_media(
chat_id = msg.chat_id if msg.chat_id != -1 else TG_ADMIN_CHAT,
text = msg.text,
Expand Down
2 changes: 1 addition & 1 deletion bot/src/telegram/utlls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .bot import bot


async def send_media(chat_id: int, text: str, files: list[str], parse_mode: str = "markdown") -> None:
async def send_media(chat_id: int, text: str, files: list[str], parse_mode: str = "html") -> None:
await bot.send_media_group(
chat_id = chat_id,
media = [
Expand Down

0 comments on commit 24c3a91

Please sign in to comment.