Decode the API's actual fields in neoirc-cli (closes #146)
check / check (push) Waiting to run
check / check (push) Waiting to run
The CLI read the poll cursor from `lastId` while the server sends `last_id`, so the cursor stayed at 0 and every poll returned the whole queue at once. It now reads `last_id`. /names decodes the member objects the server sends and prints each nick with `@` for an operator or `+` for a voiced member. /list prints each channel's name and topic, since the server sends no member count. StateResponse.Channels decodes channel objects. /topic with no text prints a usage line and sends nothing, because the HTTP API has no topic query and a TOPIC without text gets 461. The help says "Set topic". The client tests serve the bodies the handlers send, so a wrong JSON tag in types.go fails a test; another test covers the /names prefixes. Model: opus-5-5
This commit was merged in pull request #170.
This commit is contained in:
+25
-13
@@ -434,16 +434,9 @@ func (a *App) cmdTopic(args string) {
|
||||
return
|
||||
}
|
||||
|
||||
// The HTTP API has no topic query: a TOPIC needs text.
|
||||
if args == "" {
|
||||
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
|
||||
Command: irc.CmdTopic,
|
||||
To: target,
|
||||
})
|
||||
if err != nil {
|
||||
a.ui.AddStatus(fmt.Sprintf(
|
||||
"[red]Topic query failed: %v", err,
|
||||
))
|
||||
}
|
||||
a.ui.AddStatus("[red]Usage: /topic <text>")
|
||||
|
||||
return
|
||||
}
|
||||
@@ -487,12 +480,32 @@ func (a *App) cmdNames() {
|
||||
return
|
||||
}
|
||||
|
||||
nicks := make([]string, 0, len(members))
|
||||
|
||||
for _, member := range members {
|
||||
nicks = append(nicks, memberPrefix(member)+member.Nick)
|
||||
}
|
||||
|
||||
a.ui.AddLine(target, fmt.Sprintf(
|
||||
"[cyan]*** Members of %s: %s",
|
||||
target, strings.Join(members, " "),
|
||||
target, strings.Join(nicks, " "),
|
||||
))
|
||||
}
|
||||
|
||||
// memberPrefix returns "@" for an operator, "+" for a voiced
|
||||
// member, and "" for anyone else.
|
||||
func memberPrefix(member api.Member) string {
|
||||
if member.IsOperator {
|
||||
return "@"
|
||||
}
|
||||
|
||||
if member.IsVoiced {
|
||||
return "+"
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a *App) cmdList() {
|
||||
a.mu.Lock()
|
||||
connected := a.connected
|
||||
@@ -517,8 +530,7 @@ func (a *App) cmdList() {
|
||||
|
||||
for _, ch := range channels {
|
||||
a.ui.AddStatus(fmt.Sprintf(
|
||||
" %s (%d members) %s",
|
||||
ch.Name, ch.Members, ch.Topic,
|
||||
" %s %s", ch.Name, ch.Topic,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -676,7 +688,7 @@ func (a *App) cmdHelp() {
|
||||
" /part [#chan] — Leave channel",
|
||||
" /msg <nick> <text> — Send DM",
|
||||
" /query <nick> — Open DM window",
|
||||
" /topic [text] — View/set topic",
|
||||
" /topic <text> — Set topic",
|
||||
" /names — List channel members",
|
||||
" /list — List channels",
|
||||
" /who [#channel] — List users in channel",
|
||||
|
||||
Reference in New Issue
Block a user