Пример #1
0
 def channelname_to_channelid(self, webclient: WebClient, name: str):
     """Convert a Slack channel name to its channel ID"""
     name = name.lstrip('#')
     channel = [channel for channel in self.webclient.channels_list() if channel.name == name]
     if not channel:
         raise RoomDoesNotExistError(f'No channel named {name} exists')
     return channel[0].id
Пример #2
0
 def _channel(self):
     channel = self.client.api.getChannelByName(team_id=self.teamid,
                                                channel_name=self.name)
     if 'status_code' in channel and channel['status_code'] != 200:
         raise RoomDoesNotExistError("{}: {}".format(
             channel['status_code'], channel['message']))
     return channel
Пример #3
0
    def query_room(self, room):
        """
        Query a room for information.

        :param room:
            The name (preferred) or XMPP JID of the room to query for.
        :returns:
            An instance of :class:`~HipChatMUCRoom`.
        """
        if room.endswith('@conf.hipchat.com'):
            log.debug("Room specified by JID, looking up room name")
            rooms = self.conn.hypchat.rooms(expand='items')
            try:
                name = [
                    r['name'] for r in rooms['items'] if r['xmpp_jid'] == room
                ][0]
            except IndexError:
                raise RoomDoesNotExistError(
                    "No room with JID {} found.".format(room))
            log.info(
                "Found {} to be the room {}, consider specifying this directly."
                .format(room, name))
        else:
            name = room

        return HipChatMUCRoom(name, self)
Пример #4
0
    def query_room(self, room):
        """
        Query a room for information.

        :param room:
            The name (preferred) or XMPP JID of the room to query for.
        :returns:
            An instance of :class:`~HipChatRoom`.
        """
        if room.endswith("@conf.hipchat.com") or room.endswith(
                "@conf.btf.hipchat.com"):
            log.debug("Room specified by JID, looking up room name")
            rooms = self.conn.hypchat.rooms(expand="items").contents()
            try:
                name = [r["name"] for r in rooms if r["xmpp_jid"] == room][0]
            except IndexError:
                raise RoomDoesNotExistError(f"No room with JID {room} found.")
            log.info(
                "Found %s to be the room %s, consider specifying this directly.",
                room,
                name,
            )
        else:
            name = room

        return HipChatRoom(name, self)
Пример #5
0
 def _channel(self):
     channel = self.driver.channels.get_channel_by_name(
         team_id=self.teamid, channel_name=self.name)
     if "status_code" in channel and channel["status_code"] != 200:
         raise RoomDoesNotExistError("{}: {}".format(
             channel["status_code"], channel["message"]))
     return channel
Пример #6
0
 def channelname_to_channelid(self, name):
     """Convert a Slack channel name to its channel ID"""
     name = name.lstrip('#')
     channel = [channel for channel in self.sc.server.channels if channel.name == name]
     if not channel:
         raise RoomDoesNotExistError(f'No channel named {name} exists')
     return channel[0].id
Пример #7
0
	def channelname_to_channelid(self, name):
		"""Convert the channelname in the current team to the channel id"""
		channel = self.driver.channels.get_channel_by_name(team_id=self.teamid, channel_name=name)
		if 'id' not in channel:
			raise RoomDoesNotExistError("No channel with name {} exists in team with ID {}".format(
				name, self.teamid
			))
		return channel['id']
Пример #8
0
 def channelname_to_channelid(self, name):
     """Convert a Slack channel name to its channel ID"""
     if name.startswith('#'):
         name = name[1:]
     channel = [channel for channel in self.sc.server.channels if channel.name == name]
     if not channel:
         raise RoomDoesNotExistError("No channel named %s exists" % name)
     return channel[0].id
Пример #9
0
 def _channel(self):
     """
     The channel object exposed by SlackClient
     """
     id_ = self.sc.server.channels.find(self.name)
     if id_ is None:
         raise RoomDoesNotExistError(f"{str(self)} does not exist (or is a private group you don't have access to)")
     return id_
Пример #10
0
	def channelid_to_channelname(self, channelid):
		"""Convert the channelid in the current team to the channel name"""
		channel = self.driver.channels.get_channel(channel_id=channelid)
		if 'name' not in channel:
			raise RoomDoesNotExistError("No channel with ID {} exists in team with ID {}".format(
				id, self.teamid
			))
		return channel['name']
Пример #11
0
 def channelid_to_channelname(self, id_):
     """Convert a Slack channel ID to its channel name"""
     channel = [
         channel for channel in self.sc.server.channels if channel.id == id_
     ]
     if not channel:
         raise RoomDoesNotExistError("No channel with ID %s exists" % id_)
     return channel[0].name
Пример #12
0
 def room(self):
     """
     Return room information from the HipChat API
     """
     try:
         log.debug("Querying HipChat API for room %s.", self.name)
         return self.hypchat.get_room(self.name)
     except hypchat.requests.HttpNotFound:
         raise RoomDoesNotExistError("The given room does not exist.")
