From a91410d1ce2664ed78a8db7225d5f2294d5b2cf1 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 16 Oct 2021 14:44:11 +0200 Subject: [PATCH] [core] Add username fields to events Signed-off-by: Knut Ahlers --- irc.go | 17 +++++++++++------ plugins/helpers.go | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/irc.go b/irc.go index 186b13d..23ff58a 100644 --- a/irc.go +++ b/irc.go @@ -205,7 +205,7 @@ func (i ircHandler) handlePermit(m *irc.Message) { log.WithField("user", username).Debug("Added permit") timerStore.AddPermit(m.Params[0], username) - go handleMessage(i.c, m, eventTypePermit, nil) + go handleMessage(i.c, m, eventTypePermit, plugins.FieldCollection{"username": username}) } func (i ircHandler) handleTwitchNotice(m *irc.Message) { @@ -268,8 +268,9 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) { case "raid": evtData := plugins.FieldCollection{ - "channel": i.getChannel(m), + "channel": i.getChannel(m), // Compatibility to plugins.DeriveChannel "from": m.Tags["login"], + "user": m.Tags["login"], // Compatibility to plugins.DeriveUser "viewercount": m.Tags["msg-param-viewerCount"], } log.WithFields(log.Fields(evtData)).Info("Incoming raid") @@ -278,10 +279,11 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) { case "resub": evtData := plugins.FieldCollection{ - "channel": i.getChannel(m), + "channel": i.getChannel(m), // Compatibility to plugins.DeriveChannel "from": m.Tags["login"], "subscribed_months": m.Tags["msg-param-cumulative-months"], "plan": m.Tags["msg-param-sub-plan"], + "user": m.Tags["login"], // Compatibility to plugins.DeriveUser } log.WithFields(log.Fields(evtData)).Info("User re-subscribed") @@ -289,9 +291,10 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) { case "sub": evtData := plugins.FieldCollection{ - "channel": i.getChannel(m), + "channel": i.getChannel(m), // Compatibility to plugins.DeriveChannel "from": m.Tags["login"], "plan": m.Tags["msg-param-sub-plan"], + "user": m.Tags["login"], // Compatibility to plugins.DeriveUser } log.WithFields(log.Fields(evtData)).Info("User subscribed") @@ -299,11 +302,12 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) { case "subgift", "anonsubgift": evtData := plugins.FieldCollection{ - "channel": i.getChannel(m), + "channel": i.getChannel(m), // Compatibility to plugins.DeriveChannel "from": m.Tags["login"], "gifted_months": m.Tags["msg-param-gift-months"], "plan": m.Tags["msg-param-sub-plan"], "to": m.Tags["msg-param-recipient-user-name"], + "user": m.Tags["login"], // Compatibility to plugins.DeriveUser } log.WithFields(log.Fields(evtData)).Info("User gifted a sub") @@ -311,10 +315,11 @@ func (i ircHandler) handleTwitchUsernotice(m *irc.Message) { case "submysterygift": evtData := plugins.FieldCollection{ - "channel": i.getChannel(m), + "channel": i.getChannel(m), // Compatibility to plugins.DeriveChannel "from": m.Tags["login"], "number": m.Tags["msg-param-mass-gift-count"], "plan": m.Tags["msg-param-sub-plan"], + "user": m.Tags["login"], // Compatibility to plugins.DeriveUser } log.WithFields(log.Fields(evtData)).Info("User gifted subs to the community") diff --git a/plugins/helpers.go b/plugins/helpers.go index 75a7e8d..b6552b4 100644 --- a/plugins/helpers.go +++ b/plugins/helpers.go @@ -28,5 +28,9 @@ func DeriveUser(m *irc.Message, evtData FieldCollection) string { return s } + if s, err := evtData.String("username"); err == nil { + return s + } + return "" }