How to use the hangups.user function in hangups

To help you get started, we’ve selected a few hangups examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hangoutsbot / hangoutsbot / hangupsbot / permamem.py View on Github external
"""retrieve definitive user data by requesting it from the server"""

        chat_ids = list(set(chat_ids))

        chunks = [chat_ids[i:i+batch_max] for i in range(0, len(chat_ids), batch_max)]

        updated_users = 0

        for chunk in chunks:
            logger.debug("getentitybyid(): {}".format(chunk))

            try:
                response = yield from self.bot._client.getentitybyid(chunk)

                for _user in response.entities:
                    UserID = hangups.user.UserID(chat_id=_user.id_.chat_id, gaia_id=_user.id_.gaia_id)
                    User = hangups.user.User(
                        UserID,
                        _user.properties.display_name,
                        _user.properties.first_name,
                        _user.properties.photo_url,
                        _user.properties.emails,
                        False)

                    """this function usually called because hangups user list is incomplete, so help fill it in as well"""
                    logger.debug("updating hangups user list {} ({})".format(User.id_.chat_id, User.full_name))
                    self.bot._user_list._user_dict[User.id_] = User

                    if self.store_user_memory(User, is_definitive=True, automatic_save=False):
                        updated_users = updated_users + 1

            except hangups.exceptions.NetworkError as e:
github Terrance / IMMP / immp / plug / hangouts.py View on Github external
async def user_from_id(self, id_):
        user = self._users.get_user(hangups.user.UserID(chat_id=id_, gaia_id=id_))
        if user:
            return HangoutsUser.from_user(self, user)
        request = hangouts_pb2.GetEntityByIdRequest(
            request_header=self._client.get_request_header(),
            batch_lookup_spec=[hangouts_pb2.EntityLookupSpec(gaia_id=id_)])
        response = await self._client.get_entity_by_id(request)
        if response.entity:
            return HangoutsUser.from_entity(self, response.entity)
        else:
            return None
github tdryer / hangups / hangups / parsers.py View on Github external
def from_participantid(participant_id):
    """Convert hangouts_pb2.ParticipantId to UserID."""
    return user.UserID(
        chat_id=participant_id.chat_id,
        gaia_id=participant_id.gaia_id
    )
github hangoutsbot / hangoutsbot / hangupsbot / hangups_conversation.py View on Github external
if permamem_conv["type"] == "GROUP":
            type_ = hangups_shim.schemas.ConversationType.GROUP
        else:
            type_ = hangups_shim.schemas.ConversationType.STICKY_ONE_TO_ONE

        current_participant = []
        participant_data = []
        read_state = []

        participants = permamem_conv["participants"][:] # use a clone
        participants.append(bot_user["chat_id"])
        participants = set(participants)
        for chat_id in participants:
            hangups_user = bot.get_hangups_user(chat_id)

            UserID = hangups.user.UserID(chat_id=hangups_user.id_.chat_id, gaia_id=hangups_user.id_.gaia_id)
            current_participant.append(UserID)

            ParticipantInfo = ParticipantData( fallback_name=hangups_user.full_name,
                                               id_=UserID )

            participant_data.append(ParticipantInfo)

            if not hangups_conv:
                read_state.append( LastRead( last_read_timestamp=0,
                                             participant_id=UserID ))

        active_timestamp = timestamp_now
        invite_timestamp = timestamp_now
        inviter_id = hangups.user.UserID( chat_id=bot_user["chat_id"],
                                          gaia_id=bot_user["chat_id"] )
        latest_read_timestamp = timestamp_now
github tdryer / hangups / hangups / conversation_event.py View on Github external
def participant_ids(self):
        """:class:`~hangups.user.UserID` of users involved (:class:`list`)."""
        return [user.UserID(chat_id=id_.chat_id, gaia_id=id_.gaia_id)
                for id_ in self._event.membership_change.participant_ids]
github wardellbagby / HangoutsBot / Core / Util / UtilBot.py View on Github external
def is_user_conv_admin(bot, user_info, conv_id=None):
    if isinstance(user_info, hangups.ConversationEvent):
        user_id = user_info.user_id
        conv_id = user_info.conversation_id
    elif isinstance(user_info, str):
        user_id = user_info
    elif isinstance(user_info, hangups.user.User):
        user_id = user_info.user_id[0]
    elif isinstance(user_info, hangups.user.UserID):
        user_id = user_info[0]

    if conv_id is None:
        raise ValueError("conv_id can not be None.")

    if user_id is None:
        raise ValueError("user_info can not be null")

    conv_admin_list = bot.get_config_suboption(conv_id, 'conversation_admin')
    return conv_admin_list and user_id in conv_admin_list
