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

Don't hardcode client usermodes in spawnClient

Still a bit of a WIP here...
This commit is contained in:
James Lu 2015-06-20 20:54:01 -07:00
parent 379f442a14
commit d3257f9314
2 changed files with 16 additions and 8 deletions

View File

@ -16,14 +16,19 @@ def _sendFromServer(irc, 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, *args): def spawnClient(irc, nick, ident, host, modes=[], *args):
uid = uidgen.next_uid(irc.sid) uid = uidgen.next_uid(irc.sid)
ts = int(time.time()) ts = int(time.time())
if modes:
modes = utils.joinModes(modes)
else:
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, "UID {uid} {ts} {nick} {host} {host} {ident} 0.0.0.0 {ts} +o +" _sendFromServer(irc, "UID {uid} {ts} {nick} {host} {host} {ident} 0.0.0.0 "
" :PyLink Client".format(ts=ts, host=host, "{ts} {modes} + :PyLink Client".format(ts=ts, host=host,
nick=nick, ident=ident, uid=uid)) nick=nick, ident=ident, uid=uid,
modes=modes))
u = irc.users[uid] = IrcUser(nick, ts, uid, ident, host, *args) u = irc.users[uid] = IrcUser(nick, ts, uid, ident, host, *args)
irc.servers[irc.sid].users.append(uid) irc.servers[irc.sid].users.append(uid)
return u return u
@ -122,7 +127,7 @@ def connect(irc):
# :751 UID 751AAAAAA 1220196319 Brain brainwave.brainbox.cc # :751 UID 751AAAAAA 1220196319 Brain brainwave.brainbox.cc
# netadmin.chatspike.net brain 192.168.1.10 1220196324 +Siosw # netadmin.chatspike.net brain 192.168.1.10 1220196324 +Siosw
# +ACKNOQcdfgklnoqtx :Craig Edwards # +ACKNOQcdfgklnoqtx :Craig Edwards
irc.pseudoclient = spawnClient(irc, 'PyLink', 'pylink', host) irc.pseudoclient = spawnClient(irc, 'PyLink', 'pylink', host, modes=["+o"])
f(':%s ENDBURST' % (irc.sid)) f(':%s ENDBURST' % (irc.sid))
for chan in irc.serverdata['channels']: for chan in irc.serverdata['channels']:
joinClient(irc, irc.pseudoclient.uid, chan) joinClient(irc, irc.pseudoclient.uid, chan)
@ -205,9 +210,9 @@ def handle_fjoin(irc, servernumeric, command, args):
def handle_uid(irc, numeric, command, args): def handle_uid(irc, numeric, command, args):
# :70M UID 70MAAAAAB 1429934638 GL 0::1 hidden-7j810p.9mdf.lrek.0000.0000.IP gl 0::1 1429934638 +Wioswx +ACGKNOQXacfgklnoqvx :realname # :70M UID 70MAAAAAB 1429934638 GL 0::1 hidden-7j810p.9mdf.lrek.0000.0000.IP gl 0::1 1429934638 +Wioswx +ACGKNOQXacfgklnoqvx :realname
uid, ts, nick, realhost, host, ident, ip = args[0:7] uid, ts, nick, realhost, host, ident, ip = args[0:7]
modes = utils.parseModes(args[8:9])
realname = args[-1] realname = args[-1]
irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip, modes) irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
utils.applyModes(irc.users[uid].modes, utils.parseModes(args[8:9]))
irc.servers[numeric].users.append(uid) irc.servers[numeric].users.append(uid)
def handle_quit(irc, numeric, command, args): def handle_quit(irc, numeric, command, args):

View File

@ -83,7 +83,10 @@ def applyModes(modelist, changedmodes):
else: else:
# We're removing a mode # We're removing a mode
try: try:
modelist.remove(mode.replace('-', '+')) modelist.remove(mode)
except ValueError: except ValueError:
print('Attempted to remove modes %r not in %s\'s modes' % (mode, numeric)) print('Attempted to remove modes %r not in %s\'s modes' % (mode, numeric))
return modelist return modelist
def joinModes(modes):
return '+' + ''.join(mode[1] for mode in modes)