irc-config.go (849B)
1 package main 2 3 import ( 4 "crypto/tls" 5 "fmt" 6 7 "github.com/go-irc/irc" 8 ) 9 10 func GetIRCConfig() irc.ClientConfig { 11 IRC_NICK, IRC_PASS, IRC_USER, IRC_NAME := GetIRCEnvVars() 12 ircConfig := irc.ClientConfig{ 13 Nick: IRC_NICK, 14 Pass: IRC_PASS, 15 User: IRC_USER, 16 Name: IRC_NAME, 17 Handler: irc.HandlerFunc(Handler), 18 } 19 return ircConfig 20 } 21 22 func GetIRCClient(conn *tls.Conn) *irc.Client { 23 ircConfig := GetIRCConfig() // IRC configuration 24 client := irc.NewClient(conn, ircConfig) // Create IRC Client 25 return client 26 } 27 28 func Handler(c *irc.Client, m *irc.Message) { 29 if m.Command == "001" { 30 JoinChannels(c) 31 } else if m.Command == "PRIVMSG" { 32 from, to, msg := GetMsgDetails(m) 33 if IsPM(to) { 34 HandlePM(msg, from) 35 } else { 36 fmt.Println(msg, from, to) 37 } 38 } else if m.Command == "ERROR" { 39 InformErrAndQuit(c, m) 40 } 41 }