Skip to content

Commit

Permalink
fix(cooldown): use latest timestamp in case of duplicate
Browse files Browse the repository at this point in the history
Fixes #3209
  • Loading branch information
sogehige committed Feb 7, 2020
1 parent 59b0edc commit 3cdf672
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/bot/systems/cooldown.ts
Expand Up @@ -194,7 +194,14 @@ class Cooldown extends System {
continue;
}

viewer = cooldown.viewers?.find(o => o.userId === Number(opts.sender.userId));
for (const item of cooldown.viewers?.filter(o => o.userId === Number(opts.sender.userId)) ?? []) {
if (!viewer || viewer.timestamp < item.timestamp) {
viewer = {...item};
} else {
// remove duplicate
cooldown.viewers = cooldown.viewers?.filter(o => o.id !== item.id);
}
}
debug('cooldown.db', viewer ?? `${opts.sender.username}#${opts.sender.userId} not found in cooldown list`);
if (cooldown.type === 'global') {
timestamp = cooldown.timestamp ?? 0;
Expand All @@ -210,7 +217,7 @@ class Cooldown extends System {
} else {
debug('cooldown.check', `${opts.sender.username}#${opts.sender.userId} added to cooldown list.`);
cooldown.viewers?.push({
...cooldown.viewers.find(o => o.userId === Number(opts.sender.userId)),
...viewer,
userId: Number(opts.sender.userId),
lastTimestamp: timestamp,
timestamp: now,
Expand Down

0 comments on commit 3cdf672

Please sign in to comment.