Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "net"
- "bufio"
- "strings"
- "os"
- )
- func send(conn net.Conn, message string) {
- fmt.Println("> ", message)
- fmt.Fprintf(conn, message)
- }
- func read(conn net.Conn) string {
- fmt.Println("DBG: reading from server...")
- response, err := bufio.NewReader(conn).ReadString('\n')
- if err != nil {
- fmt.Println("oopsies! Error reading from server! Bailing out")
- os.Exit(1)
- }
- fmt.Println("< ", response)
- return response
- }
- func privmsg(conn net.Conn, channel string, msg string) {
- send(conn, "PRIVMSG "+channel+" "+":"+msg+"\r\n")
- }
- func handle_privmsg(conn net.Conn, words []string) {
- //:prgnick!prg@64552A1E:E6FF1A33:696E1BF9:IP PRIVMSG #testchan :thought it would be harder
- //userblock := words[0]
- channel := words[2]
- msg := strings.Join(words[3:], " ")
- if(strings.Contains(strings.ToUpper(msg), "PING")) {
- privmsg(conn, channel, "Pong, mother fuckers..")
- }
- }
- func main() {
- fmt.Println("This is pre-alpha software. USE AT YOUR OWN RISK!")
- fmt.Println("Bot initializing...")
- const nick = "super_testbot123"
- const user = nick
- const fullname = "Test bot"
- const server = "irc.whatever.net"
- const port = "6667"
- conn, err := net.Dial("tcp", server + ":" + port)
- if err != nil {
- fmt.Println("Oopsies! Failed to connect to the server!")
- }
- read(conn)
- nick_msg := "NICK " + nick + "\r\n"
- send(conn, nick_msg)
- usr_msg := "USER " + user + " * * :" + fullname + "\r\n"
- send(conn, usr_msg)
- for {
- in_msg := read(conn)
- words := strings.Split(in_msg, " ")
- if(words[0] == "PING") {
- pong_msg := "PONG " + strings.Split(in_msg, " ")[1] + "\r\n"
- send(conn, pong_msg)
- }
- if(words[1] == "PRIVMSG") {
- handle_privmsg(conn, words)
- }
- }
- fmt.Println("Terminating gobot!")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement