mirror of
				https://gitlab.com/ceda_ei/temac
				synced 2025-11-04 00:10:04 +01:00 
			
		
		
		
	Add core logic for event handlers. Add gitignore, sample config.
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					config.py
 | 
				
			||||||
 | 
					Temec.session
 | 
				
			||||||
 | 
					__pycache__/
 | 
				
			||||||
							
								
								
									
										23
									
								
								bot.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								bot.py
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										13
									
								
								sample.config.py
									
									
									
									
									
										Normal 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'),
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
		Reference in New Issue
	
	Block a user