whitespace trim
This commit is contained in:
parent
037fee7796
commit
782c3d070b
2 changed files with 33 additions and 33 deletions
|
@ -382,7 +382,7 @@ def delete_message(event, user):
|
||||||
if e is None:
|
if e is None:
|
||||||
logger.debug("- can't find the event to remove -")
|
logger.debug("- can't find the event to remove -")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r, meta = pnutpy.api.delete_message(e.pnut_chan_id, e.pnut_msg_id)
|
r, meta = pnutpy.api.delete_message(e.pnut_chan_id, e.pnut_msg_id)
|
||||||
e.deleted = True
|
e.deleted = True
|
||||||
|
@ -466,13 +466,13 @@ def new_matrix_user(username):
|
||||||
logger.warning(errmsg)
|
logger.warning(errmsg)
|
||||||
|
|
||||||
def on_admin_event(event):
|
def on_admin_event(event):
|
||||||
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
||||||
token=app.config['MATRIX_AS_TOKEN'])
|
token=app.config['MATRIX_AS_TOKEN'])
|
||||||
logger.debug("- admin room event recieved -")
|
logger.debug("- admin room event recieved -")
|
||||||
|
|
||||||
if event['type'] != 'm.room.message':
|
if event['type'] != 'm.room.message':
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
msg = event['content']['body'].split(' ')
|
msg = event['content']['body'].split(' ')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -555,7 +555,7 @@ def cmd_admin_list():
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def cmd_admin_link(room_id, pnut_chan_id):
|
def cmd_admin_link(room_id, pnut_chan_id):
|
||||||
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
||||||
token=app.config['MATRIX_AS_TOKEN'])
|
token=app.config['MATRIX_AS_TOKEN'])
|
||||||
pnutpy.api.add_authorization_token(app.config['MATRIX_PNUT_TOKEN'])
|
pnutpy.api.add_authorization_token(app.config['MATRIX_PNUT_TOKEN'])
|
||||||
|
|
||||||
|
@ -568,7 +568,7 @@ def cmd_admin_link(room_id, pnut_chan_id):
|
||||||
try:
|
try:
|
||||||
channel, meta = pnutpy.api.subscribe_channel(pnut_chan_id)
|
channel, meta = pnutpy.api.subscribe_channel(pnut_chan_id)
|
||||||
r = matrix_api.join_room(room_id)
|
r = matrix_api.join_room(room_id)
|
||||||
|
|
||||||
rec = Rooms(
|
rec = Rooms(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
pnut_chan=channel.id,
|
pnut_chan=channel.id,
|
||||||
|
@ -588,7 +588,7 @@ def cmd_admin_link(room_id, pnut_chan_id):
|
||||||
return errmsg
|
return errmsg
|
||||||
|
|
||||||
def cmd_admin_unlink(rid):
|
def cmd_admin_unlink(rid):
|
||||||
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
||||||
token=app.config['MATRIX_AS_TOKEN'])
|
token=app.config['MATRIX_AS_TOKEN'])
|
||||||
pnutpy.api.add_authorization_token(app.config['MATRIX_PNUT_TOKEN'])
|
pnutpy.api.add_authorization_token(app.config['MATRIX_PNUT_TOKEN'])
|
||||||
|
|
||||||
|
@ -730,20 +730,20 @@ def on_direct_message(event, user, room):
|
||||||
|
|
||||||
except pnutpy.errors.PnutAuthAPIException:
|
except pnutpy.errors.PnutAuthAPIException:
|
||||||
logger.exception('-unable to post to pnut channel-')
|
logger.exception('-unable to post to pnut channel-')
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception('-something bad happened here-')
|
logger.exception('-something bad happened here-')
|
||||||
|
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
def on_control_message(event):
|
def on_control_message(event):
|
||||||
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],
|
||||||
token=app.config['MATRIX_AS_TOKEN'])
|
token=app.config['MATRIX_AS_TOKEN'])
|
||||||
logger.debug("- direct room event received -")
|
logger.debug("- direct room event received -")
|
||||||
|
|
||||||
if event['type'] != 'm.room.message':
|
if event['type'] != 'm.room.message':
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
msg = event['content']['body'].split(' ')
|
msg = event['content']['body'].split(' ')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -839,7 +839,7 @@ def cmd_user_drop(sender=None):
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
reply = "Success! Your auth token has been removed."
|
reply = "Success! Your auth token has been removed."
|
||||||
else:
|
else:
|
||||||
reply = "You do not appear to be registered."
|
reply = "You do not appear to be registered."
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception('!drop')
|
logging.exception('!drop')
|
||||||
|
|
|
@ -85,7 +85,7 @@ def new_message(msg, meta):
|
||||||
return
|
return
|
||||||
|
|
||||||
matrix_id = matrix_id_from_pnut(msg.user.username)
|
matrix_id = matrix_id_from_pnut(msg.user.username)
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'],
|
token=config['MATRIX_AS_TOKEN'],
|
||||||
identity=matrix_id)
|
identity=matrix_id)
|
||||||
|
|
||||||
|
@ -94,11 +94,11 @@ def new_message(msg, meta):
|
||||||
new_matrix_user(msg.user.username)
|
new_matrix_user(msg.user.username)
|
||||||
logger.debug('-new_user-')
|
logger.debug('-new_user-')
|
||||||
profile = {'displayname': None}
|
profile = {'displayname': None}
|
||||||
|
|
||||||
if profile['displayname'] != matrix_display_from_pnut(msg.user):
|
if profile['displayname'] != matrix_display_from_pnut(msg.user):
|
||||||
set_matrix_display(msg.user)
|
set_matrix_display(msg.user)
|
||||||
logger.debug('-set_display-')
|
logger.debug('-set_display-')
|
||||||
|
|
||||||
avatar = Avatars.query.filter(Avatars.pnut_user == msg.user.username).one_or_none()
|
avatar = Avatars.query.filter(Avatars.pnut_user == msg.user.username).one_or_none()
|
||||||
if avatar is None or avatar.avatar != msg.user.content.avatar_image.url:
|
if avatar is None or avatar.avatar != msg.user.content.avatar_image.url:
|
||||||
set_matrix_avatar(msg.user)
|
set_matrix_avatar(msg.user)
|
||||||
|
@ -126,10 +126,10 @@ def new_message(msg, meta):
|
||||||
|
|
||||||
r = matrix_api.send_message(room.room_id, text, timestamp=ts)
|
r = matrix_api.send_message(room.room_id, text, timestamp=ts)
|
||||||
event = Events(
|
event = Events(
|
||||||
event_id=r['event_id'],
|
event_id=r['event_id'],
|
||||||
room_id=room.room_id,
|
room_id=room.room_id,
|
||||||
pnut_msg_id=msg.id,
|
pnut_msg_id=msg.id,
|
||||||
pnut_user_id=msg.user.id,
|
pnut_user_id=msg.user.id,
|
||||||
pnut_chan_id=msg.channel_id,
|
pnut_chan_id=msg.channel_id,
|
||||||
deleted=False)
|
deleted=False)
|
||||||
db_session.add(event)
|
db_session.add(event)
|
||||||
|
@ -141,7 +141,7 @@ def new_message(msg, meta):
|
||||||
|
|
||||||
def new_media(room_id, msg):
|
def new_media(room_id, msg):
|
||||||
matrix_id = matrix_id_from_pnut(msg.user.username)
|
matrix_id = matrix_id_from_pnut(msg.user.username)
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'],
|
token=config['MATRIX_AS_TOKEN'],
|
||||||
identity=matrix_id)
|
identity=matrix_id)
|
||||||
ts = int(time.time()) * 1000
|
ts = int(time.time()) * 1000
|
||||||
|
@ -186,10 +186,10 @@ def new_media(room_id, msg):
|
||||||
|
|
||||||
r = matrix_api.send_content(room_id, ul['content_uri'], title, msgtype, extra_information=info, timestamp=ts)
|
r = matrix_api.send_content(room_id, ul['content_uri'], title, msgtype, extra_information=info, timestamp=ts)
|
||||||
event = Events(
|
event = Events(
|
||||||
event_id=r['event_id'],
|
event_id=r['event_id'],
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
pnut_msg_id=msg.id,
|
pnut_msg_id=msg.id,
|
||||||
pnut_user_id=msg.user.id,
|
pnut_user_id=msg.user.id,
|
||||||
pnut_chan_id=msg.channel_id,
|
pnut_chan_id=msg.channel_id,
|
||||||
deleted=False)
|
deleted=False)
|
||||||
db_session.add(event)
|
db_session.add(event)
|
||||||
|
@ -197,7 +197,7 @@ def new_media(room_id, msg):
|
||||||
|
|
||||||
def delete_message(msg):
|
def delete_message(msg):
|
||||||
matrix_id = matrix_id_from_pnut(msg.user.username)
|
matrix_id = matrix_id_from_pnut(msg.user.username)
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'],
|
token=config['MATRIX_AS_TOKEN'],
|
||||||
identity=matrix_id)
|
identity=matrix_id)
|
||||||
|
|
||||||
|
@ -229,14 +229,14 @@ def get_matrix_profile(matrix_id):
|
||||||
|
|
||||||
def set_matrix_display(user):
|
def set_matrix_display(user):
|
||||||
matrix_id = matrix_id_from_pnut(user.username)
|
matrix_id = matrix_id_from_pnut(user.username)
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'],
|
token=config['MATRIX_AS_TOKEN'],
|
||||||
identity=matrix_id)
|
identity=matrix_id)
|
||||||
matrix_api.set_display_name(matrix_id, matrix_display_from_pnut(user))
|
matrix_api.set_display_name(matrix_id, matrix_display_from_pnut(user))
|
||||||
|
|
||||||
def set_matrix_avatar(user):
|
def set_matrix_avatar(user):
|
||||||
matrix_id = matrix_id_from_pnut(user.username)
|
matrix_id = matrix_id_from_pnut(user.username)
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'],
|
token=config['MATRIX_AS_TOKEN'],
|
||||||
identity=matrix_id)
|
identity=matrix_id)
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ def set_matrix_avatar(user):
|
||||||
logger.exception('failed to set user avatar')
|
logger.exception('failed to set user avatar')
|
||||||
|
|
||||||
def new_matrix_user(username):
|
def new_matrix_user(username):
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'])
|
token=config['MATRIX_AS_TOKEN'])
|
||||||
data = {
|
data = {
|
||||||
'type': 'm.login.application_service',
|
'type': 'm.login.application_service',
|
||||||
|
@ -269,15 +269,15 @@ def new_matrix_user(username):
|
||||||
matrix_api.register(content=data)
|
matrix_api.register(content=data)
|
||||||
|
|
||||||
def join_room(room_id, matrix_id):
|
def join_room(room_id, matrix_id):
|
||||||
matrix_api_as = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api_as = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'])
|
token=config['MATRIX_AS_TOKEN'])
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'],
|
token=config['MATRIX_AS_TOKEN'],
|
||||||
identity=matrix_id)
|
identity=matrix_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
matrix_api.join_room(room_id)
|
matrix_api.join_room(room_id)
|
||||||
|
|
||||||
except MatrixRequestError as e:
|
except MatrixRequestError as e:
|
||||||
if e.code == 403:
|
if e.code == 403:
|
||||||
matrix_api_as.invite_user(room_id, matrix_id)
|
matrix_api_as.invite_user(room_id, matrix_id)
|
||||||
|
@ -289,7 +289,7 @@ def join_room(room_id, matrix_id):
|
||||||
|
|
||||||
def new_room(pnut_user, invitees, chan):
|
def new_room(pnut_user, invitees, chan):
|
||||||
dr = None
|
dr = None
|
||||||
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
matrix_api = MatrixHttpApi(config['MATRIX_HOST'],
|
||||||
token=config['MATRIX_AS_TOKEN'],
|
token=config['MATRIX_AS_TOKEN'],
|
||||||
identity=pnut_user)
|
identity=pnut_user)
|
||||||
url = matrix_url + '/createRoom'
|
url = matrix_url + '/createRoom'
|
||||||
|
@ -312,7 +312,7 @@ def on_message(ws, message):
|
||||||
# logger.debug("on_message: " + message)
|
# logger.debug("on_message: " + message)
|
||||||
msg = json.loads(message)
|
msg = json.loads(message)
|
||||||
logger.debug(msg['meta'])
|
logger.debug(msg['meta'])
|
||||||
|
|
||||||
if 'data' in msg:
|
if 'data' in msg:
|
||||||
|
|
||||||
if 'channel_type' in msg['meta']:
|
if 'channel_type' in msg['meta']:
|
||||||
|
@ -407,7 +407,7 @@ if __name__ == '__main__':
|
||||||
init_db()
|
init_db()
|
||||||
|
|
||||||
# setup the websocket connection
|
# setup the websocket connection
|
||||||
ws = websocket.WebSocketApp(ws_url, on_message=on_message,
|
ws = websocket.WebSocketApp(ws_url, on_message=on_message,
|
||||||
on_error=on_error, on_close=on_close)
|
on_error=on_error, on_close=on_close)
|
||||||
ws.on_open = on_open
|
ws.on_open = on_open
|
||||||
wst = threading.Thread(target=wsthreader(ws.run_forever))
|
wst = threading.Thread(target=wsthreader(ws.run_forever))
|
||||||
|
|
Loading…
Reference in a new issue