Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bloxy Version 6 #287

Draft
wants to merge 26 commits into
base: v5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fdc8527
Fix package, update package versions, enforce node v16
Syrilai Jan 7, 2022
64095ab
Remove captcha api (#281)
Syrilai Jan 7, 2022
2b92729
Remove captcha api fully (#281)
Syrilai Jan 7, 2022
a7c9de1
Add .prettierrc
Syrilai Jan 7, 2022
b84c0c1
Export all types (#264)
Syrilai Jan 7, 2022
0fff134
Fix CircleCI errors (npm run eslint)
Syrilai Jan 7, 2022
b8eb2a8
Use `got` as http package again
Syrilai Jan 7, 2022
7da9a49
Switch from Jest to Mocha, rewrite tests
Syrilai Jan 8, 2022
4216bee
Run prettier, fix REST typings
Syrilai Jan 8, 2022
b9bfa13
Update `eslintrc.json`, ignore `security/detect-object-injection` in …
Syrilai Jan 8, 2022
08df677
Update all files to respect the new `.eslintrc.json`
Syrilai Jan 8, 2022
8e3a4c7
Update `typescript` devDependency, remove `jest` devDependency
Syrilai Jan 8, 2022
67e09ae
Update the first few APIs to a newer state
Syrilai Jan 8, 2022
c12e685
Update all APIs to a certain extend, strip all structures for the nex…
Syrilai Jan 8, 2022
e2b5f41
Remove `postinstall` from `package.json`
Syrilai Jan 8, 2022
de6c56c
Change typedoc to use `typedoc.json`
Syrilai Jan 8, 2022
f0cbe7c
Merge removal of `postinstall`
Syrilai Jan 8, 2022
7860347
Fix `RESTResponse.ts` to respect the right error name
Syrilai Jan 8, 2022
598e574
Add a suffix to all types in the api files
Syrilai Jan 9, 2022
02687a4
Merge branch 'v6' of https://github.com/Visualizememe/bloxy into v6
Syrilai Jan 9, 2022
b513358
FIX TYPEDOC
Syrilai Jan 9, 2022
12d6040
Remove default exports
Syrilai Jan 9, 2022
b1c1e74
Fix unit tests
Syrilai Jan 9, 2022
bfcfca5
Rewrite `BaseUser` and `User`, documented it
Syrilai Jan 15, 2022
3c277dc
Include the `dist` folder
Syrilai Jan 19, 2022
ea5281d
Build to latest state
Syrilai Jan 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
413 changes: 185 additions & 228 deletions .eslintrc.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
node_modules
coverage
tests/index.js
dist
# dist # Should we really ignore the dist folder?
docs
site
.idea
.nyc_output

# temporary
tests_jest
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"trailingComma": "none"
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"typescript.autoClosingTags": false,
"javascript.autoClosingTags": false
}
37 changes: 37 additions & 0 deletions dist/client/Client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ClientBase, ClientOptions } from "./ClientBase";
import { APIs } from "./apis";
import { ClientUser } from "../old_structures/ClientUser";
import { RESTController } from "../controllers/rest";
import { Group, PartialUser } from "../old_structures";
import * as ClientSocket from "./lib/ClientSocket/ClientSocket";
import { ChatManager } from "./lib/ChatManager/ChatManager";
import { DataStoreManager } from "./lib/DataStoreManager/DataStoreManager";
import { User } from "../structures/User";
import { BaseUser } from "../structures/BaseUser";
export declare class Client extends ClientBase {
user: ClientUser | null;
apis: APIs;
rest: RESTController;
socket: ClientSocket.Socket;
dataStoreManager: DataStoreManager;
chat: ChatManager;
constructor(options?: ClientOptions);
isLoggedIn(): boolean;
init(): void;
login(cookie?: string): Promise<ClientUser>;
getGroup(groupId: number): Promise<Group>;
/**
* Returns a base user object from a user id.
* @param userId The user's ID
*/
getBaseUser(userId: number): BaseUser;
/**
* Returns a user object from a user id.
* @param userId The user's ID
*/
getUser(userId: number): Promise<User>;
getUserIdFromUsername(username: string): Promise<PartialUser>;
getUsernameFromUserId(userId: number | string): Promise<PartialUser>;
getUsersByUserIds(userIds: number[] | string[], excludeBannedUsers?: boolean): Promise<PartialUser[]>;
getUsersByUsernames(usernames: string[], excludeBannedUsers?: boolean): Promise<PartialUser[]>;
}
146 changes: 146 additions & 0 deletions dist/client/Client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const tslib_1 = require("tslib");
const ClientBase_1 = require("./ClientBase");
const apis_1 = require("./apis");
const ClientUser_1 = require("../old_structures/ClientUser");
const rest_1 = require("../controllers/rest");
const old_structures_1 = require("../old_structures");
const ClientSocket = (0, tslib_1.__importStar)(require("./lib/ClientSocket/ClientSocket"));
const ChatManager_1 = require("./lib/ChatManager/ChatManager");
const DataStoreManager_1 = require("./lib/DataStoreManager/DataStoreManager");
const User_1 = require("../structures/User");
const BaseUser_1 = require("../structures/BaseUser");
class Client extends ClientBase_1.ClientBase {
constructor(options) {
super(options);
this.user = null;
this.apis = (0, apis_1.initAPIs)(this);
this.rest = new rest_1.RESTController(this, this.options.rest);
this.socket = new ClientSocket.Socket(this);
this.dataStoreManager = new DataStoreManager_1.DataStoreManager(this);
this.chat = new ChatManager_1.ChatManager(this);
this.init();
}
isLoggedIn() {
return this.user !== null;
}
init() {
if (this.options.rest) {
this.rest.setOptions(this.options.rest);
}
}
login(cookie) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
this.log("info", {
name: "Client.login",
description: `Started login process..`
});
cookie = cookie || (this.options.credentials || {}).cookie || undefined;
if (!cookie) {
throw new Error("Attempted to log in without a cookie!");
}
this.options.credentials = Object.assign(Object.assign({}, this.options.credentials), { cookie });
const createdCookie = this.rest.createCookie({
key: ".ROBLOSECURITY",
value: cookie,
domain: "roblox.com",
hostOnly: false,
httpOnly: false
});
this.rest.addCookie(createdCookie);
this.log("info", {
name: "Client.login",
description: `Added cookie to cookie jar, proceeding to fetching authenticated user information..`
});
const getAuthenticationData = yield this.apis.usersAPI.getAuthenticatedUserInformation();
this.user = new ClientUser_1.ClientUser({
id: getAuthenticationData.id,
name: getAuthenticationData.name
}, this);
this.emit("loggedIn");
this.log("info", {
name: "Client.login",
description: `Successfully logged in as ${getAuthenticationData.name}`
});
return this.user;
});
}
getGroup(groupId) {
return this.apis.groupsAPI
.getGroup({
groupId
})
.then((data) => {
if (!data) {
throw new Error(`Group not found: ${groupId}`);
}
else {
return new old_structures_1.Group(data, this);
}
});
}
/**
* Returns a base user object from a user id.
* @param userId The user's ID
*/
getBaseUser(userId) {
return new BaseUser_1.BaseUser(this, userId);
}
/**
* Returns a user object from a user id.
* @param userId The user's ID
*/
getUser(userId) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
const data = yield this.apis.usersAPI.getUserById({ userId });
return new User_1.User(this, data);
});
}
getUserIdFromUsername(username) {
return this.apis.usersAPI
.getUsersByUsernames({
usernames: [username],
excludeBannedUsers: false
})
.then((response) => {
if (response.data && response.data[0]) {
return new old_structures_1.PartialUser(response.data[0], this);
}
else {
throw new Error("Got invalid response from getUserIdFromUsername");
}
});
}
getUsernameFromUserId(userId) {
if (typeof userId === "string") {
userId = parseInt(userId);
}
return this.apis.generalApi
.getUserById({
userId
})
.then((data) => new old_structures_1.PartialUser(data, this));
}
getUsersByUserIds(userIds, excludeBannedUsers = false) {
if (typeof userIds[0] === "string") {
userIds = userIds.map((userId) => parseInt(userId));
}
return this.apis.usersAPI
.getUsersByIds({
excludeBannedUsers,
userIds: userIds
})
.then((response) => response.data.map((userData) => new old_structures_1.PartialUser(userData, this)));
}
getUsersByUsernames(usernames, excludeBannedUsers = false) {
return this.apis.usersAPI
.getUsersByUsernames({
excludeBannedUsers,
usernames
})
.then((response) => response.data.map((userData) => new old_structures_1.PartialUser(userData, this)));
}
}
exports.Client = Client;
38 changes: 38 additions & 0 deletions dist/client/ClientBase.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// <reference types="node" />
import { EventEmitter } from "events";
import { RESTControllerOptions } from "../interfaces/RESTInterfaces";
import { Debugger } from "debug";
export interface ClientCredentialsOptions {
cookie?: string;
}
export interface ClientCallbacks {
getFunCaptchaToken?: (publicKey: string, targetUrl: string) => Promise<string>;
}
export interface ClientSetup {
websocket?: {
maxRetries: number;
};
debug: boolean;
}
export interface ClientOptions {
credentials?: ClientCredentialsOptions;
rest?: RESTControllerOptions;
callbacks?: ClientCallbacks;
setup?: ClientSetup;
}
interface DebugData {
name: string;
description: string;
}
export declare class ClientBase extends EventEmitter {
options: ClientOptions;
debugger: {
info: Debugger;
warn: Debugger;
error: Debugger;
};
constructor(options?: ClientOptions);
updateOptions(options?: ClientOptions): ClientOptions;
log(level: "info" | "warn" | "error", data: DebugData): void;
}
export {};
36 changes: 36 additions & 0 deletions dist/client/ClientBase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClientBase = void 0;
const tslib_1 = require("tslib");
const events_1 = require("events");
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
const utilFunctions_1 = require("../util/utilFunctions");
class ClientBase extends events_1.EventEmitter {
constructor(options) {
super();
this.options = this.updateOptions(options);
this.debugger = {
info: (0, debug_1.default)("bloxy:info"),
warn: (0, debug_1.default)("bloxy:warn"),
error: (0, debug_1.default)("bloxy:error")
};
}
updateOptions(options) {
this.options = (0, utilFunctions_1.utilMergeDeep)({
credentials: {},
rest: {},
setup: {},
callbacks: {}
}, options || {});
return this.options;
}
log(level, data) {
const loggerToUse = level === "info"
? this.debugger.info
: level === "error"
? this.debugger.error
: this.debugger.warn;
loggerToUse(`[${new Date().toISOString()}] ${data.name}: ${data.description}`);
}
}
exports.ClientBase = ClientBase;
73 changes: 73 additions & 0 deletions dist/client/apis/AccountInformationAPI.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { BaseAPI } from "./BaseAPI";
import { Client } from "../Client";
import { UserIdOption, Privacy } from "../..";
export declare type AccountInformationBirthdate = {
birthDay: number;
birthMonth: number;
birthYear: number;
};
export declare type AccountInformationDescription = {
description: string;
};
export declare type AccountInformationGender = {
gender: number;
};
export declare type AccountInformationXboxConsecutiveLoginDays = {
count: number;
};
export declare type AccountInformationMetaData = {
isAllowedNotificationsEndpointDisabled: boolean;
isAccountSettingsPolicyEnabled: boolean;
isPhoneNumberEnabled: boolean;
MaxUserDescriptionLength: number;
isUserDescriptionEnabled: boolean;
isUserBlockEndpointsUpdated: boolean;
isIDVerificationEnabled: boolean;
isPasswordRequiredForAgingDown: boolean;
homePageUpsellCardVariation: string;
};
export declare type AccountInformationOwnPromotionChannels = {
promotionChannelsVisibilityPrivacy: Privacy;
facebook: string;
twitter: string;
youtube: string;
twitch: string;
guilded: string;
};
export declare type AccountInformationPromotionChannels = Omit<AccountInformationOwnPromotionChannels, "promotionChannelsVisibilityPrivacy">;
export declare type AccountInformationStarCodeAffiliate = {
userId: number;
name: string;
code: string;
};
export declare type AccountInformationSetStarCodeAffiliate = {
code: string;
};
export declare type AccountInformationAddStarCodeAffiliateOption = {
code: string;
};
export declare type AccountInformationRobloxBadge = {
id: number;
name: string;
description: string;
imageUrl: string;
};
export declare type AccountInformationRobloxBadges = AccountInformationRobloxBadge[];
export declare class AccountInformationAPI extends BaseAPI {
constructor(client: Client);
getUserBirthdate(): Promise<AccountInformationBirthdate>;
updateUserBirthdate(options: AccountInformationBirthdate): Promise<boolean>;
getUserDescription(): Promise<AccountInformationDescription>;
updateUserDescription(options: AccountInformationDescription): Promise<boolean>;
getUserGender(): Promise<AccountInformationGender>;
updateUserGender(options: AccountInformationGender): Promise<boolean>;
getConsecutiveXboxLoginDays(): Promise<AccountInformationXboxConsecutiveLoginDays>;
getMetaData(): Promise<AccountInformationMetaData>;
getSelfPromotionChannels(): Promise<AccountInformationOwnPromotionChannels>;
getUserPromotionChannels(options: UserIdOption): Promise<AccountInformationPromotionChannels>;
updateUserPromotionChannels(options: AccountInformationOwnPromotionChannels): Promise<boolean>;
removeStarCodeAffiliate(): Promise<boolean>;
getStarCodeAffiliate(): Promise<AccountInformationStarCodeAffiliate>;
addStarCodeAffiliate(options: AccountInformationAddStarCodeAffiliateOption): Promise<AccountInformationStarCodeAffiliate>;
getRobloxBadges(options: UserIdOption): Promise<AccountInformationRobloxBadges>;
}
Loading