3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

Make the 'bot' conf block available in Irc() as irc.botdata

Protocol modules shouldn't read conf directly, so that we can override the config in testing.
This commit is contained in:
James Lu 2015-07-08 13:54:45 -07:00
parent 2d4d8dd247
commit 8576778ddc
3 changed files with 14 additions and 7 deletions

View File

@ -60,7 +60,14 @@ class ProtocolError(Exception):
pass
global testconf
testconf = {'server':
testconf = {'bot':
{
'nick': 'PyLink',
'user': 'pylink',
'realname': 'PyLink Service Client',
'loglevel': 'DEBUG',
},
'server':
{
'netname': 'fakeirc',
'ip': '0.0.0.0',
@ -71,7 +78,7 @@ testconf = {'server':
'hostname': "pylink.unittest",
'sid': "9PY",
'channels': ["#pylink"],
}
},
}
class FakeIRC(main.Irc):

View File

@ -40,6 +40,7 @@ class Irc():
self.serverdata = conf['server']
self.sid = self.serverdata["sid"]
self.botdata = conf['bot']
self.proto = proto
self.connect()

View File

@ -7,7 +7,6 @@ from copy import copy
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
from conf import conf
from log import log
from classes import *
@ -17,7 +16,7 @@ from classes import *
# XXX figure out a way to not force-map ENCAP to KNOCK, since other commands are sent
# through it too.
hook_map = {'FJOIN': 'JOIN', 'SAVE': 'NICK', 'RSQUIT': 'SQUIT', 'FMODE': 'MODE',
hook_map = {'FJOIN': 'JOIN', 'RSQUIT': 'SQUIT', 'FMODE': 'MODE',
'FTOPIC': 'TOPIC', 'ENCAP': 'KNOCK'}
def _sendFromServer(irc, sid, msg):
@ -37,7 +36,7 @@ def spawnClient(irc, nick, ident='null', host='null', realhost=None, modes=set()
irc.uidgen[server] = utils.TS6UIDGenerator(server)
uid = irc.uidgen[server].next_uid()
ts = int(time.time())
realname = realname or conf['bot']['realname']
realname = realname or irc.botdata['realname']
realhost = realhost or host
raw_modes = utils.joinModes(modes)
if not utils.isNick(nick):
@ -142,8 +141,8 @@ def connect(irc):
f('SERVER {host} {Pass} 0 {sid} :PyLink Service'.format(host=host,
Pass=irc.serverdata["sendpass"], sid=irc.sid))
f(':%s BURST %s' % (irc.sid, ts))
nick = conf['bot'].get('nick') or 'PyLink'
ident = conf['bot'].get('ident') or 'pylink'
nick = irc.botdata.get('nick') or 'PyLink'
ident = irc.botdata.get('ident') or 'pylink'
irc.pseudoclient = spawnClient(irc, nick, ident, host, modes={("o", None)})
f(':%s ENDBURST' % (irc.sid))
for chan in irc.serverdata['channels']: