-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Проверка связки чатов сделана в виде декоратора
- Loading branch information
1 parent
82e6a46
commit 8caffee
Showing
7 changed files
with
97 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
from ..core import bot | ||
from vkbottle.user import Message | ||
from ...db import Sessions | ||
from ...db.models import Conversations | ||
from sqlalchemy import select | ||
from ...tg.core import bot as tg | ||
from ..utils import create_vk_link | ||
from ..utils import create_vk_link, check_bundle | ||
|
||
|
||
@bot.on.message() | ||
async def on_message(message: Message): | ||
async with Sessions() as session: | ||
bundle = await session.scalar( | ||
select(Conversations).where(Conversations.vk_id == message.peer_id) | ||
) | ||
if bundle: | ||
user_info = await bot.api.users.get(message.from_id) | ||
await tg.send_message( | ||
bundle.tg_id, | ||
f"<a href='{create_vk_link(message.from_id)}'>{user_info[0].first_name} {user_info[0].last_name}</a>\n" | ||
+ "‾" * 10 | ||
+ f"\n{message.text}", | ||
parse_mode="html", | ||
disable_web_page_preview=True, | ||
) | ||
@check_bundle | ||
async def on_message(message: Message, bundle): | ||
user_info = await bot.api.users.get(message.from_id) | ||
await tg.send_message( | ||
bundle.tg_id, | ||
f"<a href='{create_vk_link(message.from_id)}'>{user_info[0].first_name} {user_info[0].last_name}</a>\n" | ||
+ "‾" * 10 | ||
+ f"\n{message.text}", | ||
parse_mode="html", | ||
disable_web_page_preview=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
from ..core import bot | ||
from vkbottle.user import Message | ||
from ...db import Sessions | ||
from ...db.models import Conversations | ||
from sqlalchemy import select | ||
from ...tg.core import bot as tg | ||
from ..utils import create_vk_link | ||
from ..utils import create_vk_link, check_bundle | ||
from ...utils import get_file_from_url | ||
|
||
|
||
@bot.on.message(attachment=["audio_message"]) | ||
async def on_audio_message(message: Message): | ||
async with Sessions() as session: | ||
bundle = await session.scalar( | ||
select(Conversations).where(Conversations.vk_id == message.peer_id) | ||
) | ||
if bundle: | ||
user_info = await bot.api.users.get(message.from_id) | ||
voice_file = await get_file_from_url( | ||
message.attachments[0].audio_message.link_ogg | ||
) | ||
@check_bundle | ||
async def on_audio_message(message: Message, bundle): | ||
user_info = await bot.api.users.get(message.from_id) | ||
voice_file = await get_file_from_url(message.attachments[0].audio_message.link_ogg) | ||
|
||
await tg.send_voice( | ||
bundle.tg_id, | ||
voice_file, | ||
f"<a href='{create_vk_link(message.from_id)}'>{user_info[0].first_name} {user_info[0].last_name}</a>\n", | ||
parse_mode="html", | ||
disable_notification=True, | ||
) | ||
await tg.send_voice( | ||
bundle.tg_id, | ||
voice_file, | ||
f"<a href='{create_vk_link(message.from_id)}'>{user_info[0].first_name} {user_info[0].last_name}</a>\n", | ||
parse_mode="html", | ||
disable_notification=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .links import create_vk_link | ||
from .bundle import check_bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from ...db import Sessions | ||
from ...db.models import Conversations | ||
from sqlalchemy import select | ||
from functools import wraps | ||
from vkbottle.user import Message | ||
|
||
|
||
def check_bundle(func): | ||
@wraps(func) | ||
async def wrapper(message: Message, *args): | ||
async with Sessions() as session: | ||
bundle = await session.scalar( | ||
select(Conversations).where(Conversations.vk_id == message.peer_id) | ||
) | ||
if bundle: | ||
await func(message, bundle, *args) | ||
|
||
return wrapper |