From c2fedfb17783b5bd9a8b551d8887551e6cb27b7f Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sat, 21 Jan 2017 00:07:10 +1000 Subject: [PATCH] client: Forego the ForceTrailing func, just automagically work it out based on the command name --- irc/client.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/irc/client.go b/irc/client.go index 1e2da8cc..bd23cf03 100644 --- a/irc/client.go +++ b/irc/client.go @@ -534,18 +534,16 @@ func (client *Client) SendFromClient(msgid string, from *Client, tags *map[strin return client.Send(tags, from.nickMaskString, command, params...) } +var ( + // these are all the output commands that MUST have their last param be a trailing + commandsThatMustUseTrailing = map[string]bool{ + "PRIVMSG": true, + "NOTICE": true, + } +) + // Send sends an IRC line to the client. func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error { - return client.send(false, tags, prefix, command, params...) -} - -// SendForceTrailing sends an IRC line to the client, forcing the last param to be a trailing. -// This is a hack. However, there are clients that treat special chars differently. -func (client *Client) SendForceTrailing(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error { - return client.send(true, tags, prefix, command, params...) -} - -func (client *Client) send(forceTrailing bool, tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error { // attach server-time if client.capabilities[ServerTime] { if tags == nil { @@ -557,7 +555,7 @@ func (client *Client) send(forceTrailing bool, tags *map[string]ircmsg.TagValue, // force trailing var usedSpaceHack bool - if forceTrailing && len(params) > 0 { + if commandsThatMustUseTrailing[strings.ToUpper(command)] && len(params) > 0 { lastParam := params[len(params)-1] if !strings.Contains(lastParam, " ") { params[len(params)-1] = lastParam + " "