Skip to content

Commit 7d64792

Browse files
authored
Merge pull request #219 from Retsam/rep-mention
Allow !rep <id>
2 parents da1f2c0 + 7304069 commit 7d64792

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

src/modules/rep.ts

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ export class RepModule extends Module {
2828
super(client);
2929
}
3030

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+
3147
@listener({ event: 'messageCreate' })
3248
async onThank(msg: Message, force = false) {
3349
// Check for thanks messages
@@ -42,16 +58,10 @@ export class RepModule extends Module {
4258

4359
const recipient = mentionUsers.first()!;
4460

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, {
5162
recipient: recipient.id,
5263
initialGiver: msg.author.id,
53-
date: new Date().toISOString(),
54-
}).save();
64+
});
5565

5666
await msg.react(repEmoji);
5767
}
@@ -107,16 +117,10 @@ export class RepModule extends Module {
107117
recipient = altRecipient;
108118
}
109119

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, {
116121
recipient,
117122
initialGiver: user.id,
118-
date: new Date().toISOString(),
119-
}).save();
123+
});
120124

121125
async function removeReaction() {
122126
removedReactions.add([msg.id, user.id].toString());
@@ -158,7 +162,20 @@ export class RepModule extends Module {
158162
@command({
159163
description: 'Reputation: Give a different user some reputation points',
160164
})
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+
}
162179
this.onThank(msg, true);
163180
}
164181

0 commit comments

Comments
 (0)