Skip to content

Instantly share code, notes, and snippets.

@aidnzz
Last active July 24, 2019 10:57
Show Gist options
  • Select an option

  • Save aidnzz/123c86722ec429c4fe7c98b620e93e44 to your computer and use it in GitHub Desktop.

Select an option

Save aidnzz/123c86722ec429c4fe7c98b620e93e44 to your computer and use it in GitHub Desktop.

Revisions

  1. aidnzz revised this gist Jul 24, 2019. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    # -*- coding: utf-8 -*-
    # -*- coding: utf-8 -*-

    from requests import Session
    from enum import IntEnum, unique

    from functools import wraps, lru_cache

    class Basic:
    def __init__(self, proxy=None):
    self.session = Session()
    @@ -15,7 +17,7 @@ def csrf_token(self):
    def post(self, url, data=None, json=None, **kwargs):
    kwargs.update(headers={"X-CSRF-TOKEN": self.csrf_token()})
    return self.session.post(url, data, json, **kwargs)

    def close(self):
    self.session.close()

    @@ -46,20 +48,12 @@ def decorator(*args, **kwargs):
    return json
    return decorator

    def cache(func):
    @wraps(func)
    def decorator(*args, **kwargs):
    if not getattr(decorator, "value", None):
    decorator.value = func(*args, **kwargs)
    return decorator.value
    return decorator

    class Authenticated(Basic):
    def __init__(self, cookie, proxy=None):
    super().__init__(proxy)
    self.session.cookies[".ROBLOSECURITY"] = cookie

    @cache
    @lru_cache()
    @null_check("Invalid cookie")
    def current_user(self):
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as r:
    @@ -69,6 +63,7 @@ def current_user(self):
    class PlaceAPI(Authenticated):
    def __init__(self, cookie, proxy=None):
    super().__init__(cookie, proxy)
    self.session.headers["User-Agent"] = "Roblox/WinInet"

    @null_check("Invalid ticket recieved")
    def auth_ticket(self, place):
    @@ -80,7 +75,13 @@ def auth_ticket(self, place):
    with self.session.get("https://www.roblox.com/game-auth/getauthticket", headers=headers) as r:
    return r.text

    def place_launch(self, place, game):
    params = dict(request="RequestGameJob", placeId=place, gameId=game, isPlayTogetherGame=False)

    with self.session.get("https://assetgame.roblox.com/game/PlaceLauncher.ashx", params=params) as r:
    return r.json()


    @unique
    class Status(IntEnum):
    OFFLINE = 0
  2. aidnzz revised this gist Jul 20, 2019. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -30,10 +30,10 @@ def null_check(message):
    def decorator(func):
    @wraps(func)
    def wrap(*args, **kwargs):
    val = func(*args, **kwargs)
    if val == "null":
    value = func(*args, **kwargs)
    if value == "null":
    raise Exception(message)
    return val
    return value
    return wrap
    return decorator

    @@ -49,9 +49,9 @@ def decorator(*args, **kwargs):
    def cache(func):
    @wraps(func)
    def decorator(*args, **kwargs):
    if not getattr(decorator, "val", None):
    decorator.val = func(*args, **kwargs)
    return decorator.val
    if not getattr(decorator, "value", None):
    decorator.value = func(*args, **kwargs)
    return decorator.value
    return decorator

    class Authenticated(Basic):
  3. aidnzz revised this gist Jul 19, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion roblox.py
    Original file line number Diff line number Diff line change
    @@ -80,7 +80,6 @@ def auth_ticket(self, place):
    with self.session.get("https://www.roblox.com/game-auth/getauthticket", headers=headers) as r:
    return r.text



    @unique
    class Status(IntEnum):
  4. aidnzz revised this gist Jul 19, 2019. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -30,10 +30,10 @@ def null_check(message):
    def decorator(func):
    @wraps(func)
    def wrap(*args, **kwargs):
    value = func(*args, **kwargs)
    if value == "null":
    val = func(*args, **kwargs)
    if val == "null":
    raise Exception(message)
    return value
    return val
    return wrap
    return decorator

    @@ -49,9 +49,9 @@ def decorator(*args, **kwargs):
    def cache(func):
    @wraps(func)
    def decorator(*args, **kwargs):
    if not getattr(decorator, "value", None):
    decorator.value = func(*args, **kwargs)
    return decorator.value
    if not getattr(decorator, "val", None):
    decorator.val = func(*args, **kwargs)
    return decorator.val
    return decorator

    class Authenticated(Basic):
    @@ -62,7 +62,6 @@ def __init__(self, cookie, proxy=None):
    @cache
    @null_check("Invalid cookie")
    def current_user(self):
    # runs once and is placed in cache as the user id isn't going to change
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as r:
    return r.text

    @@ -82,6 +81,15 @@ def auth_ticket(self, place):
    return r.text



    @unique
    class Status(IntEnum):
    OFFLINE = 0
    ONLINE = 1
    PLAYING = 2
    DEVELOPING = 3


    class UserAPI(Authenticated):
    def __init__(self, cookie, proxy=None):
    super().__init__(cookie, proxy)
    @@ -94,12 +102,4 @@ def user_presence(self, *args):
    @error_check
    def username_info(self, user):
    with self.session.get("http://api.roblox.com/users/get-by-username", params=dict(username=user)) as r:
    return r.json()


    @unique
    class Status(IntEnum):
    OFFLINE = 0
    ONLINE = 1
    PLAYING = 2
    DEVELOPING = 3
    return r.json()
  5. aidnzz revised this gist Jul 18, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion roblox.py
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,6 @@ def cache(func):
    def decorator(*args, **kwargs):
    if not getattr(decorator, "value", None):
    decorator.value = func(*args, **kwargs)
    return decorator.value
    return decorator.value
    return decorator

  6. aidnzz revised this gist Jul 18, 2019. 1 changed file with 33 additions and 36 deletions.
    69 changes: 33 additions & 36 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,16 @@
    # -*- coding: utf-8 -*-

    from requests import Session

    from requests import Session
    from enum import IntEnum, unique
    from functools import wraps, lru_cache

    class UnAuthenticated:
    class Basic:
    def __init__(self, proxy=None):
    self.session = Session()
    self.session.proxies = proxy

    def csrf_token(self):
    with self.session.post("https://auth.roblox.com/v2/login") as response:
    return response.headers["X-CSRF-TOKEN"]
    with self.session.post("https://auth.roblox.com/v2/login") as r:
    return r.headers["X-CSRF-TOKEN"]

    def post(self, url, data=None, json=None, **kwargs):
    kwargs.update(headers={"X-CSRF-TOKEN": self.csrf_token()})
    @@ -31,12 +29,12 @@ def __exit__(self, *args):
    def null_check(message):
    def decorator(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
    def wrap(*args, **kwargs):
    value = func(*args, **kwargs)
    if value == "null":
    raise Exception(message)
    return value
    return wrapper
    return wrap
    return decorator

    def error_check(func):
    @@ -48,16 +46,26 @@ def decorator(*args, **kwargs):
    return json
    return decorator

    class Authenticated(UnAuthenticated):
    def cache(func):
    @wraps(func)
    def decorator(*args, **kwargs):
    if not getattr(decorator, "value", None):
    decorator.value = func(*args, **kwargs)
    return decorator.value
    return decorator.value
    return decorator

    class Authenticated(Basic):
    def __init__(self, cookie, proxy=None):
    super().__init__(proxy)
    self.session.cookies[".ROBLOSECURITY"] = cookie

    @lru_cache()
    @cache
    @null_check("Invalid cookie")
    def current_user(self):
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as response:
    return response.text
    # runs once and is placed in cache as the user id isn't going to change
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as r:
    return r.text


    class PlaceAPI(Authenticated):
    @@ -71,15 +79,8 @@ def auth_ticket(self, place):
    "Referer": f"https://www.roblox.com/games/{place}"
    }

    with self.session.get("https://www.roblox.com/game-auth/getauthticket", headers=headers) as response:
    return response.text


    @unique
    class Status(IntEnum):
    OFFLINE = 0
    ONLINE = 1
    PLAYING = 2
    with self.session.get("https://www.roblox.com/game-auth/getauthticket", headers=headers) as r:
    return r.text


    class UserAPI(Authenticated):
    @@ -88,22 +89,18 @@ def __init__(self, cookie, proxy=None):

    @error_check
    def user_presence(self, *args):
    with self.post("https://presence.roblox.com/v1/presence/users", json=dict(userIds=args)) as response:
    return response.json()
    with self.post("https://presence.roblox.com/v1/presence/users", json=dict(userIds=args)) as r:
    return r.json()

    @error_check
    def username_info(user):
    with requests.get("http://api.roblox.com/users/get-by-username", params=dict(username=user)) as response:
    return response.json()


    def init():
    cookie = "_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_9A479CC02C17F3C243D9CD447093278971AA20DC308079FBFE50A382752A3E294E93B6089AABFF3AD0F61055C886B76D22C78F63D0129BFA813E5571FE7FA86F92A471FD3A760F0990719D87BD46341E80CF3352E3EB658044632556AC575F93A8EE5B22D00B04ACBB7D629005F65E583BD3524E8701AC7A79BD7509C923D03BDBB695EAFBFB6038CA84DFD8DF6845FEFF2CD4C29649E01D9298FDC9AE9BD2451822BB3E97EDFD4A00DA452D5CBB2042BEFAEEC8DEA494EC5555810D29A4858DC8EFA05E385B148D84E7E33D2B83E595686B7FF9FBF47BBC1C0AF5C5B7A88F2F0EE3A8F7B136F520B066A16EBECC9F1F54B9D570F87B7352A2BE044178AC6F1093C13F5ADB8EFD5A04FFB3C644856F5734034F3C8A9E3AAD9C3DE8B6BAABBFAA8B6D4DF3"

    with UserAPI(cookie) as user:
    for __ in range(20):
    print(user.current_user())
    def username_info(self, user):
    with self.session.get("http://api.roblox.com/users/get-by-username", params=dict(username=user)) as r:
    return r.json()


    if __name__ == "__main__":
    init()
    @unique
    class Status(IntEnum):
    OFFLINE = 0
    ONLINE = 1
    PLAYING = 2
    DEVELOPING = 3
  7. aidnzz revised this gist Jul 14, 2019. 1 changed file with 18 additions and 2 deletions.
    20 changes: 18 additions & 2 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,7 @@ def wrapper(*args, **kwargs):
    if value == "null":
    raise Exception(message)
    return value
    return wrapper
    return decorator

    def error_check(func):
    @@ -52,7 +53,7 @@ def __init__(self, cookie, proxy=None):
    super().__init__(proxy)
    self.session.cookies[".ROBLOSECURITY"] = cookie

    @lru_cache
    @lru_cache()
    @null_check("Invalid cookie")
    def current_user(self):
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as response:
    @@ -65,7 +66,10 @@ def __init__(self, cookie, proxy=None):

    @null_check("Invalid ticket recieved")
    def auth_ticket(self, place):
    headers = {"RBX-For-Gameauth": "true", "Referer": f"https://www.roblox.com/games/{place}"}
    headers = {
    "RBX-For-Gameauth": True,
    "Referer": f"https://www.roblox.com/games/{place}"
    }

    with self.session.get("https://www.roblox.com/game-auth/getauthticket", headers=headers) as response:
    return response.text
    @@ -91,3 +95,15 @@ def user_presence(self, *args):
    def username_info(user):
    with requests.get("http://api.roblox.com/users/get-by-username", params=dict(username=user)) as response:
    return response.json()


    def init():
    cookie = "_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_9A479CC02C17F3C243D9CD447093278971AA20DC308079FBFE50A382752A3E294E93B6089AABFF3AD0F61055C886B76D22C78F63D0129BFA813E5571FE7FA86F92A471FD3A760F0990719D87BD46341E80CF3352E3EB658044632556AC575F93A8EE5B22D00B04ACBB7D629005F65E583BD3524E8701AC7A79BD7509C923D03BDBB695EAFBFB6038CA84DFD8DF6845FEFF2CD4C29649E01D9298FDC9AE9BD2451822BB3E97EDFD4A00DA452D5CBB2042BEFAEEC8DEA494EC5555810D29A4858DC8EFA05E385B148D84E7E33D2B83E595686B7FF9FBF47BBC1C0AF5C5B7A88F2F0EE3A8F7B136F520B066A16EBECC9F1F54B9D570F87B7352A2BE044178AC6F1093C13F5ADB8EFD5A04FFB3C644856F5734034F3C8A9E3AAD9C3DE8B6BAABBFAA8B6D4DF3"

    with UserAPI(cookie) as user:
    for __ in range(20):
    print(user.current_user())


    if __name__ == "__main__":
    init()
  8. aidnzz revised this gist Jul 13, 2019. 1 changed file with 0 additions and 34 deletions.
    34 changes: 0 additions & 34 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -6,34 +6,19 @@
    from functools import wraps, lru_cache

    class UnAuthenticated:
    """ UnAuthenticated for when a cookie is not needed
    Parameters
    ----------
    proxy : dict
    To specify proxy settings, None by default
    Attributes
    ----------
    session : requests.Session
    """

    def __init__(self, proxy=None):
    self.session = Session()
    self.session.proxies = proxy

    def csrf_token(self):
    """Returns a csrf token string for use with Roblox's api's"""
    with self.session.post("https://auth.roblox.com/v2/login") as response:
    return response.headers["X-CSRF-TOKEN"]

    def post(self, url, data=None, json=None, **kwargs):
    """Sends a POST request with a csrf token added."""
    kwargs.update(headers={"X-CSRF-TOKEN": self.csrf_token()})
    return self.session.post(url, data, json, **kwargs)

    def close(self):
    """Closes all adapters and as such the session"""
    self.session.close()

    def __enter__(self):
    @@ -44,7 +29,6 @@ def __exit__(self, *args):


    def null_check(message):
    """Checks if an API returned null if so, raises an exception with a custom message."""
    def decorator(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
    @@ -55,7 +39,6 @@ def wrapper(*args, **kwargs):
    return decorator

    def error_check(func):
    """Checks if an API returned any errors if so raises an exception with Roblox's warning."""
    @wraps(func)
    def decorator(*args, **kwargs):
    json = func(*args, **kwargs)
    @@ -65,27 +48,13 @@ def decorator(*args, **kwargs):
    return decorator

    class Authenticated(UnAuthenticated):
    """ Extends UnAuthendicated with cookie support for additional features
    Parameters
    ----------
    proxy : dict
    To specify proxy settings, None by default
    Attributes
    ----------
    session : requests.Session
    """

    def __init__(self, cookie, proxy=None):
    super().__init__(proxy)
    self.session.cookies[".ROBLOSECURITY"] = cookie

    @lru_cache
    @null_check("Invalid cookie")
    def current_user(self):
    """ Returns user id of current user"""
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as response:
    return response.text

    @@ -96,7 +65,6 @@ def __init__(self, cookie, proxy=None):

    @null_check("Invalid ticket recieved")
    def auth_ticket(self, place):
    """Returns a game auth ticket."""
    headers = {"RBX-For-Gameauth": "true", "Referer": f"https://www.roblox.com/games/{place}"}

    with self.session.get("https://www.roblox.com/game-auth/getauthticket", headers=headers) as response:
    @@ -116,12 +84,10 @@ def __init__(self, cookie, proxy=None):

    @error_check
    def user_presence(self, *args):
    """Returns user presence for a single or group of users."""
    with self.post("https://presence.roblox.com/v1/presence/users", json=dict(userIds=args)) as response:
    return response.json()

    @error_check
    def username_info(user):
    """Returns user info for a single user."""
    with requests.get("http://api.roblox.com/users/get-by-username", params=dict(username=user)) as response:
    return response.json()
  9. aidnzz revised this gist Jul 13, 2019. 1 changed file with 6 additions and 11 deletions.
    17 changes: 6 additions & 11 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -43,32 +43,27 @@ def __exit__(self, *args):
    self.close()


    def null_checker(message):
    def null_check(message):
    """Checks if an API returned null if so, raises an exception with a custom message."""
    def decorator(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
    value = func(*args, **kwargs)

    if value == "null":
    raise Exception(message)

    return value
    return decorator

    def error_checker(func):
    def error_check(func):
    """Checks if an API returned any errors if so raises an exception with Roblox's warning."""
    @wraps(func)
    def decorator(*args, **kwargs):
    json = func(*args, **kwargs)

    if "errors" in json:
    raise Exception(json["errors"])

    return json
    return decorator


    class Authenticated(UnAuthenticated):
    """ Extends UnAuthendicated with cookie support for additional features
    @@ -88,7 +83,7 @@ def __init__(self, cookie, proxy=None):
    self.session.cookies[".ROBLOSECURITY"] = cookie

    @lru_cache
    @null_checker("Invalid cookie")
    @null_check("Invalid cookie")
    def current_user(self):
    """ Returns user id of current user"""
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as response:
    @@ -99,7 +94,7 @@ class PlaceAPI(Authenticated):
    def __init__(self, cookie, proxy=None):
    super().__init__(cookie, proxy)

    @null_checker("Invalid ticket recieved")
    @null_check("Invalid ticket recieved")
    def auth_ticket(self, place):
    """Returns a game auth ticket."""
    headers = {"RBX-For-Gameauth": "true", "Referer": f"https://www.roblox.com/games/{place}"}
    @@ -119,13 +114,13 @@ class UserAPI(Authenticated):
    def __init__(self, cookie, proxy=None):
    super().__init__(cookie, proxy)

    @error_checker
    @error_check
    def user_presence(self, *args):
    """Returns user presence for a single or group of users."""
    with self.post("https://presence.roblox.com/v1/presence/users", json=dict(userIds=args)) as response:
    return response.json()

    @error_checker
    @error_check
    def username_info(user):
    """Returns user info for a single user."""
    with requests.get("http://api.roblox.com/users/get-by-username", params=dict(username=user)) as response:
  10. aidnzz created this gist Jul 13, 2019.
    132 changes: 132 additions & 0 deletions roblox.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,132 @@
    # -*- coding: utf-8 -*-

    from requests import Session

    from enum import IntEnum, unique
    from functools import wraps, lru_cache

    class UnAuthenticated:
    """ UnAuthenticated for when a cookie is not needed
    Parameters
    ----------
    proxy : dict
    To specify proxy settings, None by default
    Attributes
    ----------
    session : requests.Session
    """

    def __init__(self, proxy=None):
    self.session = Session()
    self.session.proxies = proxy

    def csrf_token(self):
    """Returns a csrf token string for use with Roblox's api's"""
    with self.session.post("https://auth.roblox.com/v2/login") as response:
    return response.headers["X-CSRF-TOKEN"]

    def post(self, url, data=None, json=None, **kwargs):
    """Sends a POST request with a csrf token added."""
    kwargs.update(headers={"X-CSRF-TOKEN": self.csrf_token()})
    return self.session.post(url, data, json, **kwargs)

    def close(self):
    """Closes all adapters and as such the session"""
    self.session.close()

    def __enter__(self):
    return self

    def __exit__(self, *args):
    self.close()


    def null_checker(message):
    """Checks if an API returned null if so, raises an exception with a custom message."""
    def decorator(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
    value = func(*args, **kwargs)

    if value == "null":
    raise Exception(message)

    return value
    return decorator

    def error_checker(func):
    """Checks if an API returned any errors if so raises an exception with Roblox's warning."""
    @wraps(func)
    def decorator(*args, **kwargs):
    json = func(*args, **kwargs)

    if "errors" in json:
    raise Exception(json["errors"])

    return json
    return decorator


    class Authenticated(UnAuthenticated):
    """ Extends UnAuthendicated with cookie support for additional features
    Parameters
    ----------
    proxy : dict
    To specify proxy settings, None by default
    Attributes
    ----------
    session : requests.Session
    """

    def __init__(self, cookie, proxy=None):
    super().__init__(proxy)
    self.session.cookies[".ROBLOSECURITY"] = cookie

    @lru_cache
    @null_checker("Invalid cookie")
    def current_user(self):
    """ Returns user id of current user"""
    with self.session.get("https://assetgame.roblox.com/Game/GetCurrentUser.ashx") as response:
    return response.text


    class PlaceAPI(Authenticated):
    def __init__(self, cookie, proxy=None):
    super().__init__(cookie, proxy)

    @null_checker("Invalid ticket recieved")
    def auth_ticket(self, place):
    """Returns a game auth ticket."""
    headers = {"RBX-For-Gameauth": "true", "Referer": f"https://www.roblox.com/games/{place}"}

    with self.session.get("https://www.roblox.com/game-auth/getauthticket", headers=headers) as response:
    return response.text


    @unique
    class Status(IntEnum):
    OFFLINE = 0
    ONLINE = 1
    PLAYING = 2


    class UserAPI(Authenticated):
    def __init__(self, cookie, proxy=None):
    super().__init__(cookie, proxy)

    @error_checker
    def user_presence(self, *args):
    """Returns user presence for a single or group of users."""
    with self.post("https://presence.roblox.com/v1/presence/users", json=dict(userIds=args)) as response:
    return response.json()

    @error_checker
    def username_info(user):
    """Returns user info for a single user."""
    with requests.get("http://api.roblox.com/users/get-by-username", params=dict(username=user)) as response:
    return response.json()