-
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.
Merge pull request #3 from Delitel-WEB/dev
Dev
- Loading branch information
Showing
11 changed files
with
178 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# VK-TG-SYNC | Синхронизация чатов между Вконтакте и Телеграмом | ||
|
||
> Этот скрипт предназначен для пользователей, которые уже давно сделали Телеграм своим основным мессенджером, но у них все еще есть чаты во Вконтакте, в которых им приходится участвовать. Скрипт позволяет перенести эти чаты из Вконтакте в Телеграм и упростить процесс коммуникации. | ||
⚠️ **Примечание:** На данный момент скрипт находится в недоделанном виде и может иметь ограничения и проблемы. Пожалуйста, учитывайте это при его использовании. | ||
|
||
![Поддерживаемые версии Python](https://img.shields.io/badge/python-3.7+-blue.svg) | ||
|
||
## 🚀 Установка | ||
|
||
1. Склонируйте репозиторий GitHub: | ||
|
||
```shell | ||
git clone https://github.com/Delitel-WEB/vk-tg-sync.git | ||
``` | ||
|
||
2. Перейдите в директорию проекта: | ||
|
||
```shell | ||
cd vk-tg-sync | ||
``` | ||
|
||
3. Установите необходимые пакеты Python из файла `req.txt`: | ||
```shell | ||
pip install -r req.txt | ||
``` | ||
|
||
## ⚙️ Настройка | ||
|
||
Для настройки скрипта создайте файл `settings.sh` для Linux. | ||
|
||
- Для Linux: `settings.sh` | ||
```shell | ||
export tgBotToken="" | ||
export vkBotToken="" | ||
export dbPassword="" | ||
``` | ||
|
||
Выполните следующую команду, чтобы создать таблицы в базе данных: | ||
|
||
```shell | ||
alembic upgrade head | ||
``` | ||
|
||
⚠️ Перед выполнением этой команды убедитесь, что у вас установлена база данных MySQL и создана пустая таблица `vk_to_tg`. | ||
|
||
## ▶️ Запуск бота | ||
|
||
⚠️ Перед запуском убедитесь, что вы установили значения переменных в файле `settings.sh`. | ||
|
||
Перед запуском выполните команду: | ||
|
||
```shell | ||
source settings.sh | ||
``` | ||
|
||
И запустите скрипт: | ||
|
||
```shell | ||
python main.py | ||
``` | ||
|
||
## Что реализовано на данный момент | ||
|
||
> **Синхронизация указана в виде мессенджер ➔ мессенджер. То есть если галочка стоит у ВКонтакте, то сделана синхронизация VK ➔ Telegram и наоборот. Если галочки стоят сразу на двух мессенджерах, значит, синхронизация двусторонняя.** | ||
|
||
| Виды синхронизации | Telegram | VKontakte | | ||
| ------------------------ | -------- | --------- | | ||
| **Сообщения** | | | | ||
| Текстовые сообщения | ❌ | ✅ | | ||
| Голосовые сообщения | ❌ | ❌ | | ||
| Стикеры | ❌ | ❌ | | ||
| Пересланные сообщения | ❌ | ❌ | | ||
| Документы | ❌ | ❌ | | ||
| Удаление сообщений | ❌ | ❌ | | ||
| Редактирование сообщений | ❌ | ❌ | | ||
| **Медиа** | | | | ||
| Фото | ❌ | ❌ | | ||
| Видео | ❌ | ❌ | | ||
| Геолокация | ❌ | ❌ | | ||
| Гифки | ❌ | ❌ | | ||
| **Действия с чатами** | | | | ||
| Изменение Фото | ❌ | ❌ | | ||
| Изменение Названия Чата | ❌ | ❌ | |
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,7 +1,9 @@ | ||
vkbottle==4.3.12 | ||
aiogram==2.25.1 | ||
cryptography==41.0.4 | ||
SQLAlchemy==2.0.20 | ||
alembic==1.12.0 | ||
aiomysql==0.2.0 | ||
PyMySQL==1.1.0 | ||
black==23.9.1 | ||
black==23.9.1 | ||
aiohttp==3.8.5 |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .chats import update_chat_info | ||
from .photos import get_photo_from_url |
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,15 @@ | ||
from ..core import bot | ||
from .photos import get_photo_from_url | ||
|
||
|
||
async def update_chat_info(chat_id: int, title: str, preview: str): | ||
""" | ||
Обновление информации о группе. | ||
Название, Фото | ||
""" | ||
|
||
if preview: | ||
photo = await get_photo_from_url(preview) | ||
await bot.set_chat_photo(chat_id, photo) | ||
|
||
await bot.set_chat_title(chat_id, title) |
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,15 @@ | ||
import aiohttp | ||
from io import BytesIO | ||
|
||
|
||
async def get_photo_from_url(photo_url): | ||
try: | ||
async with aiohttp.ClientSession() as session: | ||
async with session.get(photo_url) as response: | ||
if response.status == 200: | ||
photo_bytes = await response.read() | ||
return BytesIO(photo_bytes) | ||
else: | ||
return None | ||
except Exception as e: | ||
return None |
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,4 +1,5 @@ | ||
from .core import bot | ||
from . import handlers | ||
|
||
|
||
def start_vk(): | ||
|
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 @@ | ||
from . import messages |
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,24 @@ | ||
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 | ||
|
||
|
||
@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: | ||
users_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)}'>{users_info[0].first_name} {users_info[0].last_name}</a>\n" | ||
+ "_" * 10 | ||
+ f"\n{message.text}", | ||
parse_mode="html", | ||
) |
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 @@ | ||
from .links import create_vk_link |
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,3 @@ | ||
def create_vk_link(id: int): | ||
"""Создание ссылки на профиль в вк из id""" | ||
return f"https://vk.com/id{id}" |