ayust / kitnirc

Python IRC bot framework.
MIT License
11 stars 7 forks source link

Bot never joins channel, ends up with broken pipe. #22

Closed flexd closed 10 years ago

flexd commented 10 years ago

I am having a weird issue where the bot just never joins the channel (autojoin contrib module never seems to do anything), and then after a while the bot is disconnected

~/code/yamcbot] (master●●) python main.py --loglevel INFO
INFO 2014-10-23 10:49:37,929 kitnirc.modular:0263 - Loaded the following modules: ['kitnirc.contrib.healthcheck', 'kitnirc.contrib.admintools', 'kitnirc.contrib.autojoin', 'kitnirc.contrib.commands', 'kitnirc.contrib.cron', 'modules.eve', 'modules.channel_control', 'modules.ruter']
INFO 2014-10-23 10:49:37,930 kitnirc.client:0197 - Adding event handler for new event REMOVECOMMAND.
INFO 2014-10-23 10:49:37,931 kitnirc.client:0197 - Adding event handler for new event ADDCOMMAND.
INFO 2014-10-23 10:49:37,931 kitnirc.client:0197 - Adding event handler for new event STARTUP.
INFO 2014-10-23 10:49:37,931 kitnirc.client:0197 - Adding event handler for new event NICK.
INFO 2014-10-23 10:49:37,931 kitnirc.client:0197 - Adding event handler for new event LIST_COMMANDS.
INFO 2014-10-23 10:49:37,931 kitnirc.client:0197 - Adding event handler for new event ADDCRON.
INFO 2014-10-23 10:49:37,932 kitnirc.client:0197 - Adding event handler for new event REMOVECRON.
INFO 2014-10-23 10:49:37,932 kitnirc.contrib.healthcheck:0061 - Healthcheck running: delay=60 timeout=90
INFO 2014-10-23 10:49:37,932 kitnirc.client:0197 - Adding event handler for new event CORPORATION.
INFO 2014-10-23 10:49:37,933 kitnirc.client:0197 - Adding event handler for new event COMMANDS.
INFO 2014-10-23 10:49:37,933 kitnirc.client:0197 - Adding event handler for new event SOLARSYSTEM.
INFO 2014-10-23 10:49:37,933 kitnirc.client:0197 - Adding event handler for new event TYPEINFO.
INFO 2014-10-23 10:49:37,933 kitnirc.client:0197 - Adding event handler for new event MARKETQUOTE.
INFO 2014-10-23 10:49:37,933 kitnirc.client:0197 - Adding event handler for new event RUTER.
INFO 2014-10-23 10:49:37,934 modules.eve:0034 - Registering commands...
INFO 2014-10-23 10:49:37,934 kitnirc.contrib.commands:0126 - Adding command 'jita' => 'MARKETQUOTE'.
INFO 2014-10-23 10:49:37,934 kitnirc.contrib.commands:0126 - Adding command 'typeid' => 'TYPEINFO'.
INFO 2014-10-23 10:49:37,934 kitnirc.contrib.commands:0126 - Adding command 'system' => 'SOLARSYSTEM'.
INFO 2014-10-23 10:49:37,934 kitnirc.contrib.commands:0126 - Adding command 'corporation' => 'CORPORATION'.
INFO 2014-10-23 10:49:37,934 kitnirc.contrib.commands:0126 - Adding command 'corp' => 'CORPORATION'.
INFO 2014-10-23 10:49:37,935 modules.ruter:0030 - Registering commands...
INFO 2014-10-23 10:49:37,935 kitnirc.contrib.commands:0126 - Adding command 'ruter' => 'RUTER'.
INFO 2014-10-23 10:49:37,935 kitnirc.contrib.commands:0126 - Adding command 'commands' => 'LIST_COMMANDS'.
INFO 2014-10-23 10:49:37,935 kitnirc.client:0250 - Connecting to irc.freenode.org as belt ...
INFO 2014-10-23 10:49:38,198 kitnirc.client:0263 - Connected to irc.freenode.org.
INFO 2014-10-23 10:49:38,199 kitnirc.client:0323 - Requesting nick change to 'belt'
INFO 2014-10-23 10:49:38,200 kitnirc.client:0335 - Requesting user info update: username=belt realname=belt
Exception in thread healthcheck:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run() 
  File "/usr/lib/python2.7/threading.py", line 505, in run                                                                                                                             
    self.__target(*self.__args, **self.__kwargs)
  File "/home/kristoffer/code/yamcbot/venv/local/lib/python2.7/site-packages/kitnirc/contrib/healthcheck.py", line 72, in loop                                                         
    self.controller.client.send("PING")                                                                                                                                                
  File "/home/kristoffer/code/yamcbot/venv/local/lib/python2.7/site-packages/kitnirc/client.py", line 319, in send                                                                     
    self.socket.send(msg + "\r\n")
error: [Errno 32] Broken pipe
flexd commented 10 years ago

Err, the bot does not handle nick collisions at all?

DEBUG 2014-10-23 10:54:10,746 kitnirc.client:0307 - irc.freenode.org --> :sendak.freenode.net 433 * belt :Nickname is already in use.
DEBUG 2014-10-23 10:54:31,359 kitnirc.client:0307 - irc.freenode.org --> ERROR :Closing Link: 178.62.227.240 (Connection timed out)
ayust commented 10 years ago

Currently no, I've been meaning to write a module to do that.

On Thu, Oct 23, 2014, 01:54 Kristoffer Berdal notifications@github.com wrote:

Err, the bot does not handle nick collisions at all?

DEBUG 2014-10-23 10:54:10,746 kitnirc.client:0307 - irc.freenode.org --> :sendak.freenode.net 433 * belt :Nickname is already in use.DEBUG 2014-10-23 10:54:31,359 kitnirc.client:0307 - irc.freenode.org --> ERROR :Closing Link: 178.62.227.240 (Connection timed out)

— Reply to this email directly or view it on GitHub https://github.com/ayust/kitnirc/issues/22#issuecomment-60210224.

flexd commented 10 years ago

I have quickly written a module that just appends a random number between 0-9 to the nick if it's already in use. Using the NICKNAMEINUSE event.

This should be working fine, but the even does not seem to fire, what could be wrong?

I see the bot gets a 433 from the server, and 433 -> NICKNAMEINUSE in the events.py file, so it should be working?

import logging

from kitnirc.modular import Module
from random import randint

_log = logging.getLogger(__name__)

class NickInUseModule(Module):
    """A KitnIRC module which adds a random number between 0-9
    if the configured nick is already in use"""

    @Module.handle("NICKNAMEINUSE")
    def nickname_in_use(self, client, *args):
        _log.info("THIS HAPPENS YO")
        oldnick = client.user.nick
        newnick = "{}{}".format(oldnick, randint(0,9))
        _log.info("{} is already in use, changing nick to {}".format(oldnick, newnick))
        client.nick(newnick)

module = NickInUseModule

There might be better ways of solving this (such as alternative nicks in the config, and then ending up doing this if all else fails), but this should at least solve the problem of the bot not joining any channels and the INFO logs not telling you anything at all.

flexd commented 10 years ago

Oh, right. No Parse for that. Sec, let me see if I can write one!

flexd commented 10 years ago

23 should be a okay-ish fix for now :-)

flexd commented 10 years ago

This was fixed in #23.