我在哪里错了。据我所知,这应该有用。
import socket, string
#some user data, change as per your taste
SERVER = 'irc.freenode.net'
PORT = 6667
NICKNAME = 'echoquote'
CHANNEL = '#python'
PASSWORD = 'nope'
import time
#open a socket to handle the connection
IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#open a connection with the server
def irc_conn():
IRC.connect((SERVER, PORT))
#simple function to send data through the socket
def send_data(command):
IRC.send(command + '\n')
#join the channel
def join(channel):
send_data("JOIN %s" % channel)
#send login data (customizable)
def login(nickname, username='user', password = None, realname='Pythonist', hostname='Helena', servername='Server'):
send_data("USER %s %s %s %s" % (username, hostname, servername, realname))
send_data("NICK " + nickname)
send_data("nickserv identify %s %s\r\n" % (NICKNAME, PASSWORD))
time.sleep(3)
irc_conn()
login(NICKNAME)
join(CHANNEL)
while (1):
buffer = IRC.recv(1024)
msg = string.split(buffer)
message = ' '.join(msg[3:])
message = ''.join([x for x in message if x in string.printable])
if message:
print message + '\n'
if msg[0] == "PING": #check if server have sent ping command
send_data("PONG %s" % msg[1]) #answer with pong as per RFC 1459
if msg [1] == 'PRIVMSG' and msg[2] == NICKNAME:
filetxt = open('/tmp/msg.txt', 'a+') #open an arbitrary file to store the messages
nick_name = msg[0][:string.find(msg[0],"!")] #if a private message is sent to you catch it
message = ' '.join(msg[3:])
filetxt.write(string.lstrip(nick_name, ':') + ' -> ' + string.lstrip(message, ':') + '\n') #write to the file
filetxt.flush() #don't wait for next message, write it now!
答案 0 :(得分:0)
var d: domain(1) = {1..5};
writeln( d ); // SET {1..5}
// {1..5}
var e: domain(1) = d.expand(1);
writeln( e ); // OK, DOMAIN d == {1..5} EXTENDED ON BOTH ENDS INTO {0..6}
// {0..6}
var AonD: [d] int;
AonD.push_back(1);
writeln( AonD.domain ); // OK, DOMAIN EXTENDED INDIRECTLY ON DESIRED END INTO {1..6}
// {1..6}
// var f: domain(1) = {1..5}; // NEW {1..5} - A NON-SHARED, NON-USED ( NON-MAPPED ) DOMAIN
// f.add(6); // FAILS v/s A PROMISE IN: http://chapel.cray.com/docs/master/builtins/internal/ChapelArray.html#ChapelArray.add
// f += 6; // FAILS
// writeln( f );
IRC中没有 send_data("nickserv identify %s %s\r\n" % (NICKNAME, PASSWORD))
命令。这是某些IRC客户端中的别名,它所做的就是向NickServ发送私人消息。 Read the IRC specification,并停止重新发明轮子 - 使用现有的IRC库,例如。 twisted.words,或现有的IRC bot解决方案。