Пример #13
0
 def channelid_to_channelname(self, channelid):
     """Convert the channelid in the current team to the channel name"""
     channel = self.client.api.getChannel(team_id=self.teamid,
                                          channel_id=channelid)
     if 'name' not in channel['channel']:
         raise RoomDoesNotExistError(
             "No channel with ID {} exists in team with ID {}".format(
                 id, self.teamid))
     return channel['channel']['name']
Пример #14
0
    def channelname(self):
        """Convert a Slack channel ID to its channel name"""
        if self._channelid is None:
            return None

        channel = self._sc.server.channels.find(self._channelid)
        if channel is None:
            raise RoomDoesNotExistError(f'No channel with ID {self._channelid} exists.')
        return channel.name
Пример #15
0
	def get_direct_channel(self, userid, other_user_id):
		"""
		Get the direct channel to another user.
		If it does not exist, it will be created.
		"""
		try:
			return self.driver.channels.create_direct_message_channel(options=[userid, other_user_id])
		except (InvalidOrMissingParameters, NotEnoughPermissions):
			raise RoomDoesNotExistError("Could not find Direct Channel for users with ID {} and {}".format(
				userid, other_user_id
			))
Пример #16
0
 def _channel(self):
     """
     The channel object exposed by SlackClient
     """
     _id = None
     for channel in self.webclient.conversations_list()['channels']:
         if channel['name'] == self.name:
             _id = channel['id']
             break
     else:
         raise RoomDoesNotExistError(f"{str(self)} does not exist (or is a private group you don't have access to)")
     return _id
Пример #17
0
    def channelname(self):
        """Convert a Slack channel ID to its channel name"""
        if self._channelid is None:
            return None

        if self._channelname:
            return self._channelname

        channel = [channel for channel in self._webclient.channels_list() if channel['id'] == self._channelid][0]
        if channel is None:
            raise RoomDoesNotExistError(f'No channel with ID {self._channelid} exists.')
        if not self._channelname:
            self._channelname = channel['name']
        return self._channelname
Пример #18
0
    def query_room(self, room):
        """
        Query a room for information.

        :param room:
            The room to query for.
        :returns:
            An instance of :class:`~SkypeChatroom`.
        """
        log.debug("Looking for a chat matching %s", room)
        chats = [c for c in self.skype.Chats if c.Name == room]
        if len(chats) == 1:
            log.debug("Found a chat matching %s", room)
            return SkypeChatroom(chats[0], bot=self)
        raise RoomDoesNotExistError("Couldn't find a room matching %s", room)
Пример #19
0
    def occupants(self):

        if not self.exists:
            raise RoomDoesNotExistError(f"Room {self.title or self.id} does not exist, or the bot does not have access")

        occupants = []

        for person in self._backend.webex_teams_api.memberships.list(roomId=self.id):
            p = CiscoWebexTeamsPerson(backend=self._backend)
            p.id = person.personId
            p.email = person.personEmail
            occupants.append(CiscoWebexTeamsRoomOccupant(backend=self._backend, room=self, person=p))

        log.debug("Total occupants for room {} ({}) is {} ".format(self.title, self.id, len(occupants)))

        return occupants
Пример #20
0
 def get_direct_channel(self, userid, otherUserid):
     """
     Get the direct channel to another user.
     If it does not exist, we need to create it.
     """
     channels = self.channels()
     for channel in channels:
         if channel['type'] == 'D':
             # The channelname should contain both users IDs
             if userid in channel['name'] and otherUserid in channel['name']:
                 return channel
     try:
         return self.client.api.createDirectChannel(self.teamid,
                                                    otherUserid)
     except Exception:
         raise RoomDoesNotExistError(
             "Could not find Direct Channel for users with ID {} and {}".
             format(userid, otherUserid))
Пример #21
0
    def channelname(self):
        """Convert a Slack channel ID to its channel name"""
        if self.channelid is None:
            return None

        if self._channelname:
            return self._channelname

        channel = self._webclient.conversations_info(channel=self.channelid)

        if not channel or not channel['ok']:
            raise RoomDoesNotExistError(
                f"No channel with ID {self._channelid} exists.")
        channel = channel['channel']

        if channel['is_im']:
            self._channelname = channel["user"]
        else:
            self._channelname = channel["name"]
        return self._channelname
Пример #22
0
 def channelid_to_channelname(self, webclient: WebClient, id_: str):
     """Convert a Slack channel ID to its channel name"""
     channel = webclient.channels_info(channel=id_)['channel']
     if channel is None:
         raise RoomDoesNotExistError(f'No channel with ID {id_} exists.')
     return channel['name']
Пример #23
0
 def channelid_to_channelname(self, id_: str):
     """Convert a Slack channel ID to its channel name"""
     channel = self.webclient.conversations_info(channel=id_)["channel"]
     if channel is None:
         raise RoomDoesNotExistError(f"No channel with ID {id_} exists.")
     return channel["name"]