2021-09-02 21:26:39 +00:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2024-04-03 19:00:28 +00:00
|
|
|
"github.com/Luzifer/go_helpers/v2/fieldcollection"
|
2023-09-11 17:51:38 +00:00
|
|
|
"gopkg.in/irc.v4"
|
2021-09-02 21:26:39 +00:00
|
|
|
)
|
|
|
|
|
2024-01-01 16:52:18 +00:00
|
|
|
// DeriveChannel takes an irc.Message and a FieldCollection and tries
|
|
|
|
// to extract from them the channel the event / message has taken place
|
2024-04-03 19:00:28 +00:00
|
|
|
func DeriveChannel(m *irc.Message, evtData *fieldcollection.FieldCollection) string {
|
2021-09-02 21:26:39 +00:00
|
|
|
if m != nil && len(m.Params) > 0 && strings.HasPrefix(m.Params[0], "#") {
|
|
|
|
return m.Params[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
if s, err := evtData.String("channel"); err == nil {
|
|
|
|
return fmt.Sprintf("#%s", strings.TrimLeft(s, "#"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2024-01-01 16:52:18 +00:00
|
|
|
// DeriveUser takes an irc.Message and a FieldCollection and tries
|
|
|
|
// to extract from them the user causing the event / message
|
2024-04-03 19:00:28 +00:00
|
|
|
func DeriveUser(m *irc.Message, evtData *fieldcollection.FieldCollection) string {
|
2021-09-02 21:26:39 +00:00
|
|
|
if m != nil && m.User != "" {
|
|
|
|
return m.User
|
|
|
|
}
|
|
|
|
|
|
|
|
if s, err := evtData.String("user"); err == nil {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2021-10-16 12:44:11 +00:00
|
|
|
if s, err := evtData.String("username"); err == nil {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2021-09-02 21:26:39 +00:00
|
|
|
return ""
|
|
|
|
}
|