async def add_users(self, user_ids): """Add one or more users to this conversation. Args: user_ids: List of IDs of the new users to be added; accepts :class:`.UserID`, ``InviteeID`` or just :class:`str` IDs. Raises: .ConversationTypeError: If conversation is not a group. .NetworkError: If conversation cannot be invited to. Returns: :class:`.ConversationEvent` representing the change. """ if not self._conversation.type == hangouts_pb2.CONVERSATION_TYPE_GROUP: raise exceptions.ConversationTypeError( 'Can only add users to group conversations') try: response = await self._client.add_user( hangouts_pb2.AddUserRequest( request_header=self._client.get_request_header(), event_request_header=self._get_event_request_header(), invitee_id=[ self._wrap_user_id(user_id) for user_id in user_ids ], )) return self._wrap_event(response.created_event) except exceptions.NetworkError as e: logger.warning('Failed to add user: {}'.format(e)) raise
async def channel_invite(self, channel, user): try: conv = self._convs.get(channel.source) except KeyError: return request = hangouts_pb2.AddUserRequest( request_header=self._client.get_request_header(), event_request_header=conv._get_event_request_header(), invitee_id=[hangouts_pb2.InviteeID(gaia_id=user.id)]) await self._client.add_user(request)
def add_users(self, users): global client request = hangouts_pb2.AddUserRequest( request_header=client.get_request_header(), invitee_id=[hangouts_pb2.InviteeID(gaia_id=chat_id) for chat_id in users], event_request_header=hangouts_pb2.EventRequestHeader( conversation_id=hangouts_pb2.ConversationId( id=self.conv.id_, ), client_generated_id=client.get_client_generated_id(), expected_otr=hangouts_pb2.OFF_THE_RECORD_STATUS_ON_THE_RECORD, ), ) asyncio.async(client.add_user(request))
def conv_add(bot, event, conv_name, *args): """Invite users to existing conversation (use . for current conversation) Usage: /bot conv_add conversation_name [user_name_1] [user_name_2] [...]""" conv_name = strip_quotes(conv_name) unique_user_objects = get_unique_user_objects(bot, args) if not unique_user_objects: yield from command.unknown_command(bot, event) return invitee_ids = [ InviteeID(gaia_id=u.id_.gaia_id, fallback_name=u.full_name) for u in unique_user_objects ] convs = [event.conv ] if conv_name == '.' else bot.find_conversations(conv_name) for c in convs: req = hangouts_pb2.AddUserRequest( request_header=bot._client.get_request_header(), invitee_id=invitee_ids, event_request_header=c._get_event_request_header()) res = yield from bot._client.add_user(req) c.add_event(res.created_event)
def adduser(self, conversation_id, chat_id_list, otr_status=hangouts_pb2.OFF_THE_RECORD_STATUS_ON_THE_RECORD): """Add users to an existing group conversation. conversation_id must be a valid conversation ID. chat_id_list is list of users which should be invited to conversation. Raises hangups.NetworkError if the request fails. """ request = hangouts_pb2.AddUserRequest( request_header=self._get_request_header_pb(), invitee_id=[hangouts_pb2.InviteeID(gaia_id=chat_id) for chat_id in chat_id_list], event_request_header=hangouts_pb2.EventRequestHeader( conversation_id=hangouts_pb2.ConversationId( id=conversation_id, ), client_generated_id=self.get_client_generated_id(), expected_otr=otr_status, ), ) response = hangouts_pb2.AddUserResponse() yield from self._pb_request('conversations/adduser', request, response) return response
async def add_users(self, *user_ids): """Add Users into this conversation. Args: user_ids (user.UserID): a tuple of `user.UserID`s. Raises: NetworkError: If a User cannot be added. """ present_users = set( user.UserID(chat_id=part.id.chat_id, gaia_id=part.id.gaia_id) for part in self._conversation.participant_data) new_user_ids = set(user_ids) - present_users if not new_user_ids: return await self._client.add_user( hangouts_pb2.AddUserRequest( request_header=self._client.get_request_header(), invitee_id=[ hangouts_pb2.InviteeID(gaia_id=user_id.chat_id) for user_id in new_user_ids ], event_request_header=self._get_event_request_header(), ))