diff --git a/plugins/plugins.go b/plugins/plugins.go index 05b8bb4..505f6b6 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -55,6 +55,12 @@ func ToMe(user, message string) bool { return strings.Contains(message, u) } +// RemoveName removes the friendly name from a given message +func RemoveName(user, message string) string { + n := NameRE.ReplaceAllString(user, "$1") + return strings.ReplaceAll(message, n + ": ", "") +} + // HTTPRequest has the bits for making http requests type HTTPRequest struct { Client http.Client diff --git a/plugins/plugins_test.go b/plugins/plugins_test.go index 46927ab..38cc6df 100644 --- a/plugins/plugins_test.go +++ b/plugins/plugins_test.go @@ -20,6 +20,14 @@ func TestPluginsNameRE(t *testing.T) { } } +func TestPluginsRemoveName(t *testing.T) { + expected := "this is for you" + n := RemoveName("mctest", fmt.Sprintf("mctest: %s", expected)) + if n != expected { + t.Errorf("Expected %q; got %q\n", expected, n) + } +} + type testResp struct { Name string `json:"test"` }