def test_annoyiances(self): dest = User('0', 'LtWorf', None) asyncio.run(self.client._addmagic('ciao @here', dest)) == 'ciao <!here>' asyncio.run(self.client._addmagic('ciao @channel', dest)) == 'ciao <!channel>' asyncio.run(self.client._addmagic('ciao @everyone </', dest)) == 'ciao <!everyone> </'
def events_iter(self) -> Iterator[Optional[SlackEvent]]: while True: if self._internalevents: data: Optional[Dict[str, Any]] = self._internalevents.pop() else: data = self._read() if not data: yield None continue r: Optional[SlackEvent] = None log('Scanning ', data) if not isinstance(data, dict): continue # Skip stuff sent by this client try: if data['fields']['args'][0]['_id'].startswith( self._id_prefix): continue except Exception: pass if data.get('msg') == 'changed' and data.get( 'collection') == 'stream-room-messages': # New message try: # If the sender is unknown, add it if data['fields']['args'][0]['u'][ '_id'] not in self._users: self._users[ data['fields']['args'][0]['u']['_id']] = User( id=data['fields']['args'][0]['u']['_id'], name=data['fields']['args'][0]['u'] ['username'], profile=Profile(real_name='noname'), ) r = Message( channel=data['fields']['args'][0]['rid'], user=data['fields']['args'][0]['u']['_id'], text=data['fields']['args'][0]['msg'], ) if 'editedBy' in data['fields']['args'][0]: r = MessageEdit(type='message', subtype='message_changed', channel=r.channel, previous=NoChanMessage(user=r.user, text=''), current=NoChanMessage(user=r.user, text=r.text)) except Exception: pass if r is None: log('Not handled: ', data) else: yield r
def get_members(self, id_: str) -> Set[str]: data = self.loader.load(self._call('getUsersOfRoom', [id_, True], True), ChannelUsers) for i in data.records: if i.id_ not in self._users: self._users[i.id_] = User( id=i.id_, name=i.username, profile=Profile(real_name=i.name), ) return {i.id_ for i in data.records}
def events_iter(self): # -> Iterator[Optional[SlackEvent]]: while True: if self._internalevents: data = self._internalevents.pop() else: data = self._read() if not data: yield None continue r = None # type: Optional[SlackEvent] print('Scanning ', data) if not isinstance(data, dict): continue if data.get('msg') == 'changed' and data.get( 'collection') == 'stream-room-messages': # New message try: # If the sender is unknown, add it if data['fields']['args'][0]['u'][ '_id'] not in self._users: self._users[ data['fields']['args'][0]['u']['_id']] = User( id=data['fields']['args'][0]['u']['_id'], name=data['fields']['args'][0]['u'] ['username'], profile=Profile(real_name='noname'), ) r = Message( channel=data['fields']['args'][0]['rid'], user=data['fields']['args'][0]['u']['_id'], text=data['fields']['args'][0]['msg'], ) if 'editedBy' in data['fields']['args'][0]: r = MessageEdit(previous=Message(channel=r.channel, user=r.user, text=''), current=r) except: pass if r is None: print('Not handled: ', data) else: yield r
async def get_user(self, id_): return User('0', 'LtWorf', None)
async def get_user_by_name(self, username): return User(username, username, None)
def test_escapes(self): dest = User('0', 'LtWorf', None) assert asyncio.run(self.client._addmagic('<', dest)) == '<' assert asyncio.run(self.client._addmagic('>ciao', dest)) == '>ciao'