Skip to content

Commit 6afc7e0

Browse files
authored
Merge pull request #82 from typescript-community/fix-81-regression
Fix regression from commit 8322ae1 (#81)
2 parents 8322ae1 + 1ffe9a2 commit 6afc7e0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/modules/rep.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export class RepModule extends Module {
3636

3737
@listener({ event: 'message' })
3838
async onThank(msg: Message) {
39-
const GAVE = '✅';
39+
const GIVE = '✅';
40+
const PARTIAL_GIVE = '🤔';
41+
const NO_GIVE = '❌';
4042

4143
// Check for thanks or thx
4244
const THANKS_REGEX = /(thanks|thx)+/gi;
@@ -48,10 +50,16 @@ export class RepModule extends Module {
4850
if (!mentionUsers.length) return;
4951

5052
const senderRU = await this.getOrMakeUser(msg.author);
51-
if ((await senderRU.sent()) >= this.MAX_REP) return;
53+
// track how much rep the author has sent
54+
// 3 possible outcomes: NO_GIVE, PARTIAL_GIVE and GAVE
55+
let currentSent = await senderRU.sent();
56+
57+
if (currentSent >= this.MAX_REP) return await msg.react(NO_GIVE);
5258

5359
for (const user of mentionUsers) {
5460
if (user.id === msg.member?.id) continue;
61+
if (currentSent >= this.MAX_REP)
62+
return await msg.react(PARTIAL_GIVE);
5563

5664
// give rep
5765
const targetRU = await this.getOrMakeUser(user);
@@ -60,9 +68,11 @@ export class RepModule extends Module {
6068
from: senderRU,
6169
to: targetRU,
6270
}).save();
71+
72+
currentSent++;
6373
}
6474

65-
await msg.react(GAVE);
75+
await msg.react(GIVE);
6676
}
6777

6878
@command({

0 commit comments

Comments
 (0)