Phase out TELEGRAM_CHATS and MATRIX_ROOMS

This commit is contained in:
Sijmen Schoon 2016-11-27 01:13:09 +01:00
parent ad842ada4d
commit 5bcaf1ba74

View File

@ -40,11 +40,8 @@ try:
MATRIX_MEDIA_PREFIX = MATRIX_HOST + '_matrix/media/r0/' MATRIX_MEDIA_PREFIX = MATRIX_HOST + '_matrix/media/r0/'
USER_ID_FORMAT = CONFIG['user_id_format'] USER_ID_FORMAT = CONFIG['user_id_format']
TELEGRAM_CHATS = CONFIG['chats']
MATRIX_ROOMS = {v: k for k, v in TELEGRAM_CHATS.items()}
DATABASE_URL = CONFIG['db_url'] DATABASE_URL = CONFIG['db_url']
except (OSError, IOError) as exception: except (OSError, IOError) as exception:
print('Error opening config file:') print('Error opening config file:')
print(exception) print(exception)
@ -354,7 +351,8 @@ async def matrix_room(request):
chat = '_'.join(localpart.split('_')[1:]) chat = '_'.join(localpart.split('_')[1:])
# Look up the chat in the database # Look up the chat in the database
if chat in TELEGRAM_CHATS: link = db.session.query(db.ChatLink).filter_by(tg_room=chat.id).first()
if link:
await matrix_post('client', 'createRoom', None, await matrix_post('client', 'createRoom', None,
{'room_alias_name': localpart[1:]}) {'room_alias_name': localpart[1:]})
return create_response(200, {}) return create_response(200, {})
@ -408,12 +406,12 @@ async def register_join_matrix(chat, room_id, user_id):
@TG_BOT.handle('photo') @TG_BOT.handle('photo')
async def aiotg_photo(chat, photo): async def aiotg_photo(chat, photo):
try: link = db.session.query(db.ChatLink).filter_by(tg_room=chat.id).first()
room_id = TELEGRAM_CHATS[str(chat.id)] if not link:
except KeyError: print('Unknown telegram chat {}: {}'.format(chat, chat.id))
print('Unknown telegram chat {}'.format(chat))
return return
room_id = link.matrix_room
user_id = USER_ID_FORMAT.format(chat.sender['id']) user_id = USER_ID_FORMAT.format(chat.sender['id'])
txn_id = quote('{}:{}'.format(chat.message['message_id'], chat.id)) txn_id = quote('{}:{}'.format(chat.message['message_id'], chat.id))