Changeset 6:ea25f7a285c6 in misc


Ignore:
Timestamp:
02/17/07 04:21:48 (5 years ago)
Author:
Eriol
Branch:
misc
Convert:
svn:e60e002c-0983-44b9-b2ae-8842d539f768/misc@9
Message:

Clean up. The joining problem depends on IRC server!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • swirc.py

    r5 r6  
    2525# -- 
    2626# Thanks to AlpT and KatolaZ for sharing this idea and coding with me at JD06! 
     27# Thanks to MancaUSoft for helping with the absurd problems' debug ;) 
    2728# 
    2829# python-irclib sucks, long life to twisted ;) 
     
    4041                datefmt='%d/%m/%Y %H:%M:%S %Z', 
    4142                filename='swirc.log', 
    42                 filemode='a+') 
     43                filemode='w') 
    4344console = log.StreamHandler() 
    4445console.setLevel(log.INFO) 
    45 log.getLogger('').addHandler(console) 
     46log.getLogger().addHandler(console) 
    4647 
    4748BOT_NICKNAME = 'swirc' 
    48 MAX_CURRENT_CHANNEL = 2 
    49 STOP_AFTER_N_CHANNELS = 5000 
     49MAX_CURRENT_CHANNEL = 10 
    5050 
    5151class Graph(object): 
     
    110110        self.vchannels = [] # Channels we have to visit 
    111111        self.wcount = 0 
    112         self.stopc = STOP_AFTER_N_CHANNELS 
     112        self.j = True 
    113113 
    114114        self.joinNextChannel() 
    115  
    116115 
    117116    def joinNextChannel(self): 
    118117        print self.wcount 
    119         if not self.wcount and self.stopc: 
     118        if not self.wcount and self.j: 
    120119            try: 
    121120                chan = self.vchannels.pop(0) 
    122                 self.stopc -=1 
     121                self.j = False 
    123122                self.join(chan) 
    124123            except IndexError: 
    125124                pass 
    126125 
    127         print self.vchannels 
    128  
    129126        reactor.callLater(5, self.joinNextChannel) 
    130127 
     
    142139    def joined(self, channel): 
    143140        log.info('Joined: %s', channel) 
     141        self.j = True 
    144142        self.cnicks = [] 
    145143        self.inchannels.append(channel) 
     
    154152 
    155153    def irc_RPL_NAMREPLY(self, prefix, params): 
    156         ''' ['swirc', '=', '#etna', 'swirc @Eriol @AlpT @mancausoft @markgreene '] ''' 
    157154        for nick in params[3].split(): 
    158155            if nick == BOT_NICKNAME: 
     
    165162        self.graphmaker.addNick(self.cnicks) 
    166163 
    167  
    168164    def irc_RPL_ENDOFNAMES(self, prefix, params): 
    169165        for nick in self.cnicks: 
     
    171167                self.whois(nick) 
    172168                self.wcount += 1 
    173                 time.sleep(0.25) 
     169                time.sleep(0.2) 
    174170 
    175171    def irc_RPL_WHOISCHANNELS(self, prefix, params): 
     
    187183        if nick not in self.knownnicks: 
    188184            self.knownnicks.append(nick) 
    189         time.sleep(0.25) 
     185        time.sleep(0.2) 
    190186 
    191187        self.wcount -= 1 
    192  
    193     def privmsg(self, user, channel, msg): 
    194         user = user.split('!', 1)[0] 
    195  
    196         # Private message 
    197         if channel == self.nickname: 
    198             if msg.startswith('!'): 
    199                 if msg[1:] == 'users': 
    200                     msg = "%s" % str(self.knownnicks) 
    201                 elif msg[1:] == 'nusers': 
    202                     msg = "%s" % str(len(self.knownnicks)) 
    203                 elif msg[1:] == 'channels': 
    204                     msg = "%s" % str(self.knownchannels) 
    205                 elif msg[1:] == 'nchannels': 
    206                     msg = "%s" % str(len(self.knownchannels)) 
    207                 elif msg[1:5] == 'join': 
    208                     chan = msg[6:] 
    209                     msg = "Joining %s..." % msg[6:] 
    210                     self.join(chan) 
    211                 elif msg[1:] == 'cnicks': 
    212                     msg = "%s" % str(self.cnicks) 
    213                 elif msg[1:] == 'vchannels': 
    214                     msg = "%s" % str(self.vchannels) 
    215                 elif msg[1:] == 'ichannels': 
    216                     msg = "%s" % str(self.inchannels) 
    217                 self.msg(user, msg) 
    218  
    219     #def lineReceived(self, line): 
    220         #irc.IRCClient.lineReceived(self, line) 
    221         #print line 
    222188 
    223189class SwircBotFactory(protocol.ClientFactory): 
Note: See TracChangeset for help on using the changeset viewer.