Skip to content

Finalize Matrix support#55

Open
jfrederickson wants to merge 3 commits into
jahschwa:masterfrom
jfrederickson:feature/room-alias-support
Open

Finalize Matrix support#55
jfrederickson wants to merge 3 commits into
jahschwa:masterfrom
jfrederickson:feature/room-alias-support

Conversation

@jfrederickson

Copy link
Copy Markdown
Collaborator

Previously you were only able to join a Matrix room using its room ID.
This prevented us from doing some automated setup, and was just
generally inconvenient as room IDs are cumbersome to work with.

Previously you were only able to join a Matrix room using its room ID.
This prevented us from doing some automated setup, and was just
generally inconvenient as room IDs are cumbersome to work with.
@jfrederickson jfrederickson force-pushed the feature/room-alias-support branch from d123431 to 7a76e1d Compare October 14, 2018 00:09
@jfrederickson jfrederickson changed the title Add support for room aliases Add support for Matrix room aliases Oct 14, 2018
@jfrederickson jfrederickson changed the title Add support for Matrix room aliases Finalize Matrix support Oct 14, 2018
Comment thread protocols/sibyl_matrix.py
# Sibyl: A modular Python chat bot framework
# Copyright (c) 2015-2017 Joshua Haas <haas.josh.a@gmail.com>
# Copyright (c) 2016-2017 Jonathan Frederickson <jonathan@terracrypt.net>
# Copyright (c) 2016-2018 Jonathan Frederickson <jonathan@terracrypt.net>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, let's 2019 it

Comment thread protocols/sibyl_matrix.py
# @return (User) the "real" User behind the specified nick/room
def get_real(self,room,nick):
raise NotImplementedError
return self.get_user().get_base()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be resolving display names to MXIDs.

Comment thread protocols/sibyl_matrix.py
self.room_aliases[room_id_or_alias] = room
return room
else:
return MatrixRoom(self,room_id_or_alias,nick,pword)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[OPTIONAL] This can be more compactly written:

def new_room(self,room_id_or_alias,nick=None,pword=None):
  if room_id_or_alias in self.room_aliases:
    return self.room_aliases[room_id_or_alias]

  room = MatrixRoom(self,room_id_or_alias,nick,pword)
  if room_id_or_alias.startswith("#"):
    self.room_aliases[room_id_or_alias] = room
  return room

Comment thread protocols/sibyl_matrix.py
elif self.room_alias:
room_id = self.protocol.client.api.get_room_id(self.room_alias)
self.room = mxRoom.Room(self.protocol.client, room_id)
return self.room

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[OPTIONAL] We can do this more compactly:

def get_mx_room(self):
  # We have a room alias but haven't resolved it yet
  if not self.room:
    room_id = self.protocol.client.api.get_room_id(self.room_alias)
    self.room = mxRoom.Room(self.protocol.client, room_id)
  return self.room

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants