Skip to content

Commit bb36057

Browse files
committed
robot: don't receive commands from shared chat
For #97.
1 parent e784f76 commit bb36057

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

privmsg.go

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ func (robo *Robot) tmiMessage(ctx context.Context, send chan<- *tmi.Message, msg
2929
// channel that isn't configured. Ignore it.
3030
return
3131
}
32+
room, _ := msg.Tag("room-id")
33+
source, ok := msg.Tag("source-room-id")
34+
// TODO(zeph): This prevents commands from any shared chat, even if the bot
35+
// isn't in the source room. We should still allow commands from shared
36+
// chats that we aren't in.
37+
shared := ok && room != source
3238
m := message.FromTMI(msg)
3339
log := slog.With(slog.String("trace", m.ID), slog.String("in", ch.Name))
3440
log.InfoContext(ctx, "privmsg", slog.Duration("bias", time.Since(m.Time())))
@@ -42,6 +48,10 @@ func (robo *Robot) tmiMessage(ctx context.Context, send chan<- *tmi.Message, msg
4248
return
4349
}
4450
if cmd, ok := parseCommand(robo.tmi.name, m.Text); ok {
51+
if shared {
52+
log.InfoContext(ctx, "ignore shared chat command")
53+
return
54+
}
4555
robo.command(ctx, log, ch, m, cmd)
4656
return
4757
}
@@ -100,6 +110,11 @@ func (robo *Robot) tmiMessage(ctx context.Context, send chan<- *tmi.Message, msg
100110
log.ErrorContext(ctx, "failed copypasta check", slog.Any("err", err))
101111
// Continue on.
102112
}
113+
// If this is a shared chat, we don't want to respond unprompted, so that
114+
// we don't get double probability if we're in multiple shared chats.
115+
if shared {
116+
return
117+
}
103118
if rand.Float64() > ch.Responses {
104119
return
105120
}

0 commit comments

Comments
 (0)