minor cleanup

This commit is contained in:
Thorsten
2015-11-30 19:50:11 +01:00
parent a7b53d855a
commit f40add54b5
3 changed files with 57 additions and 45 deletions

View File

@@ -21,7 +21,7 @@ except ImportError:
from sleekxmpp import ClientXMPP
got_hangup = False
# got_hangup = False
class IdleBot(ClientXMPP):
@@ -65,8 +65,7 @@ class IdleBot(ClientXMPP):
self.logger.warn("got 'hangup' from '%s': '%s'" % (
msg_obj['mucnick'], msg_obj['body']
))
global got_hangup
got_hangup = True
self.hangup()
return False
elif msg_obj['mucnick'] in conf_load().get("other_bots", ()):
# not talking to the other bot.
@@ -74,6 +73,13 @@ class IdleBot(ClientXMPP):
else:
return True
def hangup(self):
"""
disconnect and exit
"""
self.disconnect()
sys.exit(1)
def start(botclass, active=False):
logging.basicConfig(
@@ -103,14 +109,12 @@ def start(botclass, active=False):
bot.connect()
bot.register_plugin('xep_0045')
bot.process()
global got_hangup
while 1:
try:
# print("hangup: %s" % got_hangup)
if got_hangup or not plugins.event_trigger():
bot.disconnect()
sys.exit(1)
if not plugins.event_trigger():
bot.hangup()
time.sleep(EVENTLOOP_DELAY)
except KeyboardInterrupt: