better support for echo-message

This commit is contained in:
Liam Stanley 2018-01-27 16:16:20 -05:00
parent 4e577e7ee0
commit 9517b2fb8c
2 changed files with 21 additions and 4 deletions

9
cap.go
View File

@ -13,6 +13,8 @@ import (
"strings"
)
// Something not in the list? Depending on the type of capability, you can
// enable it using Config.SupportedCaps.
var possibleCap = map[string][]string{
"account-notify": nil,
"account-tag": nil,
@ -25,6 +27,13 @@ var possibleCap = map[string][]string{
"message-tags": nil,
"multi-prefix": nil,
"userhost-in-names": nil,
// "echo-message" is supported, but it's not enabled by default. This is
// to prevent unwanted confusion and utilize less traffic if it's not needed.
// echo messages aren't sent to girc.PRIVMSG and girc.NOTICE handlers,
// rather they are only sent to girc.ALL_EVENTS handlers (this is to prevent
// each handler to have to check these types of things for each message).
// You can compare events using Event.Equals() to see if they are the same.
}
func (c *Client) listCAP() {

View File

@ -21,20 +21,28 @@ func (c *Client) RunHandlers(event *Event) {
return
}
// Check if it's an echo-message.
isEcho := event.Source != nil && event.Source.Name == c.GetNick() && (event.Command == PRIVMSG || event.Command == NOTICE)
// Log the event.
c.debug.Print("< " + StripRaw(event.String()))
if c.Config.Out != nil {
if c.Config.Out != nil && !isEcho {
if pretty, ok := event.Pretty(); ok {
fmt.Fprintln(c.Config.Out, StripRaw(pretty))
}
}
// Background handlers first.
// Background handlers first. If the event is an echo-message, then only
// send the echo version to ALL_EVENTS.
c.Handlers.exec(ALL_EVENTS, true, c, event.Copy())
c.Handlers.exec(event.Command, true, c, event.Copy())
if !isEcho {
c.Handlers.exec(event.Command, true, c, event.Copy())
}
c.Handlers.exec(ALL_EVENTS, false, c, event.Copy())
c.Handlers.exec(event.Command, false, c, event.Copy())
if !isEcho {
c.Handlers.exec(event.Command, false, c, event.Copy())
}
// Check if it's a CTCP.
if ctcp := decodeCTCP(event.Copy()); ctcp != nil {