From 0689c7410131c036832a3b8f24748122a4093b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Mon, 29 May 2017 00:42:00 +0200 Subject: [PATCH] Dont forward irc errors that are handled elsewhere --- server/irc.go | 2 +- server/irc_handler.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/irc.go b/server/irc.go index 653a4583..4b12fd8e 100644 --- a/server/irc.go +++ b/server/irc.go @@ -13,7 +13,7 @@ import ( func createNickInUseHandler(i *irc.Client, session *Session) func(string) string { return func(nick string) string { newNick := nick + "_" - session.print(i.Host, "Nickname", nick, "is already in use, using", newNick, "instead") + session.printError("Nickname", nick, "is already in use, using", newNick, "instead") return newNick } diff --git a/server/irc_handler.go b/server/irc_handler.go index 6a302737..2820c2e3 100644 --- a/server/irc_handler.go +++ b/server/irc_handler.go @@ -11,6 +11,10 @@ import ( "github.com/khlieng/dispatch/storage" ) +var excludedErrors = []string{ + irc.ErrNicknameInUse, +} + type ircHandler struct { client *irc.Client session *Session @@ -53,7 +57,7 @@ func (i *ircHandler) run() { } func (i *ircHandler) dispatchMessage(msg *irc.Message) { - if msg.Command[0] == '4' { + if msg.Command[0] == '4' && !isExcludedError(msg.Command) { i.session.printError(formatIRCError(msg)) } @@ -322,6 +326,15 @@ func isChannel(s string) bool { return strings.IndexAny(s, "&#+!") == 0 } +func isExcludedError(cmd string) bool { + for _, err := range excludedErrors { + if cmd == err { + return true + } + } + return false +} + func formatIRCError(msg *irc.Message) string { errMsg := strings.TrimSuffix(msg.LastParam(), ".") if len(msg.Params) > 2 {