Created
December 8, 2011 17:19
-
-
Save ryoco/1447688 to your computer and use it in GitHub Desktop.
only join irc ,write a message and leave
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import socket, string | |
import codecs, sys | |
SERVER = sys.argv[1] | |
PORT = int(sys.argv[2]) | |
PASS = sys.argv[3] | |
NICKNAME = sys.argv[4] | |
CHANNEL = "#%s" % sys.argv[5] | |
ENCODING = "utf-8" | |
ircserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
def connection(): | |
ircserver.connect((SERVER, PORT)) | |
def send_data(command): | |
ircserver.send(command + "\n") | |
def join(channel): | |
send_data("JOIN %s" % channel) | |
def login(hostname="0", servername="*", realname=NICKNAME): | |
send_data("PASS " + PASS) | |
send_data("USER %s %s %s %s" % (NICKNAME, hostname, servername, realname)) | |
send_data("NICK " + NICKNAME) | |
if __name__ == "__main__": | |
if len(sys.argv) < 7: | |
print "usaeg -- python ircconnect.py hostname port password nickname channel message" | |
else: | |
connection() | |
login() | |
join(CHANNEL) | |
while(1): | |
buf = ircserver.recv(4096) | |
msg = string.split(buf) | |
if "JOIN" in msg: | |
message = unicode(sys.argv[6],ENCODING) | |
data = u"PRIVMSG %s :%s" % (unicode(CHANNEL, ENCODING), message) | |
send_data(data.encode(ENCODING)) | |
ircserver.shutdown(socket.SHUT_RDWR) | |
break | |
elif "ERROR" in msg: | |
print msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use with cron etc.