Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Commit

Permalink
add m.sticker event support
Browse files Browse the repository at this point in the history
  • Loading branch information
Redlinkk committed May 6, 2018
1 parent d5272ce commit e08a6da
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions telematrix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,37 @@ async def matrix_transaction(request):
print('Unsupported message type {}'.format(content['msgtype']))
print(json.dumps(content, indent=4))

elif event['type'] == 'm.sticker':
user_id = event['user_id']
if matrix_is_telegram(user_id):
continue

sender = db.session.query(db.MatrixUser) \
.filter_by(matrix_id=user_id).first()

if not sender:
response = await matrix_get('client', 'profile/{}/displayname'
.format(user_id), None)
try:
displayname = response['displayname']
except KeyError:
displayname = get_username(user_id)
sender = db.MatrixUser(user_id, displayname)
db.session.add(sender)
else:
displayname = sender.name or get_username(user_id)
content = event['content']

try:
url = urlparse(content['url'])
await download_matrix_file(url, content['body'])

with open('/tmp/{}'.format(content['body']), 'rb') as file:
response = await group.send_sticker(file)

except:
pass

elif event['type'] == 'm.room.member':
if HIDE_MEMBERSHIP_CHANGES: # Hide everything, could be improved to be
# more specific
Expand Down

0 comments on commit e08a6da

Please sign in to comment.