import Client from "../client"; import { GetUserAvatar, GetUserCurrentlyWearing, GetUserOutfits, GetUserOutfitsOptions } from "../client/apis/AvatarAPI"; import { DeleteBadgeFromUser, GetUserBadges, GetUserBadgesOptions } from "../client/apis/BadgesAPI"; import { CursorPage } from "./Asset"; import { GetUserBundles, GetUserBundlesByType, GetUserBundlesOptions } from "../client/apis/CatalogAPI"; import { AddUsersToConversation, RemoveUserFromConversation, StartOneToOneConversation } from "../client/apis/ChatAPI"; import { GetUsersTags, SetPendingUserTag, SetUserTag } from "../client/apis/ContactsAPI"; import { RemoveUserFromUniverseTeamCreate } from "../client/apis/DevelopAPI"; import { GetUserResellableAssetCopies } from "../client/apis/EconomyAPI"; import { AcceptFriendRequest, DeclineFriendRequest, FollowUser, GetUserFollowers, GetUserFollowersOptions, GetUserFollowing, GetUserFollowingOptions, GetUserFriendsWithStatuses, SendFriendRequest, UnFollowUser, UnfriendUser } from "../client/apis/FriendsAPI"; import { GetJoinRequest, GetUserGroups, GetUserPrimaryGroup, PayoutMembersOptions } from "../client/apis/GroupsAPI"; import { GetUserCollectibles, GetUserCollectiblesOptions, GetUserInventory, GetUserInventoryByAssetTypeId, GetUserInventoryByAssetTypeIdOptions, GetUserInventoryOptions, GetUserItemsByTypeAndTargetId, GetUserItemsByTypeAndTargetIdOptions } from "../client/apis/InventoryAPI"; import { PremiumUpsellCheck, PremiumUpsellCheckOptions, ValidateUserMembership } from "../client/apis/PremiumFeaturesAPI"; import { GetUsersPresences } from "../client/apis/PresenceAPI"; import { SendMessage, SendMessageOptions } from "../client/apis/PrivateMessagesAPI"; import { GetUsersAvatarBustImages, GetUsersAvatarBustImagesOptions, GetUsersAvatarHeadShotsImages, GetUsersAvatarHeadShotsImagesOptions, GetUsersFullBodyAvatarImages, GetUsersFullBodyAvatarImagesOptions } from "../client/apis/ThumbnailsAPI"; import { SendTrade, SendTradeOptions } from "../client/apis/TradesAPI"; import { UpdateUser, UpdateUserAccess } from "../client/apis/TranslationRolesAPI"; import { EnumUserPresence } from "../interfaces/GeneralInterfaces"; export interface UserBaseOptions { id: number; name?: string | null; displayName?: string; membership?: boolean; } export class UserBase { public client: Client; public id: number; public name: string | null; public displayName: string | null; public membership: unknown; constructor (data: UserBaseOptions, client: Client) { this.client = client; this.id = data.id; this.name = data.name || null; this.displayName = data.displayName || null; this.membership = data.membership || null; } getStatus (): Promise { return this.client.apis.usersAPI.getUserStatus({ userId: this.id }) .then(response => response.status); } getAvatar (): Promise { return this.client.apis.avatarAPI.getUserAvatar({ userId: this.id }); } getCurrentlyWearing (): Promise { return this.client.apis.avatarAPI.getUserCurrentlyWearing({ userId: this.id }); } getOutfits (options: Omit): Promise { return this.client.apis.avatarAPI.getUserOutfits({ ...options, userId: this.id }); } getBadges (options?: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.badgesAPI.getUserBadges({ ...options, userId: this.id }) .then(response => new CursorPageClass(this.client, options || {}, response, this.getBadges) as CursorPage); } getBadgesAwardedDates (badges: number[]): Promise<{ id: number; awardedAt: Date }[]> { return this.client.apis.badgesAPI.getUserBadgesAwardedDates({ badgeIds: badges, userId: this.id }) .then(response => response.data.map(badgeAwarded => ({ id: badgeAwarded.badgeId, awardedAt: new Date(badgeAwarded.awardedDate) }))); } deleteBadge (badgeId: number): Promise { return this.client.apis.badgesAPI.deleteBadgeFromUser({ badgeId, userId: this.id }); } getBundles (options?: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.catalogAPI.getUserBundles({ ...options, userId: this.id }) .then(response => new CursorPageClass(this.client, options || {}, response, this.getBundles)); } getBundlesByType (bundleType: string, options?: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.catalogAPI.getUserBundlesByType({ ...options, userId: this.id, bundleType }) .then(response => new CursorPageClass(this.client, options || {}, response, this.getBundlesByType)); } addToChatConversation (conversationId: number): Promise { return this.client.apis.chatAPI.addUsersToConversation({ conversationId, participantUserIds: [this.id] }); } removeFromConversation (conversationId: number): Promise { return this.client.apis.chatAPI.removeUserFromConversation({ conversationId, participantUserId: this.id }); } startConversation (): Promise { return this.client.apis.chatAPI.startOneToOneConversation({ participantUserId: this.id }); } getTag (): Promise { return this.client.apis.contactsAPI.getUsersTags({ targetUserIds: [this.id] }) .then(response => response[0]); } setPendingTag (tag: string): Promise { return this.client.apis.contactsAPI.setPendingUserTag({ userTag: tag, targetUserId: this.id }); } setTag (tag: string): Promise { return this.client.apis.contactsAPI.setUserTag({ targetUserId: this.id, userTag: tag }); } removeFromTeamCreate (universeId: number): Promise { return this.client.apis.developAPI.removeUserFromUniverseTeamCreate({ userId: this.id, universeId }); } getResellableAssetCopies (assetId: number): Promise { return this.client.apis.economyAPI.getUserResellableAssetCopies({ assetId, userId: this.id }); } getFollowers (options?: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.friendsAPI.getUserFollowers({ ...options, userId: this.id }) .then(response => new CursorPageClass(this.client, options || {}, response, this.getFollowers)); } getFollowersCount (): Promise { return this.client.apis.friendsAPI.getUserFollowersCount({ userId: this.id }) .then(response => response.count); } getFollowing (options?: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.friendsAPI.getUserFollowing({ ...options, userId: this.id }) .then(response => new CursorPageClass(this.client, options || {}, response, this.getFollowing)); } getFollowingCount (): Promise { return this.client.apis.friendsAPI.getUserFollowingCount({ userId: this.id }) .then(response => response.count); } getFriends (): Promise { return this.client.apis.friendsAPI.getUserFriends({ userId: this.id }) .then(response => response.data.map(friendRequest => new FriendRequest(friendRequest, this.client))); } getFriendsCount (): Promise { return this.client.apis.friendsAPI.getUserFriendsCount({ userId: this.id }) .then(data => data.count); } getFriendsWithStatuses (userIds: number[]): Promise { return this.client.apis.friendsAPI.getUserFriendsWithStatuses({ userId: this.id, withUserIds: userIds }); } follow (): Promise { return this.client.apis.friendsAPI.followUser({ userId: this.id }); } friend (source?: string): Promise { return this.client.apis.friendsAPI.sendFriendRequest({ source: source || "Unknown", userId: this.id }); } unFollow (): Promise { return this.client.apis.friendsAPI.unFollowUser({ userId: this.id }); } unfriend (): Promise { return this.client.apis.friendsAPI.unfriendUser({ userId: this.id }); } acceptFriendRequest (): Promise { return this.client.apis.friendsAPI.acceptFriendRequest({ userId: this.id }); } declineFriendRequest (): Promise { return this.client.apis.friendsAPI.declineFriendRequest({ userId: this.id }); } canInviteToVIPServer (): Promise { return this.client.apis.gamesAPI.canSelfInviteUserToVIPServer({ userId: this.id }) .then(response => response.canInvite); } awardBadge (badgeId: number, placeId: number): Promise { return this.client.apis.generalApi.awardBadge({ badgeId, placeId, userId: this.id }) .then(response => response as unknown as string); } isFollowedByUser (userId: number): Promise { return this.client.apis.generalApi.isUserFollowing({ userId, followUserId: this.id }); } getGroups (): Promise { return this.client.apis.groupsAPI.getUserGroups({ userId: this.id }); } ownsAsset (assetId: number): Promise { return this.client.apis.generalApi.userOwnsAsset({ userId: this.id, assetId }); } block (): Promise { return this.client.apis.generalApi.blockUser({ userId: this.id }); } unblock (): Promise { return this.client.apis.generalApi.unblockUser({ userId: this.id }); } canManageAsset (assetId: number): Promise { return this.client.apis.generalApi.userCanManageAsset({ assetId, userId: this.id }); } acceptJoinRequestInGroup (groupId: number): Promise { return this.client.apis.groupsAPI.acceptJoinRequest({ groupId, userId: this.id }); } declineJoinRequestInGroup (groupId: number): Promise { return this.client.apis.groupsAPI.declineJoinRequest({ groupId, userId: this.id }); } getJoinRequestInGroup (groupId: number): Promise { return this.client.apis.groupsAPI.getJoinRequest({ groupId, userId: this.id }); } setGroupOwner (groupId: number): Promise { return this.client.apis.groupsAPI.changeGroupOwner({ groupId, userId: this.id }); } kickFromGroup (groupId: number): Promise { return this.client.apis.groupsAPI.kickMember({ groupId: groupId, userId: this.id }); } updateMemberInGroup (groupId: number, roleId: number): Promise { return this.client.apis.groupsAPI.updateMember({ groupId, roleId, userId: this.id }); } payoutUserFromGroup (options: { groupId: number; type: PayoutMembersOptions["type"]; amount: number; }): Promise { return this.client.apis.groupsAPI.payoutMembers({ type: options.type, groupId: options.groupId, users: [ { userId: this.id, amount: options.amount } ] }); } deleteGroupWallPosts (groupId: number): Promise { return this.client.apis.groupsAPI.deleteUserWallPosts({ groupId, userId: this.id }); } getPrimaryGroup (): Promise { return this.client.apis.groupsAPI.getUserPrimaryGroup({ userId: this.id }); } getCollectibles (options?: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.inventoryAPI.getUserCollectibles({ ...options, userId: this.id }) .then(response => new CursorPageClass(this.client, options || {}, response, this.getCollectibles)); } getItemsByTypeAndTargetId (itemType: GetUserItemsByTypeAndTargetIdOptions["itemType"], id: number): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.inventoryAPI.getUserItemsByTypeAndTargetId({ itemType, itemTargetId: id, userId: this.id }) .then(response => new CursorPageClass(this.client, {}, response, this.getItemsByTypeAndTargetId)); } getInventory (options: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.inventoryAPI.getUserInventory({ ...options, userId: this.id }) .then(response => new CursorPageClass(this.client, options, response, this.getInventory)); } getInventoryByAssetTypeId (options: Omit): Promise> { const CursorPageClass = require("./Asset").CursorPage; return this.client.apis.inventoryAPI.getUserInventoryByAssetTypeId({ ...options, userId: this.id }) .then(response => new CursorPageClass(this.client, options, response, this.getInventoryByAssetTypeId)); } getUser (): Promise { return this.client.getUser(this.id); } getPremiumMembership (): Promise { return this.client.apis.premiumFeaturesAPI.validateUserMembership({ userId: this.id }); } upsellPremiumCheck (options: Omit): Promise { return this.client.apis.premiumFeaturesAPI.premiumUpsellCheck({ ...options, userId: this.id }); } getPresence (): Promise { return this.client.apis.presenceAPI.getUsersPresences({ userIds: [this.id] }) .then(response => response.userPresences[0]); } sendMessage (options: Omit): Promise { return this.client.apis.privateMessagesAPI.sendMessage({ ...options, userId: this.id }); } getFullBodyAvatarImage (options: Omit): Promise { return this.client.apis.thumbnailsAPI.getUsersFullBodyAvatarImages({ ...options, userIds: [this.id] }) .then(response => response.data[0]); } getAvatarBustImage (options: Omit): Promise { return this.client.apis.thumbnailsAPI.getUsersAvatarBustImages({ ...options, userIds: [this.id] }) .then(response => response.data[0]); } getAvatarHeadShotImage (options: Omit): Promise { return this.client.apis.thumbnailsAPI.getUsersAvatarHeadShotImages({ ...options, userIds: [this.id] }) .then(response => response.data[0]); } getCanTrade (): Promise { return this.client.apis.tradesAPI.canTradeWith({ userId: this.id }) .then(response => response.canTrade); } sendTrade (offers: Omit[]): Promise { return this.client.apis.tradesAPI.sendTrade({ offers: offers.map(offerData => ({ userId: this.id, robux: offerData.robux, userAssetIds: offerData.userAssetIds })) }); } updateTranslationGameAccess (options: Omit): Promise { return this.client.apis.translationRolesAPI.updateUserAccess({ ...options, userId: this.id }); } } export interface FriendRequestOptions { description: string; created: string; isBanned: boolean; id: number; name: string; } export class FriendRequest { public client: Client; public user: PartialUser; public isBanned: boolean; public created: Date; public description: string; constructor (data: FriendRequestOptions, client: Client) { this.client = client; this.user = new PartialUser({ id: data.id, name: data.name }, client); this.created = new Date(data.created); this.description = data.description; this.isBanned = data.isBanned; } } export interface PartialUserOptions { id: number; name?: string; displayName?: string; } export class PartialUser extends UserBase { // Eslint, I'm getting tired of you complaining about useless constructors. // You are useless // eslint-disable-next-line no-useless-constructor constructor (data: PartialUserOptions, client: Client) { super(data, client); } } export interface UserOptions { id: number; name: string; displayName: string; friendsCount: number; presenceType: EnumUserPresence; lastLocation: string | null; userStatus: string | null; userStatusDate: string | null; userPlaceId: number | null; followersCount: number; followingsCount: number; isVieweeBlocked: boolean; isViewerBlocked: boolean; areFriends: boolean; canFollow: boolean; canMessage: boolean; canFriend: boolean; canTrade: boolean; incomingFriendRequest: boolean; sentFriendRequest: boolean; canSeeFavorites: boolean; messagesDisabled: boolean; canSeeInventory: boolean; headShotImage: { final: boolean; url: string; retryUrl: string | null; userId: number; endpointType: "Avatar" | string; }; previousUsernames: string; } export class User extends PartialUser { public friendsCount: number; public presenceType: EnumUserPresence; public lastLocation: string | null; public status: string | null; public statusDate: Date | null; public placeId: number | null; public followersCount: number; public followingCount: number; /** * If the authenticated user has blocked the user */ public isBlocked: boolean; /** * If the user has blocked the authenticated user */ public hasBlocked: boolean; /** * If the authenticated user and the target user are friends */ public areFriends: boolean; public canFollow: boolean; public canMessage: boolean; public canFriend: boolean; /** * If the authenticated user has sent a friend request to this user */ public sentFriendRequest: boolean; /** * If the target user has sent a friend request to the authenticated user */ public incomingFriendRequest: boolean; public messagesDisabled: boolean; public canSeeFavorites: boolean; public canTrade: boolean; public canSeeInventory: boolean; public previousNames: string[]; public headshotImage: { final: boolean; url: string | null; retryUrl: string | null; userId: number; endpointType: "Avatar" | string; }; constructor (data: UserOptions, client: Client) { super(data, client); this.friendsCount = data.friendsCount; this.presenceType = data.presenceType; this.lastLocation = data.lastLocation || null; this.status = data.userStatus || null; const matchedStatusTimestamp = data.userStatusDate ? data.userStatusDate.match(/\((.*)\)/) : null; this.statusDate = matchedStatusTimestamp ? new Date(parseInt(matchedStatusTimestamp[1])) : null; this.placeId = data.userPlaceId; this.followersCount = data.followersCount; this.followingCount = data.followingsCount; this.isBlocked = data.isVieweeBlocked; this.hasBlocked = data.isViewerBlocked; this.areFriends = data.areFriends; this.canFollow = data.canFollow; this.canMessage = data.canMessage; this.canFriend = data.canFriend; this.sentFriendRequest = data.sentFriendRequest; this.incomingFriendRequest = data.incomingFriendRequest; this.messagesDisabled = data.messagesDisabled; this.canSeeFavorites = data.canSeeFavorites; this.canTrade = data.canTrade; this.canSeeInventory = data.canSeeInventory; this.previousNames = data.previousUsernames.split("\r\n"); this.headshotImage = { final: data.headShotImage.final, url: data.headShotImage.url, retryUrl: data.headShotImage.retryUrl, userId: data.headShotImage.userId, endpointType: data.headShotImage.endpointType }; } }