Skip to content

Commit 3041b38

Browse files
committed
channel: set send reply via builder
1 parent 6657668 commit 3041b38

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func (robo *Robot) SetTwitchChannels(ctx context.Context, global Global, channel
332332
Effects: effects,
333333
}
334334
v.Message = func(ctx context.Context, reply, text string) {
335-
msg := message.Format(reply, v.Name, "%s", text)
335+
msg := message.Format(v.Name, "%s", text).AsReply(reply)
336336
robo.sendTMI(ctx, robo.tmi.send, msg)
337337
}
338338
robo.channels.Store(p, v)

message/message.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ type Sent struct {
4848
Text string
4949
}
5050

51+
func (m Sent) AsReply(reply string) Sent {
52+
m.Reply = reply
53+
return m
54+
}
55+
5156
// formatString is a type to prevent misuse of format strings passed to [Format].
5257
type formatString string
5358

5459
// Format constructs a message to send from a format string literal and
5560
// formatting arguments.
56-
func Format(reply, to string, f formatString, args ...any) Sent {
61+
func Format(to string, f formatString, args ...any) Sent {
5762
return Sent{
58-
Reply: reply,
59-
To: to,
60-
Text: strings.TrimSpace(fmt.Sprintf(string(f), args...)),
63+
To: to,
64+
Text: strings.TrimSpace(fmt.Sprintf(string(f), args...)),
6165
}
6266
}

privmsg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (robo *Robot) tmiMessage(ctx context.Context, send chan<- *tmi.Message, msg
8585
slog.String("text", s),
8686
slog.String("effect", f),
8787
)
88-
msg := message.Format("", ch.Name, "%s", s)
88+
msg := message.Format(ch.Name, "%s", s)
8989
robo.sendTMI(ctx, send, msg)
9090
return
9191
default:
@@ -136,7 +136,7 @@ func (robo *Robot) tmiMessage(ctx context.Context, send chan<- *tmi.Message, msg
136136
r.CancelAt(t)
137137
return
138138
}
139-
out := message.Format("", ch.Name, "%s", sef)
139+
out := message.Format(ch.Name, "%s", sef)
140140
robo.sendTMI(ctx, send, out)
141141
}
142142

0 commit comments

Comments
 (0)