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

IrcUser & pr/insp: Implement user channel tracking

This commit is contained in:
James Lu 2015-07-16 12:20:40 -07:00
parent 35f1c88a4e
commit d97fce8205
2 changed files with 5 additions and 0 deletions

View File

@ -19,6 +19,7 @@ class IrcUser():
self.modes = modes self.modes = modes
self.identified = False self.identified = False
self.channels = set()
def __repr__(self): def __repr__(self):
return repr(self.__dict__) return repr(self.__dict__)

View File

@ -62,6 +62,7 @@ def joinClient(irc, client, channel):
ts=irc.channels[channel].ts, uid=client, channel=channel, ts=irc.channels[channel].ts, uid=client, channel=channel,
modes=utils.joinModes(irc.channels[channel].modes))) modes=utils.joinModes(irc.channels[channel].modes)))
irc.channels[channel].users.add(client) irc.channels[channel].users.add(client)
irc.users[client].channels.add(channel)
def sjoinServer(irc, server, channel, users, ts=None): def sjoinServer(irc, server, channel, users, ts=None):
channel = channel.lower() channel = channel.lower()
@ -91,6 +92,7 @@ def sjoinServer(irc, server, channel, users, ts=None):
uids.append(user) uids.append(user)
for m in prefixes: for m in prefixes:
changedmodes.append(('+%s' % m, user)) changedmodes.append(('+%s' % m, user))
irc.users[user].channels.add(channel)
utils.applyModes(irc, channel, changedmodes) utils.applyModes(irc, channel, changedmodes)
namelist = ' '.join(namelist) namelist = ' '.join(namelist)
_send(irc, server, "FJOIN {channel} {ts} {modes} :{users}".format( _send(irc, server, "FJOIN {channel} {ts} {modes} :{users}".format(
@ -351,6 +353,7 @@ def handle_part(irc, source, command, args):
channel = args[0].lower() channel = args[0].lower()
# We should only get PART commands for channels that exist, right?? # We should only get PART commands for channels that exist, right??
irc.channels[channel].removeuser(source) irc.channels[channel].removeuser(source)
irc.users[source].channels.remove(channel)
try: try:
reason = args[1] reason = args[1]
except IndexError: except IndexError:
@ -380,6 +383,7 @@ def handle_fjoin(irc, servernumeric, command, args):
for user in userlist: for user in userlist:
modeprefix, user = user.split(',', 1) modeprefix, user = user.split(',', 1)
namelist.append(user) namelist.append(user)
irc.users[user].channels.add(channel)
utils.applyModes(irc, channel, [('+%s' % mode, user) for mode in modeprefix]) utils.applyModes(irc, channel, [('+%s' % mode, user) for mode in modeprefix])
irc.channels[channel].users.add(user) irc.channels[channel].users.add(user)
return {'channel': channel, 'users': namelist, 'modes': parsedmodes, 'ts': their_ts} return {'channel': channel, 'users': namelist, 'modes': parsedmodes, 'ts': their_ts}