github hangoutsbot / hangoutsbot / hangupsbot / hangups_conversation.py View on Github external
invite_timestamp = hangups_conv.self_conversation_state.invite_timestamp
            inviter_id = hangups_conv.self_conversation_state.inviter_id
            latest_read_timestamp = hangups_conv.self_conversation_state.self_read_state.latest_read_timestamp
            sort_timestamp = hangups_conv.self_conversation_state.sort_timestamp
            logger.debug("properties cloned from hangups conversation")

        conversation_id = ConversationID( id = conv_id,
                                          id_ = conv_id )

        self_conversation_state = SelfConversationState( active_timestamp=timestamp_now,
                                                         invite_timestamp=timestamp_now,
                                                         inviter_id=hangups.user.UserID( chat_id=bot_user["chat_id"],
                                                                                         gaia_id=bot_user["chat_id"] ),
                                                         notification_level=hangups_shim.schemas.ClientNotificationLevel.RING,
                                                         self_read_state=LatestRead( latest_read_timestamp=latest_read_timestamp,
                                                                                     participant_id=hangups.user.UserID( chat_id=bot_user["chat_id"],
                                                                                                                         gaia_id=bot_user["chat_id"] )),
                                                         sort_timestamp=sort_timestamp,
                                                         status=hangups_shim.schemas.ClientConversationStatus.ACTIVE,
                                                         view=hangups_shim.schemas.ClientConversationView.INBOX_VIEW )

        self._conversation = ClientConversation( conversation_id=conversation_id,
                                                 current_participant=current_participant,
                                                 name=permamem_conv["title"],
                                                 otr_status=otr_status,
                                                 participant_data=participant_data,
                                                 read_state=read_state,
                                                 self_conversation_state=self_conversation_state,
                                                 type_=type_ )

        # initialise blank
        self._user_list = []
github hangoutsbot / hangoutsbot / hangupsbot / permamem.py View on Github external
convs = self.bot.memory.get_by_path(['convmem'])
            logger.info("loading {} conversations from memory".format(len(convs)))

            _users_added = {}
            _users_incomplete = {}
            _users_unknown = {}

            _users_to_fetch = []

            for convid in convs:
                self.catalog[convid] = convs[convid]

                if "participants" in self.catalog[convid] and len(self.catalog[convid]["participants"]) > 0:
                    for _chat_id in self.catalog[convid]["participants"]:
                        try:
                            UserID = hangups.user.UserID(chat_id=_chat_id, gaia_id=_chat_id)
                            User = self.bot._user_list._user_dict[UserID]
                            results = self.store_user_memory(User, is_definitive=True, automatic_save=False)
                            if results:
                                _users_added[_chat_id] = User.full_name

                        except KeyError:
                            cached = False
                            if self.bot.memory.exists(["user_data", _chat_id, "_hangups"]):
                                cached = self.bot.memory.get_by_path(["user_data", _chat_id, "_hangups"])
                                if cached["is_definitive"]:
                                    if cached["full_name"].upper() == "UNKNOWN" and cached["full_name"] == cached["first_name"]:
                                        # XXX: crappy way to detect hangups unknown users
                                        logger.debug("user {} needs refresh".format(_chat_id))
                                    else:
                                        continue
github tdryer / hangups / hangups / conversation.py View on Github external
logger.warning('Failed to request missing users: {}'.format(e))

    # Build list of conversation participants.
    conv_part_list = []
    for conv_state in conv_states:
        conv_part_list.extend(conv_state.conversation.participant_data)

    # Retrieve self entity.
    get_self_info_response = await client.get_self_info(
        hangouts_pb2.GetSelfInfoRequest(
            request_header=client.get_request_header(),
        )
    )
    self_entity = get_self_info_response.self_entity

    user_list = user.UserList(client, self_entity, required_entities,
                              conv_part_list)
    conversation_list = ConversationList(client, conv_states,
                                         user_list, sync_timestamp)
    return (user_list, conversation_list)