3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-12 13:12:36 +01:00

pr/insp: smarter spawnClient() with kwargs; implement conf['bot']['prefix']

Red #26.
This commit is contained in:
James Lu 2015-07-06 19:42:09 -07:00
parent 33d23893f8
commit d833be5f4b

View File

@ -3,10 +3,11 @@ import sys
import os import os
import traceback import traceback
import re import re
from copy import copy
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils import utils
from copy import copy from conf import conf
from log import log from log import log
from classes import * from classes import *
@ -22,7 +23,8 @@ def _sendFromServer(irc, sid, msg):
def _sendFromUser(irc, numeric, msg): def _sendFromUser(irc, numeric, msg):
irc.send(':%s %s' % (numeric, msg)) irc.send(':%s %s' % (numeric, msg))
def spawnClient(irc, nick, ident, host, modes=[], server=None, *args): def spawnClient(irc, nick, ident='null', host='null', realhost=None, modes=[],
server=None, ip='0.0.0.0', realname=None):
server = server or irc.sid server = server or irc.sid
if not utils.isInternalServer(irc, server): if not utils.isInternalServer(irc, server):
raise ValueError('Server %r is not a PyLink internal PseudoServer!' % server) raise ValueError('Server %r is not a PyLink internal PseudoServer!' % server)
@ -32,17 +34,22 @@ def spawnClient(irc, nick, ident, host, modes=[], server=None, *args):
irc.uidgen[server] = utils.TS6UIDGenerator(server) irc.uidgen[server] = utils.TS6UIDGenerator(server)
uid = irc.uidgen[server].next_uid() uid = irc.uidgen[server].next_uid()
ts = int(time.time()) ts = int(time.time())
realname = realname or conf['bot']['realname']
realhost = realhost or host
if modes: if modes:
modes = utils.joinModes(modes) raw_modes = utils.joinModes(modes)
else: else:
modes = '+' raw_modes = '+'
if not utils.isNick(nick): if not utils.isNick(nick):
raise ValueError('Invalid nickname %r.' % nick) raise ValueError('Invalid nickname %r.' % nick)
_sendFromServer(irc, server, "UID {uid} {ts} {nick} {host} {host} {ident} 0.0.0.0 " _sendFromServer(irc, server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
"{ts} {modes} + :PyLink Client".format(ts=ts, host=host, " {ts} {modes} + :{realname}".format(ts=ts, host=host,
nick=nick, ident=ident, uid=uid, nick=nick, ident=ident, uid=uid,
modes=modes)) modes=raw_modes, ip=ip, realname=realname,
u = irc.users[uid] = IrcUser(nick, ts, uid, ident, host, *args) realhost=realhost))
# XXX Deduplicate the code here
u = irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, modes=modes)
irc.servers[server].users.append(uid) irc.servers[server].users.append(uid)
return u return u