@@ -51,41 +51,44 @@ class FirebotPronounManager {
5151 }
5252 }
5353
54- async getUserPronouns ( username : string ) : Promise < UserPronoun | undefined > {
55- const cachedPronouns = this . _userPronounCache . get < UserPronoun > ( username ) ;
54+ async getUserPronouns ( username : string , fallback : string = "they/them" ) : Promise < UserPronoun | undefined > {
55+ if ( ! ! username ?. length ) {
56+ const cachedPronouns = this . _userPronounCache . get < UserPronoun > ( username ) ;
5657
57- if ( cachedPronouns ) {
58- return cachedPronouns ;
59- } else if ( this . _userNoPronounCache [ username ] === true ) {
60- return ;
61- }
62-
63- const url = `${ PRONOUN_SERVICE_BASE_URL } users/${ username } ?t=${ new Date ( ) . getTime ( ) } ` ;
64-
65- try {
66- const response = await this . callUrl ( url ) ;
67-
68- if ( response . ok ) {
69- const pronouns = await response . json ( ) as UserPronounResponse ;
70- this . _userPronounCache . set < UserPronoun > ( username , {
71- primary : pronouns . pronoun_id ,
72- secondary : pronouns . alt_pronoun_id
73- } ) ;
74- return this . _userPronounCache . get < UserPronoun > ( username ) ;
75- } else if ( response . status === 404 ) {
76- logger . debug ( `No pronouns set for ${ username } ` ) ;
77- this . _userNoPronounCache . set ( username , true ) ;
58+ if ( cachedPronouns ) {
59+ return cachedPronouns ;
60+ } else if ( this . _userNoPronounCache [ username ] === true ) {
7861 return ;
7962 }
80- } catch ( error ) {
81- logger . warn ( `Unable to get pronouns for ${ username } ` , error ) ;
63+
64+ const url = `${ PRONOUN_SERVICE_BASE_URL } users/${ username } ?t=${ new Date ( ) . getTime ( ) } ` ;
65+
66+ try {
67+ const response = await this . callUrl ( url ) ;
68+
69+ if ( response . ok ) {
70+ const pronouns = await response . json ( ) as UserPronounResponse ;
71+ this . _userPronounCache . set < UserPronoun > ( username , {
72+ primary : pronouns . pronoun_id ,
73+ secondary : pronouns . alt_pronoun_id
74+ } ) ;
75+ return this . _userPronounCache . get < UserPronoun > ( username ) ;
76+ } else if ( response . status === 404 ) {
77+ logger . debug ( `No pronouns set for ${ username } ` ) ;
78+ this . _userNoPronounCache . set ( username , true ) ;
79+ }
80+ } catch ( error ) {
81+ logger . warn ( `Unable to get pronouns for ${ username } ` , error ) ;
82+ }
8283 }
8384
84- return ;
85+ return ! ! fallback ?. length
86+ ? { primary : fallback . replace ( "/" , "" ) }
87+ : undefined ;
8588 } ;
8689
87- async getUserFriendlyPronounString ( username : string , type : "subject" | "object" | "both" = "both" ) {
88- const pronouns = await this . getUserPronouns ( username ) ;
90+ async getUserFriendlyPronounString ( username : string , fallback : string = "they/them" , type : "subject" | "object" | "both" = "both" ) {
91+ const pronouns = await this . getUserPronouns ( username , fallback ) ;
8992
9093 if ( pronouns ) {
9194 return this . getFriendlyPronounString ( pronouns . primary , pronouns . secondary , type ) ;
0 commit comments