4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-03 22:27:44 +00:00

Update direct dependencies where possible

This commit is contained in:
Duco van Amstel
2018-11-18 17:55:05 +00:00
committed by Wim
parent f716b8fc0f
commit 09875fe160
356 changed files with 27318 additions and 11078 deletions

View File

@ -1,14 +1,13 @@
language: go
go:
- 1.8
- 1.9
- 1.11.x
- tip
before_install:
- go get -v github.com/golang/lint/golint
- go get -v golang.org/x/lint/golint
script:
- $HOME/gopath/bin/golint -min_confidence 0.9 -set_exit_status
- GORACE="exitcode=1 halt_on_error=1" go test -v -coverprofile=coverage.txt -race -timeout 3m -count 3 -cpu 1,4
- go tool vet -v -all .
- go vet -v .
after_success:
- bash <(curl -s https://codecov.io/bash)
branches:

View File

@ -70,7 +70,7 @@ func (cmd *Commands) PartMessage(channel, message string) {
// PRIVMSG specifically. ctcpType is the CTCP command, e.g. "FINGER", "TIME",
// "VERSION", etc.
func (cmd *Commands) SendCTCP(target, ctcpType, message string) {
out := encodeCTCPRaw(ctcpType, message)
out := EncodeCTCPRaw(ctcpType, message)
if out == "" {
panic(fmt.Sprintf("invalid CTCP: %s -> %s: %s", target, ctcpType, message))
}
@ -95,7 +95,7 @@ func (cmd *Commands) SendCTCPReplyf(target, ctcpType, format string, a ...interf
// SendCTCPReply sends a CTCP response to target. Note that this method uses
// NOTICE specifically.
func (cmd *Commands) SendCTCPReply(target, ctcpType, message string) {
out := encodeCTCPRaw(ctcpType, message)
out := EncodeCTCPRaw(ctcpType, message)
if out == "" {
panic(fmt.Sprintf("invalid CTCP: %s -> %s: %s", target, ctcpType, message))
}

View File

@ -6,6 +6,7 @@ package girc
// Standard CTCP based constants.
const (
CTCP_ACTION = "ACTION"
CTCP_PING = "PING"
CTCP_PONG = "PONG"
CTCP_VERSION = "VERSION"

View File

@ -30,18 +30,22 @@ type CTCPEvent struct {
Reply bool `json:"reply"`
}
// decodeCTCP decodes an incoming CTCP event, if it is CTCP. nil is returned
// if the incoming event does not match a valid CTCP.
func decodeCTCP(e *Event) *CTCPEvent {
// DecodeCTCP decodes an incoming CTCP event, if it is CTCP. nil is returned
// if the incoming event does not have valid CTCP encoding.
func DecodeCTCP(e *Event) *CTCPEvent {
// http://www.irchelp.org/protocol/ctcpspec.html
if e == nil {
return nil
}
// Must be targeting a user/channel, AND trailing must have
// DELIM+TAG+DELIM minimum (at least 3 chars).
if len(e.Params) != 1 || len(e.Trailing) < 3 {
return nil
}
if (e.Command != PRIVMSG && e.Command != NOTICE) || !IsValidNick(e.Params[0]) {
if e.Command != PRIVMSG && e.Command != NOTICE {
return nil
}
@ -88,18 +92,18 @@ func decodeCTCP(e *Event) *CTCPEvent {
}
}
// encodeCTCP encodes a CTCP event into a string, including delimiters.
func encodeCTCP(ctcp *CTCPEvent) (out string) {
// EncodeCTCP encodes a CTCP event into a string, including delimiters.
func EncodeCTCP(ctcp *CTCPEvent) (out string) {
if ctcp == nil {
return ""
}
return encodeCTCPRaw(ctcp.Command, ctcp.Text)
return EncodeCTCPRaw(ctcp.Command, ctcp.Text)
}
// encodeCTCPRaw is much like encodeCTCP, however accepts a raw command and
// EncodeCTCPRaw is much like EncodeCTCP, however accepts a raw command and
// string as input.
func encodeCTCPRaw(cmd, text string) (out string) {
func EncodeCTCPRaw(cmd, text string) (out string) {
if len(cmd) <= 0 {
return ""
}
@ -145,6 +149,11 @@ func (c *CTCP) call(client *Client, event *CTCPEvent) {
}
if _, ok := c.handlers[event.Command]; !ok {
// If ACTION, don't do anything.
if event.Command == CTCP_ACTION {
return
}
// Send a ERRMSG reply, if we know who sent it.
if event.Source != nil && IsValidNick(event.Source.Name) {
client.Cmd.SendCTCPReply(event.Source.Name, CTCP_ERRMSG, "that is an unknown CTCP query")

View File

@ -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
}

View File

@ -113,7 +113,7 @@ func Fmt(text string) string {
if last > -1 {
// A-Z, a-z, and ","
if text[i] != ',' && (text[i] <= 'A' || text[i] >= 'Z') && (text[i] <= 'a' || text[i] >= 'z') {
if text[i] != ',' && (text[i] < 'A' || text[i] > 'Z') && (text[i] < 'a' || text[i] > 'z') {
last = -1
continue
}

1
vendor/github.com/lrstanley/girc/go.mod generated vendored Normal file
View File

@ -0,0 +1 @@
module github.com/lrstanley/girc

View File

@ -46,7 +46,7 @@ func (c *Client) RunHandlers(event *Event) {
}
// Check if it's a CTCP.
if ctcp := decodeCTCP(event.Copy()); ctcp != nil {
if ctcp := DecodeCTCP(event.Copy()); ctcp != nil {
// Execute it.
c.CTCP.call(c, ctcp)
}