@@ -54,20 +54,28 @@ async function handleCreate(
5454 return ;
5555 }
5656
57- await logEvent ( ctx , guild , null , "roleCreate" , async ( ) => {
58- const changes = parseRoleUpdates ( entry . changes ?? [ ] ) ;
59- const actor = await fetchMemberCached ( ctx . bot , guild , entry . userID ! ) ;
60-
61- return {
62- actor : makeMemberUserView ( actor ) ,
63- role : makeRoleView ( {
64- id : entry . targetID ! ,
65- name : changes . name ! . new ! ,
66- color : changes . color ?. new ,
67- hoist : changes . hoist ?. new ,
68- mentionable : changes . mentionable ?. new ,
69- } ) ,
70- } ;
57+ await logEvent ( ctx , {
58+ guild,
59+ key : "roleCreate" ,
60+ async supply ( ) {
61+ const changes = parseRoleUpdates ( entry . changes ?? [ ] ) ;
62+ const actor = await fetchMemberCached (
63+ ctx . bot ,
64+ guild ,
65+ entry . userID ! ,
66+ ) ;
67+
68+ return {
69+ actor : makeMemberUserView ( actor ) ,
70+ role : makeRoleView ( {
71+ id : entry . targetID ! ,
72+ name : changes . name ! . new ! ,
73+ color : changes . color ?. new ,
74+ hoist : changes . hoist ?. new ,
75+ mentionable : changes . mentionable ?. new ,
76+ } ) ,
77+ } ;
78+ } ,
7179 } ) ;
7280}
7381
@@ -84,38 +92,46 @@ async function handleUpdate(
8492 return ;
8593 }
8694
87- await logEvent ( ctx , guild , null , "roleUpdate" , async ( ) => {
88- const changes = parseRoleUpdates ( entry . changes ?? [ ] ) ;
89- const name =
90- changes . name ?. new ?? guild . roles . get ( entry . targetID ! ) ?. name ;
91-
92- if ( name === undefined ) {
93- return null ;
94- }
95-
96- const actor = await fetchMemberCached ( ctx . bot , guild , entry . userID ! ) ;
97-
98- return {
99- actor : makeMemberUserView ( actor ) ,
100- nameChanged : changes . name ?. new !== undefined ,
101- colorChanged : changes . color ?. new !== undefined ,
102- hoistedChanged : changes . hoist ?. new !== undefined ,
103- mentionableChanged : changes . mentionable ?. new !== undefined ,
104- oldRole : makeRoleView ( {
105- id : entry . targetID ! ,
106- name : changes . name ?. old ,
107- color : changes . color ?. old ,
108- hoist : changes . hoist ?. old ,
109- mentionable : changes . mentionable ?. old ,
110- } ) ,
111- newRole : makeRoleView ( {
112- id : entry . targetID ! ,
113- name : changes . name ! . new ! ,
114- color : changes . color ?. new ,
115- hoist : changes . hoist ?. new ,
116- mentionable : changes . mentionable ?. new ,
117- } ) ,
118- } ;
95+ await logEvent ( ctx , {
96+ guild,
97+ key : "roleUpdate" ,
98+ async supply ( ) {
99+ const changes = parseRoleUpdates ( entry . changes ?? [ ] ) ;
100+ const name =
101+ changes . name ?. new ?? guild . roles . get ( entry . targetID ! ) ?. name ;
102+
103+ if ( name === undefined ) {
104+ return null ;
105+ }
106+
107+ const actor = await fetchMemberCached (
108+ ctx . bot ,
109+ guild ,
110+ entry . userID ! ,
111+ ) ;
112+
113+ return {
114+ actor : makeMemberUserView ( actor ) ,
115+ nameChanged : changes . name ?. new !== undefined ,
116+ colorChanged : changes . color ?. new !== undefined ,
117+ hoistedChanged : changes . hoist ?. new !== undefined ,
118+ mentionableChanged : changes . mentionable ?. new !== undefined ,
119+ oldRole : makeRoleView ( {
120+ id : entry . targetID ! ,
121+ name : changes . name ?. old ,
122+ color : changes . color ?. old ,
123+ hoist : changes . hoist ?. old ,
124+ mentionable : changes . mentionable ?. old ,
125+ } ) ,
126+ newRole : makeRoleView ( {
127+ id : entry . targetID ! ,
128+ name : changes . name ! . new ! ,
129+ color : changes . color ?. new ,
130+ hoist : changes . hoist ?. new ,
131+ mentionable : changes . mentionable ?. new ,
132+ } ) ,
133+ } ;
134+ } ,
119135 } ) ;
120136}
121137
@@ -132,19 +148,23 @@ async function handleDelete(
132148 return ;
133149 }
134150
135- await logEvent ( ctx , guild , null , "roleDelete" , async ( ) => {
136- const changes = parseRoleUpdates ( entry . changes ?? [ ] ) ;
137- const actor = await fetchUserCached ( ctx . bot , entry . userID ! ) ;
138-
139- return {
140- moderator : makeUserView ( actor ) ,
141- role : makeRoleView ( {
142- id : entry . targetID ! ,
143- name : changes . name ! . new ! ,
144- color : changes . color ?. new ,
145- hoist : changes . hoist ?. new ,
146- mentionable : changes . mentionable ?. new ,
147- } ) ,
148- } ;
151+ await logEvent ( ctx , {
152+ guild,
153+ key : "roleDelete" ,
154+ async supply ( ) {
155+ const changes = parseRoleUpdates ( entry . changes ?? [ ] ) ;
156+ const actor = await fetchUserCached ( ctx . bot , entry . userID ! ) ;
157+
158+ return {
159+ moderator : makeUserView ( actor ) ,
160+ role : makeRoleView ( {
161+ id : entry . targetID ! ,
162+ name : changes . name ! . new ! ,
163+ color : changes . color ?. new ,
164+ hoist : changes . hoist ?. new ,
165+ mentionable : changes . mentionable ?. new ,
166+ } ) ,
167+ } ;
168+ } ,
149169 } ) ;
150170}
0 commit comments