@@ -7,6 +7,9 @@ const basePunishmentHelper = require('../base-punishment-helper');
7
7
const formatDuration = require ( '../../chat-utils/format-duration' ) ;
8
8
9
9
function voteBan ( ipBan , defaultBanTime , weighted ) {
10
+ const pollDuration = 30000 ;
11
+
12
+ let failSafeTimeout = null ;
10
13
let votebanActive = false ;
11
14
12
15
return function ban ( input , services , rawMessage ) {
@@ -39,6 +42,7 @@ function voteBan(ipBan, defaultBanTime, weighted) {
39
42
listener . on ( 'err' , ( message ) => {
40
43
const error = JSON . parse ( message ) ;
41
44
if ( error . description === 'activepoll' && ! votebanActive ) {
45
+ clearTimeout ( failSafeTimeout ) ;
42
46
services . messageRelay . stopRelay ( 'voteban' ) ;
43
47
services . messageRelay . sendOutputMessage (
44
48
'Poll in progress. Please wait for the current poll to finish.' ,
@@ -53,14 +57,19 @@ function voteBan(ipBan, defaultBanTime, weighted) {
53
57
muteString === 'PERMANENTLY' ? muteString : `for ${ muteString } `
54
58
} ${ parsedReason ? ` Reason: ${ parsedReason } ` : '' } ?`,
55
59
) ;
60
+
61
+ // Fail-safe
62
+ failSafeTimeout = setTimeout ( ( ) => {
63
+ votebanActive = false ;
64
+ services . messageRelay . stopRelay ( 'voteban' ) ;
65
+ } , pollDuration + 5000 ) ;
56
66
} ) ;
57
67
58
68
listener . on ( 'pollstop' , ( message ) => {
69
+ clearTimeout ( failSafeTimeout ) ;
59
70
votebanActive = false ;
60
71
services . messageRelay . stopRelay ( 'voteban' ) ;
61
72
62
- if ( message === null ) return ; // pollstop is null if the bot loses connection to chat.
63
-
64
73
services . messageRelay . sendOutputMessage ( 'Total votes:' ) ;
65
74
66
75
const poll = JSON . parse ( message ) ;
@@ -93,7 +102,7 @@ function voteBan(ipBan, defaultBanTime, weighted) {
93
102
'poll' ,
94
103
JSON . stringify ( {
95
104
weighted,
96
- time : 30000 ,
105
+ time : pollDuration ,
97
106
question : `Should we ban ${ userToPunish } ${
98
107
muteString === 'PERMANENTLY' ? muteString : `for ${ muteString } `
99
108
} ${ parsedReason ? ` Reason: ${ parsedReason } ` : '' } `,
0 commit comments