@@ -28,6 +28,22 @@ export class RepModule extends Module {
28
28
super ( client ) ;
29
29
}
30
30
31
+ private giveRep (
32
+ msg : Pick < Message , 'id' | 'channelId' > ,
33
+ { recipient, initialGiver } : Pick < Rep , 'recipient' | 'initialGiver' > ,
34
+ ) {
35
+ console . log ( 'Creating a Rep with recipient' , recipient ) ;
36
+
37
+ return Rep . create ( {
38
+ messageId : msg . id ,
39
+ channel : msg . channelId ,
40
+ amount : 1 ,
41
+ recipient,
42
+ initialGiver,
43
+ date : new Date ( ) . toISOString ( ) ,
44
+ } ) . save ( ) ;
45
+ }
46
+
31
47
@listener ( { event : 'messageCreate' } )
32
48
async onThank ( msg : Message , force = false ) {
33
49
// Check for thanks messages
@@ -42,16 +58,10 @@ export class RepModule extends Module {
42
58
43
59
const recipient = mentionUsers . first ( ) ! ;
44
60
45
- console . log ( 'Creating a Rep with recipient' , recipient ) ;
46
-
47
- await Rep . create ( {
48
- messageId : msg . id ,
49
- channel : msg . channelId ,
50
- amount : 1 ,
61
+ await this . giveRep ( msg , {
51
62
recipient : recipient . id ,
52
63
initialGiver : msg . author . id ,
53
- date : new Date ( ) . toISOString ( ) ,
54
- } ) . save ( ) ;
64
+ } ) ;
55
65
56
66
await msg . react ( repEmoji ) ;
57
67
}
@@ -107,16 +117,10 @@ export class RepModule extends Module {
107
117
recipient = altRecipient ;
108
118
}
109
119
110
- console . log ( 'Creating a Rep with recipient' , recipient ) ;
111
-
112
- await Rep . create ( {
113
- messageId : msg . id ,
114
- channel : msg . channelId ,
115
- amount : 1 ,
120
+ await this . giveRep ( msg , {
116
121
recipient,
117
122
initialGiver : user . id ,
118
- date : new Date ( ) . toISOString ( ) ,
119
- } ) . save ( ) ;
123
+ } ) ;
120
124
121
125
async function removeReaction ( ) {
122
126
removedReactions . add ( [ msg . id , user . id ] . toString ( ) ) ;
@@ -158,7 +162,20 @@ export class RepModule extends Module {
158
162
@command ( {
159
163
description : 'Reputation: Give a different user some reputation points' ,
160
164
} )
161
- async rep ( msg : Message , targetMember : GuildMember ) {
165
+ async rep ( msg : Message , targetMember : string ) {
166
+ if ( targetMember . match ( / \d + / ) ) {
167
+ const user = await this . client . users
168
+ . fetch ( targetMember )
169
+ . catch ( ( ) => null ) ;
170
+ if ( user ) {
171
+ if ( user . id === msg . author . id ) return msg . react ( '🤡' ) ;
172
+ await this . giveRep ( msg , {
173
+ recipient : targetMember ,
174
+ initialGiver : msg . author . id ,
175
+ } ) ;
176
+ return msg . react ( repEmoji ) ;
177
+ }
178
+ }
162
179
this . onThank ( msg , true ) ;
163
180
}
164
181
0 commit comments