Exemplo n.º 1
0
    def __init__(self, groupid: int, cookie: str = None, **kwargs):
        """
        Creates an object that provides Roblox group information and endpoint interactions.

        :param groupid: The id of the group to create an object of.
        :param cookie: Optional: The user's cookie to use for authentication. This will be required for certain,
        but not all interactions.
        :key cookies: Optional: List of cookies to use with a proxy.
        :key proxies: Optional: List of proxies to use with a single cookie or several cookies.
        """
        super().__init__(cookie, data=kwargs)
        if kwargs.get('proxies', ''):
            requests = self.session
        else:
            import requests
        data = requests.get(f'{api.base}/groups/{groupid}').json()
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        else:
            self.__dict__.update({k.lower(): v for k, v in data.items()})
            self.owner = User(self.owner['Id'])
            self.__description = self.__dict__.pop('description')
            self.__membercount = None
            self.__enemies = None
            self.__allies = None
            self.__roles = None
            self.__shout = None
Exemplo n.º 2
0
    def payout(self, type: str, amount: int,
               recipients: Union[List[User], List[int]]) -> str:
        """
        Pays out group funds to the given users.

        :param type: Either a type of `FixedAmount` or `Percentage`. Must enter the type as shown here or it will fail.
        :param amount: The fixed amount of robux or percentage of robux to pay out to the given users.
        :return: 'Success'
        """
        if isinstance(recipients[0], User):
            _recipients = [{
                "recipientId": user.id,
                "recipientType": "User",
                "amount": amount
            } for user in recipients]
        else:
            _recipients = [{
                "recipientId": _id,
                "recipientType": "User",
                "amount": amount
            } for _id in recipients]
        data = self.session.post(f'{api.groups}/groups/{self.id}/payouts',
                                 json={
                                     "PayoutType": type,
                                     "Recipients": _recipients
                                 }).json()
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        return 'Success'
Exemplo n.º 3
0
    def friends(self) -> List['User']:
        """
        Contains a list of User objects representing the current user's friends.

        :return: List[User]
        """
        if not self.__friends:
            data = requests.get(f'{api.base}/users/{self.id}/friends').json()
            if not data:
                utils.handle_code(data['errors'][0]['code'])
            else:
                page = 2
                results = [*data]
                while data:
                    data = requests.get(
                        f'{api.base}/users/{self.id}/friends?page={page}'
                    ).json()
                    results += data
                    page += 1
                with ThreadPoolExecutor() as exe:
                    tasks = [
                        exe.submit(User, friend['Id']) for friend in results
                    ]
                    self.__friends = [t.result() for t in as_completed(tasks)]
        return self.__friends
Exemplo n.º 4
0
    def owners(self) -> List[User]:
        """
        Contains a list of User objects referencing the owners of the current asset.

        :return: List[User]
        """
        if not self.__owners:
            data = self.session.get(
                f'{api.inventory}/v2/assets/{self.id}/owners?limit=100').json(
                )
            if data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            elif not data['data']:
                self.__owners = 'No owners found for this asset'
            results = [data['data']]
            while data['nextPageCursor']:
                data = self.session.get(
                    f'{api.inventory}/v2/assets/{self.id}/owners?limit=100&cursor={data["nextPageCursor"]}'
                ).json()
                results.append(data['data'])
            with ThreadPoolExecutor() as exe:
                tasks = [
                    exe.submit(User, data['owner']['id']) for page in results
                    for data in page if data['owner']
                ]
                self.__owners = [t.result() for t in as_completed(tasks)]
        return self.__owners
Exemplo n.º 5
0
    def description(self, description: str):
        """
        Sets the description of the current group.

        :param description: The description to set for the current group.
        """
        data = self.session.patch(f'{api.groups}/groups/{self.id}/description',
                                  data={
                                      'description': description
                                  }).json()
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        self.__description = data['newDescription']
Exemplo n.º 6
0
    def shout(self, message: str):
        """
        Sets the shout of the current group.

        :param message: The message for the shout to set.
        """
        data = self.session.patch(f'{api.groups}/groups/{self.id}/status',
                                  data={
                                      'message': message
                                  }).json()
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        self.__shout = Shout(data)
Exemplo n.º 7
0
    def by_username(cls, username: str) -> 'User':
        """
        Class method that returns a User object based on the given username rather than id.

        :param username: The name of the user to create an object of.
        :return: User
        """
        data = requests.post(f'{api.user}/usernames/users',
                             data={
                                 'usernames': [username],
                                 'excludeBannedUsers': False
                             }).json()
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        elif not data['data']:
            raise UserWarning('Invalid User was given')
        return cls(data['data'][0]['id'])
