Require at least one vote to skip

This commit is contained in:
Calvin Montgomery 2022-05-09 20:25:34 -07:00
parent cc283c0be9
commit fd451fe9d2
3 changed files with 22 additions and 2 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "3.82.9", "version": "3.82.10",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -80,7 +80,10 @@ VoteskipModule.prototype.update = function () {
const { counts } = this.poll.toUpdateFrame(false); const { counts } = this.poll.toUpdateFrame(false);
const { total, eligible, noPermission, afk } = this.calcUsercounts(); const { total, eligible, noPermission, afk } = this.calcUsercounts();
const need = Math.ceil(eligible * this.channel.modules.options.get("voteskip_ratio")); const need = Math.max(
1, // Require at least one vote, see #944
Math.ceil(eligible * this.channel.modules.options.get("voteskip_ratio"))
);
if (counts[0] >= need) { if (counts[0] >= need) {
const info = `${counts[0]}/${eligible} skipped; ` + const info = `${counts[0]}/${eligible} skipped; ` +
`eligible voters: ${eligible} = total (${total}) - AFK (${afk}) ` + `eligible voters: ${eligible} = total (${total}) - AFK (${afk}) ` +

View File

@ -102,6 +102,23 @@ describe('VoteskipModule', () => {
voteskipModule.update(); voteskipModule.update();
assert(sentMessage, 'Expected voteskip passed message'); assert(sentMessage, 'Expected voteskip passed message');
}); });
it('requires at least one vote to pass', () => {
let sentMessage = false;
fakeChannel.broadcastAll = (frame, data) => {
assert.strictEqual(frame, 'chatMsg');
assert(/voteskip passed/i.test(data.msg), 'Expected voteskip passed message')
sentMessage = true;
};
fakeUser.is = flag => (flag == Flags.U_AFK);
voteskipModule.poll = {
toUpdateFrame() {
return { counts: [0] };
}
};
voteskipModule.update();
assert(!sentMessage, 'Expected voteskip not to pass');
});
}); });
describe('#calcUsercounts', () => { describe('#calcUsercounts', () => {