Move USER, NICK to right after connecting

This commit is contained in:
tj 2009-11-19 04:37:56 +01:00
parent 6f212340c5
commit f9ea765794

12
irc.go
View File

@ -30,7 +30,6 @@ func writer(irc *IRCConnection) {
for { for {
b := strings.Bytes(<-irc.pwrite); b := strings.Bytes(<-irc.pwrite);
_, err := irc.socket.Write(b); _, err := irc.socket.Write(b);
fmt.Printf("<-- %s", b);
if err != nil { if err != nil {
irc.perror <- err irc.perror <- err
} }
@ -149,7 +148,8 @@ func (irc *IRCConnection) handle_command(msg string) *IRCEvent {
case "ERROR": case "ERROR":
e.Code = IRC_PING; e.Code = IRC_PING;
e.Message = matches[2]; e.Message = matches[2];
e.Error = os.ErrorString(matches[2]);; e.Error = os.ErrorString(matches[2]);
;
irc.perror <- e.Error; irc.perror <- e.Error;
} }
return e; return e;
@ -162,17 +162,13 @@ func (irc *IRCConnection) handle_command(msg string) *IRCEvent {
func handler(irc *IRCConnection) { func handler(irc *IRCConnection) {
go reader(irc); go reader(irc);
go writer(irc); go writer(irc);
irc.pwrite <- fmt.Sprintf("NICK %s\r\n", irc.nick);
irc.pwrite <- fmt.Sprintf("USER %s 0.0.0.0 0.0.0.0 :GolangBOT\r\n", irc.user);
for { for {
select { select {
case msg := <-irc.pread: case msg := <-irc.pread:
e := irc.handle_command(msg); e := irc.handle_command(msg);
switch e.Code { switch e.Code {
case IRC_NOTICE_AUTH:
if irc.registered == false {
irc.pwrite <- fmt.Sprintf("NICK %s\r\n", irc.nick);
irc.pwrite <- fmt.Sprintf("USER %s 0.0.0.0 0.0.0.0 :GolangBOT\r\n", irc.user);
irc.registered = true;
}
case IRC_PING: case IRC_PING:
irc.pwrite <- fmt.Sprintf("PONG %s\r\n", e.Message) irc.pwrite <- fmt.Sprintf("PONG %s\r\n", e.Message)
case IRC_PRIVMSG: case IRC_PRIVMSG: