Skip to content

Commit

Permalink
More logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dyakovri committed May 6, 2024
1 parent ae89ca4 commit 8cea5e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 15 additions & 4 deletions social/utils/telegram_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@


def get_chat_info(id: int) -> dict:
return requests.post(
resp = requests.post(
f'https://api.telegram.org/bot{settings.TELEGRAM_BOT_TOKEN}/getChat',
json={'chat_id': id},
).json()
)
if not resp.ok:
logger.error(resp.text)
return {}
else:
return resp.json()


def create_telegram_group(update: Update):
Expand Down Expand Up @@ -59,8 +64,14 @@ def approve_telegram_group(update: Update):
logger.info("Telegram group %d validated (secret=%s)", group.id, text)


def update_tg_chat(group: TelegramChat):
chat_info = get_chat_info(group.chat_id)
def update_tg_chat(group: TelegramChat | TelegramChannel):
if isinstance(group, TelegramChat):
chat_info = get_chat_info(group.chat_id)
elif isinstance(group, TelegramChannel):
chat_info = get_chat_info(group.channel_id)
else:
raise TypeError("Only TelegramChat and TelegramChannel are supported")
logger.info("TG chat info: %s", chat_info)
group.name = chat_info.get("title")
group.description = chat_info.get("description")
group.invite_link = chat_info.get("invite_link")
6 changes: 4 additions & 2 deletions social/utils/vk_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
settings = get_settings()


def get_chat_info(peer_id):
def get_chat_info(peer_id) -> dict:
"""Получить название чата ВК"""
conversation = requests.post(
"https://api.vk.com/method/messages.getConversationsById",
Expand Down Expand Up @@ -87,7 +87,9 @@ def approve_vk_chat(request_data: dict[str]):
def update_vk_chat(group: VkChat):
"""Обновляет информацию о группе ВК"""
chat_info = get_chat_info(group.peer_id)
chat_invite = get_chat_invite_link(group.peer_id)
logger.info("Chat info: %s, invite: %s", chat_info, chat_invite)
group.name = chat_info.get("title")
group.description = chat_info.get("description")
group.invite_link = get_chat_invite_link(group.peer_id)
group.invite_link = chat_invite
return group

0 comments on commit 8cea5e5

Please sign in to comment.