diff options
author | Duco van Amstel <helcaraxan@gmail.com> | 2018-11-18 17:55:05 +0000 |
---|---|---|
committer | Wim <wim@42.be> | 2018-11-25 21:21:04 +0100 |
commit | 09875fe1603307080f3a4172985c5dca3bd9912d (patch) | |
tree | a23220772f6f6597d509ca71b2df3480a77b8076 /vendor/github.com/lrstanley/girc/event.go | |
parent | f716b8fc0ff90f47b61e218ef34019b38bd70e0d (diff) | |
download | matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.tar.gz matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.tar.bz2 matterbridge-msglm-09875fe1603307080f3a4172985c5dca3bd9912d.zip |
Update direct dependencies where possible
Diffstat (limited to 'vendor/github.com/lrstanley/girc/event.go')
-rw-r--r-- | vendor/github.com/lrstanley/girc/event.go | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/vendor/github.com/lrstanley/girc/event.go b/vendor/github.com/lrstanley/girc/event.go index 5e17b15b..0b40b40b 100644 --- a/vendor/github.com/lrstanley/girc/event.go +++ b/vendor/github.com/lrstanley/girc/event.go @@ -355,11 +355,15 @@ func (e *Event) Pretty() (out string, ok bool) { } if (e.Command == PRIVMSG || e.Command == NOTICE) && len(e.Params) > 0 { - if ctcp := decodeCTCP(e); ctcp != nil { + if ctcp := DecodeCTCP(e); ctcp != nil { if ctcp.Reply { return } + if ctcp.Command == CTCP_ACTION { + return fmt.Sprintf("[%s] **%s** %s", strings.Join(e.Params, ","), ctcp.Source.Name, ctcp.Text), true + } + return fmt.Sprintf("[*] CTCP query from %s: %s%s", ctcp.Source.Name, ctcp.Command, " "+ctcp.Text), true } return fmt.Sprintf("[%s] (%s) %s", strings.Join(e.Params, ","), e.Source.Name, e.Trailing), true @@ -448,23 +452,27 @@ func (e *Event) Pretty() (out string, ok bool) { return "", false } -// IsAction checks to see if the event is a PRIVMSG, and is an ACTION (/me). +// IsAction checks to see if the event is an ACTION (/me). func (e *Event) IsAction() bool { - if e.Source == nil || e.Command != PRIVMSG || len(e.Trailing) < 9 { + if e.Command != PRIVMSG { return false } - if !strings.HasPrefix(e.Trailing, "\001ACTION") || e.Trailing[len(e.Trailing)-1] != ctcpDelim { - return false - } + ok, ctcp := e.IsCTCP() + return ok && ctcp.Command == CTCP_ACTION +} - return true +// IsCTCP checks to see if the event is a CTCP event, and if so, returns the +// converted CTCP event. +func (e *Event) IsCTCP() (ok bool, ctcp *CTCPEvent) { + ctcp = DecodeCTCP(e) + return ctcp != nil, ctcp } // IsFromChannel checks to see if a message was from a channel (rather than // a private message). func (e *Event) IsFromChannel() bool { - if e.Source == nil || e.Command != PRIVMSG || len(e.Params) < 1 { + if e.Source == nil || (e.Command != PRIVMSG && e.Command != NOTICE) || len(e.Params) < 1 { return false } @@ -478,7 +486,7 @@ func (e *Event) IsFromChannel() bool { // IsFromUser checks to see if a message was from a user (rather than a // channel). func (e *Event) IsFromUser() bool { - if e.Source == nil || e.Command != PRIVMSG || len(e.Params) < 1 { + if e.Source == nil || (e.Command != PRIVMSG && e.Command != NOTICE) || len(e.Params) < 1 { return false } |