Last active
July 24, 2019 10:57
-
-
Save aidnzz/123c86722ec429c4fe7c98b620e93e44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from requests import Session | |
| from enum import IntEnum, unique | |
| from functools import wraps, lru_cache | |
| class UnAuthenticated: | |
| 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"] | |
| 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() | |
| def __enter__(self): | |
| return self | |
| def __exit__(self, *args): | |
| self.close() | |
| def null_check(message): | |
| def decorator(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| value = func(*args, **kwargs) | |
| if value == "null": | |
| raise Exception(message) | |
| return value | |
| return wrapper | |
| return decorator | |
| def error_check(func): | |
| @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): | |
| def __init__(self, cookie, proxy=None): | |
| super().__init__(proxy) | |
| self.session.cookies[".ROBLOSECURITY"] = cookie | |
| @lru_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 | |
| class PlaceAPI(Authenticated): | |
| def __init__(self, cookie, proxy=None): | |
| super().__init__(cookie, proxy) | |
| @null_check("Invalid ticket recieved") | |
| def auth_ticket(self, 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 | |
| @unique | |
| class Status(IntEnum): | |
| OFFLINE = 0 | |
| ONLINE = 1 | |
| PLAYING = 2 | |
| class UserAPI(Authenticated): | |
| def __init__(self, cookie, proxy=None): | |
| super().__init__(cookie, proxy) | |
| @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() | |
| @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()) | |
| if __name__ == "__main__": | |
| init() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment