Clean up. The joining problem depends on IRC server!
This commit is contained in:
parent
28ae590ec1
commit
8799626070
54
swirc.py
54
swirc.py
|
@ -24,6 +24,7 @@
|
|||
#
|
||||
# --
|
||||
# Thanks to AlpT and KatolaZ for sharing this idea and coding with me at JD06!
|
||||
# Thanks to MancaUSoft for helping with the absurd problems' debug ;)
|
||||
#
|
||||
# python-irclib sucks, long life to twisted ;)
|
||||
|
||||
|
@ -39,14 +40,13 @@ log.basicConfig(level=log.DEBUG,
|
|||
format='[%(asctime)s] %(levelname)s %(message)s',
|
||||
datefmt='%d/%m/%Y %H:%M:%S %Z',
|
||||
filename='swirc.log',
|
||||
filemode='a+')
|
||||
filemode='w')
|
||||
console = log.StreamHandler()
|
||||
console.setLevel(log.INFO)
|
||||
log.getLogger('').addHandler(console)
|
||||
log.getLogger().addHandler(console)
|
||||
|
||||
BOT_NICKNAME = 'swirc'
|
||||
MAX_CURRENT_CHANNEL = 2
|
||||
STOP_AFTER_N_CHANNELS = 5000
|
||||
MAX_CURRENT_CHANNEL = 10
|
||||
|
||||
class Graph(object):
|
||||
|
||||
|
@ -109,23 +109,20 @@ class SwircBot(irc.IRCClient):
|
|||
self.cnicks = []
|
||||
self.vchannels = [] # Channels we have to visit
|
||||
self.wcount = 0
|
||||
self.stopc = STOP_AFTER_N_CHANNELS
|
||||
self.j = True
|
||||
|
||||
self.joinNextChannel()
|
||||
|
||||
|
||||
def joinNextChannel(self):
|
||||
print self.wcount
|
||||
if not self.wcount and self.stopc:
|
||||
if not self.wcount and self.j:
|
||||
try:
|
||||
chan = self.vchannels.pop(0)
|
||||
self.stopc -=1
|
||||
self.j = False
|
||||
self.join(chan)
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
print self.vchannels
|
||||
|
||||
reactor.callLater(5, self.joinNextChannel)
|
||||
|
||||
def connectionMade(self):
|
||||
|
@ -141,6 +138,7 @@ class SwircBot(irc.IRCClient):
|
|||
|
||||
def joined(self, channel):
|
||||
log.info('Joined: %s', channel)
|
||||
self.j = True
|
||||
self.cnicks = []
|
||||
self.inchannels.append(channel)
|
||||
if len(self.inchannels) > MAX_CURRENT_CHANNEL:
|
||||
|
@ -153,7 +151,6 @@ class SwircBot(irc.IRCClient):
|
|||
self.sendLine('WHOIS %s' % (nick,))
|
||||
|
||||
def irc_RPL_NAMREPLY(self, prefix, params):
|
||||
''' ['swirc', '=', '#etna', 'swirc @Eriol @AlpT @mancausoft @markgreene '] '''
|
||||
for nick in params[3].split():
|
||||
if nick == BOT_NICKNAME:
|
||||
continue
|
||||
|
@ -164,13 +161,12 @@ class SwircBot(irc.IRCClient):
|
|||
|
||||
self.graphmaker.addNick(self.cnicks)
|
||||
|
||||
|
||||
def irc_RPL_ENDOFNAMES(self, prefix, params):
|
||||
for nick in self.cnicks:
|
||||
if nick not in self.knownnicks:
|
||||
self.whois(nick)
|
||||
self.wcount += 1
|
||||
time.sleep(0.25)
|
||||
time.sleep(0.2)
|
||||
|
||||
def irc_RPL_WHOISCHANNELS(self, prefix, params):
|
||||
for channel in params[2].split():
|
||||
|
@ -186,40 +182,10 @@ class SwircBot(irc.IRCClient):
|
|||
nick = params[1]
|
||||
if nick not in self.knownnicks:
|
||||
self.knownnicks.append(nick)
|
||||
time.sleep(0.25)
|
||||
time.sleep(0.2)
|
||||
|
||||
self.wcount -= 1
|
||||
|
||||
def privmsg(self, user, channel, msg):
|
||||
user = user.split('!', 1)[0]
|
||||
|
||||
# Private message
|
||||
if channel == self.nickname:
|
||||
if msg.startswith('!'):
|
||||
if msg[1:] == 'users':
|
||||
msg = "%s" % str(self.knownnicks)
|
||||
elif msg[1:] == 'nusers':
|
||||
msg = "%s" % str(len(self.knownnicks))
|
||||
elif msg[1:] == 'channels':
|
||||
msg = "%s" % str(self.knownchannels)
|
||||
elif msg[1:] == 'nchannels':
|
||||
msg = "%s" % str(len(self.knownchannels))
|
||||
elif msg[1:5] == 'join':
|
||||
chan = msg[6:]
|
||||
msg = "Joining %s..." % msg[6:]
|
||||
self.join(chan)
|
||||
elif msg[1:] == 'cnicks':
|
||||
msg = "%s" % str(self.cnicks)
|
||||
elif msg[1:] == 'vchannels':
|
||||
msg = "%s" % str(self.vchannels)
|
||||
elif msg[1:] == 'ichannels':
|
||||
msg = "%s" % str(self.inchannels)
|
||||
self.msg(user, msg)
|
||||
|
||||
#def lineReceived(self, line):
|
||||
#irc.IRCClient.lineReceived(self, line)
|
||||
#print line
|
||||
|
||||
class SwircBotFactory(protocol.ClientFactory):
|
||||
|
||||
protocol = SwircBot
|
||||
|
|
Loading…
Reference in a new issue