Fix failure detection in irc access check
Two problems are corrected: 1) If a channel is not registered with chanserv, consider it an access failure. 2) The failure flag was being reset on every successful private message. That was intended to ensure that we failed if we were unable to communicate with ChanServ. But the logic was flawed. Correct this by treating the failure flag as trinary. On the first channel where we have verified access is okay, set the flag to indicate that we have not failed, iff the flag has not already been set. So now either failure to communicate with ChanServ or an actual access failure will cause it to exit 1. Change-Id: I8d51b706ed6f499827f8046ab4522b342589cb90
This commit is contained in:
parent
8ae55a6364
commit
d1673c9063
@ -40,10 +40,10 @@ class CheckAccess(irc.client.SimpleIRCClient):
|
||||
self.flags = flags
|
||||
self.current_channel = None
|
||||
self.current_list = []
|
||||
self.failed = True
|
||||
self.failed = None
|
||||
|
||||
def on_disconnect(self, connection, event):
|
||||
if self.failed:
|
||||
if self.failed is not False:
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(0)
|
||||
@ -73,7 +73,6 @@ class CheckAccess(irc.client.SimpleIRCClient):
|
||||
self.log.debug("Ignoring message from unauthenticated "
|
||||
"user %s" % nick)
|
||||
return
|
||||
self.failed = False
|
||||
self.advance(msg)
|
||||
|
||||
def advance(self, msg=None):
|
||||
@ -87,6 +86,13 @@ class CheckAccess(irc.client.SimpleIRCClient):
|
||||
self.current_channel)
|
||||
time.sleep(1)
|
||||
return
|
||||
if msg.endswith('is not registered.'):
|
||||
self.failed = True
|
||||
print ("%s is not registered with ChanServ." %
|
||||
self.current_channel)
|
||||
self.current_channel = None
|
||||
self.advance()
|
||||
return
|
||||
if msg.startswith('End of'):
|
||||
found = False
|
||||
for nick, flags, msg in self.current_list:
|
||||
@ -102,6 +108,11 @@ class CheckAccess(irc.client.SimpleIRCClient):
|
||||
for nick, flags, msg in self.current_list:
|
||||
print msg
|
||||
print
|
||||
# If this is the first channel checked, set the failure
|
||||
# flag to false because we know that the system is
|
||||
# operating well enough to check at least one channel.
|
||||
if self.failed is None:
|
||||
self.failed = False
|
||||
self.current_channel = None
|
||||
self.advance()
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user