about summary refs log tree commit diff stats
path: root/main.go
blob: a865c47bab0d791768aaca5c10fd74b9df08e869 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main

import (
	"crypto/tls"
	"log"
	"net"

	"gopkg.in/irc.v3"
)

func setConfs() (bool, irc.ClientConfig, tls.Config) {
	//set this to false if you need
	useTLS := true

	// set all the necessities
	// also specifies the initial channel
	// to join
	config := irc.ClientConfig{
		Nick: "goofbot",
		Pass: "password",
		User: "goofbot",
		Name: "Goofus McBot",
		Handler: irc.HandlerFunc(func(c *irc.Client, m *irc.Message) {
			if m.Command == "001" {
				// 001 = welcome
				c.Write("JOIN #institute") //initial channel join
			} else if m.Command == "PRIVMSG" && c.FromChannel(m) {
				c.WriteMessage(&irc.Message{
					Command: "PRIVMSG",
					Params: []string{
						m.Params[0],
						m.Trailing(),
					},
				})
			}
		}),
	}

	// set up the tls params for the connection
	// see: https://golang.org/pkg/crypto/tls/#Config
	tlsconfig := tls.Config{
		InsecureSkipVerify:       false, //set to true if you want to be dumb
		RootCAs:                  nil,   //use the OS's root CAs
		PreferServerCipherSuites: true,  //use the server's cipher list
	}
	return useTLS, config, tlsconfig
}

func main() {
	useTLS, config, tlsconfig := setConfs()

	switch useTLS {
	case true:
		conn, err := tls.Dial("tcp", "irc.tilde.chat:6697", &tlsconfig)
	case false:
		conn, err := net.Dial("tcp", "irc.tilde.chat:6667")
	}
	if err != nil {
		log.Fatalln(err)
	}

	// create the connection
	client := irc.NewClient(conn, config)
	err = client.Run()
	if err != nil {
		log.Fatalln(err)
	}
}