mirror of
https://github.com/fluffle/goirc
synced 2025-09-06 00:43:20 +00:00
reformat source with gofmt to nuke all of those unneeded semicolons
This commit is contained in:
parent
1c31d5fb47
commit
ae8e34ff0e
6 changed files with 474 additions and 477 deletions
75
client.go
75
client.go
|
@ -1,73 +1,70 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./irc/_obj/irc";
|
||||
"fmt";
|
||||
"os";
|
||||
"bufio";
|
||||
"strings";
|
||||
"./irc/_obj/irc"
|
||||
"fmt"
|
||||
"os"
|
||||
"bufio"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// create new IRC connection
|
||||
c := irc.New("GoTest", "gotest", "GoBot");
|
||||
c := irc.New("GoTest", "gotest", "GoBot")
|
||||
c.AddHandler("connected",
|
||||
func(conn *irc.Conn, line *irc.Line) {
|
||||
conn.Join("#go-lang");
|
||||
}
|
||||
);
|
||||
func(conn *irc.Conn, line *irc.Line) { conn.Join("#go-nuts") })
|
||||
|
||||
// connect to server
|
||||
if err := c.Connect("irc.freenode.net", ""); err != nil {
|
||||
fmt.Printf("Connection error: %s\n", err);
|
||||
return;
|
||||
fmt.Printf("Connection error: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// set up a goroutine to read commands from stdin
|
||||
in := make(chan string, 4);
|
||||
reallyquit := false;
|
||||
in := make(chan string, 4)
|
||||
reallyquit := false
|
||||
go func() {
|
||||
con := bufio.NewReader(os.Stdin);
|
||||
con := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
s, err := con.ReadString('\n');
|
||||
s, err := con.ReadString('\n')
|
||||
if err != nil {
|
||||
// wha?, maybe ctrl-D...
|
||||
close(in);
|
||||
break;
|
||||
close(in)
|
||||
break
|
||||
}
|
||||
// no point in sending empty lines down the channel
|
||||
if len(s) > 2 {
|
||||
in <- s[0:len(s)-1]
|
||||
}
|
||||
}
|
||||
}();
|
||||
}()
|
||||
|
||||
// set up a goroutine to do parsey things with the stuff from stdin
|
||||
go func() {
|
||||
for {
|
||||
if closed(in) {
|
||||
break;
|
||||
break
|
||||
}
|
||||
cmd := <-in;
|
||||
cmd := <-in
|
||||
if cmd[0] == ':' {
|
||||
switch idx := strings.Index(cmd, " "); {
|
||||
case idx == -1:
|
||||
continue;
|
||||
case cmd[1] == 'q':
|
||||
reallyquit = true;
|
||||
c.Quit(cmd[idx+1:len(cmd)]);
|
||||
case cmd[1] == 'j':
|
||||
c.Join(cmd[idx+1:len(cmd)]);
|
||||
case cmd[1] == 'p':
|
||||
c.Part(cmd[idx+1:len(cmd)]);
|
||||
case cmd[1] == 'd':
|
||||
fmt.Printf(c.String());
|
||||
case idx == -1:
|
||||
continue
|
||||
case cmd[1] == 'q':
|
||||
reallyquit = true
|
||||
c.Quit(cmd[idx+1 : len(cmd)])
|
||||
case cmd[1] == 'j':
|
||||
c.Join(cmd[idx+1 : len(cmd)])
|
||||
case cmd[1] == 'p':
|
||||
c.Part(cmd[idx+1 : len(cmd)])
|
||||
case cmd[1] == 'd':
|
||||
fmt.Printf(c.String())
|
||||
}
|
||||
} else {
|
||||
c.Raw(cmd)
|
||||
}
|
||||
}
|
||||
}();
|
||||
}()
|
||||
|
||||
// stall here waiting for asplode on error channel
|
||||
for {
|
||||
|
@ -76,17 +73,17 @@ func main() {
|
|||
// server for some reason (e.g. quit, kill or ping timeout)
|
||||
// if we don't really want to quit, reconnect!
|
||||
if !reallyquit {
|
||||
fmt.Println("Reconnecting...");
|
||||
fmt.Println("Reconnecting...")
|
||||
if err := c.Connect("irc.freenode.net", ""); err != nil {
|
||||
fmt.Printf("Connection error: %s\n", err);
|
||||
break;
|
||||
fmt.Printf("Connection error: %s\n", err)
|
||||
break
|
||||
}
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
break;
|
||||
break
|
||||
}
|
||||
if err := <-c.Err; err != nil {
|
||||
fmt.Printf("goirc error: %s\n", err);
|
||||
fmt.Printf("goirc error: %s\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue