|
10 | 10 | import os
|
11 | 11 | import shutil
|
12 | 12 | import time
|
13 |
| -from IRCHandler import CmdHandler,CmdGenerator,Sender,Color, EOL |
| 13 | +from IRCHandler import CmdHandler, CmdGenerator, Sender, Color, EOL |
14 | 14 | from ConfigHandler import AdvConfigParser
|
15 | 15 |
|
16 | 16 |
|
@@ -48,7 +48,7 @@ def run(self):
|
48 | 48 | last_start = time.time()
|
49 | 49 |
|
50 | 50 | if not self.bot.isRunning:
|
51 |
| - self.bot.resetSockets() |
| 51 | + self.bot = self.bot.clone() |
52 | 52 | self.start()
|
53 | 53 |
|
54 | 54 | try:
|
@@ -80,6 +80,7 @@ def run(self):
|
80 | 80 | class BotBase(object):
|
81 | 81 | def __init__(self, configfile=None, nspass=None, backupcfg=False):
|
82 | 82 | self.configfile = configfile if configfile else 'bot.cfg'
|
| 83 | + self.backupcfg = backupcfg |
83 | 84 |
|
84 | 85 | if backupcfg and os.path.exists(self.configfile):
|
85 | 86 | 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):
|
163 | 164 | self.socket = None
|
164 | 165 | self.dccSocketv4 = None
|
165 | 166 | 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 |
167 | 175 | self.cmdHandler = CmdHandler(self)
|
168 | 176 |
|
169 | 177 | 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):
|
191 | 199 | if self.about_msg and self.about_msg != '':
|
192 | 200 | self.registerCommand('about', self.aboutcmd, ['any'], 0, 0, '', 'About this bot.', allowpub=True)
|
193 | 201 |
|
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) |
203 | 204 |
|
204 | 205 | def run(self):
|
205 | 206 | if self.host == "":
|
|
0 commit comments