Files
Claude 139dcfd153 IRC: Solanum's channel modes for registered rooms, INVITE and KNOCK
A registered room's ops set its modes with MODE (/mode in the BBS's
chat): n t s p m i z g T, the key (k) and limit (l), and the lists: bans
(b), quiets (q), exceptions (e) and invite exceptions (I), with masks
nick!how@nodeN and the extbans $a, $a:mask and $o (~ negates). c and C
are always on, as the rooms always were. MODE b/q/e/I with no mask lists
them (367, 728, 348, 346). Modes and lists are kept in room_reg and the
new room_lists table, and are the room's: a caller on the text BBS, AOL
or Yahoo is kept out or quiet as an IRC user is.

INVITE (an op, or anyone in a +g room) gets one past i, k and l for the
hour; KNOCK asks the ops of a room one is kept out of, once a minute,
but not in a +p room. ChanServ gains INVITE and GETKEY (the i flag, which
also gets past i, k and l), and INFO shows the modes. JOIN takes keys;
/join ROOM KEY, /invite and /knock come to the BBS's chat. ISUPPORT gives
CHANMODES=Ibeq,k,l,CcTgimnpstz, EXCEPTS, INVEX, EXTBAN, MAXLIST, KEYLEN
and KNOCK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRTXE7MNm3r3hHAmTG2
2026-11-11 04:20:31 +00:00

308 lines
9.2 KiB
Go

