mirror of https://gitlab.com/ceda_ei/temac
Add core logic for event handlers. Add gitignore, sample config.
This commit is contained in:
parent
f5103d920c
commit
c0a5fb3d3e
|
@ -0,0 +1,3 @@
|
|||
config.py
|
||||
Temec.session
|
||||
__pycache__/
|
|
@ -0,0 +1,23 @@
|
|||
from telethon import TelegramClient, events
|
||||
from matrix_client.client import MatrixClient
|
||||
import config
|
||||
|
||||
|
||||
async def send_to_matrix(event, room):
|
||||
room.send_text(event.raw_text)
|
||||
|
||||
|
||||
matrix_bot = MatrixClient(config.matrix_creds['server'])
|
||||
matrix_bot.login(
|
||||
username=config.matrix_creds['username'],
|
||||
password=config.matrix_creds['password']
|
||||
)
|
||||
client = TelegramClient('Temec', config.api_id, config.api_hash).start()
|
||||
rooms = matrix_bot.get_rooms()
|
||||
|
||||
for chan_id, room_id in config.mappings:
|
||||
client.add_event_handler(lambda x: send_to_matrix(x, rooms[room_id]),
|
||||
events.NewMessage(chats=[chan_id]))
|
||||
|
||||
|
||||
client.run_until_disconnected()
|
|
@ -0,0 +1,13 @@
|
|||
api_id = 12345
|
||||
api_hash = "abcdefghj..."
|
||||
|
||||
matrix_creds = {
|
||||
"username": "username",
|
||||
"password": "password",
|
||||
"server": "server"
|
||||
}
|
||||
|
||||
mappings = [
|
||||
# Each pair is tg channel id, matrix room id
|
||||
(-123456789, '!asdfghjkl'),
|
||||
]
|
Loading…
Reference in New Issue