Changeset 13

Show
Ignore:
Timestamp:
02/01/04 17:11:45 (5 years ago)
Author:
jajcus
Message:

- color stripping
- login optimizations

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/jjigw.py

    r12 r13  
    4747 
    4848evil_characters_re=re.compile(r"[\000-\010\013\014\016-\037]") 
    49  
    5049def remove_evil_characters(s): 
    5150    return evil_characters_re.sub(" ",s) 
     51 
     52color_re=re.compile(r"\x03\d\d|\x0f") 
     53def strip_colors(s): 
     54    return color_re.sub("",s) 
    5255 
    5356numeric_re=re.compile(r"\d\d\d") 
     
    108111class IRCUser: 
    109112    def __init__(self,session,nick,user="",host=""): 
     113        self.sync_delay=0 
    110114        self.session=session 
    111115        if "!" in nick: 
     
    123127        self.current_thread=None 
    124128 
     129    def sync_in_channel(self,channel): 
     130        if self.sync_delay>0: 
     131            return 
     132        elif self.sync_delay<0: 
     133            self.debug("Warning: %r.sync_delay<0" % (self,)) 
     134        return channel.sync_user(self) 
     135 
    125136    def join_channel(self,channel): 
    126137        self.channels[normalize(channel.name)]=channel 
    127         channel.sync_user(self
     138        self.sync_in_channel(channel
    128139 
    129140    def leave_channel(self,channel): 
    130141        try: 
    131142            del self.channels[normalize(channel.name)] 
    132             channel.sync_user(self
     143            self.sync_in_channel(channel
    133144        except KeyError: 
    134145            pass 
     
    140151    def sync_all(self): 
    141152        for channel in self.channels.values(): 
    142             channel.sync_user(self
     153            self.sync_in_channel(channel
    143154 
    144155    def whoreply(self,params): 
     
    157168        else: 
    158169            channel=None 
    159         self.nick=nick 
    160         self.host=host 
    161         self.user=user 
    162         if channel: 
    163             self.debug("Channel: %r" % (channel,)) 
    164             self.join_channel(channel) 
    165             if "@" in flags: 
    166                 channel.set_mode("o",self) 
    167             elif "+" in flags: 
    168                 channel.set_mode("v",self) 
     170        self.sync_delay+=1 
     171        try: 
     172            self.nick=nick 
     173            self.host=host 
     174            self.user=user 
     175            if channel: 
     176                self.debug("Channel: %r" % (channel,)) 
     177                self.join_channel(channel) 
     178                if "@" in flags: 
     179                    channel.set_mode("o",self) 
     180                elif "+" in flags: 
     181                    channel.set_mode("v",self) 
     182                else: 
     183                    channel.reset_mode("o",self) 
     184                    channel.reset_mode("v",self) 
     185            if "G" in flags: 
     186                self.mode["a"]=1 
    169187            else: 
    170                 channel.reset_mode("o",self) 
    171                 channel.reset_mode("v",self) 
    172         if "G" in flags: 
    173             self.mode["a"]=1 
    174         else: 
    175             self.mode["a"]=0 
     188                self.mode["a"]=0 
     189        finally: 
     190            self.sync_delay-=1 
    176191        if channel: 
    177192            channel.sync_user(self) 
     
    410425            if self.state=="join": 
    411426                self.debug("Channel %r joined!" % (self.name,)) 
    412                 self.session.user.join_channel(self) 
     427                self.session.user.sync_delay+=1 
     428                try: 
     429                    self.session.user.join_channel(self) 
     430                finally: 
     431                    self.session.user.sync_delay-=1 
    413432                self.state="joined" 
    414433                self.stanza=None 
     
    442461        else: 
    443462            m=Message(type="groupchat",fr=self.prefix_to_jid(prefix),to=self.session.jid, 
    444                     body=remove_evil_characters(body)) 
     463                    body=remove_evil_characters(strip_colors(body))) 
    445464            self.session.component.send(m) 
    446465     
     
    452471        if command=="ACTION": 
    453472            m=Message(type="groupchat",fr=self.prefix_to_jid(prefix),to=self.session.jid, 
    454                     body="/me "+remove_evil_characters(arg)) 
     473                    body="/me "+remove_evil_characters(strip_colors(arg))) 
    455474            self.session.component.send(m) 
    456475        else: 
     
    703722            fr=user.jid() 
    704723        body=unicode(params[1],self.default_encoding,"replace") 
    705         m=Message(type=typ,fr=fr,to=self.jid,body=remove_evil_characters(body)) 
     724        m=Message(type=typ,fr=fr,to=self.jid,body=remove_evil_characters(strip_colors(body))) 
    706725        self.component.send(m) 
    707726