Add default callback for ERROR

This commit is contained in:
Thomas Jager 2014-06-18 15:58:18 +02:00
parent 9909b5a3d3
commit 14db1acfd0

View File

@ -10,7 +10,6 @@ import (
"time"
)
// Register a callback to a connection and event code. A callback is a function
// which takes only an Event pointer as parameter. Valid event codes are all
// IRC/CTCP commands and error/response codes. This function returns the ID of
@ -29,7 +28,6 @@ func (irc *Connection) AddCallback(eventcode string, callback func(*Event)) stri
return id
}
// Remove callback i (ID) from the given event code. This functions returns
// true upon success, false if any error occurs.
func (irc *Connection) RemoveCallback(eventcode string, i string) bool {
@ -48,7 +46,6 @@ func (irc *Connection) RemoveCallback(eventcode string, i string) bool {
return false
}
// Remove all callbacks from a given event code. It returns true
// if given event code is found and cleared.
func (irc *Connection) ClearCallback(eventcode string) bool {
@ -63,7 +60,6 @@ func (irc *Connection) ClearCallback(eventcode string) bool {
return false
}
// Replace callback i (ID) associated with a given event code with a new callback function.
func (irc *Connection) ReplaceCallback(eventcode string, i string, callback func(*Event)) {
eventcode = strings.ToUpper(eventcode)
@ -78,7 +74,6 @@ func (irc *Connection) ReplaceCallback(eventcode string, i string, callback func
irc.Log.Printf("Event not found. Use AddCallBack\n")
}
// Execute all callbacks associated with a given event.
func (irc *Connection) RunCallbacks(event *Event) {
msg := event.Message()
@ -134,11 +129,13 @@ func (irc *Connection) RunCallbacks(event *Event) {
}
}
// Set up some initial callbacks to handle the IRC/CTCP protocol.
func (irc *Connection) setupCallbacks() {
irc.events = make(map[string]map[string]func(*Event))
//Handle error events
irc.AddCallback("ERROR", func(e *Event) { irc.Disconnect() })
//Handle ping events
irc.AddCallback("PING", func(e *Event) { irc.SendRaw("PONG :" + e.Message()) })
@ -160,7 +157,7 @@ func (irc *Connection) setupCallbacks() {
irc.SendRawf("NOTICE %s :\x01TIME %s\x01", e.Nick, ltime.String())
})
irc.AddCallback("CTCP_PING", func(e *Event) { irc.SendRawf("NOTICE %s :\x01%s\x01", e.Nick, e.Message ()) })
irc.AddCallback("CTCP_PING", func(e *Event) { irc.SendRawf("NOTICE %s :\x01%s\x01", e.Nick, e.Message()) })
irc.AddCallback("437", func(e *Event) {
irc.nickcurrent = irc.nickcurrent + "_"