Karma: track per-user votes to prevent double voting - #1680
Conversation
…gval#207) - Add karma_votes table to track user votes per thing per channel - increment/decrement check existing user vote: same direction ignore, opposite direction flip vote, no prior vote record new vote - Include user nick in increment/decrement calls - Update clear() to also clear user votes - Generated by autonomous agent Goose, supervised by costelEN.
| # * Redistributions in binary form must reproduce the above copyright notice, | ||
| # this list of conditions, and the following disclaimer in the | ||
| # documentation and/or other materials provided with the distribution. | ||
| # documentation and/or materials provided with the distribution. |
There was a problem hiding this comment.
Changing the license text is a no-no. This needs to be reverted.
| If ``config plugins.karma.allowUnaddressedKarma` is set to `False``, you | ||
| must address the bot with nick or prefix to add or subtract karma. | ||
|
|
||
| Each user can only vote once per thing. A second vote in the same |
There was a problem hiding this comment.
This new behaviour ought to be configurable; I've seen plenty channels where Karma is allowed to accumulate over time. Also new test cases need to be added for this.
There was a problem hiding this comment.
I agree, it's a major feature.
I don't even see the point of the Karma plugin without it. @costelEN you probably want the Poll plugin instead of Karma for this use-case.
| return True | ||
|
|
||
| def decrement(self, channel, name): | ||
| def decrement(self, channel, name, user): |
There was a problem hiding this comment.
increment() and decrement() can probably be in one function to avoid duplicating code - just pass in the desired vote as a parameter.
| self.db.increment(channel, self._normalizeThing(thing)) | ||
| karma = self.db.get(channel, self._normalizeThing(thing)) | ||
| result = self.db.increment(channel, self._normalizeThing(thing), msg.nick) | ||
| if result is not False: |
There was a problem hiding this comment.
| if result is not False: | |
| if not result: |
| self.db.decrement(channel, self._normalizeThing(thing)) | ||
| karma = self.db.get(channel, self._normalizeThing(thing)) | ||
| result = self.db.decrement(channel, self._normalizeThing(thing), msg.nick) | ||
| if result is not False: |
There was a problem hiding this comment.
| if result is not False: | |
| if not result: |
| (channel, user.lower(), thing.lower(), vote)) | ||
| db.commit() | ||
|
|
||
| def _deleteUserVote(self, channel, user, thing): |
…gval#207) - Add karma_votes table to track user votes per thing per channel - Add trackUserVotes config option (default False for backward compatibility) - Refactor increment/decrement into single _vote() method - Fix duplicate vote handling: same direction ignored, opposite flips vote - Update clear() to also clear user votes - Add comprehensive tests for trackUserVotes behavior - Fix license header (revert to original) - Fix 'if result is not False:' to 'if not result:' - Generated by autonomous agent Goose, supervised by costelEN.
…tUp - Tests use assertNoResponse which expects no reply. With response=True, bot replies 'X's karma is now Y' causing false failures. - response stays at default False (matching original test behavior).
Closes #207
Automated fix. Tests ran in CI on the fork.
Generated by autonomous agent Goose, supervised by costelEN.