ScuttleBot

fix: auditbot JOIN/PART handlers — syntax errors, indentation, missing constants - Add EventUserJoin and EventUserPart constants - Fix missing closing brace in PART handler shouldAudit check - Replace undefined extractNick() with inline e.Source.Name - Use EventUserPart constant instead of hardcoded "user.part" - Fix tab indentation throughout (was spaces) - Fix write() error log indentation

lmata 2026-04-04 19:58 trunk
Commit e135cfef6c969f1724c7d8a1d443e730251a4ca7299c4be635d5281339268ccf
--- internal/bots/auditbot/auditbot.go
+++ internal/bots/auditbot/auditbot.go
@@ -34,10 +34,16 @@
3434
// KindIRC indicates the event was observed on the IRC message stream.
3535
KindIRC EventKind = "irc"
3636
// KindRegistry indicates the event was injected by the registry.
3737
KindRegistry EventKind = "registry"
3838
)
39
+
40
+// Event types for user presence changes.
41
+const (
42
+ EventUserJoin = "user.join"
43
+ EventUserPart = "user.part"
44
+)
3945
4046
// Entry is an immutable audit record.
4147
type Entry struct {
4248
At time.Time
4349
Kind EventKind
@@ -154,50 +160,49 @@
154160
Nick: nick,
155161
MessageType: env.Type,
156162
MessageID: env.ID,
157163
})
158164
})
159
- c.Handlers.AddBg(girc.JOIN, func(_ *girc.Client, e girc.Event) {
160
- if len(e.Params) == 0 {
161
- return
162
- }
163
-
164
-
165
- if !b.shouldAudit(EventUserJoin) {
166
- return
167
- }
168
-
169
- channel := e.Params[0]
170
- nick := extractNick(e)
171
-
172
- b.write(Entry{
173
- Kind: KindIRC,
174
- Channel: channel,
175
- Nick: nick,
176
- MessageType: EventUserJoin,
177
- })
178
-})
179
-
180
-c.Handlers.AddBg(girc.PART, func(_ *girc.Client, e girc.Event) {
181
- if len(e.Params) == 0 {
182
- return
183
- }
184
- if !b.shouldAudit(EventUserPart) {
185
- return
186
- channel := e.Params[0]
187
- nick := ""
188
- if e.Source != nil {
189
- nick = e.Source.Name
190
- }
191
-
192
- b.write(Entry{
193
- Kind: KindIRC,
194
- Channel: channel,
195
- Nick: nick,
196
- MessageType: "user.part",
197
- })
198
-})
165
+ c.Handlers.AddBg(girc.JOIN, func(_ *girc.Client, e girc.Event) {
166
+ if len(e.Params) == 0 {
167
+ return
168
+ }
169
+ if !b.shouldAudit(EventUserJoin) {
170
+ return
171
+ }
172
+ channel := e.Params[0]
173
+ nick := ""
174
+ if e.Source != nil {
175
+ nick = e.Source.Name
176
+ }
177
+ b.write(Entry{
178
+ Kind: KindIRC,
179
+ Channel: channel,
180
+ Nick: nick,
181
+ MessageType: EventUserJoin,
182
+ })
183
+ })
184
+
185
+ c.Handlers.AddBg(girc.PART, func(_ *girc.Client, e girc.Event) {
186
+ if len(e.Params) == 0 {
187
+ return
188
+ }
189
+ if !b.shouldAudit(EventUserPart) {
190
+ return
191
+ }
192
+ channel := e.Params[0]
193
+ nick := ""
194
+ if e.Source != nil {
195
+ nick = e.Source.Name
196
+ }
197
+ b.write(Entry{
198
+ Kind: KindIRC,
199
+ Channel: channel,
200
+ Nick: nick,
201
+ MessageType: EventUserPart,
202
+ })
203
+ })
199204
b.client = c
200205
201206
errCh := make(chan error, 1)
202207
go func() {
203208
if err := c.Connect(); err != nil && ctx.Err() == nil {
@@ -230,17 +235,17 @@
230235
}
231236
232237
func (b *Bot) write(e Entry) {
233238
e.At = time.Now()
234239
if err := b.store.Append(e); err != nil {
235
- b.log.Error("failed to write audit entry",
236
- "type", e.MessageType,
237
- "nick", e.Nick,
238
- "channel", e.Channel,
239
- "kind", e.Kind,
240
- "err", err,
241
-)
240
+ b.log.Error("auditbot: failed to write entry",
241
+ "type", e.MessageType,
242
+ "nick", e.Nick,
243
+ "channel", e.Channel,
244
+ "kind", e.Kind,
245
+ "err", err,
246
+ )
242247
}
243248
}
244249
245250
func (b *Bot) auditTypesList() []string {
246251
if len(b.auditTypes) == 0 {
247252
--- internal/bots/auditbot/auditbot.go
+++ internal/bots/auditbot/auditbot.go
@@ -34,10 +34,16 @@
34 // KindIRC indicates the event was observed on the IRC message stream.
35 KindIRC EventKind = "irc"
36 // KindRegistry indicates the event was injected by the registry.
37 KindRegistry EventKind = "registry"
38 )
 
 
 
 
 
 
39
40 // Entry is an immutable audit record.
41 type Entry struct {
42 At time.Time
43 Kind EventKind
@@ -154,50 +160,49 @@
154 Nick: nick,
155 MessageType: env.Type,
156 MessageID: env.ID,
157 })
158 })
159 c.Handlers.AddBg(girc.JOIN, func(_ *girc.Client, e girc.Event) {
160 if len(e.Params) == 0 {
161 return
162 }
163
164
165 if !b.shouldAudit(EventUserJoin) {
166 return
167 }
168
169 channel := e.Params[0]
170 nick := extractNick(e)
171
172 b.write(Entry{
173 Kind: KindIRC,
174 Channel: channel,
175 Nick: nick,
176 MessageType: EventUserJoin,
177 })
178 })
179
180 c.Handlers.AddBg(girc.PART, func(_ *girc.Client, e girc.Event) {
181 if len(e.Params) == 0 {
182 return
183 }
184 if !b.shouldAudit(EventUserPart) {
185 return
186 channel := e.Params[0]
187 nick := ""
188 if e.Source != nil {
189 nick = e.Source.Name
190 }
191
192 b.write(Entry{
193 Kind: KindIRC,
194 Channel: channel,
195 Nick: nick,
196 MessageType: "user.part",
197 })
198 })
199 b.client = c
200
201 errCh := make(chan error, 1)
202 go func() {
203 if err := c.Connect(); err != nil && ctx.Err() == nil {
@@ -230,17 +235,17 @@
230 }
231
232 func (b *Bot) write(e Entry) {
233 e.At = time.Now()
234 if err := b.store.Append(e); err != nil {
235 b.log.Error("failed to write audit entry",
236 "type", e.MessageType,
237 "nick", e.Nick,
238 "channel", e.Channel,
239 "kind", e.Kind,
240 "err", err,
241 )
242 }
243 }
244
245 func (b *Bot) auditTypesList() []string {
246 if len(b.auditTypes) == 0 {
247
--- internal/bots/auditbot/auditbot.go
+++ internal/bots/auditbot/auditbot.go
@@ -34,10 +34,16 @@
34 // KindIRC indicates the event was observed on the IRC message stream.
35 KindIRC EventKind = "irc"
36 // KindRegistry indicates the event was injected by the registry.
37 KindRegistry EventKind = "registry"
38 )
39
40 // Event types for user presence changes.
41 const (
42 EventUserJoin = "user.join"
43 EventUserPart = "user.part"
44 )
45
46 // Entry is an immutable audit record.
47 type Entry struct {
48 At time.Time
49 Kind EventKind
@@ -154,50 +160,49 @@
160 Nick: nick,
161 MessageType: env.Type,
162 MessageID: env.ID,
163 })
164 })
165 c.Handlers.AddBg(girc.JOIN, func(_ *girc.Client, e girc.Event) {
166 if len(e.Params) == 0 {
167 return
168 }
169 if !b.shouldAudit(EventUserJoin) {
170 return
171 }
172 channel := e.Params[0]
173 nick := ""
174 if e.Source != nil {
175 nick = e.Source.Name
176 }
177 b.write(Entry{
178 Kind: KindIRC,
179 Channel: channel,
180 Nick: nick,
181 MessageType: EventUserJoin,
182 })
183 })
184
185 c.Handlers.AddBg(girc.PART, func(_ *girc.Client, e girc.Event) {
186 if len(e.Params) == 0 {
187 return
188 }
189 if !b.shouldAudit(EventUserPart) {
190 return
191 }
192 channel := e.Params[0]
193 nick := ""
194 if e.Source != nil {
195 nick = e.Source.Name
196 }
197 b.write(Entry{
198 Kind: KindIRC,
199 Channel: channel,
200 Nick: nick,
201 MessageType: EventUserPart,
202 })
203 })
 
204 b.client = c
205
206 errCh := make(chan error, 1)
207 go func() {
208 if err := c.Connect(); err != nil && ctx.Err() == nil {
@@ -230,17 +235,17 @@
235 }
236
237 func (b *Bot) write(e Entry) {
238 e.At = time.Now()
239 if err := b.store.Append(e); err != nil {
240 b.log.Error("auditbot: failed to write entry",
241 "type", e.MessageType,
242 "nick", e.Nick,
243 "channel", e.Channel,
244 "kind", e.Kind,
245 "err", err,
246 )
247 }
248 }
249
250 func (b *Bot) auditTypesList() []string {
251 if len(b.auditTypes) == 0 {
252

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button