Exemplo n.º 8
0
    def update_user_role(self, user: Union[User, int],
                         role: Union[Role, int]) -> str:
        """
        Updates the given user's group role to the given role.

        :param user: Either a User object or the userid of the user to alter.
        :param role: Either a Role object or the roleid of the role to assign.
        :return: 'Success'
        """
        _id = user.id if isinstance(user, User) else user
        _role_id = role.id if isinstance(role, Role) else role
        data = self.session.patch(f'{api.groups}/groups/{self.id}/users/{_id}',
                                  data={
                                      'roleId': _role_id
                                  }).json()
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        return 'Success'
Exemplo n.º 9
0
    def status(self, status: str):
        """
        Sets the current user's status.

        :param status: New status to set.
        """
        if self.session:
            data = self.session.patch(f'{api.user}/users/{self.id}/status',
                                      data={
                                          'status': status
                                      }).json()
            if data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            else:
                self.__status = data['status']
        else:
            raise UserWarning(
                'Authentication required for this endpoint, session must be set'
            )
Exemplo n.º 10
0
    def follow(self, user: Union['User', int]):
        """
        Follows the given user.

        :param user: The user to follow in the form of a User object or the userid.
        """
        if self.session:
            _id = user if isinstance(user, int) else user.id
            data = self.session.post(f'{api.friends}/users/{_id}/follow',
                                     data={
                                         'targetUserId': _id
                                     }).json()
            if data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            elif not data.get('success', ''):
                raise UserWarning('Error occurred following user')
        else:
            raise UserWarning(
                'Authentication required for this endpoint, session must be set'
            )
Exemplo n.º 11
0
    def groups(self) -> List['Group']:
        """
        Contains a list of Group objects representing the groups the current user is in.

        :return: List[Group]
        """
        if not self.__groups:
            data = requests.get(
                f'{api.groups}/users/{self.id}/groups/roles').json()
            if type(data) == dict and data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            elif not data:
                raise UserWarning('User not in any groups')
            else:
                with ThreadPoolExecutor() as exe:
                    tasks = [
                        exe.submit(Group, d['group']['id'])
                        for d in data['data']
                    ]
                    self.__groups = [t.result() for t in as_completed(tasks)]
        return self.__groups
Exemplo n.º 12
0
    def presence(self) -> conversion.UserPresence:
        """
        Contains a UserPresence object representing the current user's presence.

        :return: UserPresence
        """
        if not self.__presence:
            if self.session:
                data = self.session.post(api.presence,
                                         data={
                                             'userids': [self.id]
                                         }).json()
                if data.get('errors', ''):
                    utils.handle_code(data['errors'][0]['code'])
                else:
                    self.__presence = conversion.UserPresence._make(
                        data['userPresences'][0].values())
            else:
                raise UserWarning(
                    'Authentication required for this endpoint, session must be set'
                )
        return self.__presence
Exemplo n.º 13
0
    def __init__(self, gameid: int, cookie: str, **kwargs):
        """
        Creates an object that provides Roblox game information and endpoint interactions.

        :param gameid: The id of the game to create an object of.
        :param cookie: The user's cookie to use for authentication. This will be required for certain,
        but not all interactions.
        :key cookies: Optional: List of cookies to use with a proxy.
        :key proxies: Optional: List of proxies to use with a single cookie or several cookies.
        """
        super().__init__(cookie, data=kwargs)
        if kwargs.get('proxies', ''):
            requests = self.session
        else:
            import requests
        resp = self.session.get(
            f'{api.games}/games/multiget-place-details?placeIds={gameid}'
        ).json()
        if isinstance(resp, dict) and resp.get('errors', ''):
            utils.handle_code(resp['errors'][0]['code'])
        elif not resp:
            raise UserWarning('Invalid Game was given')
        else:
            resp = requests.get(
                f'{api.games}/games?universeIds={resp[0]["universeId"]}').json(
                )['data'][0]
            data = {k.lower(): v for k, v in resp.items()}
            self.__dict__.update(data)
            self.creator = User(self.creator.get('id')) if self.creator.get(
                'type') == 'User' else Group(self.creator.get('id'))
            self.__session_ticket = self.session.post(
                'https://auth.roblox.com/v1/authentication-ticket',
                headers={
                    'Referer': 'https://www.roblox.com'
                }).headers['rbx-authentication-ticket']
            self.__favorites = None
            self.__servers = None
            self.__votes = None
Exemplo n.º 14
0
    def sellers(self) -> List[Resell]:
        """
        Contains a list of Resell objects referencing the resellers of the current asset.

        :return: List[Resell]
        """
        if not self.__sellers:
            data = self.session.get(
                f'{api.economy}/{self.id}/resellers?limit=100').json()
            if data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            elif not data['data']:
                self.__sellers = []
            results = [*data['data']]
            while data['nextPageCursor']:
                data = requests.get(
                    f'{api.economy}/{self.id}/resellers?limit=100&cursor={data["nextPageCursor"]}'
                ).json()
                results.append(*data['data'])
            with ThreadPoolExecutor() as exe:
                tasks = [exe.submit(Resell, data) for data in results]
                self.__sellers = [t.result() for t in as_completed(tasks)]
        return self.__sellers
