Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Added (broken) support for actually keeping user states
Browse files Browse the repository at this point in the history
  • Loading branch information
SnoFox committed Mar 17, 2012
1 parent ea8b407 commit dd09860
Showing 1 changed file with 119 additions and 3 deletions.
122 changes: 119 additions & 3 deletions sparks/modules/userclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# <snofox@snofox.net>
########################

from time import time

class User:

# irc = an IRC object that this user is in
Expand All @@ -17,14 +19,15 @@ def __init__( self, irc, nick ):
self.__address = None # string of everything after the @ in hostname
self.__gecos = None # The user's gecos/realname field
self.__channels = dict() # dicts where chan is the key and the modes they have in it (+ohv ... ) is the value
self.__time = int(time()) # time we found this user (useful for users that PM'd us)
# currently unused

irc.userList.append( self )

def changeNick( self, newNick ):
# Iterate through our list of objects to look for duplicates
# If no dupes, just set self.nick to newNick, remove the old entry, add a new one
self.__nick = newNick

# If no dupes, just set self.nick to newNick, remove the old entry, add a new one self.__nick = newNick
pass
def setAddress( self, address ):
self.__address = address

Expand Down Expand Up @@ -73,3 +76,116 @@ def getChans( self ):
def modinit( irc ):
irc.userList = []

def sr_join( irc, client, chan, null ):
if client[0] == irc.nick:
irc.push( 'WHO %s' % chan )
else:
user = None
for thisUser in irc.userList:
if thisUser.getNick().lower() == client[0].lower():
# XXX: temporary until I do proper case checks
user = thisUser
break

if not user:
user = User( irc, client[0] )
user.setIdent( client[1] )
user.setAddress( client[2] )
user.addChan( chan.lower(), None )

def sr_part( irc, client, chan, reason ):
if client[0] == irc.nick:
# clean up the userlist by iterating through the userlist and deleting
# all users who were just in that channel with the bot
pass
else:
user = None
for thisUser in irc.userList:
if thisUser.getNick().lower() == client[0].lower():
# XXX: temporary until I do proper case checks
user = thisUser
break
if not user:
print "Error: got a part for user we don't know about: %s!%s@%s on %s" % (client[0],client[1],client[2],chan)
else:
try:
user.delChan( chan.lower() )
except KeyError:
print "Error: got a part for user %s on %s, but they weren't there" % ( user.getNick(), chan )

def sr_quit( irc, client, reason, null ):
user = None
for thisUser in irc.userList:
if thisUser.getNick().lower() == client[0].lower():
# XXX: temporary until I do proper case checks
user = thisUser
break
if not user:
print "Error: got a quit for user we don't know about: %s!%s@%s" % (client[0],client[1],client[2])
else:
irc.userList.remove( user )


def sr_kick( irc, client, chan, params ):
victim = params[0]

user = None
for thisUser in irc.userList:
if thisUser.getNick().lower() == victim.lower():
# XXX: temporary until I do proper case checks
user = thisUser
break
if not user:
print "Error: got a kick for user we don't know about: %s kicking %s in %s" % (client[0],victim,chan)
else:
try:
user.delChan( chan.lower() )
except KeyError:
print "Error: user %s was kicked from %s, but they weren't there" % ( user.getNick(), chan )

def sr_352( irc, client, target, params ):
# >> :dualcore.ext3.net 352 PyFox #foxtest ~SnoFox is.in-addr.arpa void.ext3.net SnoFox H*! :2 Fox of Sno
chan = params[0]
ident = params[1]
address = params[2]
nick = params[4]
prefix = params[5] # need to be cleaned
gecos = ' '.join( params[7:] )

# XXX: sort out prefixes and add them

user = User( irc, nick )

user.setIdent( ident )
user.setAddress( address )
user.setGecos( gecos )
user.addChan( chan, None )



def ca_ulist( irc, client, chan, params ):
irc.privmsg( chan, "I know about the following users: " )
for thisUser in irc.userList:
irc.privmsg( chan, 'Nick: %s u@h: %s@%s' % (thisUser.getNick(),thisUser.getIdent(),thisUser.getAddress()) )
irc.privmsg( chan, 'Chan info: %s' % thisUser.getChans() )
irc.privmsg( chan, "== End of userlist ==" )



'''
Behavior notes:
- Learning a user from join will not fill in their GECOS
- Nicks are compared via basic checks; changing them to lowercase and matching
- this means Sno|Fox and Sno\Fox; and Sno[Fox] and Sno{Fox} are "different" nicks,
which is incorrect behavior for IRC.
TODO:
- Nick changes are currently not supported
- Mode changes do not work
- Prefixes don't work
'''


#######
# EOF #
#######

0 comments on commit dd09860

Please sign in to comment.