From 9517b2fb8ce492bfe7f3aae0f3f9e48a864587c3 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Sat, 27 Jan 2018 16:16:20 -0500 Subject: [PATCH] better support for echo-message --- cap.go | 9 +++++++++ handler.go | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cap.go b/cap.go index 31ce6c6..465c60e 100644 --- a/cap.go +++ b/cap.go @@ -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() { diff --git a/handler.go b/handler.go index 6c08270..eebf4c0 100644 --- a/handler.go +++ b/handler.go @@ -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 {