refactor: replace all bare command string literals with named constants
All checks were successful
check / check (push) Successful in 2m15s
All checks were successful
check / check (push) Successful in 2m15s
Extract cmdLusers, cmdMode, cmdMotd, cmdNames, cmdNotice, cmdPing, cmdPong constants in internal/handlers/api.go. Add corresponding constants in cmd/neoirc-cli/main.go and cmd/neoirc-cli/api/client.go. Replace every bare IRC command string literal in switch cases and command dispatch code with the named constant. Zero bare command strings remain in any dispatch path.
This commit is contained in:
@@ -19,6 +19,9 @@ const (
|
||||
httpTimeout = 30 * time.Second
|
||||
pollExtraTime = 5
|
||||
httpErrThreshold = 400
|
||||
|
||||
cmdJoin = "JOIN"
|
||||
cmdPart = "PART"
|
||||
)
|
||||
|
||||
var errHTTP = errors.New("HTTP error")
|
||||
@@ -168,7 +171,7 @@ func (client *Client) PollMessages(
|
||||
func (client *Client) JoinChannel(channel string) error {
|
||||
return client.SendMessage(
|
||||
&Message{ //nolint:exhaustruct // only command+to needed
|
||||
Command: "JOIN", To: channel,
|
||||
Command: cmdJoin, To: channel,
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -177,7 +180,7 @@ func (client *Client) JoinChannel(channel string) error {
|
||||
func (client *Client) PartChannel(channel string) error {
|
||||
return client.SendMessage(
|
||||
&Message{ //nolint:exhaustruct // only command+to needed
|
||||
Command: "PART", To: channel,
|
||||
Command: cmdPart, To: channel,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,17 @@ const (
|
||||
pollTimeout = 15
|
||||
pollRetry = 2 * time.Second
|
||||
timeFormat = "15:04"
|
||||
|
||||
cmdJoin = "JOIN"
|
||||
cmdMotd = "MOTD"
|
||||
cmdNick = "NICK"
|
||||
cmdNotice = "NOTICE"
|
||||
cmdPart = "PART"
|
||||
cmdPrivmsg = "PRIVMSG"
|
||||
cmdQuit = "QUIT"
|
||||
cmdTopic = "TOPIC"
|
||||
cmdWho = "WHO"
|
||||
cmdWhois = "WHOIS"
|
||||
)
|
||||
|
||||
// App holds the application state.
|
||||
@@ -86,7 +97,7 @@ func (a *App) handleInput(text string) {
|
||||
}
|
||||
|
||||
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
|
||||
Command: "PRIVMSG",
|
||||
Command: cmdPrivmsg,
|
||||
To: target,
|
||||
Body: []string{text},
|
||||
})
|
||||
@@ -241,7 +252,7 @@ func (a *App) cmdNick(nick string) {
|
||||
}
|
||||
|
||||
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
|
||||
Command: "NICK",
|
||||
Command: cmdNick,
|
||||
Body: []string{nick},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -376,7 +387,7 @@ func (a *App) cmdMsg(args string) {
|
||||
}
|
||||
|
||||
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
|
||||
Command: "PRIVMSG",
|
||||
Command: cmdPrivmsg,
|
||||
To: target,
|
||||
Body: []string{text},
|
||||
})
|
||||
@@ -434,7 +445,7 @@ func (a *App) cmdTopic(args string) {
|
||||
|
||||
if args == "" {
|
||||
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
|
||||
Command: "TOPIC",
|
||||
Command: cmdTopic,
|
||||
To: target,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -447,7 +458,7 @@ func (a *App) cmdTopic(args string) {
|
||||
}
|
||||
|
||||
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
|
||||
Command: "TOPIC",
|
||||
Command: cmdTopic,
|
||||
To: target,
|
||||
Body: []string{args},
|
||||
})
|
||||
@@ -535,7 +546,7 @@ func (a *App) cmdMotd() {
|
||||
}
|
||||
|
||||
err := a.client.SendMessage(
|
||||
&api.Message{Command: "MOTD"}, //nolint:exhaustruct
|
||||
&api.Message{Command: cmdMotd}, //nolint:exhaustruct
|
||||
)
|
||||
if err != nil {
|
||||
a.ui.AddStatus(fmt.Sprintf(
|
||||
@@ -572,7 +583,7 @@ func (a *App) cmdWho(args string) {
|
||||
|
||||
err := a.client.SendMessage(
|
||||
&api.Message{ //nolint:exhaustruct
|
||||
Command: "WHO", To: channel,
|
||||
Command: cmdWho, To: channel,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -603,7 +614,7 @@ func (a *App) cmdWhois(args string) {
|
||||
|
||||
err := a.client.SendMessage(
|
||||
&api.Message{ //nolint:exhaustruct
|
||||
Command: "WHOIS", To: args,
|
||||
Command: cmdWhois, To: args,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -653,7 +664,7 @@ func (a *App) cmdQuit() {
|
||||
|
||||
if a.connected && a.client != nil {
|
||||
_ = a.client.SendMessage(
|
||||
&api.Message{Command: "QUIT"}, //nolint:exhaustruct
|
||||
&api.Message{Command: cmdQuit}, //nolint:exhaustruct
|
||||
)
|
||||
}
|
||||
|
||||
@@ -738,19 +749,19 @@ func (a *App) handleServerMessage(msg *api.Message) {
|
||||
a.mu.Unlock()
|
||||
|
||||
switch msg.Command {
|
||||
case "PRIVMSG":
|
||||
case cmdPrivmsg:
|
||||
a.handlePrivmsgEvent(msg, timestamp, myNick)
|
||||
case "JOIN":
|
||||
case cmdJoin:
|
||||
a.handleJoinEvent(msg, timestamp)
|
||||
case "PART":
|
||||
case cmdPart:
|
||||
a.handlePartEvent(msg, timestamp)
|
||||
case "QUIT":
|
||||
case cmdQuit:
|
||||
a.handleQuitEvent(msg, timestamp)
|
||||
case "NICK":
|
||||
case cmdNick:
|
||||
a.handleNickEvent(msg, timestamp, myNick)
|
||||
case "NOTICE":
|
||||
case cmdNotice:
|
||||
a.handleNoticeEvent(msg, timestamp)
|
||||
case "TOPIC":
|
||||
case cmdTopic:
|
||||
a.handleTopicEvent(msg, timestamp)
|
||||
default:
|
||||
a.handleDefaultEvent(msg, timestamp)
|
||||
|
||||
Reference in New Issue
Block a user