setup for polling with matrixbot user and join pnut-bridge when invited

This commit is contained in:
Morgan McMillian 2017-05-24 17:04:27 -07:00
parent 600bd65546
commit c4707b08d0
3 changed files with 12 additions and 4 deletions

View file

@ -118,7 +118,7 @@ def on_receive_events(transaction):
if event['content']['membership'] == 'invite' and 'is_direct' in event['content'] and event['content']['is_direct'] == True:
logging.info('>> GOT INVITE')
logging.info('>> GOT PRIVATE INVITE')
txId += 1
url = app.config['MATRIX_HOST']
url += '/_matrix/client/r0/join/' + event['room_id']
@ -130,6 +130,15 @@ def on_receive_events(transaction):
db.session.add(addadminrm)
db.session.commit()
elif event['content']['membership'] == 'invite':
logging.info('>> GOT ROOM INVITE')
txId += 1
url = app.config['MATRIX_HOST']
url += '/_matrix/client/r0/join/' + event['room_id']
url += "?access_token=" + app.config['MATRIX_AS_TOKEN']
r = requests.post(url, headers={"Content-Type": "application/json"},
data=json.dumps({}))
elif event['membership'] == 'leave':
adminrm = MatrixAdminRooms.query.filter_by(room_id=event['room_id']).first()
if adminrm:

View file

@ -93,7 +93,7 @@ class ChannelMonitor(threading.Thread):
db.session.commit()
def poll_channel(self, room):
r = Pnut().get_channel_stream(room.pnut_chan, room.pnut_since)
r = Pnut(app.config['MATRIX_PNUT_TOKEN']).get_channel_stream(room.pnut_chan, room.pnut_since)
if r is not None and r.status_code == 200:
rdata = r.json()
pqueue = []

View file

@ -50,8 +50,7 @@ class Pnut:
def get_channel_stream(self,chan_id,since_id=None):
url = "https://api.pnut.io/v0/channels/" + str(chan_id) + "/messages?include_raw=1"
# headers = { "Authorization": "Bearer " + self.token }
headers = {}
headers = { "Authorization": "Bearer " + self.token }
parameters = {}
if since_id:
parameters = { "since_id": since_id }