ScuttleBot

Merge pull request #98 from ayushpoojari3699/patch-2 add audit support for user join and part events

noreply 2026-04-04 19:58 trunk merge
Commit 9460ec23895407342458cc5491f92d09d4f67aacad23dcbfb158c5d6bfc9257b
--- 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,11 +160,49 @@
154160
Nick: nick,
155161
MessageType: env.Type,
156162
MessageID: env.ID,
157163
})
158164
})
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
+ })
159184
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
+ })
160204
b.client = c
161205
162206
errCh := make(chan error, 1)
163207
go func() {
164208
if err := c.Connect(); err != nil && ctx.Err() == nil {
@@ -191,11 +235,17 @@
191235
}
192236
193237
func (b *Bot) write(e Entry) {
194238
e.At = time.Now()
195239
if err := b.store.Append(e); err != nil {
196
- b.log.Error("auditbot: failed to write entry", "type", e.MessageType, "err", err)
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
+ )
197247
}
198248
}
199249
200250
func (b *Bot) auditTypesList() []string {
201251
if len(b.auditTypes) == 0 {
202252
--- 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,11 +160,49 @@
154 Nick: nick,
155 MessageType: env.Type,
156 MessageID: env.ID,
157 })
158 })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160 b.client = c
161
162 errCh := make(chan error, 1)
163 go func() {
164 if err := c.Connect(); err != nil && ctx.Err() == nil {
@@ -191,11 +235,17 @@
191 }
192
193 func (b *Bot) write(e Entry) {
194 e.At = time.Now()
195 if err := b.store.Append(e); err != nil {
196 b.log.Error("auditbot: failed to write entry", "type", e.MessageType, "err", err)
 
 
 
 
 
 
197 }
198 }
199
200 func (b *Bot) auditTypesList() []string {
201 if len(b.auditTypes) == 0 {
202
--- 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,11 +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 {
@@ -191,11 +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