Scrape horse doc constants, handle all nick collision error types

This commit is contained in:
Ken-Håvard Lieng 2020-05-23 02:30:48 +02:00
parent e937f5d8b9
commit be8b785813
6 changed files with 202 additions and 110 deletions

View file

@ -23,7 +23,7 @@ func createNickInUseHandler(i *irc.Client, state *State) func(string) string {
state.sendJSON("error", IRCError{
Server: i.Host,
Message: fmt.Sprintf("Nickname %s is already in use, using %s instead", nick, newNick),
Message: fmt.Sprintf("Nickname %s is unavailable, trying %s instead", nick, newNick),
})
return newNick

View file

@ -16,8 +16,10 @@ import (
)
var excludedErrors = []string{
irc.ErrNicknameInUse,
irc.ErrForward,
irc.ERR_NICKNAMEINUSE,
irc.ERR_NICKCOLLISION,
irc.ERR_UNAVAILRESOURCE,
irc.ERR_FORWARD,
}
type ircHandler struct {
@ -229,7 +231,7 @@ func (i *ircHandler) quit(msg *irc.Message) {
}
func (i *ircHandler) info(msg *irc.Message) {
if msg.Command == irc.ReplyWelcome {
if msg.Command == irc.RPL_WELCOME {
i.state.sendJSON("nick", Nick{
Server: i.client.Host,
New: msg.Params[0],
@ -293,7 +295,7 @@ func (i *ircHandler) topic(msg *irc.Message) {
var channel string
var nick string
if msg.Command == irc.Topic {
if msg.Command == irc.TOPIC {
channel = msg.Params[0]
nick = msg.Nick
} else {
@ -437,39 +439,39 @@ func (i *ircHandler) receiveDCCSend(pack *irc.DCCSend, msg *irc.Message) {
func (i *ircHandler) initHandlers() {
i.handlers = map[string]func(*irc.Message){
irc.Nick: i.nick,
irc.Join: i.join,
irc.Part: i.part,
irc.Mode: i.mode,
irc.Privmsg: i.message,
irc.Notice: i.message,
irc.Quit: i.quit,
irc.Topic: i.topic,
irc.Error: i.error,
irc.ReplyWelcome: i.info,
irc.ReplyYourHost: i.info,
irc.ReplyCreated: i.info,
irc.ReplyISupport: i.features,
irc.ReplyLUserClient: i.info,
irc.ReplyLUserOp: i.info,
irc.ReplyLUserUnknown: i.info,
irc.ReplyLUserChannels: i.info,
irc.ReplyLUserMe: i.info,
irc.ReplyWhoisUser: i.whoisUser,
irc.ReplyWhoisServer: i.whoisServer,
irc.ReplyWhoisChannels: i.whoisChannels,
irc.ReplyEndOfWhois: i.whoisEnd,
irc.ReplyNoTopic: i.noTopic,
irc.ReplyTopic: i.topic,
irc.ReplyNamReply: i.names,
irc.ReplyEndOfNames: i.namesEnd,
irc.ReplyMotdStart: i.motdStart,
irc.ReplyMotd: i.motd,
irc.ReplyEndOfMotd: i.motdEnd,
irc.ReplyList: i.list,
irc.ReplyListEnd: i.listEnd,
irc.ErrErroneousNickname: i.badNick,
irc.ErrForward: i.forward,
irc.NICK: i.nick,
irc.JOIN: i.join,
irc.PART: i.part,
irc.MODE: i.mode,
irc.PRIVMSG: i.message,
irc.NOTICE: i.message,
irc.QUIT: i.quit,
irc.TOPIC: i.topic,
irc.ERROR: i.error,
irc.RPL_WELCOME: i.info,
irc.RPL_YOURHOST: i.info,
irc.RPL_CREATED: i.info,
irc.RPL_ISUPPORT: i.features,
irc.RPL_LUSERCLIENT: i.info,
irc.RPL_LUSEROP: i.info,
irc.RPL_LUSERUNKNOWN: i.info,
irc.RPL_LUSERCHANNELS: i.info,
irc.RPL_LUSERME: i.info,
irc.RPL_WHOISUSER: i.whoisUser,
irc.RPL_WHOISSERVER: i.whoisServer,
irc.RPL_WHOISCHANNELS: i.whoisChannels,
irc.RPL_ENDOFWHOIS: i.whoisEnd,
irc.RPL_NOTOPIC: i.noTopic,
irc.RPL_TOPIC: i.topic,
irc.RPL_NAMREPLY: i.names,
irc.RPL_ENDOFNAMES: i.namesEnd,
irc.RPL_MOTDSTART: i.motdStart,
irc.RPL_MOTD: i.motd,
irc.RPL_ENDOFMOTD: i.motdEnd,
irc.RPL_LIST: i.list,
irc.RPL_LISTEND: i.listEnd,
irc.ERR_ERRONEUSNICKNAME: i.badNick,
irc.ERR_FORWARD: i.forward,
}
}

View file

@ -70,7 +70,7 @@ func checkResponse(t *testing.T, expectedType string, expectedData interface{},
func TestHandleIRCNick(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.Nick,
Command: irc.NICK,
Nick: "old",
Params: []string{"new"},
})
@ -84,7 +84,7 @@ func TestHandleIRCNick(t *testing.T) {
func TestHandleIRCJoin(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.Join,
Command: irc.JOIN,
Nick: "joining",
Params: []string{"#chan"},
})
@ -98,7 +98,7 @@ func TestHandleIRCJoin(t *testing.T) {
func TestHandleIRCPart(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.Part,
Command: irc.PART,
Nick: "parting",
Params: []string{"#chan", "the reason"},
})
@ -111,7 +111,7 @@ func TestHandleIRCPart(t *testing.T) {
}, res)
res = dispatchMessage(&irc.Message{
Command: irc.Part,
Command: irc.PART,
Nick: "parting",
Params: []string{"#chan"},
})
@ -125,7 +125,7 @@ func TestHandleIRCPart(t *testing.T) {
func TestHandleIRCMode(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.Mode,
Command: irc.MODE,
Params: []string{"#chan", "+o-v", "nick"},
})
@ -140,7 +140,7 @@ func TestHandleIRCMode(t *testing.T) {
func TestHandleIRCMessage(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.Privmsg,
Command: irc.PRIVMSG,
Nick: "nick",
Params: []string{"#chan", "the message"},
})
@ -153,7 +153,7 @@ func TestHandleIRCMessage(t *testing.T) {
assert.Equal(t, "the message", msg.Content)
res = dispatchMessage(&irc.Message{
Command: irc.Privmsg,
Command: irc.PRIVMSG,
Nick: "someone",
Params: []string{"nick", "the message"},
})
@ -168,7 +168,7 @@ func TestHandleIRCMessage(t *testing.T) {
func TestHandleIRCQuit(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.Quit,
Command: irc.QUIT,
Nick: "nick",
Params: []string{"the reason"},
})
@ -182,7 +182,7 @@ func TestHandleIRCQuit(t *testing.T) {
func TestHandleIRCWelcome(t *testing.T) {
res := dispatchMessageMulti(&irc.Message{
Command: irc.ReplyWelcome,
Command: irc.RPL_WELCOME,
Nick: "nick",
Params: []string{"nick", "some", "text"},
})
@ -206,18 +206,18 @@ func TestHandleIRCWhois(t *testing.T) {
i := newIRCHandler(c, s)
i.dispatchMessage(&irc.Message{
Command: irc.ReplyWhoisUser,
Command: irc.RPL_WHOISUSER,
Params: []string{"", "nick", "user", "host", "", "realname"},
})
i.dispatchMessage(&irc.Message{
Command: irc.ReplyWhoisServer,
Command: irc.RPL_WHOISSERVER,
Params: []string{"", "", "srv.com"},
})
i.dispatchMessage(&irc.Message{
Command: irc.ReplyWhoisChannels,
Command: irc.RPL_WHOISCHANNELS,
Params: []string{"#chan #chan1"},
})
i.dispatchMessage(&irc.Message{Command: irc.ReplyEndOfWhois})
i.dispatchMessage(&irc.Message{Command: irc.RPL_ENDOFWHOIS})
checkResponse(t, "whois", WhoisReply{
Nick: "nick",
@ -231,7 +231,7 @@ func TestHandleIRCWhois(t *testing.T) {
func TestHandleIRCTopic(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.ReplyTopic,
Command: irc.RPL_TOPIC,
Params: []string{"target", "#chan", "the topic"},
})
@ -242,7 +242,7 @@ func TestHandleIRCTopic(t *testing.T) {
}, res)
res = dispatchMessage(&irc.Message{
Command: irc.Topic,
Command: irc.TOPIC,
Params: []string{"#chan", "the topic"},
Nick: "bob",
})
@ -257,7 +257,7 @@ func TestHandleIRCTopic(t *testing.T) {
func TestHandleIRCNoTopic(t *testing.T) {
res := dispatchMessage(&irc.Message{
Command: irc.ReplyNoTopic,
Command: irc.RPL_NOTOPIC,
Params: []string{"target", "#chan", "No topic set."},
})
@ -274,15 +274,15 @@ func TestHandleIRCNames(t *testing.T) {
i := newIRCHandler(c, s)
i.dispatchMessage(&irc.Message{
Command: irc.ReplyNamReply,
Command: irc.RPL_NAMREPLY,
Params: []string{"", "", "#chan", "a b c"},
})
i.dispatchMessage(&irc.Message{
Command: irc.ReplyNamReply,
Command: irc.RPL_NAMREPLY,
Params: []string{"", "", "#chan", "d"},
})
i.dispatchMessage(&irc.Message{
Command: irc.ReplyEndOfNames,
Command: irc.RPL_ENDOFNAMES,
Params: []string{"", "#chan"},
})
@ -300,18 +300,18 @@ func TestHandleIRCMotd(t *testing.T) {
i := newIRCHandler(c, s)
i.dispatchMessage(&irc.Message{
Command: irc.ReplyMotdStart,
Command: irc.RPL_MOTDSTART,
Params: []string{"motd title"},
})
i.dispatchMessage(&irc.Message{
Command: irc.ReplyMotd,
Command: irc.RPL_MOTD,
Params: []string{"line 1"},
})
i.dispatchMessage(&irc.Message{
Command: irc.ReplyMotd,
Command: irc.RPL_MOTD,
Params: []string{"line 2"},
})
i.dispatchMessage(&irc.Message{Command: irc.ReplyEndOfMotd})
i.dispatchMessage(&irc.Message{Command: irc.RPL_ENDOFMOTD})
checkResponse(t, "motd", MOTD{
Server: "host.com",
@ -327,7 +327,7 @@ func TestHandleIRCBadNick(t *testing.T) {
i := newIRCHandler(c, s)
i.dispatchMessage(&irc.Message{
Command: irc.ErrErroneousNickname,
Command: irc.ERR_ERRONEUSNICKNAME,
})
// It should print the error message first