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) {
|
func command(conn *irc.Conn, nick, text, target string) {
|
||||||
if !strings.HasPrefix(text, trigger) {
|
if !strings.HasPrefix(text, trigger) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -6,6 +6,7 @@ server: irc.rizon.net
|
||||||
nick: rbot
|
nick: rbot
|
||||||
user: rbot
|
user: rbot
|
||||||
ssl: true
|
ssl: true
|
||||||
|
nickserv: identify_password
|
||||||
autoconnect: true
|
autoconnect: true
|
||||||
|
|
||||||
[Rizon #raylu]
|
[Rizon #raylu]
|
||||||
|
|
54
rbot.go
54
rbot.go
|
@ -10,52 +10,53 @@ import (
|
||||||
|
|
||||||
var trigger string
|
var trigger string
|
||||||
var sections []string
|
var sections []string
|
||||||
|
var conf *config.Config
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
conf, err := config.ReadDefault("rbot.conf")
|
var err os.Error;
|
||||||
|
conf, err = config.ReadDefault("rbot.conf")
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
fmt.Printf("Config error: %s\n", err)
|
fmt.Printf("Config error: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger = readConfString(conf, "DEFAULT", "trigger")
|
trigger = readConfString("DEFAULT", "trigger")
|
||||||
|
|
||||||
sections = conf.Sections()
|
sections = conf.Sections()
|
||||||
for _, s := range sections {
|
for _, s := range sections {
|
||||||
if strings.Index(s, " ") == -1 && s != "DEFAULT" {
|
if strings.Index(s, " ") == -1 && s != "DEFAULT" {
|
||||||
// found a network
|
// found a network
|
||||||
go connect(conf, s)
|
go connect(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<- make(chan bool)
|
<- make(chan bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(conf *config.Config, network string) {
|
func connect(network string) {
|
||||||
if !readConfBool(conf, network, "autoconnect") {
|
if !readConfBool(network, "autoconnect") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
server := readConfString(conf, network, "server")
|
server := readConfString(network, "server")
|
||||||
nick := readConfString(conf, network, "nick")
|
nick := readConfString(network, "nick")
|
||||||
user := readConfString(conf, network, "user")
|
user := readConfString(network, "user")
|
||||||
ssl := readConfBool(conf, network, "ssl")
|
ssl := readConfBool(network, "ssl")
|
||||||
|
nickserv, _ := conf.String(network, "nickserv")
|
||||||
|
|
||||||
c := irc.New(nick, user, user)
|
c := irc.New(nick, user, user)
|
||||||
|
c.Network = network
|
||||||
c.AddHandler("connected",
|
c.AddHandler("connected",
|
||||||
func(conn *irc.Conn, line *irc.Line) {
|
func(conn *irc.Conn, line *irc.Line) {
|
||||||
fmt.Printf("Connected to %s!\n", conn.Host)
|
fmt.Printf("Connected to %s!\n", conn.Host)
|
||||||
for _, s := range sections {
|
|
||||||
split := strings.Split(s, " ", 2)
|
if len(nickserv) > 0 {
|
||||||
if len(split) == 2 && split[0] == network {
|
conn.Privmsg("NickServ", "IDENTIFY " + nickserv)
|
||||||
// found a channel
|
} else {
|
||||||
if readConfBool(conf, s, "autojoin") {
|
autojoin(conn)
|
||||||
fmt.Printf("Joining %s on %s\n", split[1], network)
|
|
||||||
conn.Join(split[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
c.AddHandler("privmsg", handlePrivmsg)
|
c.AddHandler("privmsg", handlePrivmsg)
|
||||||
|
c.AddHandler("mode", handleMode)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Printf("Connecting to %s...\n", server)
|
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)
|
value, err := conf.String(section, option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Config error: %s", err));
|
panic(fmt.Sprintf("Config error: %s", err));
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
func readConfBool(conf *config.Config, section, option string) bool {
|
func readConfBool(section, option string) bool {
|
||||||
value, err := conf.Bool(section, option)
|
value, err := conf.Bool(section, option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Config error: %s", err));
|
panic(fmt.Sprintf("Config error: %s", err));
|
||||||
|
|
Loading…
Reference in New Issue