add helper function to remove the bot name from messages

This commit is contained in:
Aaron Bieber 2020-05-07 19:34:24 -06:00
parent 1c8f8fe2b0
commit 09ba1cade3
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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"`
}