ayust / kitnirc

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

Authentication module #2

Open ghost opened 10 years ago

ghost commented 10 years ago

I don't know how much you would like to to have built in but a standard authentication module might be a good idea.

The one I wrote is a bit premature. I had a section in the config file for each host which contained nicks and passwords.

[irc.freenode.net]
nick = foo
nick_password = bar

[irc.geekshed.net]
nick = oof
nick_pasword = rab

The module could look something like this

class NickToolsModule(Module):
    """A KitnIRC module which automatically configures nick.  """

    @Module.handle("WELCOME")
    def register_nick(self, client, hostmask):

        _log.info("Beginning automatic nick configuration...")

        host = client.server.host
        if self.controller.config.has_option(str(host), "nick"):
            nick = self.controller.config.get(str(host), "nick")
            client.nick(nick)
        if self.controller.config.has_option(str(host), "nick_password"):
            nick_password = self.controller.config.get(str(host), "nick_password")
            client.msg("NickServ", "IDENTIFY {}".format(nick_password))

        _log.info("Automatic nick configuration complete.")
ayust commented 10 years ago

Authentication tends to vary from server to server. While there are definitely patterns, there's no one standard; as such I've mostly been leaning towards putting authentication functionality in network-specific utility modules (e.g. kitnirc.contrib.freenode and kitnirc.contrib.foonetic).

That said, a generic "nickserv" module might not go amiss as another alternative for contrib/ - it'd cover cases where there isn't already a network-specific utility module, and while it wouldn't work for every network, it'd work for a lot of them.

ghost commented 10 years ago

If you were to implement the nickserv module how would implement the configs?

The following seams to fit with the existing code.

[nickserv]
nick@server = password
ayust commented 10 years ago

The configs typically don't specify server, because the way they're laid out is usually for a single server (i.e. you'd have one config per network and run a separate instance of the bot per network you wanted it on). As such, it'd probably be more like...

[nickserv]
nick = BottyMcBotters
password = hunter2

nick could potentially be optional (and just result in a /msg nickserv identify no matter what the current nick was).