@@ -10,7 +10,7 @@ exports.optional = ['actionType', 'userId', 'sortOrder', 'limit', 'cursor', 'jar
1010 * @category Group
1111 * @alias getAuditLog
1212 * @param {number } group - The id of the group.
13- * @param {("DeletePost" | "RemoveMember" | "AcceptJoinRequest" | "DeclineJoinRequest" | "PostStatus" | "ChangeRank" | "BuyAd" | "SendAllyRequest" | "CreateEnemy" | "AcceptAllyRequest" | "DeclineAllyRequest" | "DeleteAlly" | "DeleteEnemy" | "AddGroupPlace" | "RemoveGroupPlace" | "CreateItems" | "ConfigureItems" | "SpendGroupFunds" | "ChangeOwner" | "Delete" | "AdjustCurrencyAmounts" | "Abandon" | "Claim" | "Rename" | "ChangeDescription" | "InviteToClan" | "KickFromClan" | "CancelClanInvite" | "BuyClan" | "CreateGroupAsset" | "UpdateGroupAsset" | "ConfigureGroupAsset" | "RevertGroupAsset" | "CreateGroupDeveloperProduct" | "ConfigureGroupGame" | "Lock" | "Unlock" | "CreateGamePass" | "CreateBadge" | "ConfigureBadge" | "SavePlace" | "PublishPlace")= } actionType - The action type to filter for.
13+ * @param {("DeletePost" | "RemoveMember" | "AcceptJoinRequest" | "DeclineJoinRequest" | "PostStatus" | "ChangeRank" | "BuyAd" | "SendAllyRequest" | "CreateEnemy" | "AcceptAllyRequest" | "DeclineAllyRequest" | "DeleteAlly" | "DeleteEnemy" | "AddGroupPlace" | "RemoveGroupPlace" | "CreateItems" | "ConfigureItems" | "SpendGroupFunds" | "ChangeOwner" | "Delete" | "AdjustCurrencyAmounts" | "Abandon" | "Claim" | "Rename" | "ChangeDescription" | "InviteToClan" | "KickFromClan" | "CancelClanInvite" | "BuyClan" | "CreateGroupAsset" | "UpdateGroupAsset" | "ConfigureGroupAsset" | "RevertGroupAsset" | "CreateGroupDeveloperProduct" | "ConfigureGroupGame" | "Lock" | "Unlock" | "CreateGamePass" | "CreateBadge" | "ConfigureBadge" | "SavePlace" | "PublishPlace" | "joinGroup" | "leaveGroup" )= } actionType - The action type to filter for.
1414 * @param {number= } userId - The user's id to filter for.
1515 * @param {SortOrder= } sortOrder - The order to sort the logs by.
1616 * @param {Limit= } limit - The maximum logs per a page.
@@ -21,38 +21,64 @@ exports.optional = ['actionType', 'userId', 'sortOrder', 'limit', 'cursor', 'jar
2121 * const rankLogs = await noblox.getAuditLog(1, "ChangeRank", 2, "Asc")
2222**/
2323
24- function getAuditLog ( group , actionType , userId , sortOrder , limit , cursor , jar ) {
25- return new Promise ( ( resolve , reject ) => {
26- const httpOpt = {
27- url : `https://groups.roblox.com/v1/groups/${ group } /audit-log?actionType=${ actionType } &cursor=${ cursor } &limit=${ limit } &sortOrder=${ sortOrder } &userId=${ userId } ` ,
28- options : {
29- method : 'GET' ,
30- resolveWithFullResponse : true ,
31- jar
32- }
33- }
24+ function getAuditLog ( group , actionType , userId , sortOrder , limit , cursor , jar ) {
25+ return new Promise ( async ( resolve , reject ) => {
26+ try {
27+ const fetchLogs = async ( type ) => {
28+ const httpOpt = {
29+ url : `https://groups.roblox.com/v1/groups/${ group } /audit-log?actionType=${ type } &cursor=${ cursor } &limit=${ limit } &sortOrder=${ sortOrder } &userId=${ userId } ` ,
30+ options : {
31+ method : 'GET' ,
32+ resolveWithFullResponse : true ,
33+ jar
34+ }
35+ } ;
36+
37+ const res = await http ( httpOpt ) ;
38+ const json = JSON . parse ( res . body ) ;
3439
35- return http ( httpOpt )
36- . then ( function ( res ) {
37- const responseData = JSON . parse ( res . body )
3840 if ( res . statusCode !== 200 ) {
39- let error = 'An unknown error has occurred.'
40- if ( responseData && responseData . errors ) {
41- error = responseData . errors . map ( ( e ) => e . message ) . join ( '\n' )
41+ let error = "Unknown error." ;
42+ if ( json . errors ) {
43+ error = json . errors . map ( ( e ) => e . message ) . join ( "\n" ) ;
4244 }
43- reject ( new Error ( error ) )
44- } else {
45- responseData . data = responseData . data . map ( ( entry ) => {
46- // We need to set milliseconds to 0 because Roblox does this fascinating thing
47- // Where they vary the ms value on each request, for an existing action.
48- entry . created = new Date ( entry . created )
49- entry . created . setMilliseconds ( 0 )
50- return entry
51- } )
52- resolve ( responseData )
45+ throw new Error ( error ) ;
5346 }
54- } ) . catch ( error => reject ( error ) )
55- } )
47+
48+ json . data = json . data . map ( entry => {
49+ entry . created = new Date ( entry . created ) ;
50+ entry . created . setMilliseconds ( 0 ) ;
51+ return entry ;
52+ } ) ;
53+
54+ return json ;
55+ } ;
56+
57+ if ( actionType && actionType !== "all" ) {
58+ const result = await fetchLogs ( actionType ) ;
59+ return resolve ( result ) ;
60+ }
61+
62+ const allLogs = await fetchLogs ( "" ) ;
63+
64+ const [ joinLogs , leaveLogs ] = await Promise . all ( [
65+ fetchLogs ( "joinGroup" ) ,
66+ fetchLogs ( "leaveGroup" )
67+ ] ) ;
68+
69+ const combined = [
70+ ...allLogs . data ,
71+ ...joinLogs . data ,
72+ ...leaveLogs . data
73+ ] . sort ( ( a , b ) => new Date ( b . created ) - new Date ( a . created ) ) ;
74+
75+ allLogs . data = combined ;
76+ return resolve ( allLogs ) ;
77+
78+ } catch ( err ) {
79+ reject ( err ) ;
80+ }
81+ } ) ;
5682}
5783
5884// Define
0 commit comments