Add core logic for event handlers. Add gitignore, sample config.

This commit is contained in:
Ceda EI 2019-05-16 14:58:34 +05:30
parent f5103d920c
commit c0a5fb3d3e
3 changed files with 39 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
config.py
Temec.session
__pycache__/

23
bot.py Normal file
View File

@ -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()

13
sample.config.py Normal file
View File

@ -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'),
]