Changeset 6:ea25f7a285c6 in misc
- Timestamp:
- 02/17/07 04:21:48 (5 years ago)
- Branch:
- misc
- Convert:
- svn:e60e002c-0983-44b9-b2ae-8842d539f768/misc@9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
swirc.py
r5 r6 25 25 # -- 26 26 # 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 ;) 27 28 # 28 29 # python-irclib sucks, long life to twisted ;) … … 40 41 datefmt='%d/%m/%Y %H:%M:%S %Z', 41 42 filename='swirc.log', 42 filemode=' a+')43 filemode='w') 43 44 console = log.StreamHandler() 44 45 console.setLevel(log.INFO) 45 log.getLogger( '').addHandler(console)46 log.getLogger().addHandler(console) 46 47 47 48 BOT_NICKNAME = 'swirc' 48 MAX_CURRENT_CHANNEL = 2 49 STOP_AFTER_N_CHANNELS = 5000 49 MAX_CURRENT_CHANNEL = 10 50 50 51 51 class Graph(object): … … 110 110 self.vchannels = [] # Channels we have to visit 111 111 self.wcount = 0 112 self. stopc = STOP_AFTER_N_CHANNELS112 self.j = True 113 113 114 114 self.joinNextChannel() 115 116 115 117 116 def joinNextChannel(self): 118 117 print self.wcount 119 if not self.wcount and self. stopc:118 if not self.wcount and self.j: 120 119 try: 121 120 chan = self.vchannels.pop(0) 122 self. stopc -=1121 self.j = False 123 122 self.join(chan) 124 123 except IndexError: 125 124 pass 126 125 127 print self.vchannels128 129 126 reactor.callLater(5, self.joinNextChannel) 130 127 … … 142 139 def joined(self, channel): 143 140 log.info('Joined: %s', channel) 141 self.j = True 144 142 self.cnicks = [] 145 143 self.inchannels.append(channel) … … 154 152 155 153 def irc_RPL_NAMREPLY(self, prefix, params): 156 ''' ['swirc', '=', '#etna', 'swirc @Eriol @AlpT @mancausoft @markgreene '] '''157 154 for nick in params[3].split(): 158 155 if nick == BOT_NICKNAME: … … 165 162 self.graphmaker.addNick(self.cnicks) 166 163 167 168 164 def irc_RPL_ENDOFNAMES(self, prefix, params): 169 165 for nick in self.cnicks: … … 171 167 self.whois(nick) 172 168 self.wcount += 1 173 time.sleep(0.2 5)169 time.sleep(0.2) 174 170 175 171 def irc_RPL_WHOISCHANNELS(self, prefix, params): … … 187 183 if nick not in self.knownnicks: 188 184 self.knownnicks.append(nick) 189 time.sleep(0.2 5)185 time.sleep(0.2) 190 186 191 187 self.wcount -= 1 192 193 def privmsg(self, user, channel, msg):194 user = user.split('!', 1)[0]195 196 # Private message197 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 line222 188 223 189 class SwircBotFactory(protocol.ClientFactory):
Note: See TracChangeset
for help on using the changeset viewer.
