openblox
Version:
Roblox API Wrapper For Both Classic And OpenCloud APIs.
135 lines (134 loc) • 5.92 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var groupsQuery_exports = {};
__export(groupsQuery_exports, {
ClassicGroups: () => ClassicGroups
});
module.exports = __toCommonJS(groupsQuery_exports);
var import_classic = require("../../apis/classic");
var import_queries = require("../queries.utils");
const prepareJoinRequestsPage = async (joinReqs, handlerFn, userIdsToAccept, userIdsToDecline) => {
await Promise.allSettled(
joinReqs.map((joinReq) => (async () => {
let state = null;
await handlerFn({
...joinReq,
accept: () => {
state = "accept";
},
decline: () => {
state = "decline";
}
});
if (state == "accept") userIdsToAccept.push(joinReq.requester.userId);
else if (state == "decline") userIdsToDecline.push(joinReq.requester.userId);
})())
);
};
const submitJoinRequestsPage = async (groupId, userIdsToAccept, userIdsToDecline) => {
return await Promise.allSettled([
userIdsToAccept.length ? import_classic.ClassicGroupsApi.batchAcceptGroupJoinRequests({ groupId, userIds: userIdsToAccept }) : null,
userIdsToDecline.length ? import_classic.ClassicGroupsApi.batchDeclineGroupJoinRequests({ groupId, userIds: userIdsToDecline }) : null
]);
};
const prepareAndSubmitWallPostsPage = async (wallPosts, handlerFn, groupId) => {
const wallPostIdsToRemove = [];
await Promise.allSettled(
wallPosts.map((wallPost) => (async () => {
let toRemove = false;
await handlerFn({
...wallPost,
remove: () => {
toRemove = true;
}
});
if (toRemove) wallPostIdsToRemove.push(wallPost.id);
})())
);
await Promise.allSettled(wallPostIdsToRemove.map((wallPostId) => import_classic.ClassicGroupsApi.removeGroupWallPost({ groupId, wallPostId })));
};
const ClassicGroups = (0, import_queries.addObjectToFunction)(
(groupId) => ({
on: (eventName, handlerFn, config) => {
switch (eventName) {
case "auditLog":
return (0, import_queries.pollForLatest)(
import_classic.ClassicGroupsApi.groupAuditLogs,
{ groupId, limit: 25, sortOrder: "Desc" },
"created",
config,
async (newResults) => await Promise.allSettled(newResults.map((result) => handlerFn(result)))
);
case "joinRequest":
return (0, import_queries.pollForLatest)(
import_classic.ClassicGroupsApi.groupJoinRequests,
{ groupId, limit: 25, sortOrder: "Desc" },
"created",
config,
async (joinReqs) => {
const userIdsToAccept = [], userIdsToDecline = [];
await prepareJoinRequestsPage(joinReqs, handlerFn, userIdsToAccept, userIdsToDecline);
await submitJoinRequestsPage(groupId, userIdsToAccept, userIdsToDecline);
}
);
case "wallPost":
return (0, import_queries.pollForLatest)(
import_classic.ClassicGroupsApi.groupWallPosts_V2,
{ groupId, limit: 25, sortOrder: "Desc" },
"created",
{ iterations: config?.iterations ?? 2, multiplyer: config?.multiplyer ?? 5e3, retryOffset: config?.retryOffset ?? 1, debug: config?.debug },
async (wallPosts) => await prepareAndSubmitWallPostsPage(wallPosts, handlerFn, groupId)
);
case "transaction:sale":
return (0, import_queries.pollForLatest)(
import_classic.ClassicEconomyApi.groupTransactionHistory,
{ groupId, limit: 25, transactionType: "Sale" },
"created",
{ iterations: config?.iterations ?? 2, multiplyer: config?.multiplyer ?? 5e3, retryOffset: config?.retryOffset ?? 1, debug: config?.debug },
async (newResults) => await Promise.allSettled(newResults.map((result) => handlerFn(result)))
);
case "transaction:advanceRebate":
return (0, import_queries.pollForLatest)(
import_classic.ClassicEconomyApi.groupTransactionHistory,
{ groupId, limit: 25, transactionType: "PublishingAdvanceRebates" },
"created",
{ iterations: config?.iterations ?? 2, multiplyer: config?.multiplyer ?? 5e3, retryOffset: config?.retryOffset ?? 1, debug: config?.debug },
async (newResults) => await Promise.allSettled(newResults.map((result) => handlerFn(result)))
);
}
return void 0;
},
processJoinRequests: async (handlerFn) => {
const userIdsToAccept = [], userIdsToDecline = [];
for await (const { data: joinReqs } of await import_classic.ClassicGroupsApi.groupJoinRequests({ groupId, limit: 100, sortOrder: "Desc" })) {
await prepareJoinRequestsPage(joinReqs, handlerFn, userIdsToAccept, userIdsToDecline);
}
await submitJoinRequestsPage(groupId, userIdsToAccept, userIdsToDecline);
}
}),
{
/*get: (fields: ArrayNonEmptyIfConst<string>) => ({
forIds: async (userIds: ArrayNonEmptyIfConst<Identifier>) => "" as any
})*/
}
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ClassicGroups
});
;