Compare commits
6 commits
67856a849d
...
82907916b7
Author | SHA1 | Date | |
---|---|---|---|
def | 82907916b7 | ||
2ea41e1187 | |||
def | f212a8d411 | ||
def | 5931f252a0 | ||
def | 381b198427 | ||
def | 7c75f786cb |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ __pycache__/
|
||||||
/.env
|
/.env
|
||||||
/data/
|
/data/
|
||||||
!/data/.keep
|
!/data/.keep
|
||||||
|
test_database.db
|
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"python.testing.pytestArgs": [
|
||||||
|
"tests"
|
||||||
|
],
|
||||||
|
"python.testing.unittestEnabled": false,
|
||||||
|
"python.testing.pytestEnabled": true
|
||||||
|
}
|
17
README.md
17
README.md
|
@ -1,21 +1,21 @@
|
||||||
MirrorTea 🐦
|
MirrorTea 🐦
|
||||||
=========
|
=========
|
||||||
|
|
||||||
**New lite Matrix <-> Telegram bridge for personal use, replacement of
|
**New lite [Matrix](https://matrix.org) <-> [Telegram](https://telegram.org) bridge for personal use, replacement of
|
||||||
mautrix-telegram**.
|
[mautrix-telegram](https://github.com/mautrix/telegram)**.
|
||||||
|
|
||||||
|
|
||||||
For the matrix server is represented by a single and regular user. To simulate chats with different users, creates rooms in matrix, and sets /roomnick and /roomavatar corresponding to the simulated user in telegram.
|
For the matrix server is represented by a single and regular user. To simulate chats with different users, creates rooms in matrix, and sets /roomnick and /roomavatar corresponding to the simulated user in telegram.
|
||||||
|
|
||||||
For telegram, it can be represented as a single bot.
|
For telegram, it can be represented as a single bot.
|
||||||
|
|
||||||
#### Advantages over the current mautrix bridge:
|
#### Advantages over the current [mautrix-bridge](https://github.com/mautrix/telegram):
|
||||||
|
|
||||||
- Supports the bot's private message bridge
|
- Supports the bot's private message bridge
|
||||||
- Requires no permanent host (server)
|
- Requires no permanent host (server)
|
||||||
- Can run from a phone (termux) or user computer
|
- Can run from a phone (termux) or user computer
|
||||||
- Does not require a domain
|
- Does not require a domain
|
||||||
- Doesn't require a statistical IP
|
- Doesn't require a static IP
|
||||||
- No synapse server required
|
- No synapse server required
|
||||||
- Easy to deploy, unlike synapse
|
- Easy to deploy, unlike synapse
|
||||||
- Doesn't require any computing power like synapse
|
- Doesn't require any computing power like synapse
|
||||||
|
@ -40,6 +40,15 @@ For telegram, it can be represented as a single bot.
|
||||||
|
|
||||||
```nano .env```
|
```nano .env```
|
||||||
|
|
||||||
|
Make sure the .env file have permissions 600 (read\write only for owner)
|
||||||
|
|
||||||
|
```chmod 600 .env```
|
||||||
|
|
||||||
|
#### Edit ```config.yaml```
|
||||||
|
|
||||||
|
```nano config.yaml```
|
||||||
|
|
||||||
|
Do not change options with brackets ```"{{ }}"```, these are templates.
|
||||||
|
|
||||||
#### Run on *unix-like systems:
|
#### Run on *unix-like systems:
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import asyncio as telegram
|
from messengers import Matrix as MatrixLoop, Telegram as TelegramLoop
|
||||||
import nio as matrix
|
|
||||||
|
|
||||||
from config_dataclass import Config
|
from config_dataclass import Config
|
||||||
|
|
||||||
|
@ -65,14 +64,14 @@ class Application:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.matrix_loop = MatrixLoop(self)
|
self.matrix_loop = MatrixLoop(self)
|
||||||
self.telegram = TelegramLopp(self)
|
self.telegram_loop = TelegramLoop(self)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
try:
|
try:
|
||||||
await self.matrix_loop.prepare()
|
await self.matrix_loop.prepare()
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
self.matrix_loop.run(),
|
self.matrix_loop.run(),
|
||||||
self.telegram.run(),
|
self.telegram_loop.run(),
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
if self.matrix_loop:
|
if self.matrix_loop:
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
from abstract_source_platform.telegram import Telegram
|
|
||||||
|
|
||||||
platforms = [Telegram]
|
|
2
mirrortea/messengers/__init__.py
Normal file
2
mirrortea/messengers/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
from .matrix import Matrix
|
||||||
|
from .telegram import Telegram
|
23
mirrortea/messengers/matrix.py
Normal file
23
mirrortea/messengers/matrix.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import nio
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class Matrix:
|
||||||
|
def __init__(self, app):
|
||||||
|
self.app = app
|
||||||
|
self.client = nio.AsyncClient(
|
||||||
|
app.config.matrix_homeserver_url,
|
||||||
|
app.config.matrix_full_bot_id,
|
||||||
|
)
|
||||||
|
self.client.add_event_callback(self.on_message, nio.RoomMessage)
|
||||||
|
|
||||||
|
async def prepare(self):
|
||||||
|
await self.client.login(self.app.config.matrix_bot_password)
|
||||||
|
|
||||||
|
async def finish(self):
|
||||||
|
await self.client.close()
|
||||||
|
|
||||||
|
async def run(self):
|
||||||
|
await self.client.sync_forever(timeout=30000)
|
||||||
|
|
||||||
|
async def on_message(self, room, event):
|
||||||
|
print(room, event, file=sys.stderr)
|
15
mirrortea/messengers/telegram.py
Normal file
15
mirrortea/messengers/telegram.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import aiogram
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class Telegram:
|
||||||
|
def __init__(self, app):
|
||||||
|
self.app = app
|
||||||
|
self.bot = aiogram.Bot(token=app.config.telegram_bot_token)
|
||||||
|
self.dispatcher = aiogram.Dispatcher(bot=self.bot)
|
||||||
|
self.dispatcher.register_message_handler(self.on_message)
|
||||||
|
|
||||||
|
async def run(self):
|
||||||
|
await self.dispatcher.start_polling()
|
||||||
|
|
||||||
|
async def on_message(self, msg):
|
||||||
|
print(msg, file=sys.stderr)
|
Reference in a new issue