Rewritten to use callbacks, bit easier to use.

This commit is contained in:
tj
2010-01-06 19:32:35 +01:00
parent 455e0cd0dd
commit 7019ec3d0e
5 changed files with 181 additions and 296 deletions

View File

@@ -1,44 +1,19 @@
package main
import (
"irc";
"fmt";
"os";
"irc"
"fmt"
"os"
)
func main() {
events := make(chan *irc.IRCEvent, 100);
irccon, err := irc.IRC("irc.efnet.net:6667", "testgo", "testgo", events);
irccon := irc.IRC("testgo", "testgo")
err := irccon.Connect("irc.efnet.net:6667")
if err != nil {
fmt.Printf("%s\n", err);
fmt.Printf("%#v\n", irccon);
os.Exit(1);
}
for {
event := <-events;
/* switch event.Code {
case UNKNOWN:
fmt.Printf("%#v\n", event)
case 0:
fmt.Printf("%#v\n", event)
case IRC_PRIVMSG:
fmt.Printf("%#v\n", event)
case IRC_CHAN_TOPIC:
fmt.Printf("%#v\n", event)
case IRC_CHAN_MODE:
fmt.Printf("%#v\n", event)
case IRC_ACTION:
fmt.Printf("%#v\n", event)
case IRC_WELCOME:
irc.Join("#ggpre")
}*/
if event.Code == irc.IRC_WELCOME {
irccon.Join("#gotestchan")
} else if event.Code == irc.IRC_PRIVMSG {
if event.Message == "!test" {
irccon.Privmsg(event.Target, "Whatever man!");
}
}
fmt.Printf("%#v\n", event);
fmt.Printf("%s\n", err)
fmt.Printf("%#v\n", irccon)
os.Exit(1)
}
irccon.AddCallback("001", func(e *irc.IRCEvent) { irccon.Join("#testgo") })
irccon.Loop();
}