Created
August 3, 2011 14:59
-
-
Save kaimallea/1122835 to your computer and use it in GitHub Desktop.
Useless IRC bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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