@@ -11,6 +11,7 @@ import { TS_BLUE } from '../env';
11
11
12
12
import { RepGive } from '../entities/RepGive' ;
13
13
import { RepUser } from '../entities/RepUser' ;
14
+ import { sendPaginatedMessage } from '../util/sendPaginatedMessage' ;
14
15
15
16
export class RepModule extends Module {
16
17
constructor ( client : CookiecordClient ) {
@@ -125,35 +126,49 @@ export class RepModule extends Module {
125
126
description : "Reputation: View a user's reputation history" ,
126
127
} )
127
128
async getrep ( msg : Message , @optional user ?: User ) {
129
+ if ( ! msg . member || msg . channel . type !== 'text' ) {
130
+ return ;
131
+ }
128
132
if ( ! user ) user = msg . author ;
129
133
130
134
const targetRU = await this . getOrMakeUser ( user ) ;
135
+ const records = ( await targetRU . got )
136
+ . concat ( await targetRU . given )
137
+ // Decreasing chronologically
138
+ . sort ( ( a , b ) => b . createdAt . getTime ( ) - a . createdAt . getTime ( ) )
139
+ . map ( rg => {
140
+ if ( rg . from . id == targetRU . id )
141
+ return `:white_small_square: Gave 1 rep to <@${
142
+ rg . to . id
143
+ } > (${ prettyMilliseconds (
144
+ Date . now ( ) - rg . createdAt . getTime ( ) ,
145
+ ) } ago)`;
146
+ else
147
+ return `:white_small_square: Got 1 rep from <@${
148
+ rg . from . id
149
+ } > (${ prettyMilliseconds (
150
+ Date . now ( ) - rg . createdAt . getTime ( ) ,
151
+ ) } ago)`;
152
+ } ) ;
153
+ const recordsPerPage = 30 ;
154
+ const pages = records
155
+ . reduce ( ( acc , cur , index ) => {
156
+ const curChunk = Math . floor ( index / recordsPerPage ) ;
157
+ acc [ curChunk ] ??= [ ] ;
158
+ acc [ curChunk ] . push ( cur ) ;
159
+ return acc ;
160
+ } , [ ] as string [ ] [ ] )
161
+ . map ( page => page . join ( '\n' ) ) ;
131
162
const embed = new MessageEmbed ( )
132
163
. setColor ( TS_BLUE )
133
- . setAuthor ( user . tag , user . displayAvatarURL ( ) )
134
- . setDescription (
135
- (
136
- await Promise . all (
137
- ( await targetRU . got )
138
- . concat ( await targetRU . given )
139
- . map ( async rg => {
140
- if ( rg . from . id == targetRU . id )
141
- return `:white_small_square: Gave 1 rep to <@${
142
- rg . to . id
143
- } > (${ prettyMilliseconds (
144
- Date . now ( ) - rg . createdAt . getTime ( ) ,
145
- ) } ago)`;
146
- else
147
- return `:white_small_square: Got 1 rep from <@${
148
- rg . from . id
149
- } > (${ prettyMilliseconds (
150
- Date . now ( ) - rg . createdAt . getTime ( ) ,
151
- ) } ago)`;
152
- } ) ,
153
- )
154
- ) . join ( '\n' ) ,
155
- ) ;
156
- await msg . channel . send ( embed ) ;
164
+ . setAuthor ( user . tag , user . displayAvatarURL ( ) ) ;
165
+ await sendPaginatedMessage (
166
+ embed ,
167
+ pages ,
168
+ msg . member ,
169
+ msg . channel ,
170
+ 300000 ,
171
+ ) ;
157
172
}
158
173
159
174
@command ( {
0 commit comments