matrix-shoutbox

git clone https://git.tarina.org/matrix-shoutbox
Log | Files | Refs

recv.py (664B)


      1 import asyncio
      2 from nio import (AsyncClient, RoomMessageText)
      3 import config
      4 
      5 open('msg.txt', 'w').close()
      6 
      7 async def message_cb(room, event):
      8     if room.display_name == config.display_name:
      9         print("{}: {}".format(room.user_name(event.sender), event.body))
     10         msg_file = open('msg.txt', 'a')
     11         msg_file.write(room.user_name(event.sender) + ': ' + event.body + '\n')
     12 
     13 async def main():
     14     client = AsyncClient(config.matrixserver, config.username)
     15     client.add_event_callback(message_cb, RoomMessageText)
     16 
     17     await client.login(config.password)
     18     await client.sync_forever(timeout=30000)
     19 
     20 asyncio.get_event_loop().run_until_complete(main())