mirror of https://github.com/fluffle/goirc
Add nickserv autoidentify
This also waits until identified before autojoining Unfortunately, testing for the +r mode to mean registered is network- specific. This happens to work on Rizon but not on Freenode, for example
This commit is contained in:
parent
90a5268dfa
commit
283f03a108
|
@ -28,6 +28,12 @@ func handlePrivmsg(conn *irc.Conn, line *irc.Line) {
|
|||
}
|
||||
}
|
||||
|
||||
func handleMode(conn *irc.Conn, line *irc.Line) {
|
||||
if line.Args[0] == conn.Me.Nick && line.Text == "+r" {
|
||||
autojoin(conn)
|
||||
}
|
||||
}
|
||||
|
||||
func command(conn *irc.Conn, nick, text, target string) {
|
||||
if !strings.HasPrefix(text, trigger) {
|
||||
return
|
||||
|
|
|
@ -6,6 +6,7 @@ server: irc.rizon.net
|
|||
nick: rbot
|
||||
user: rbot
|
||||
ssl: true
|
||||
nickserv: identify_password
|
||||
autoconnect: true
|
||||
|
||||
[Rizon #raylu]
|
||||
|
|
54
rbot.go
54
rbot.go
|
@ -10,52 +10,53 @@ import (
|
|||
|
||||
var trigger string
|
||||
var sections []string
|
||||
var conf *config.Config
|
||||
|
||||
func main() {
|
||||
conf, err := config.ReadDefault("rbot.conf")
|
||||
var err os.Error;
|
||||
conf, err = config.ReadDefault("rbot.conf")
|
||||
if (err != nil) {
|
||||
fmt.Printf("Config error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
trigger = readConfString(conf, "DEFAULT", "trigger")
|
||||
trigger = readConfString("DEFAULT", "trigger")
|
||||
|
||||
sections = conf.Sections()
|
||||
for _, s := range sections {
|
||||
if strings.Index(s, " ") == -1 && s != "DEFAULT" {
|
||||
// found a network
|
||||
go connect(conf, s)
|
||||
go connect(s)
|
||||
}
|
||||
}
|
||||
|
||||
<- make(chan bool)
|
||||
}
|
||||
|
||||
func connect(conf *config.Config, network string) {
|
||||
if !readConfBool(conf, network, "autoconnect") {
|
||||
func connect(network string) {
|
||||
if !readConfBool(network, "autoconnect") {
|
||||
return
|
||||
}
|
||||
server := readConfString(conf, network, "server")
|
||||
nick := readConfString(conf, network, "nick")
|
||||
user := readConfString(conf, network, "user")
|
||||
ssl := readConfBool(conf, network, "ssl")
|
||||
server := readConfString(network, "server")
|
||||
nick := readConfString(network, "nick")
|
||||
user := readConfString(network, "user")
|
||||
ssl := readConfBool(network, "ssl")
|
||||
nickserv, _ := conf.String(network, "nickserv")
|
||||
|
||||
c := irc.New(nick, user, user)
|
||||
c.Network = network
|
||||
c.AddHandler("connected",
|
||||
func(conn *irc.Conn, line *irc.Line) {
|
||||
fmt.Printf("Connected to %s!\n", conn.Host)
|
||||
for _, s := range sections {
|
||||
split := strings.Split(s, " ", 2)
|
||||
if len(split) == 2 && split[0] == network {
|
||||
// found a channel
|
||||
if readConfBool(conf, s, "autojoin") {
|
||||
fmt.Printf("Joining %s on %s\n", split[1], network)
|
||||
conn.Join(split[1])
|
||||
}
|
||||
}
|
||||
|
||||
if len(nickserv) > 0 {
|
||||
conn.Privmsg("NickServ", "IDENTIFY " + nickserv)
|
||||
} else {
|
||||
autojoin(conn)
|
||||
}
|
||||
})
|
||||
c.AddHandler("privmsg", handlePrivmsg)
|
||||
c.AddHandler("mode", handleMode)
|
||||
|
||||
for {
|
||||
fmt.Printf("Connecting to %s...\n", server)
|
||||
|
@ -69,14 +70,27 @@ func connect(conf *config.Config, network string) {
|
|||
}
|
||||
}
|
||||
|
||||
func readConfString(conf *config.Config, section, option string) string {
|
||||
func autojoin(conn *irc.Conn) {
|
||||
for _, s := range sections {
|
||||
split := strings.Split(s, " ", 2)
|
||||
if len(split) == 2 && split[0] == conn.Network {
|
||||
// found a channel
|
||||
if readConfBool(s, "autojoin") {
|
||||
fmt.Printf("Joining %s on %s\n", split[1], conn.Network)
|
||||
conn.Join(split[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func readConfString(section, option string) string {
|
||||
value, err := conf.String(section, option)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Config error: %s", err));
|
||||
}
|
||||
return value
|
||||
}
|
||||
func readConfBool(conf *config.Config, section, option string) bool {
|
||||
func readConfBool(section, option string) bool {
|
||||
value, err := conf.Bool(section, option)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Config error: %s", err));
|
||||
|
|
Loading…
Reference in New Issue