File tree 2 files changed +14
-2
lines changed
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
import {
11
11
getCurrentCoinLeaderboard ,
12
12
getCoinBalanceByUserId ,
13
+ getPrivateUserIdList ,
13
14
UserCoinEntry ,
14
15
getUserIdCurrentCoinPosition
15
16
} from '../../components/coin' ;
@@ -27,6 +28,7 @@ const getCurrentCoinLeaderboardEmbed = async (
27
28
// Initialise user's coin balance if they have not already
28
29
const userBalance = await getCoinBalanceByUserId ( currentUserId ) ;
29
30
const currentPosition = await getUserIdCurrentCoinPosition ( currentUserId ) ;
31
+ const isUserPrivate = await getPrivateUserIdList ( currentUserId ) ;
30
32
31
33
const leaderboardArray : string [ ] = [ ] ;
32
34
for ( let i = 0 ; i < leaderboard . length && leaderboardArray . length < limit ; i ++ ) {
@@ -38,8 +40,10 @@ const getCurrentCoinLeaderboardEmbed = async (
38
40
continue ;
39
41
}
40
42
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 =
46
+ `${ leaderboardArray . length + 1 } . ${ displayTag } - ${ userCoinEntry . balance } ${ getCoinEmoji ( ) } ` ;
43
47
leaderboardArray . push ( userCoinEntryText ) ;
44
48
}
45
49
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> =>
81
81
return _ . get ( res , 'balance' , 0 ) ;
82
82
} ;
83
83
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
+
84
92
/*
85
93
If user doesn't exist, create row with newBalance as the balance.
86
94
Otherwise, update balance to newBalance.
You can’t perform that action at this time.
0 commit comments