Created
March 1, 2014 16:14
-
-
Save bloodywing/9292094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from circuits import Component, Debugger | |
from circuits.core.events import started | |
from circuits.net.sockets import TCPClient | |
from circuits.net.events import connect | |
from circuits.protocols.irc import IRC, PRIVMSG, USER, NICK, JOIN | |
from circuits.protocols.irc import ERR_NICKNAMEINUSE, RPL_ENDOFMOTD, ERR_NOMOTD | |
class Bot(Component): | |
channel = "ircbot" | |
def init(self, host, port=6667, channel=channel): | |
self.port = port | |
self.host = host | |
TCPClient(channel=channel).register(self) | |
IRC(channel=channel).register(self) | |
def ready(self, component): | |
self.fire(connect(self.host, self.port)) | |
def connected(self, host, port): | |
self.fire(USER("circuitsbot", host, host, "Bloodys Circuits Bot")) | |
self.fire(NICK("circuitsbot")) | |
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("#bloodysbot")) | |
def message(self, source, target, message): | |
self.fire(PRIVMSG(source[0], message.swapcase())) | |
bot = Bot("tiger.irc.bakashimoe.me") | |
(bot + Debugger()).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment