Skip to content

Instantly share code, notes, and snippets.

@kaimallea
Created August 3, 2011 14:59
Show Gist options
  • Save kaimallea/1122835 to your computer and use it in GitHub Desktop.
Save kaimallea/1122835 to your computer and use it in GitHub Desktop.
Useless IRC bot
package main
import (
"fmt"
"net/textproto"
"regexp"
)
var (
ping = regexp.MustCompile("^PING :([a-zA-Z0-9\\.]+)$")
motd = regexp.MustCompile(":End of /MOTD command\\.$")
)
func main() {
c, err := textproto.Dial("tcp", "chat.freenode.net:6667")
if err != nil {
fmt.Printf("%s", err)
return
}
defer c.Close()
c.Cmd("NICK KaiBot\n\rUSER kaibot 8 * :KaiBot")
for {
text, err := c.ReadLine()
if err != nil {
fmt.Printf("%s", err)
return
}
fmt.Println(text)
if match := ping.FindStringSubmatch(text); match != nil {
c.Cmd("PONG :" + match[1])
fmt.Printf("PONG :%s\n", match[1])
}
if match := motd.FindString(text); match != "" {
c.Cmd("JOIN #KaiBot")
fmt.Println("JOIN #KaiBot")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment