Skip to content

Instantly share code, notes, and snippets.

@prologic
Created June 15, 2014 05:59
Show Gist options
  • Save prologic/c2c6670f8d23b29f268b to your computer and use it in GitHub Desktop.
Save prologic/c2c6670f8d23b29f268b to your computer and use it in GitHub Desktop.
Simple IRC BOt
from circuits import Component
from circuits.net.sockets import TCPClient, connect
from circuits.protocols.irc import IRC, PRIVMSG, USER, NICK, JOIN
from circuits.protocols.irc import ERR_NICKNAMEINUSE
from circuits.protocols.irc import RPL_ENDOFMOTD, ERR_NOMOTD
class Bot(Component):
def init(self, host, port=6667):
self.host = host
self.port = port
TCPClient(channel=self.channel).register(self)
IRC(channel=self.channel).register(self)
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):
tokens = message.lower().split()
if tokens and tokens[0] == "hello":
self.fire(PRIVMSG(source[0], "Hello!"))
else:
self.fire(PRIVMSG(source[0], "Unknown Command!"))
def main():
Bot("irc.freenode.net").run()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment