File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010import {
1111 getCurrentCoinLeaderboard ,
1212 getCoinBalanceByUserId ,
13+ getPrivateUserIdList ,
1314 UserCoinEntry ,
1415 getUserIdCurrentCoinPosition
1516} from '../../components/coin' ;
@@ -27,6 +28,7 @@ const getCurrentCoinLeaderboardEmbed = async (
2728 // Initialise user's coin balance if they have not already
2829 const userBalance = await getCoinBalanceByUserId ( currentUserId ) ;
2930 const currentPosition = await getUserIdCurrentCoinPosition ( currentUserId ) ;
31+ const isUserPrivate = await getPrivateUserIdList ( currentUserId ) ;
3032
3133 const leaderboardArray : string [ ] = [ ] ;
3234 for ( let i = 0 ; i < leaderboard . length && leaderboardArray . length < limit ; i ++ ) {
@@ -38,8 +40,9 @@ const getCurrentCoinLeaderboardEmbed = async (
3840 continue ;
3941 }
4042 if ( user . bot ) continue ;
41- const userTag = user ?. tag ?? '<unknown>' ;
42- const userCoinEntryText = `${ leaderboardArray . length + 1 } . ${ userTag } - ${ userCoinEntry . balance } ${ getCoinEmoji ( ) } ` ;
43+ const userTag = user ?. tag ;
44+ const displayTag = ( userTag && ! isUserPrivate ) ? userTag : '<unknown>' ;
45+ const userCoinEntryText = `${ leaderboardArray . length + 1 } . ${ displayTag } - ${ userCoinEntry . balance } ${ getCoinEmoji ( ) } ` ;
4346 leaderboardArray . push ( userCoinEntryText ) ;
4447 }
4548 const currentLeaderboardText = leaderboardArray . join ( '\n' ) ;
Original file line number Diff line number Diff line change @@ -81,6 +81,14 @@ export const getCoinBalanceByUserId = async (userId: string): Promise<number> =>
8181 return _ . get ( res , 'balance' , 0 ) ;
8282} ;
8383
84+ export const getPrivateUserIdList = async ( userId : string ) : Promise < number > => {
85+ const db = await openDB ( ) ;
86+ // Query user privacy from DB.
87+ const res = await db . get ( 'SELECT is_private FROM user_coin WHERE user_id = ?' , userId ) ;
88+ // If user doesn't have a privacy value, default to false (public).
89+ return _ . get ( res , 'is_private' , 0 ) ;
90+ } ;
91+
8492/*
8593 If user doesn't exist, create row with newBalance as the balance.
8694 Otherwise, update balance to newBalance.
You can’t perform that action at this time.
0 commit comments