Add default callback for ERROR
This commit is contained in:
parent
9909b5a3d3
commit
14db1acfd0
@ -10,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Register a callback to a connection and event code. A callback is a function
|
// 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
|
// 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
|
// 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
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Remove callback i (ID) from the given event code. This functions returns
|
// Remove callback i (ID) from the given event code. This functions returns
|
||||||
// true upon success, false if any error occurs.
|
// true upon success, false if any error occurs.
|
||||||
func (irc *Connection) RemoveCallback(eventcode string, i string) bool {
|
func (irc *Connection) RemoveCallback(eventcode string, i string) bool {
|
||||||
@ -48,7 +46,6 @@ func (irc *Connection) RemoveCallback(eventcode string, i string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Remove all callbacks from a given event code. It returns true
|
// Remove all callbacks from a given event code. It returns true
|
||||||
// if given event code is found and cleared.
|
// if given event code is found and cleared.
|
||||||
func (irc *Connection) ClearCallback(eventcode string) bool {
|
func (irc *Connection) ClearCallback(eventcode string) bool {
|
||||||
@ -63,7 +60,6 @@ func (irc *Connection) ClearCallback(eventcode string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Replace callback i (ID) associated with a given event code with a new callback function.
|
// 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)) {
|
func (irc *Connection) ReplaceCallback(eventcode string, i string, callback func(*Event)) {
|
||||||
eventcode = strings.ToUpper(eventcode)
|
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")
|
irc.Log.Printf("Event not found. Use AddCallBack\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Execute all callbacks associated with a given event.
|
// Execute all callbacks associated with a given event.
|
||||||
func (irc *Connection) RunCallbacks(event *Event) {
|
func (irc *Connection) RunCallbacks(event *Event) {
|
||||||
msg := event.Message()
|
msg := event.Message()
|
||||||
@ -134,11 +129,13 @@ func (irc *Connection) RunCallbacks(event *Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set up some initial callbacks to handle the IRC/CTCP protocol.
|
// Set up some initial callbacks to handle the IRC/CTCP protocol.
|
||||||
func (irc *Connection) setupCallbacks() {
|
func (irc *Connection) setupCallbacks() {
|
||||||
irc.events = make(map[string]map[string]func(*Event))
|
irc.events = make(map[string]map[string]func(*Event))
|
||||||
|
|
||||||
|
//Handle error events
|
||||||
|
irc.AddCallback("ERROR", func(e *Event) { irc.Disconnect() })
|
||||||
|
|
||||||
//Handle ping events
|
//Handle ping events
|
||||||
irc.AddCallback("PING", func(e *Event) { irc.SendRaw("PONG :" + e.Message()) })
|
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.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.AddCallback("437", func(e *Event) {
|
||||||
irc.nickcurrent = irc.nickcurrent + "_"
|
irc.nickcurrent = irc.nickcurrent + "_"
|
||||||
|
Loading…
Reference in New Issue
Block a user