Skip to content

Commit beb0ce7

Browse files
committed
Deal with bot disconnection to chat during poll
1 parent e6df07b commit beb0ce7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Diff for: lib/commands/implementations/gulag.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ function gulag(defaultBanTime) {
6060
});
6161

6262
listener.on('pollstop', (message) => {
63-
const poll = JSON.parse(message);
64-
6563
gulagActive = false;
6664
services.messageRelay.stopRelay('gulag');
65+
66+
if (message === null) return; // pollstop is null if the bot loses connection to chat.
67+
6768
services.messageRelay.sendOutputMessage('GULAG has ended:');
6869

70+
const poll = JSON.parse(message);
6971
const winnerVotes = Math.max(...poll.totals);
7072
const winners = [];
7173
const losers = [];

Diff for: lib/commands/implementations/voteban.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ function voteBan(ipBan, defaultBanTime, weighted) {
5656
});
5757

5858
listener.on('pollstop', (message) => {
59-
const poll = JSON.parse(message);
60-
6159
votebanActive = false;
6260
services.messageRelay.stopRelay('voteban');
61+
62+
if (message === null) return; // pollstop is null if the bot loses connection to chat.
63+
6364
services.messageRelay.sendOutputMessage('Total votes:');
6465

66+
const poll = JSON.parse(message);
6567
const votes = _.zipObject(poll.options, poll.totals);
6668

6769
services.messageRelay.sendOutputMessage(`Yes votes: ${votes.yes}`);

Diff for: lib/message-routing/chat-service-router.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ChatServiceRouter {
3333
this.bot.on('closed', () => {
3434
this.logger.info('Chat socket closed. Attempting to reconnect....');
3535
if (this.chatToConnectTo === 'dgg') {
36+
this.messageRelay.relayMessageToListeners('pollstop', null);
3637
setTimeout(() => {
3738
this.bot.connect();
3839
}, 5000);

0 commit comments

Comments
 (0)