summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/lrstanley/girc/builtin.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-02-16 17:24:04 +0100
committerGitHub <noreply@github.com>2019-02-16 17:24:04 +0100
commit312369586925e0419271df7466e9b40756738f89 (patch)
tree247b181b64cd589afa3ab865058f47d26db662ea /vendor/github.com/lrstanley/girc/builtin.go
parent777af73e2bafc0b2c6e1d1eaa554106efec36a70 (diff)
downloadmatterbridge-msglm-312369586925e0419271df7466e9b40756738f89.tar.gz
matterbridge-msglm-312369586925e0419271df7466e9b40756738f89.tar.bz2
matterbridge-msglm-312369586925e0419271df7466e9b40756738f89.zip
Upgrade to latest girc version (irc) (#718)
Diffstat (limited to 'vendor/github.com/lrstanley/girc/builtin.go')
-rw-r--r--vendor/github.com/lrstanley/girc/builtin.go81
1 files changed, 40 insertions, 41 deletions
diff --git a/vendor/github.com/lrstanley/girc/builtin.go b/vendor/github.com/lrstanley/girc/builtin.go
index 9dd02804..7f285fda 100644
--- a/vendor/github.com/lrstanley/girc/builtin.go
+++ b/vendor/github.com/lrstanley/girc/builtin.go
@@ -93,7 +93,7 @@ func handleConnect(c *Client, e Event) {
}
time.Sleep(2 * time.Second)
- c.RunHandlers(&Event{Command: CONNECTED, Trailing: c.Server()})
+ c.RunHandlers(&Event{Command: CONNECTED, Params: []string{c.Server()}})
}
// nickCollisionHandler helps prevent the client from having conflicting
@@ -109,7 +109,7 @@ func nickCollisionHandler(c *Client, e Event) {
// handlePING helps respond to ping requests from the server.
func handlePING(c *Client, e Event) {
- c.Cmd.Pong(e.Trailing)
+ c.Cmd.Pong(e.Last())
}
func handlePONG(c *Client, e Event) {
@@ -120,16 +120,11 @@ func handlePONG(c *Client, e Event) {
// handleJOIN ensures that the state has updated users and channels.
func handleJOIN(c *Client, e Event) {
- if e.Source == nil {
+ if e.Source == nil || len(e.Params) == 0 {
return
}
- var channelName string
- if len(e.Params) > 0 {
- channelName = e.Params[0]
- } else {
- channelName = e.Trailing
- }
+ channelName := e.Params[0]
c.state.Lock()
@@ -158,13 +153,13 @@ func handleJOIN(c *Client, e Event) {
user.addChannel(channel.Name)
// Assume extended-join (ircv3).
- if len(e.Params) == 2 {
+ if len(e.Params) >= 2 {
if e.Params[1] != "*" {
user.Extras.Account = e.Params[1]
}
- if len(e.Trailing) > 0 {
- user.Extras.Name = e.Trailing
+ if len(e.Params) > 2 {
+ user.Extras.Name = e.Params[2]
}
}
c.state.Unlock()
@@ -192,16 +187,13 @@ func handleJOIN(c *Client, e Event) {
// handlePART ensures that the state is clean of old user and channel entries.
func handlePART(c *Client, e Event) {
- if e.Source == nil {
+ if e.Source == nil || len(e.Params) < 1 {
return
}
- var channel string
- if len(e.Params) > 0 {
- channel = e.Params[0]
- } else {
- channel = e.Trailing
- }
+ // TODO: does this work if it's not the bot?
+
+ channel := e.Params[0]
if channel == "" {
return
@@ -231,7 +223,7 @@ func handleTOPIC(c *Client, e Event) {
case 1:
name = e.Params[0]
default:
- name = e.Params[len(e.Params)-1]
+ name = e.Params[1]
}
c.state.Lock()
@@ -241,7 +233,7 @@ func handleTOPIC(c *Client, e Event) {
return
}
- channel.Topic = e.Trailing
+ channel.Topic = e.Last()
c.state.Unlock()
c.state.notify(c, UPDATE_STATE)
}
@@ -253,7 +245,7 @@ func handleWHO(c *Client, e Event) {
// Assume WHOX related.
if e.Command == RPL_WHOSPCRPL {
- if len(e.Params) != 7 {
+ if len(e.Params) != 8 {
// Assume there was some form of error or invalid WHOX response.
return
}
@@ -266,12 +258,24 @@ func handleWHO(c *Client, e Event) {
}
ident, host, nick, account = e.Params[3], e.Params[4], e.Params[5], e.Params[6]
- realname = e.Trailing
+ realname = e.Last()
} else {
// Assume RPL_WHOREPLY.
- ident, host, nick = e.Params[2], e.Params[3], e.Params[5]
- if len(e.Trailing) > 2 {
- realname = e.Trailing[2:]
+ // format: "<client> <channel> <user> <host> <server> <nick> <H|G>[*][@|+] :<hopcount> <real_name>"
+ ident, host, nick, realname = e.Params[2], e.Params[3], e.Params[5], e.Last()
+
+ // Strip the numbers from "<hopcount> <realname>"
+ for i := 0; i < len(realname); i++ {
+ // Check if it's not 0-9.
+ if realname[i] < 0x30 || i > 0x39 {
+ realname = strings.TrimLeft(realname[i+1:], " ")
+ break
+ }
+
+ if i == len(realname)-1 {
+ // Assume it's only numbers?
+ realname = ""
+ }
}
}
@@ -326,10 +330,8 @@ func handleNICK(c *Client, e Event) {
c.state.Lock()
// renameUser updates the LastActive time automatically.
- if len(e.Params) == 1 {
- c.state.renameUser(e.Source.ID(), e.Params[0])
- } else if len(e.Trailing) > 0 {
- c.state.renameUser(e.Source.ID(), e.Trailing)
+ if len(e.Params) >= 1 {
+ c.state.renameUser(e.Source.ID(), e.Last())
}
c.state.Unlock()
c.state.notify(c, UPDATE_STATE)
@@ -372,12 +374,10 @@ func handleMYINFO(c *Client, e Event) {
// events. These commonly contain the server capabilities and limitations.
// For example, things like max channel name length, or nickname length.
func handleISUPPORT(c *Client, e Event) {
- // Must be a ISUPPORT-based message. 005 is also used for server bounce
- // related things, so this handler may be triggered during other
- // situations.
+ // Must be a ISUPPORT-based message.
// Also known as RPL_PROTOCTL.
- if !strings.HasSuffix(e.Trailing, "this server") {
+ if !strings.HasSuffix(e.Last(), "this server") {
return
}
@@ -387,8 +387,8 @@ func handleISUPPORT(c *Client, e Event) {
}
c.state.Lock()
- // Skip the first parameter, as it's our nickname.
- for i := 1; i < len(e.Params); i++ {
+ // Skip the first parameter, as it's our nickname, and the last, as it's the doc.
+ for i := 1; i < len(e.Params)-1; i++ {
j := strings.IndexByte(e.Params[i], '=')
if j < 1 || (j+1) == len(e.Params[i]) {
@@ -421,10 +421,9 @@ func handleMOTD(c *Client, e Event) {
// Otherwise, assume we're getting sent the MOTD line-by-line.
if len(c.state.motd) != 0 {
- e.Trailing = "\n" + e.Trailing
+ c.state.motd += "\n"
}
-
- c.state.motd += e.Trailing
+ c.state.motd += e.Last()
c.state.Unlock()
}
@@ -436,12 +435,12 @@ func handleNAMES(c *Client, e Event) {
return
}
- channel := c.state.lookupChannel(e.Params[len(e.Params)-1])
+ channel := c.state.lookupChannel(e.Params[2])
if channel == nil {
return
}
- parts := strings.Split(e.Trailing, " ")
+ parts := strings.Split(e.Last(), " ")
var modes, nick string
var ok bool