# HG changeset patch # User prologic # Date 1313186385 -36000 # Node ID 17666b8f7f6d7eed3d16a720085179a132d9713f # Parent 76fbbe75d2d8cd988b41067a000d5cc651ea4b31 Added modified example of ircbot that demonstrates multiple client connections diff -r 76fbbe75d2d8cd988b41067a000d5cc651ea4b31 -r 17666b8f7f6d7eed3d16a720085179a132d9713f examples/multi_ircbot.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/multi_ircbot.py Sat Aug 13 07:59:45 2011 +1000 @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +from circuits import Component, Debugger, Manager +from circuits.net.sockets import TCPClient, Connect +from circuits.net.protocols.irc import IRC, PRIVMSG, USER, NICK, JOIN + +from circuits.net.protocols.irc import ERR_NICKNAMEINUSE +from circuits.net.protocols.irc import RPL_ENDOFMOTD, ERR_NOMOTD + +class Bot(Component): + + channel = "ircbot" + + def __init__(self, host, port=6667, channel=channel): + super(Bot, self).__init__(channel=channel) + + self._host = host + self._port = port + + self += TCPClient(channel=self.channel) + IRC(channel=self.channel) + + def ready(self, component): + self.fire(Connect(self._host, self._port)) + + def connected(self, host, port): + self.fire(USER("circuits", host, host, "Test circuits IRC Bot")) + self.fire(NICK("circuits")) + + def numeric(self, source, target, numeric, args, message): + if numeric == ERR_NICKNAMEINUSE: + self.fire(NICK("%s_" % args)) + if numeric in (RPL_ENDOFMOTD, ERR_NOMOTD): + self.fire(JOIN("#circuits")) + + def message(self, source, target, message): + self.fire(PRIVMSG(source[0], message)) + +m = Manager() + Debugger() +Bot("irc.freenode.net", channel="1").register(m) +Bot("irc.freenode.net", channel="2").register(m) +m.run()