Last active
October 2, 2015 16:03
-
-
Save cabrinha/8db727e057d904e63271 to your computer and use it in GitHub Desktop.
yet another irc bot, in Python!
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
| #!/usr/bin/env python | |
| import socket | |
| irc_host = "chat.freenode.net" | |
| irc_port = 6667 | |
| irc_nick = "alister" | |
| irc_chan = "##bikes" | |
| ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| def ping(): | |
| ircsock.send("PONG :pingis\n") | |
| def sendmsg(chan, msg): | |
| ircsock.send("PRIVMSG "+ irc_chan +" :"+ msg + "\n") | |
| def joinchan(chan): | |
| ircsock.send("JOIN "+ irc_chan +"\n") | |
| def hello(newnick): | |
| ircsock.send("PRIVMSG "+ irc_chan +" Hello!\n") | |
| ircsock.connect((irc_host,irc_port)) | |
| ircsock.send("USER %s * * :%s \r\n" % ("alister", "alister")) | |
| ircsock.send("NICK %s \r\n" % ("alister")) | |
| joinchan(irc_chan) | |
| while 1: | |
| ircmsg = ircsock.recv(2048) | |
| ircmsg = ircmsg.strip('\r\n') | |
| print(ircmsg) | |
| if ircmsg.find(":Hello "+ irc_nick) != -1: | |
| hello() | |
| if ircmsg.find("PING :"): | |
| ping() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment