Skip to content

Commit 20d23b5

Browse files
author
bspkrs
committed
added restart command and fixed shutdown command
1 parent d85b82d commit 20d23b5

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

AsyncSocket.py

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def handle_write(self):
9191
self.sendBuffer.put_nowait(CmdGenerator.getUSER(self.bot.nick))
9292
self.bot.isIdentified = True
9393

94+
if self.bot.isTerminating or self.bot.isRestarting:
95+
sys.exit(187)
96+
9497
def _ssl_send(self, data):
9598
""" Replacement for self.send() during SSL connections. """
9699
try:

BotBase.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ def run(self):
6161
except SystemExit:
6262
self.bot.logger.error('SystemExit: Shutting down.')
6363
self.stop()
64-
raise
6564
except:
6665
self.bot.logger.error('Other Exception: Shutting down.')
6766
self.stop()
6867
raise
6968

7069
if not self.bot.isTerminating:
71-
self.bot.logger.warning('IRC connection was lost.')
70+
if not self.bot.isRestarting:
71+
self.bot.logger.warning('IRC connection was lost.')
72+
reconnect_attempts += 1
7273

7374
if time.time() - last_start > self.reset_attempt_secs:
7475
reconnect_attempts = 0
7576

76-
reconnect_attempts += 1
77-
restart = reconnect_attempts <= self.max_reconnects
77+
restart = (reconnect_attempts <= self.max_reconnects) or self.bot.isRestarting
78+
else:
79+
restart = False
7880

7981

8082
class BotBase(object):
@@ -147,8 +149,8 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
147149
for option in self.config.options('BANLIST'):
148150
self.banList[option] = set(self.config.get('BANLIST',option).lower().split(';') if self.config.get('BANLIST',option).strip() else [])
149151

150-
self.logger.info("Users : %s"%self.authUsers)
151-
self.logger.info("Groups : %s"%self.groups)
152+
self.logger.info("Users : %s" % self.authUsers)
153+
self.logger.info("Groups : %s" % self.groups)
152154
self.txtcmds = {}
153155

154156
self.updateConfig()
@@ -158,7 +160,8 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
158160

159161
self.isIdentified = False #Turn to true when nick/ident commands are sent
160162
self.isReady = False #Turn to true after RPL_ENDOFMOTD. Every join/nick etc commands should be sent once this is True.
161-
self.isTerminating = False #This is set to true by the stop command to bypass restarting
163+
self.isTerminating = False #This is set to true by the stop command to bypass restarting
164+
self.isRestarting = False
162165
self.isRunning = False
163166

164167
self.socket = None
@@ -194,6 +197,7 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
194197

195198
self.registerCommand('sendraw', self.sendRawCmd, ['admin'], 0, 999, "<irccmd>", "Send a raw IRC cmd.")
196199
self.registerCommand('shutdown', self.killSelf, ['admin'], 0, 0, "", "Kills the bot.")
200+
self.registerCommand('restart', self.restart, ['admin'], 0, 0, '', 'Restarts the bot.')
197201

198202
self.registerCommand('help', self.helpcmd, ['any'], 0, 1, "[<command>|*]", "Lists available commands or help about a specific command.", allowpub=True)
199203

@@ -255,6 +259,10 @@ def killSelf(self, bot, sender, dest, cmd, args):
255259
self.logger.info("Killing self.")
256260
self.isTerminating = True
257261

262+
def restart(self, bot, sender, dest, cmd, args):
263+
self.logger.info('Restarting...')
264+
self.isRestarting = True
265+
258266
# User handling commands
259267
def useradd(self, bot, sender, dest, cmd, args):
260268
user = args[0].lower()

0 commit comments

Comments
 (0)