package bbs
import (
"fmt"
"strconv"
"strings"
"time"
)
// ChatHelp is what the chat commands are.
var ChatHelp = []string{
"Type to talk. Commands:",
" /who who is in this room /rooms the rooms in use",
" /join ROOM go to another room /me ACTION * you do something",
" /msg WHO TEXT to a user, kept if away /topic this room's topic",
" /history [WHO] your talks with a user /friends your friends list",
" /friend WHO put one on your list /unfriend WHO take one off it",
" /block WHO stop their messages /unblock WHO let them again",
" /msg NICK TEXT to someone on a linked IRC network",
" /quit leave the chat",
" /cs COMMAND ChanServ: register a room, its access list (/cs HELP)",
" /topic TEXT set the topic (a registered room's ops)",
" /kick WHO [WHY] put one out of the room (its ops)",
" /mode [+m-i...] a registered room's modes (its ops) /invite WHO ask one in",
" /join ROOM KEY a room with a key /knock ROOM [WHY] ask its ops in",
"Sysops: /pages callers paging /answer [NODE] answer one /busy pages on or off",
" /topic TEXT set a permanent room's topic",
}
// ChatCommand does a line typed in chat: talk, or a /command. It gives
// the lines to show (besides the room's events), and whether to leave.
func (n *Node) ChatCommand(line string) (out []string, leave bool, err error) {
line = strings.TrimSpace(line)
if line == "" {
return nil, false, nil
}
if !strings.HasPrefix(line, "/") {
return nil, false, n.Say(line, false)
}
cmd, arg, _ := strings.Cut(line[1:], " ")
arg = strings.TrimSpace(arg)
switch strings.ToLower(cmd) {
case "q", "quit", "leave", "exit", "x":
return nil, true, nil
case "?", "h", "help":
return ChatHelp, false, nil
case "me":
return nil, false, n.Say(arg, true)
case "who":
for _, r := range n.Rooms() {
if r.Name == n.Room() {
return []string{"In " + r.Name + ": " + strings.Join(r.Users, ", ")}, false, nil
}
}
return []string{"You are in no room."}, false, nil
case "rooms":
rs := n.Rooms()
if len(rs) == 0 {
return []string{"No one is chatting."}, false, nil
}
for _, r := range rs {
who := strings.Join(r.Users, ", ")
if r.Permanent {
if who == "" {
who = "(no one yet)"
}
if r.Topic != "" {
who += " - " + r.Topic
}
}
out = append(out, fmt.Sprintf("%-20s %s", r.Name, who))
}
return out, false, nil
case "topic":
room := n.Room()
if room == "" {
return nil, false, ErrNotInRoom
}
if arg == "" {
topic, _ := n.b.RoomTopic(room)
if topic == "" {
return []string{"No topic is set."}, false, nil
}
return []string{"Topic: " + topic}, false, nil
}
return nil, false, n.SetTopic(room, arg)
case "cs", "chanserv":
return n.ChanServ(arg), false, nil
case "mode":
room := n.Room()
if room == "" {
return nil, false, ErrNotInRoom
}
f := strings.Fields(arg)
if len(f) == 0 {
modes, args := n.b.RoomModes(room, true)
return []string{strings.TrimSpace("The modes of " + room + ": " + modes + " " + strings.Join(args, " "))}, false, nil
}
changes := ParseModes(f[0], f[1:])
if len(changes) == 0 {
// a list: /mode +b
for _, k := range f[0] {
if strings.ContainsRune(RoomListModes, k) {
out = append(out, fmt.Sprintf("The +%c list of %s:", k, room))
for _, e := range n.b.RoomList(room, k) {
out = append(out, fmt.Sprintf(" %-40s set by %s, %s", e.Mask, e.SetBy, e.SetAt.Format("Jan 2 2006")))
}
}
}
if out == nil {
return nil, false, fmt.Errorf("/mode +m, -m, +k KEY, +l N, +b MASK ...: see /cs HELP")
}
return out, false, nil
}
_, errs := n.SetModes(room, changes)
for _, err := range errs {
out = append(out, capital(err.Error())+".")
}
return out, false, nil
case "invite":
room := n.Room()
if room == "" {
return nil, false, ErrNotInRoom
}
t, err := n.Invite(room, strings.TrimSpace(arg))
if err != nil {
return nil, false, err
}
return []string{Nick(t.Name) + " is invited into " + room + "."}, false, nil
case "knock":
room, why, _ := strings.Cut(arg, " ")
if err := n.Knock(strings.ToLower(strings.TrimPrefix(room, "#")), why); err != nil {
return nil, false, err
}
return []string{"You knocked: its ops are told."}, false, nil
case "kick":
room := n.Room()
if room == "" {
return nil, false, ErrNotInRoom
}
who, reason, _ := strings.Cut(arg, " ")
if who == "" {
return nil, false, fmt.Errorf("/kick WHO [WHY]: a user's name (Carol_Ann for Carol Ann)")
}
if err := n.Kick(room, who, reason); err != nil {
return nil, false, err
}
return nil, false, nil
case "join", "j":
room, key, _ := strings.Cut(arg, " ")
hist, err := n.JoinRoomKey(room, strings.TrimSpace(key))
if err != nil {
return nil, false, err
}
for _, e := range hist {
out = append(out, e.String())
}
return append(out, "You are in "+n.Room()+"."), false, nil
case "msg", "m", "tell":
to, text, _ := strings.Cut(arg, " ")
if to == "" {
return nil, false, fmt.Errorf("/msg WHO TEXT: a user's name (or a node's number), then the message")
}
if num, err := strconv.Atoi(to); err == nil {
if err := n.Message(num, text); err != nil {
return nil, false, err
}
if o := n.b.node(num); o != nil {
n.Keep(o.User(), text, true)
}
return []string{fmt.Sprintf("Sent to node %d.", num)}, false, nil
}
u, err := n.b.Store.UserByName(to)
if err != nil {
// not one of ours: someone on a linked chat network?
if err := n.MessageRemote(to, text, false, false); err == nil {
return []string{"Sent to " + to + "."}, false, nil
} else if err != ErrNoSuchNick {
return nil, false, err
}
return nil, false, ErrNoUser
}
online, err := n.TellUser(u, text)
if err != nil {
return nil, false, err
}
if !online {
return []string{u.Name + " is away; they will have it when they next log in."}, false, nil
}
return []string{"Sent to " + u.Name + "."}, false, nil
case "history":
if arg == "" {
ps, err := n.Conversations()
if err != nil {
return nil, false, err
}
if len(ps) == 0 {
return []string{"You have no conversations yet (/msg WHO TEXT starts one)."}, false, nil
}
out = append(out, "Your conversations (/history WHO to read one):")
for _, p := range ps {
out = append(out, fmt.Sprintf(" %-20s %d lines, the last %s", p.Name, p.Lines, p.Last.Format("Jan 2 15:04")))
}
return out, false, nil
}
u, err := n.b.Store.UserByName(arg)
if err != nil {
return nil, false, ErrNoUser
}
cs, err := n.History(u, 50)
if err != nil {
return nil, false, err
}
if len(cs) == 0 {
return []string{"You and " + u.Name + " have not talked yet."}, false, nil
}
return HistoryLines(cs), false, nil
case "friends":
u := n.User()
if u == nil {
return nil, false, ErrNoUser
}
lines, err := n.b.FriendLines(u)
return lines, false, err
case "friend", "unfriend":
u := n.User()
if u == nil || arg == "" {
return nil, false, fmt.Errorf("/%s WHO: a user's name", strings.ToLower(cmd))
}
if strings.ToLower(cmd) == "friend" {
f, err := n.b.AddFriend(u, arg)
if err != nil {
return nil, false, err
}
return []string{f.Name + " is on your friends list."}, false, nil
}
f, err := n.b.RemoveFriend(u, arg)
if err != nil {
return nil, false, err
}
return []string{f.Name + " is off your friends list."}, false, nil
case "block", "unblock":
u := n.User()
if u == nil || arg == "" {
return nil, false, fmt.Errorf("/%s WHO: a user's name", strings.ToLower(cmd))
}
if strings.ToLower(cmd) == "block" {
f, err := n.b.Block(u, arg)
if err != nil {
return nil, false, err
}
return []string{f.Name + " is blocked: you will not get their messages."}, false, nil
}
f, err := n.b.Unblock(u, arg)
if err != nil {
return nil, false, err
}
return []string{f.Name + " is no longer blocked."}, false, nil
case "pages":
ps := n.b.Pages()
if len(ps) == 0 {
return []string{"No one is paging."}, false, nil
}
for _, p := range ps {
out = append(out, fmt.Sprintf("node %d %s %s ago: %s", p.Node, p.User,
Since(p.Since), p.Reason))
}
return out, false, nil
case "answer", "a":
num := 0
if arg != "" {
if num, err = strconv.Atoi(arg); err != nil {
return nil, false, fmt.Errorf("/answer NODE: a node's number")
}
}
hist, node, err := n.Answer(num)
if err != nil {
return nil, false, err
}
for _, e := range hist {
out = append(out, e.String())
}
return append(out, fmt.Sprintf("You are with the caller on node %d (room %s).", node, n.Room())), false, nil
case "busy":
if u := n.User(); u == nil || !u.Sysop {
return nil, false, fmt.Errorf("/busy is for sysops")
}
n.SetBusy(!n.Busy())
if n.Busy() {
return []string{"You will not be paged."}, false, nil
}
return []string{"You may be paged."}, false, nil
}
return nil, false, fmt.Errorf("no such command: /%s (/help)", cmd)
}
// Since is how long ago t was, roughly: 5s, 3m, 2h.
func Since(t time.Time) string {
d := int64(time.Since(t) / time.Second)
switch {
case d < 60:
return fmt.Sprintf("%ds", d)
case d < 3600:
return fmt.Sprintf("%dm", d/60)
}
return fmt.Sprintf("%dh", d/3600)
}