Exemplo n.º 15
0
    def __init__(self, assetid: int, cookie: str = None, **kwargs):
        """
        Creates an object that provides Roblox asset information and endpoint interactions.

        :param gameid: The id of the asset to create an object of.
        :param cookie: Optional: The user's cookie to use for authentication. This will be required for certain,
        but not all interactions.
        :key cookies: Optional: List of cookies to use with a proxy.
        :key proxies: Optional: List of proxies to use with a single cookie or several cookies.
        """
        super().__init__(cookie, data=kwargs)
        if kwargs.get('proxies', ''):
            requests = self.session
        else:
            import requests
        data = requests.get(f'{api.economy}/{assetid}/resale-data').json()
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        else:
            self.__dict__.update(data)
            self.__sellers = None
            self.__owners = None
            self.id = assetid
Exemplo n.º 16
0
    def rap(self) -> int:
        """
        Contains the total RAP of the current user.

        :return: int
        """
        if not self.__rap:
            data = requests.get(
                f'{api.inventory}/v1/users/{self.id}/assets/collectibles?sortOrder=Asc&limit=100'
            ).json()
            if data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            else:
                results = [data['data']]
                while data['nextPageCursor']:
                    data = requests.get(
                        f'{api.inventory}/v1/users/{self.id}/assets/collectibles?sortOrder=Asc&limit=100&cursor={data["nextPageCursor"]}'
                    ).json()
                    results.append(data['data'])
                self.__rap = utils.reduce(
                    utils.add,
                    [utils.map_reduce_rap(page) for page in results])
        return self.__rap
Exemplo n.º 17
0
    def change_description(self, description: str, pin: str = None):
        """
        Sets a new description for the current user.

        :param description: New description to set.
        :param pin: Optional: Account PIN to unlock settings if applicable.
        """
        if self.session:
            if pin:
                self.session.post(api.auth, data={'pin': pin})
            data = self.session.post(f'{api.account}/description',
                                     data={
                                         'description': description
                                     }).json()
            if data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            else:
                self.description = self.session.get(
                    f'{api.account}/description').json()['description']
        else:
            raise UserWarning(
                'Authentication required for this endpoint, session must be set'
            )
Exemplo n.º 18
0
    def __init__(self, userid: int, cookie: str = None, **kwargs):
        """
        Creates an object that provides Roblox user information and endpoint interactions.

        :param userid: The id of the user to create an object of.
        :param cookie: Optional: The user's cookie to use for authentication. This will be required for certain, but not all interactions.

        :key cookies: Optional: List of cookies to use with a proxy.
        :key proxies: Optional: List of proxies to use with a single cookie or several cookies.
        """
        super().__init__(cookie, data=kwargs)
        if kwargs.get('proxies', ''):
            requests = self.session
        else:
            import requests
        data = {
            k.lower(): v
            for k, v in requests.get(
                f'{api.base}/users/{userid}').json().items()
        }
        data.update({
            "isonline":
            requests.get(f'{api.base}/users/{userid}/onlinestatus').json()
            ["IsOnline"]
        })
        data.update(requests.get(f'{api.user}/users/{userid}').json())
        if data.get('errors', ''):
            utils.handle_code(data['errors'][0]['code'])
        else:
            del data['name'], data['displayName']
            self.__dict__.update(data)
            self.__cookie_info = None
            self.__presence = None
            self.__friends = None
            self.__status = None
            self.__groups = None
            self.__rap = None
Exemplo n.º 19
0
    def message(self,
                subject: str,
                body: str,
                recipient: Union['User', int] = None):
        """
        Sends a message to the current user or the given recipient.

        :param subject: The subject to use for the message.
        :param body: The message itself to send.
        :param recipient: Optional: Recipient to send the message to in the form of a User object or the userid.
        """
        if self.session:
            if recipient:
                _id = recipient if isinstance(recipient, int) else recipient.id
            else:
                _id = self.id
            data = self.session.post(
                f'{api.messages}/messages/send',
                data={
                    'userId':
                    self.by_cookie(self.session.cookies['.ROBLOSECURITY']).id,
                    'subject':
                    subject,
                    'body':
                    body,
                    'recipientId':
                    _id
                }).json()
            if data.get('errors', ''):
                utils.handle_code(data['errors'][0]['code'])
            elif not data.get('success', ''):
                raise UserWarning('Error occurred sending message')
        else:
            raise UserWarning(
                'Authentication required for this endpoint, session must be set'
            )