Skip to content

Commit 1982c44

Browse files
author
bspkrs
committed
new approach for IRC reconnect: replace the bot object itself!
1 parent 84cc561 commit 1982c44

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Diff for: BotBase.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import os
1111
import shutil
1212
import time
13-
from IRCHandler import CmdHandler,CmdGenerator,Sender,Color, EOL
13+
from IRCHandler import CmdHandler, CmdGenerator, Sender, Color, EOL
1414
from ConfigHandler import AdvConfigParser
1515

1616

@@ -48,7 +48,7 @@ def run(self):
4848
last_start = time.time()
4949

5050
if not self.bot.isRunning:
51-
self.bot.resetSockets()
51+
self.bot = self.bot.clone()
5252
self.start()
5353

5454
try:
@@ -80,6 +80,7 @@ def run(self):
8080
class BotBase(object):
8181
def __init__(self, configfile=None, nspass=None, backupcfg=False):
8282
self.configfile = configfile if configfile else 'bot.cfg'
83+
self.backupcfg = backupcfg
8384

8485
if backupcfg and os.path.exists(self.configfile):
8586
backupcfgname = self.configfile + '.' + datetime.datetime.now().strftime('%Y%m%d%H%M%S') + '.bak'
@@ -163,7 +164,14 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
163164
self.socket = None
164165
self.dccSocketv4 = None
165166
self.dccSocketv6 = None
166-
self.resetSockets()
167+
self.socket = AsyncSocket.AsyncSocket(self, self.host, self.port, self.floodLimit)
168+
self.dccSocketv4 = DCCSocket.DCCSocket(self, False)
169+
if socket.has_ipv6:
170+
try:
171+
self.dccSocketv6 = DCCSocket.DCCSocket(self, True)
172+
except socket.error, e:
173+
if e.message.find('A socket operation was attempted to an unreachable network') != -1:
174+
self.dccSocketv6 = None
167175
self.cmdHandler = CmdHandler(self)
168176

169177
self.registerCommand('dcc', self.requestDCC, ['any'], 0, 0, "", "Requests a DCC connection to the bot.")
@@ -191,15 +199,8 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
191199
if self.about_msg and self.about_msg != '':
192200
self.registerCommand('about', self.aboutcmd, ['any'], 0, 0, '', 'About this bot.', allowpub=True)
193201

194-
def resetSockets(self):
195-
self.socket = AsyncSocket.AsyncSocket(self, self.host, self.port, self.floodLimit)
196-
self.dccSocketv4 = DCCSocket.DCCSocket(self, False)
197-
if socket.has_ipv6:
198-
try:
199-
self.dccSocketv6 = DCCSocket.DCCSocket(self, True)
200-
except socket.error, e:
201-
if e.message.find('A socket operation was attempted to an unreachable network') != -1:
202-
self.dccSocketv6 = None
202+
def clone(self):
203+
return BotBase(self.configfile, self.nspass, self.backupcfg)
203204

204205
def run(self):
205206
if self.host == "":

Diff for: MCPBot.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import zipfile, os, re
1212
import psycopg2.extras
1313

14-
__version__ = "0.8.0"
14+
__version__ = "0.9.0"
1515

1616
class MCPBot(BotBase):
1717
def __init__(self, configfile=None, nspass=None, backupcfg=False):
@@ -117,6 +117,8 @@ def __init__(self, configfile=None, nspass=None, backupcfg=False):
117117
self.legacyCommandMap = {'gcc': 'gc', 'gsc': 'gc', 'gcf': 'gf', 'gsf' : 'gf', 'gcm' : 'gm', 'gsm' : 'gm', 'scf' : 'sf',
118118
'ssf': 'sf', 'scm': 'sm', 'ssm': 'sm', 'fscf': 'fsf', 'fssf': 'fsf', 'fscm': 'fsm', 'fssm': 'fsm'}
119119

120+
def clone(self):
121+
return MCPBot(self.configfile, self.nspass, self.backupcfg)
120122

121123
def onStartUp(self):
122124
super(MCPBot, self).onStartUp()

0 commit comments

Comments
 (0)