@@ -20,6 +20,7 @@ import { definePluginSettings } from "@api/Settings";
2020import ErrorBoundary from "@components/ErrorBoundary" ;
2121import { makeRange } from "@components/PluginSettings/components" ;
2222import { Devs } from "@utils/constants" ;
23+ import { Logger } from "@utils/Logger" ;
2324import definePlugin , { OptionType } from "@utils/types" ;
2425import { findByCodeLazy } from "@webpack" ;
2526import { ChannelStore , GuildMemberStore , GuildStore } from "@webpack/common" ;
@@ -51,6 +52,12 @@ const settings = definePluginSettings({
5152 description : "Show role colors in the reactors list" ,
5253 restartNeeded : true
5354 } ,
55+ pollResults : {
56+ type : OptionType . BOOLEAN ,
57+ default : true ,
58+ description : "Show role colors in the poll results" ,
59+ restartNeeded : true
60+ } ,
5461 colorChatMessages : {
5562 type : OptionType . BOOLEAN ,
5663 default : false ,
@@ -62,127 +69,159 @@ const settings = definePluginSettings({
6269 description : "Intensity of message coloring." ,
6370 markers : makeRange ( 0 , 100 , 10 ) ,
6471 default : 30
65- } ,
72+ }
6673} ) ;
6774
68-
6975export default definePlugin ( {
7076 name : "RoleColorEverywhere" ,
71- authors : [ Devs . KingFish , Devs . lewisakura , Devs . AutumnVN , Devs . Kyuuhachi ] ,
77+ authors : [ Devs . KingFish , Devs . lewisakura , Devs . AutumnVN , Devs . Kyuuhachi , Devs . jamesbt365 ] ,
7278 description : "Adds the top role color anywhere possible" ,
79+ settings,
80+
7381 patches : [
7482 // Chat Mentions
7583 {
7684 find : ".USER_MENTION)" ,
7785 replacement : [
7886 {
7987 match : / o n C o n t e x t M e n u : \i , c o l o r : \i , \. \. \. \i (? = , c h i l d r e n : ) (?< = u s e r : ( \i ) , c h a n n e l : ( \i ) .{ 0 , 500 } ?) / ,
80- replace : "$&,color:$self.getUserColor ($1?.id,{channelId: $2?.id} )"
88+ replace : "$&,color:$self.getColorInt ($1?.id,$2?.id)"
8189 }
8290 ] ,
83- predicate : ( ) => settings . store . chatMentions ,
91+ predicate : ( ) => settings . store . chatMentions
8492 } ,
8593 // Slate
8694 {
8795 find : ".userTooltip,children" ,
8896 replacement : [
8997 {
90- match : / l e t \{ i d : ( \i ) , g u i l d I d : ( \i ) [ ^ } ] * \} .* ?\. \i , { (? = c h i l d r e n ) / ,
91- replace : "$&color:$self.getUserColor ($1,{guildId:$2} ),"
98+ match : / l e t \{ i d : ( \i ) , g u i l d I d : \i , c h a n n e l I d : ( \i ) [ ^ } ] * \} .* ?\. \i , { (? = c h i l d r e n ) / ,
99+ replace : "$&color:$self.getColorInt ($1,$2 ),"
92100 }
93101 ] ,
94- predicate : ( ) => settings . store . chatMentions ,
102+ predicate : ( ) => settings . store . chatMentions
95103 } ,
104+ // Member List Role Headers
96105 {
97106 find : 'tutorialId:"whos-online' ,
98107 replacement : [
99108 {
100109 match : / n u l l , \i , " — " , \i \] / ,
101- replace : "null,$self.roleGroupColor (arguments[0])]"
110+ replace : "null,$self.RoleGroupColor (arguments[0])]"
102111 } ,
103112 ] ,
104- predicate : ( ) => settings . store . memberList ,
113+ predicate : ( ) => settings . store . memberList
105114 } ,
106115 {
107116 find : "#{intl::THREAD_BROWSER_PRIVATE}" ,
108117 replacement : [
109118 {
110119 match : / c h i l d r e n : \[ \i , " — " , \i \] / ,
111- replace : "children:[$self.roleGroupColor (arguments[0])]"
120+ replace : "children:[$self.RoleGroupColor (arguments[0])]"
112121 } ,
113122 ] ,
114- predicate : ( ) => settings . store . memberList ,
123+ predicate : ( ) => settings . store . memberList
115124 } ,
125+ // Voice Users
116126 {
117- find : "renderPrioritySpeaker" ,
127+ find : "renderPrioritySpeaker(){ " ,
118128 replacement : [
119129 {
120130 match : / r e n d e r N a m e \( \) { .+ ?u s e r n a m e S p e a k i n g \] : .+ ?(? = c h i l d r e n ) / ,
121- replace : "$&... $self.getVoiceProps (this.props),"
131+ replace : "$&style: $self.getColorStyle (this? .props?.user?.id,this?.props?.guildId ),"
122132 }
123133 ] ,
124- predicate : ( ) => settings . store . voiceUsers ,
134+ predicate : ( ) => settings . store . voiceUsers
125135 } ,
136+ // Reaction List
126137 {
127138 find : ".reactorDefault" ,
128139 replacement : {
129- match : / , o n C o n t e x t M e n u : e = > .{ 0 , 15 } \( ( \i ) , ( \i ) , ( \i ) \) .{ 0 , 250 } t a g : " s t r o n g " / ,
130- replace : "$&,style:{color: $self.getColor ($2?.id,$1)} "
140+ match : / , o n C o n t e x t M e n u : \i = > .{ 0 , 15 } \( ( \i ) , ( \i ) , ( \i ) \) .{ 0 , 250 } t a g : " s t r o n g " / ,
141+ replace : "$&,style:$self.getColorStyle ($2?.id,$1?.channel?.id) "
131142 } ,
132143 predicate : ( ) => settings . store . reactorsList ,
133144 } ,
145+ // Poll Results
146+ {
147+ find : ",reactionVoteCounts" ,
148+ replacement : {
149+ match : / \. n i c k n a m e , (? = c h i l d r e n : ) / ,
150+ replace : "$&style:$self.getColorStyle(arguments[0]?.user?.id,arguments[0]?.channel?.id),"
151+ } ,
152+ predicate : ( ) => settings . store . pollResults
153+ } ,
154+ // Messages
134155 {
135156 find : "#{intl::MESSAGE_EDITED}" ,
136157 replacement : {
137158 match : / (?< = i s U n s u p p o r t e d \] : ( \i ) \. i s U n s u p p o r t e d \} \) , ) (? = c h i l d r e n : \[ ) / ,
138- replace : "style:{color: $self.useMessageColor ($1)} ,"
159+ replace : "style:$self.useMessageColorStyle ($1),"
139160 } ,
140- predicate : ( ) => settings . store . colorChatMessages ,
141- } ,
161+ predicate : ( ) => settings . store . colorChatMessages
162+ }
142163 ] ,
143- settings,
144164
145- getColor ( userId : string , { channelId, guildId } : { channelId ?: string ; guildId ?: string ; } ) {
146- if ( ! ( guildId ??= ChannelStore . getChannel ( channelId ! ) ?. guild_id ) ) return null ;
147- return GuildMemberStore . getMember ( guildId , userId ) ?. colorString ?? null ;
165+ getColorString ( userId : string , channelOrGuildId : string ) {
166+ try {
167+ const guildId = ChannelStore . getChannel ( channelOrGuildId ) ?. guild_id ?? GuildStore . getGuild ( channelOrGuildId ) ?. id ;
168+ if ( guildId == null ) return null ;
169+
170+ return GuildMemberStore . getMember ( guildId , userId ) ?. colorString ?? null ;
171+ } catch ( e ) {
172+ new Logger ( "RoleColorEverywhere" ) . error ( "Failed to get color string" , e ) ;
173+ }
174+
175+ return null ;
148176 } ,
149177
150- getUserColor ( userId : string , ids : { channelId ?: string ; guildId ?: string ; } ) {
151- const colorString = this . getColor ( userId , ids ) ;
178+ getColorInt ( userId : string , channelOrGuildId : string ) {
179+ const colorString = this . getColorString ( userId , channelOrGuildId ) ;
152180 return colorString && parseInt ( colorString . slice ( 1 ) , 16 ) ;
153181 } ,
154182
155- roleGroupColor : ErrorBoundary . wrap ( ( { id , count , title , guildId , label } : { id : string ; count : number ; title : string ; guildId : string ; label : string ; } ) => {
156- const role = GuildStore . getRole ( guildId , id ) ;
183+ getColorStyle ( userId : string , channelOrGuildId : string ) {
184+ const colorString = this . getColorString ( userId , channelOrGuildId ) ;
157185
158- return (
159- < span style = { {
160- color : role ?. colorString ,
161- fontWeight : "unset" ,
162- letterSpacing : ".05em"
163- } } >
164- { title ?? label } — { count }
165- </ span >
166- ) ;
167- } , { noop : true } ) ,
168-
169- getVoiceProps ( { user : { id : userId } , guildId } : { user : { id : string ; } ; guildId : string ; } ) {
170- return {
171- style : {
172- color : this . getColor ( userId , { guildId } )
173- }
186+ return colorString && {
187+ color : colorString
174188 } ;
175189 } ,
176190
177191 useMessageColor ( message : any ) {
178192 try {
179193 const { messageSaturation } = settings . use ( [ "messageSaturation" ] ) ;
180194 const author = useMessageAuthor ( message ) ;
181- if ( author . colorString !== undefined && messageSaturation !== 0 )
195+
196+ if ( author . colorString != null && messageSaturation !== 0 ) {
182197 return `color-mix(in oklab, ${ author . colorString } ${ messageSaturation } %, var(--text-normal))` ;
198+ }
183199 } catch ( e ) {
184- console . error ( "[RCE] failed to get message color" , e ) ;
200+ new Logger ( "RoleColorEverywhere" ) . error ( "Failed to get message color" , e ) ;
185201 }
186- return undefined ;
202+
203+ return null ;
187204 } ,
205+
206+ useMessageColorStyle ( message : any ) {
207+ const color = this . useMessageColor ( message ) ;
208+
209+ return color && {
210+ color
211+ } ;
212+ } ,
213+
214+ RoleGroupColor : ErrorBoundary . wrap ( ( { id, count, title, guildId, label } : { id : string ; count : number ; title : string ; guildId : string ; label : string ; } ) => {
215+ const role = GuildStore . getRole ( guildId , id ) ;
216+
217+ return role != null && (
218+ < span style = { {
219+ color : role . colorString ,
220+ fontWeight : "unset" ,
221+ letterSpacing : ".05em"
222+ } } >
223+ { title ?? label } — { count }
224+ </ span >
225+ ) ;
226+ } , { noop : true } )
188227} ) ;
0 commit comments