Created
May 19, 2014 03:06
-
-
Save prologic/d11b6f1cc74368a5c6f8 to your computer and use it in GitHub Desktop.
Pico IRC Bot using circuits in 24 Lines of Code.
This file contains hidden or 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 | |
| from circuits.net.sockets import TCPClient, connect | |
| from circuits.net.protocols.irc import IRC, PRIVMSG, USER, NICK, JOIN, RPL_ENDOFMOTD, ERR_NOMOTD # noqa | |
| class PBot(Component): | |
| def init(self, host, port=6667): | |
| self.target = (host, port) | |
| self += (TCPClient() + IRC()) | |
| def ready(self, *args): | |
| self.fire(connect(*self.target)) | |
| def connected(self, host, port): | |
| self.fire(USER("pbot", self.target[0], self.target[1], "pbot")) | |
| self.fire(NICK("pbot")) | |
| def numeric(self, source, target, numeric, args, message): | |
| if numeric in (RPL_ENDOFMOTD, ERR_NOMOTD): | |
| self.fire(JOIN("#circuits")) | |
| self.fire(PRIVMSG("#circuits", "Hello World!")) | |
| PBot("irc.freenode.net").run() |
Author
Author
Upon further review of the article this gist is challenging, I notice that there are a few bugs off the bat.
connectedis never set toTrue- The 19 loc bot will fail miserably on imperfect server responses.
- The 19 loc bot will likely not succeed in connecting or joining the channel due to various edge cases.
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is in response to Python: IRC client in 19 lines which I can't beat in circuits but nevertheless 24 Lines of Code is still pretty good for a framework like circuits.
Enjoy!